Code

bbb417f7925bf49c38c36aab4d55e78a743dbe47
[gosa.git] / gosa-core / include / class_gosaSupportDaemon.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class gosaSupportDaemon
24 {
25   private $s_host       = "";
26   private $i_port       = 0;
27   private $s_encryption_key = "";
29   private $o_sock       = NULL;
30   private $f_timeout    = 2;
31   private $s_error      = "";
32   private $b_error      = FALSE;
34   private $is_connected     = FALSE;
37   /*! \brief  Creates a new gosaSupportDaemon object.
38     @param string   Host    The Host where the daemon is running on.  
39     @param integer  Port    The port which the daemon use.
40     @param string   Key     The encryption string.
41     @param boolean  Connect Directly connect to daemon socket.
42     @param float    Timeout The timelimit for all socket actions.
43    */
44   public function __construct($connect=TRUE,$timeout=2)
45   {
46     #FIXME: bad idea about referencing global variables from within classes
47     global $config;
49     # load from config, store statically
50     if (isset($config->current['GOSA_SI'])){
52       if ($this->s_host == ""){
53         $this->s_host= preg_replace("/^.*@([^:]+):.*$/", "$1", $config->current['GOSA_SI']);
54         $this->i_port= preg_replace("/^.*@[^:]+:(.*)$/", "$1", $config->current['GOSA_SI']);
55         $this->s_encryption_key = preg_replace("/^(.*)@[^:]+:.*$/", "$1", $config->current['GOSA_SI']);
56       }
58       $this->f_timeout = $timeout;
59       if($connect){
60         $this->connect();
61       }
62     }
63   }
66   /*! \brief  Establish daemon connection. 
67     @return boolean Returns true if the connection was succesfully established. 
68    */
69   public function connect()
70   {
71     $this->o_sock = new Socket_Client($this->s_host,$this->i_port,TRUE,$this->f_timeout);
72     if($this->o_sock->connected()){ 
73       $this->o_sock->setEncryptionKey($this->s_encryption_key); 
74       $this->is_connected = TRUE;
75     }else{
76       $this->set_error($this->o_sock->get_error());
77       $this->disconnect();
78       new log("debug","gosaSupportDaemon::connect()", "Could not connect to server.", array(),$this->get_error());
79     }
80     return($this->is_connected);
81   }
84   /*! \brief  Disconnect from gosa daemon.
85    */
86   public function disconnect()
87   {
88     $this->o_sock->close();
89     $this->is_connected = FALSE;
90   }
93   /*! \brief  Sets an error message, which can be returned with get_error().
94     @param  string  The Error message,
95    */
96   private function set_error($str)
97   {
98     $this->b_error = TRUE;
99     $this->s_error = $str;
100   }
103   /*! \brief  Sets an error message, which can be returned with get_error().
104     @param  string  The Error message,
105    */
106   private function reset_error()
107   {
108     $this->b_error = FALSE;
109     $this->s_error = "";
110   }
113   /*! \brief  Checks if an error occured.
114     @return boolean returns TRUE or FALSE, whether there is an error or not.
115    */
116   public function is_error()
117   {
118     return($this->b_error);
119   }
122   /*! \brief  Returns the last error. 
123     @return Returns the last error.
124    */
125   public function get_error()
126   {
127     $str = $this->s_error;
128     $str = preg_replace("/ /","&nbsp;",$str);
129     return($str);
130   }
133   public function FAI_get_server($name = "")
134   {
135     $this->reset_error();
137     $xml_msg = "<xml><header>gosa_query_fai_server</header><target>GOSA</target><source>GOSA</source></xml>";
138     $ret = array();
139     if($this->connect()){
140       $this->o_sock->write($xml_msg);
141       $str = trim($this->o_sock->read());
142       $entries = $this->xml_to_array($str);
143       if(isset($entries['XML']) && is_array($entries['XML'])){
145         /* Check if returned values represent a valid answer */
146         if(isset($entries['XML'])){
147           if(isset($entries['XML']['ERROR_STRING'])) {
148             $this->set_error($entries['XML']['ERROR_STRING']);
149             new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::update_entries()", $ids,"FAILED setting (".$attr.") error was ".$this->get_error());
150             return($ret);
151           }
153           /* Unset header tags */
154           foreach(array("HEADER","SOURCE","TARGET") as $type){
155             unset($entries['XML'][$type]);
156           }
157           $ret = $entries['XML']; 
158         }
159       }
160     }
161     return($ret);
162   }
165   public function FAI_get_classes($name = "")
166   {
167     $this->reset_error();
169     $xml_msg = "<xml><header>gosa_query_fai_release</header><target>GOSA</target><where><clause><RELEASE>siga</RELEASE></clause></where><source>GOSA</source></xml>";
170     $xml_msg = "<xml><header>gosa_query_fai_release</header><target>GOSA</target><source>GOSA</source><where><clause><RELEASE>siga</RELEASE></clause></where></xml>";
171     $xml_msg = "<xml><header>gosa_query_fai_release</header><target>GOSA</target><source>GOSA</source></xml>";
172     $ret = array();
173     if($this->connect()){
174       $this->o_sock->write($xml_msg);
175       $str = trim($this->o_sock->read());
176       $entries = $this->xml_to_array($str);
177   print_a($entries);
178       if(isset($entries['XML']) && is_array($entries['XML'])){
180         /* Check if returned values represent a valid answer */
181         if(isset($entries['XML'])){
182           if(isset($entries['XML']['ERROR_STRING'])) {
183             $this->set_error($entries['XML']['ERROR_STRING']);
184             new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::update_entries()", $ids,"FAILED setting (".$attr.") error was ".$this->get_error());
185             return($ret);
186           }
188           /* Unset header tags */
189           foreach(array("HEADER","SOURCE","TARGET") as $type){
190             unset($entries['XML'][$type]);
191           }
192           $ret = $entries['XML']; 
193         }
194       }
195     }
196     return($ret);
197   }
200   /*! \brief  Returns an array containing all queued entries.
201     @return Array All queued entries as an array.
202    */
203   public function get_queued_entries($event_types = array("*"),$from=-1,$to=-1,$sort="timestamp DESC")
204   {
205     $this->reset_error();
206     $ret = array();
208     $tags = "";
209     foreach($event_types as $type){
210       $tags .= "<phrase><headertag>".$type."</headertag></phrase>";
211     }
212     if(count($event_types) > 1){
213       $tags = "<connector>or</connector>".$tags;
214     }
215     if(count($event_types)){
216       $tags = "<where><clause>".$tags."</clause></where>";
217     }
219     $xml_msg = 
220 "<xml>
221       <header>gosa_query_jobdb</header>
222       <target>GOSA</target>
223       <source>GOSA</source>
224       ".$tags."
226       <orderby>".$sort."</orderby>";
227 if($from != -1 && $to != -1){
228 $xml_msg.= "
229       <limit>
230        <from>".$from."</from>
231        <to>".$to."</to>
232       </limit>";
234 $xml_msg.= "
235       </xml>";
237     if($this->connect()){
238       $this->o_sock->write($xml_msg);
239       $str = trim($this->o_sock->read());
240       $entries = $this->xml_to_array($str);
241       if(isset($entries['XML']) && is_array($entries['XML'])){
243         /* Check if returned values represent a valid answer */
244         if(isset($entries['XML'])){
245           
246           /* Unset header tags */
247           foreach(array("HEADER","SOURCE","TARGET") as $type){
248             unset($entries['XML'][$type]);
249           }
250           $ret = $entries['XML']; 
251         }
252       }
253     }
254     
255     /* Remove session ID. No one is interested in this... */
256     unset($ret['SESSION_ID']);
258     return($ret);
259   }
262   /*! \brief  Checks if the given ids are used queue ids.
263     @param  Array   The ids we want to check..
264     @return Array   An array containing all ids as index and TRUE/FALSE as value. 
265    */
266   public function ids_exist($ids)
267   {
268     if(!is_array($ids)){
269       trigger_error("Requires an array as parameter.");
270       return;
271     }
272     $this->reset_error();
274     $ret = array();
276     $xml_msg = "<xml>
277       <header>gosa_query_jobdb</header>
278       <target>GOSA</target>
279       <source>GOSA</source>
280       <where>
281       <clause>
282       <connector>or</connector>";
283     foreach($ids as $id){
284       $xml_msg .= "<phrase>
285         <operator>eq</operator>
286         <id>".$id."</id>
287         </phrase>";
288     }
289     $xml_msg .= "</clause>
290       </where>
291       </xml>";
293     if($this->connect()){
294       $this->o_sock->write($xml_msg);
295       $str = trim($this->o_sock->read());
296       $entries = $this->xml_to_array($str);
297       if(isset($entries['XML']) && is_array($entries['XML'])){
298         foreach($entries['XML'] as $entry){
299           if(isset($entry['ID'])){
300             $ret[] = $entry['ID'];
301           }
302         }
303       }
304     }
305     return($ret);
306   }
309   /*! \brief  Returns an entry containing all requested ids.
310     @param  Array   The IDs of the entries we want to return.
311     @return Array   Of the requested entries. 
312    */
313   public function get_entries_by_mac($macs)
314   {
315     if(!is_array($macs)){
316       trigger_error("Requires an array as parameter.");
317       return;
318     }
319     $this->reset_error();
321     $ret = array();
323     $xml_msg = "<xml>
324       <header>gosa_query_jobdb</header>
325       <target>GOSA</target>
326       <source>GOSA</source>
327       <where>
328       <clause>
329       <connector>or</connector>";
330     foreach($macs as $mac){
331       $xml_msg .= "<phrase>
332         <operator>eq</operator>
333         <macaddress>".$mac."</macaddress>
334         </phrase>";
335     }
336     $xml_msg .= "</clause>
337       </where>
338       </xml>";
340     if($this->connect()){
341       $this->o_sock->write($xml_msg);
342       $str = trim($this->o_sock->read());
343       $entries = $this->xml_to_array($str); 
344       if(isset($entries['XML'])){
345         foreach($entries['XML'] as $name => $entry){
346           if(preg_match("/^ANSWER[0-9]*$/",$name)){
347             $ret[$name] = $entry;
348           }
349         }
350       }
351     }
352     return($ret);
353   }
356   /*! \brief  Returns an entry containing all requested ids.
357     @param  Array   The IDs of the entries we want to return.
358     @return Array   Of the requested entries. 
359    */
360   public function get_entries_by_id($ids)
361   {
362     if(!is_array($ids)){
363       trigger_error("Requires an array as parameter.");
364       return;
365     }
366     $this->reset_error();
368     $ret = array();
370     $xml_msg = "<xml>
371       <header>gosa_query_jobdb</header>
372       <target>GOSA</target>
373       <source>GOSA</source>
374       <where>
375       <clause>
376       <connector>or</connector>";
377     foreach($ids as $id){
378       $xml_msg .= "<phrase>
379         <operator>eq</operator>
380         <id>".$id."</id>
381         </phrase>";
382     }
383     $xml_msg .= "</clause>
384       </where>
385       </xml>";
387     if($this->connect()){
388       $this->o_sock->write($xml_msg);
389       $str = trim($this->o_sock->read());
390       $entries = $this->xml_to_array($str); 
391       if(isset($entries['XML'])){
392         foreach($entries['XML'] as $name => $entry){
393           if(preg_match("/^ANSWER[0-9]*$/",$name)){
394             $ret[$name] = $entry;
395           }
396         }
397       }
398     }
399     return($ret);
400   }
403   /*! \brief  Checks if the given id is in use.
404     @param  Integer The ID of the entry.
405     @return Boolean TRUE if entry exists. 
406    */
407   public function id_exists($id)
408   {
409     if(!is_numeric($id)){
410       trigger_error("Requires an integer as parameter.");
411       return;
412     }
414     $this->reset_error();
416     $xml_msg = "<xml>
417       <header>gosa_query_jobdb</header>
418       <target>GOSA</target>
419       <source>GOSA</source>
420       <where>
421       <clause>
422       <phrase>
423       <operator>eq</operator>
424       <id>".$id."</id>
425       </phrase>
426       </clause>
427       </where>
428       </xml>";
430     if($this->connect()){
431       $this->o_sock->write($xml_msg);
432       $str = trim($this->o_sock->read());
433       $entries = $this->xml_to_array($str); 
434       if( isset($entries['XML']['HEADER']) && 
435           $entries['XML']['HEADER']=="answer" && 
436           isset($entries['XML']['ANSWER1'])){
437         return(TRUE);
438       }
439     }
440     return(FALSE);
441   }
444   /*! \brief  Returns an entry from the gosaSupportQueue
445     @param  Integer The ID of the entry we want to return.
446     @return Array   Of the requested entry. 
447    */
448   public function get_entry_by_id($id)
449   {
450     if(!is_numeric($id)){
451       trigger_error("Requires an integer as parameter.");
452       return;
453     }
454     $this->reset_error();
455   
456     $ret = array();
457     $xml_msg = "<xml>
458       <header>gosa_query_jobdb</header>
459       <target>GOSA</target>
460       <source>GOSA</source>
461       <where>
462       <clause>
463       <phrase>
464       <operator>eq</operator>
465       <id>".$id."</id>
466       </phrase>
467       </clause>
468       </where>
469       </xml>";
470     if($this->connect()){
471       $this->o_sock->write($xml_msg);
472       $str = trim($this->o_sock->read());
473       $entries = $this->xml_to_array($str); 
474       if( isset($entries['XML']['HEADER']) &&
475           $entries['XML']['HEADER']=="answer" &&
476           isset($entries['XML']['ANSWER1'])){
477         $ret = $entries['XML']['ANSWER1'];
478       }
479     }
480     return($ret);
481   }
484   /*! \brief  Removes a set of entries from the GOsa support queue. 
485     @param  Array The IDs to remove.
486     @return Boolean True on success.
487    */
488   public function remove_entries($ids)
489   {
490     if(!is_array($ids)){
491       trigger_error("Requires an array as parameter.");
492       return;
493     }
495     $this->reset_error();
497     $ret = array();
499     $xml_msg = "<xml>
500       <header>gosa_delete_jobdb_entry</header>
501       <target>GOSA</target>
502       <source>GOSA</source>
503       <where>
504       <clause>
505       <connector>or</connector>";
506     foreach($ids as $id){
507       $xml_msg .= "<phrase>
508         <operator>eq</operator>
509         <id>".$id."</id>
510         </phrase>";
511     }
512     $xml_msg .= "</clause>
513       </where>
514       </xml>";
516     if($this->connect()){
517       $this->o_sock->write($xml_msg);
518       $str = $this->o_sock->read();
519       $entries = $this->xml_to_array($str);
520       if(isset($entries['XML']) || isset($entries['COUNT'])){
521         new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::remove_entries()", $ids,"SUCCESS");
522         return(TRUE);
523       }else{
524         new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::remove_entries()", $ids,"FAILED ".$this->get_error());
525       }
526     }
527     return(FALSE);
528   }
532   /*! \brief  Removes an entry from the GOsa support queue. 
533     @param  Integer The ID of the entry we want to remove.
534     @return Boolean True on success.
535    */
536   public function remove_entry($id)
537   {
538     return($this->remove_entries(array($id)));
539   }
542   /*! \brief  Parses the given xml string into an array 
543     @param  String XML string  
544     @return Array Returns an array containing the xml structure. 
545    */
546   private function xml_to_array($xml)
547   {
548     $params = array();
549     $level = array();
550     $parser  = xml_parser_create_ns();
551     xml_parse_into_struct($parser, $xml, $vals, $index);
553     $err_id = xml_get_error_code($parser);
554     if($err_id){
555       xml_parser_free($parser);
556     }else{
557       xml_parser_free($parser);
559       foreach ($vals as $xml_elem) {
560         if ($xml_elem['type'] == 'open') {
561           if (array_key_exists('attributes',$xml_elem)) {
562             list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
563           } else {
564             $level[$xml_elem['level']] = $xml_elem['tag'];
565           }
566         }
567         if ($xml_elem['type'] == 'complete') {
568           $start_level = 1;
569           $php_stmt = '$params';
570           while($start_level < $xml_elem['level']) {
571             $php_stmt .= '[$level['.$start_level.']]';
572             $start_level++;
573           }
574           $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
575           @eval($php_stmt);
576         }
577       }
578     }
580     if(!isset($params['XML'])){
581       if (!array_key_exists('XML', $params)){
582         $this->set_error(_("Cannot not parse XML!"));
583       }
584       $params = array("COUNT" => 0);
585     }
587     return($params); 
588   }
591   /*! \brief  Updates an entry with a set of new values, 
592     @param  Integer The ID of the entry, we want to update.
593     @param  Array   The variables to update.   
594     @return Boolean Returns TRUE on success. 
595    */
596   public function update_entries($ids,$data)
597   {
598     $this->reset_error();
599     if(!is_array($ids)){
600       trigger_error("Requires an array as first parameter.");
601       return;
602     }
604     if(!is_array($data)){
605       trigger_error("Requires an array as second parameter.");
606       return;
607     }
609     $attr = "";
610     foreach($data as $key => $value){
611       if(is_array($value)){
612         foreach($value as $sub_value){
613           $attr.= "<$key>".strtolower($sub_value)."</$key>\n";
614         }
615       }else{
616         $attr.= "<$key>".strtolower($value)."</$key>\n";
617       }
618     }
620     $xml_msg = "<xml>
621       <header>gosa_update_status_jobdb_entry</header>
622       <target>GOSA</target>
623       <source>GOSA</source>
624       <where>
625       <clause>
626       <connector>or</connector>";
627     foreach($ids as $id){
628       $xml_msg .= "<phrase>
629         <operator>eq</operator>
630         <id>".$id."</id>
631         </phrase>";
632     }
633     $xml_msg .= "</clause>
634       </where>
635       <update>
636       ".$attr." 
637       </update>
638       </xml>";
640     if($this->connect()){
642       $this->o_sock->write($xml_msg);
643       $str      = trim($this->o_sock->read());
644       $entries = $this->xml_to_array($str);
645       if(isset($entries['XML'])){
646         if(isset($entries['XML']['ERROR_STRING'])) {
647           $this->set_error($entries['XML']['ERROR_STRING']);
648           new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::update_entries()", $ids,"FAILED setting (".$attr.") error was ".$this->get_error());
649           return(FALSE);
650         }
651         new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::update_entries()", $ids,"SUCCESS");
652         return(TRUE);
653       }
654     }
655     return(FALSE);
656   }
659   /*! \brief  Returns the number of currently queued objects.
660       @return Integer  
661    */
662   public function number_of_queued_entries()
663   {
664     $xml_msg ="<xml><header>gosa_count_jobdb</header><target>GOSA</target><source>GOSA</source></xml>";
665     $this->connect();
666     if($this->connect()){
667       $this->o_sock->write($xml_msg);
668       $str     = trim($this->o_sock->read());
669       $entries = $this->xml_to_array($str);
670       if(isset($entries['XML'])){
671         return($entries['XML']['COUNT']);
672       }
673     }
674     return(-1);
675   } 
678   public function send_data($header, $to, $data= array(), $answer_expected = FALSE)
679   {
680     $xml_message= "";
682     /* Prepare data */
683     foreach ($data as $key => $value){
684       if(is_array($value)){
685         foreach($value as $sub_value){
686           $xml_message.= "<$key>$sub_value</$key>";
687         }
688       }else{
689         $xml_message.= "<$key>$value</$key>";
690       }
691     }
693     /* Multiple targets? */
694     if (!is_array($to)){
695       $to_targets= array($to);
696     } else {
697       $to_targets= $to;
698     }
700     /* Build target strings */
701     $target ="";
702     foreach($to_targets as $to){
703       $target.= "<target>$to</target>";
704     }
706     return $this->_send("<xml><header>$header</header><source>GOSA</source>$target".$xml_message."</xml>",$answer_expected);
707   }
710   /* Allows simply appending a new DaemonEvent 
711    */
712   public function append($event)
713   {
714     if(!($event instanceof DaemonEvent)){
715       return(FALSE);
716     }
717   
718     $this->reset_error();
720     /* Add to queue if new 
721      */
722     if($event->is_new()){
724       $request_answer = FALSE;
725       if($event->get_type() == SCHEDULED_EVENT){
726         $action = $event->get_schedule_action();
727       }elseif($event->get_type() == TRIGGERED_EVENT){
728         $action = $event->get_trigger_action();
729       }else{
730         trigger_error("Unknown type of queue event given.");
731         return(FALSE);
732       }
734       /* Get event informations, like targets..
735        */
736       $targets    = $event->get_targets();
737       $data       = $event->save();
739       /* Append an entry for each target 
740        */
741       foreach($targets as $target){
742         $data['macaddress'] = $target;
743         $this->send_data($action,$target,$data,$request_answer);
745         if($this->is_error()){
746           return(FALSE);
747         }
748       }
749       return(TRUE);
750     }else{
752       /* Updated edited entry.
753        */
754       $id                 = $event->get_id();
755       $data               = $event->save();
756       return($this->update_entries(array($id),$data));
757     }
759     return(FALSE);
760   }
763 /*! \brief  Returns an array containing all queued entries.
764     @return Array All queued entries as an array.
765    */
766   public function _send($data, $answer_expected= FALSE)
767   {
768     $this->reset_error();
769     $ret = array();
771     if($this->connect()){
772       $this->o_sock->write($data);
773       if ($answer_expected){
774         $str = trim($this->o_sock->read());
775         $entries = $this->xml_to_array($str);
776         if(isset($entries['XML']) && is_array($entries['XML'])){
777           $ret = $entries;
778           if(isset($entries['XML']['ERROR_STRING'])) {
779             $this->set_error($entries['XML']['ERROR_STRING']);
780             new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"FAILED ".$this->get_error());
781           }else{
782             new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"SUCCESS");
783           }
784         }
785       }else{
786         new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"Fire & forget, not result.! ".$this->get_error());
787       }
788     }
789     return($ret);
790   }
793   static function send($header, $to, $data= array(), $answer_expected = FALSE)
794   {
795     $xml_message= "";
797     /* Get communication object */
798     $d= new gosaSupportDaemon(TRUE,10);
800     /* Prepare data */
801     foreach ($data as $key => $value){
802       if(is_array($value)){
803         foreach($value as $sub_val){
804           $xml_message.= "<$key>$sub_value</$key>";
805         }
806       }else{
807         $xml_message.= "<$key>$value</$key>";
808       }
809     }
811     /* Multiple targets? */
812     if (!is_array($to)){
813       $to_targets= array($to);
814     } else {
815       $to_targets= $to;
816     }
818     /* Build target strings */
819     $target ="";
820     foreach($to_targets as $to){
821       $target.= "<target>$to</target>";
822     }
824     return $d->_send("<xml><header>$header</header><source>GOSA</source>$target".$xml_message."</xml>",$answer_expected);
825   }
828   /*! \brief  Removes all jobs from the queue that are tiggered with a specific macAddress.
829       @param  String  $mac  The mac address for which we want to remove all jobs.      
830    */
831   function clean_queue_from_mac($mac)
832   {
833     global $config;
835     /* First of all we have to check which jobs are startet 
836      *  for $mac 
837      */
838     $xml_msg ="<xml><header>gosa_query_jobdb</header><target>GOSA</target><source>GOSA</source><where><clause><phrase><macaddress>".$mac."</macaddress></phrase></clause></where></xml>";  
839     
840     new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac)," start cleaning.");
841  
842     $data = $this->_send($xml_msg,TRUE);
843     if(is_array($data) && isset($data['XML'])){
844       $already_aborted = FALSE;
845       foreach($data['XML']  as $name => $entry){
846         if(preg_match("/answer[0-9]*/i",$name)){
847           $entry['STATUS'] = strtoupper($entry['STATUS']);
848           switch($entry['STATUS']){
850             case 'PROCESSING' :
852               /* Send abort event, but only once 
853                */
854               if($already_aborted){
855                 break;
856               }elseif(class_available("DaemonEvent_faireboot")){
857                 $already_aborted = TRUE;
858                 $tmp = new DaemonEvent_faireboot($config);
859                 $tmp->add_targets(array($mac));
860                 $tmp->set_type(TRIGGERED_EVENT);
861                 if(!$this->append($tmp)){
862                   msg_dialog::display(_("Error"), sprintf(_("Cannot send abort event for entry %s!"),$entry['ID']) , ERROR_DIALOG);
863                   new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac),
864                       "FAILED, could not send 'DaemonEvent_faireboot' for entry ID (".$entry['ID'].") - ".$this->get_error());
865                 }else{
866                   new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac),
867                       "SUCCESS, send 'DaemonEvent_faireboot' for entry ID (".$entry['ID'].")");
868                 }
869                 ;break;
870               }else{
871                 /* Couldn't find abort event, just remove entry */
872               }
874             case 'WAITING':
875             case 'ERROR':
876             default :
877             
878               /* Simply remove entries from queue. 
879                *  Failed or waiting events, can be removed without any trouble.
880                */ 
881               if(!$this->remove_entries(array($entry['ID']))){
882                 msg_dialog::display(_("Error"), sprintf(_("Cannot remove entry %s!"),$entry['ID']) , ERROR_DIALOG);
883               }
884               ;break;
885           }
886     
887         }
888       }
889     }
890   }
893 static function ping($target)
895   if (tests::is_mac($target)){
896     /* Get communication object */
897     $d= new gosaSupportDaemon(TRUE,0.5);
898     $answer= $d->_send("<xml><header>gosa_ping</header><source>GOSA</source><target>$target</target></xml>", TRUE);
899     return (count($answer) ? TRUE:FALSE);
900   }
902   return (FALSE);
907 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
908 ?>