9850be249085bfbe7e6229c44f012277a0f5f442
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=10)
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 if(!empty($this->s_host) && !empty($this->i_port)){
72 $this->o_sock = new Socket_Client($this->s_host,$this->i_port,TRUE,$this->f_timeout);
73 if($this->o_sock->connected()){
74 $this->o_sock->setEncryptionKey($this->s_encryption_key);
75 $this->is_connected = TRUE;
76 }else{
77 $this->set_error($this->o_sock->get_error());
78 $this->disconnect();
79 new log("debug","gosaSupportDaemon::connect()", "Could not connect to server.", array(),$this->get_error());
80 }
81 }else{
82 $this->set_error(msgPool::cmdnotfound("GOSA_SI",_("GOsa support daemon")));
83 }
84 return($this->is_connected);
85 }
88 /*! \brief Disconnect from gosa daemon.
89 */
90 public function disconnect()
91 {
92 $this->o_sock->close();
93 $this->is_connected = FALSE;
94 }
97 /*! \brief Sets an error message, which can be returned with get_error().
98 @param string The Error message,
99 */
100 private function set_error($str)
101 {
102 $this->b_error = TRUE;
103 $this->s_error = $str;
104 }
107 /*! \brief Sets an error message, which can be returned with get_error().
108 @param string The Error message,
109 */
110 private function reset_error()
111 {
112 $this->b_error = FALSE;
113 $this->s_error = "";
114 }
117 /*! \brief Checks if an error occured.
118 @return boolean returns TRUE or FALSE, whether there is an error or not.
119 */
120 public function is_error()
121 {
122 return($this->b_error);
123 }
126 /*! \brief Returns the last error.
127 @return Returns the last error.
128 */
129 public function get_error()
130 {
131 $str = $this->s_error;
132 $str = preg_replace("/ /"," ",$str);
133 return($str);
134 }
137 public function FAI_get_server($name = "")
138 {
139 $this->reset_error();
141 $xml_msg = "<xml><header>gosa_query_fai_server</header><target>GOSA</target><source>GOSA</source></xml>";
142 $ret = array();
143 if($this->connect()){
144 $this->o_sock->write($xml_msg);
145 $str = trim($this->o_sock->read());
146 $entries = $this->xml_to_array($str);
147 if(isset($entries['XML']) && is_array($entries['XML'])){
149 /* Check if returned values represent a valid answer */
150 if(isset($entries['XML'])){
151 if(isset($entries['XML']['ERROR_STRING'])) {
152 $this->set_error($entries['XML']['ERROR_STRING']);
153 new log("debug","GOsa-si",
154 get_class($this)."::".__FUNCTION__, array(),
155 "FAILED error was ".$this->get_error());
156 return($ret);
157 }
159 /* Unset header tags */
160 foreach(array("HEADER","SOURCE","TARGET","SESSION_ID") as $type){
161 if(isset($entries['XML'][$type])){
162 unset($entries['XML'][$type]);
163 }
164 }
165 $ret = $entries['XML'];
166 }
167 }
168 }
169 return($ret);
170 }
173 public function FAI_get_classes($name)
174 {
175 $this->reset_error();
176 $xml_msg = "<xml><header>gosa_query_fai_release</header><target>GOSA</target><source>GOSA</source>".
177 "<where><clause><phrase><release>".$name."</release></phrase></clause></where></xml>";;
178 $ret = array();
179 if($this->connect()){
180 $this->o_sock->write($xml_msg);
181 $str = trim($this->o_sock->read());
182 $entries = $this->xml_to_array($str);
183 if(isset($entries['XML']) && is_array($entries['XML'])){
185 /* Check if returned values represent a valid answer */
186 if(isset($entries['XML'])){
187 if(isset($entries['XML']['ERROR_STRING'])) {
188 $this->set_error($entries['XML']['ERROR_STRING']);
189 new log("debug","GOsa-si",
190 get_class($this)."::".__FUNCTION__, array($name),
191 "FAILED error was ".$this->get_error());
192 return($ret);
193 }
195 /* Unset header tags */
196 foreach(array("HEADER","SOURCE","TARGET","SESSION_ID") as $type){
197 if(isset($entries['XML'][$type])){
198 unset($entries['XML'][$type]);
199 }
200 }
201 $ret = $entries['XML'];
202 }
203 }
204 }
205 return($ret);
206 }
209 /*! \brief Returns an array containing all queued entries.
210 @return Array All queued entries as an array.
211 */
212 public function get_queued_entries($event_types = array("*"),$from=-1,$to=-1,$sort="timestamp DESC")
213 {
214 $this->reset_error();
215 $ret = array();
217 $tags = "";
218 foreach($event_types as $type){
219 $tags .= "<phrase><headertag>".$type."</headertag></phrase>";
220 }
221 if(count($event_types) > 1){
222 $tags = "<connector>or</connector>".$tags;
223 }
224 if(count($event_types)){
225 $tags = "<where><clause>".$tags."</clause></where>";
226 }
228 $xml_msg =
229 "<xml>
230 <header>gosa_query_jobdb</header>
231 <target>GOSA</target>
232 <source>GOSA</source>
233 ".$tags."
235 <orderby>".$sort."</orderby>";
236 if($from != -1 && $to != -1){
237 $xml_msg.= "
238 <limit>
239 <from>".$from."</from>
240 <to>".$to."</to>
241 </limit>";
242 }
243 $xml_msg.= "
244 </xml>";
246 if($this->connect()){
247 $this->o_sock->write($xml_msg);
248 $str = trim($this->o_sock->read());
249 $entries = $this->xml_to_array($str);
250 if(isset($entries['XML']) && is_array($entries['XML'])){
252 /* Check if returned values represent a valid answer */
253 if(isset($entries['XML'])){
255 /* Unset header tags */
256 foreach(array("HEADER","SOURCE","TARGET") as $type){
257 unset($entries['XML'][$type]);
258 }
259 $ret = $entries['XML'];
260 }
261 }
262 }
264 /* Remove session ID. No one is interested in this... */
265 unset($ret['SESSION_ID']);
267 return($ret);
268 }
271 /*! \brief Checks if the given ids are used queue ids.
272 @param Array The ids we want to check..
273 @return Array An array containing all ids as index and TRUE/FALSE as value.
274 */
275 public function ids_exist($ids)
276 {
277 if(!is_array($ids)){
278 trigger_error("Requires an array as parameter.");
279 return;
280 }
281 $this->reset_error();
283 $ret = array();
285 $xml_msg = "<xml>
286 <header>gosa_query_jobdb</header>
287 <target>GOSA</target>
288 <source>GOSA</source>
289 <where>
290 <clause>
291 <connector>or</connector>";
292 foreach($ids as $id){
293 $xml_msg .= "<phrase>
294 <operator>eq</operator>
295 <id>".$id."</id>
296 </phrase>";
297 }
298 $xml_msg .= "</clause>
299 </where>
300 </xml>";
302 if($this->connect()){
303 $this->o_sock->write($xml_msg);
304 $str = trim($this->o_sock->read());
305 $entries = $this->xml_to_array($str);
306 if(isset($entries['XML']) && is_array($entries['XML'])){
307 foreach($entries['XML'] as $entry){
308 if(isset($entry['ID'])){
309 $ret[] = $entry['ID'];
310 }
311 }
312 }
313 }
314 return($ret);
315 }
318 /*! \brief Returns an entry containing all requested ids.
319 @param Array The IDs of the entries we want to return.
320 @return Array Of the requested entries.
321 */
322 public function get_entries_by_mac($macs)
323 {
324 if(!is_array($macs)){
325 trigger_error("Requires an array as parameter.");
326 return;
327 }
328 $this->reset_error();
330 $ret = array();
332 $xml_msg = "<xml>
333 <header>gosa_query_jobdb</header>
334 <target>GOSA</target>
335 <source>GOSA</source>
336 <where>
337 <clause>
338 <connector>or</connector>";
339 foreach($macs as $mac){
340 $xml_msg .= "<phrase>
341 <operator>eq</operator>
342 <macaddress>".$mac."</macaddress>
343 </phrase>";
344 }
345 $xml_msg .= "</clause>
346 </where>
347 </xml>";
349 if($this->connect()){
350 $this->o_sock->write($xml_msg);
351 $str = trim($this->o_sock->read());
352 $entries = $this->xml_to_array($str);
353 if(isset($entries['XML'])){
354 foreach($entries['XML'] as $name => $entry){
355 if(preg_match("/^ANSWER[0-9]*$/",$name)){
356 $ret[$name] = $entry;
357 }
358 }
359 }
360 }
361 return($ret);
362 }
365 /*! \brief Returns an entry containing all requested ids.
366 @param Array The IDs of the entries we want to return.
367 @return Array Of the requested entries.
368 */
369 public function get_entries_by_id($ids)
370 {
371 if(!is_array($ids)){
372 trigger_error("Requires an array as parameter.");
373 return;
374 }
375 $this->reset_error();
377 $ret = array();
379 $xml_msg = "<xml>
380 <header>gosa_query_jobdb</header>
381 <target>GOSA</target>
382 <source>GOSA</source>
383 <where>
384 <clause>
385 <connector>or</connector>";
386 foreach($ids as $id){
387 $xml_msg .= "<phrase>
388 <operator>eq</operator>
389 <id>".$id."</id>
390 </phrase>";
391 }
392 $xml_msg .= "</clause>
393 </where>
394 </xml>";
396 if($this->connect()){
397 $this->o_sock->write($xml_msg);
398 $str = trim($this->o_sock->read());
399 $entries = $this->xml_to_array($str);
400 if(isset($entries['XML'])){
401 foreach($entries['XML'] as $name => $entry){
402 if(preg_match("/^ANSWER[0-9]*$/",$name)){
403 $ret[$name] = $entry;
404 }
405 }
406 }
407 }
408 return($ret);
409 }
412 /*! \brief Checks if the given id is in use.
413 @param Integer The ID of the entry.
414 @return Boolean TRUE if entry exists.
415 */
416 public function id_exists($id)
417 {
418 if(!is_numeric($id)){
419 trigger_error("Requires an integer as parameter.");
420 return;
421 }
423 $this->reset_error();
425 $xml_msg = "<xml>
426 <header>gosa_query_jobdb</header>
427 <target>GOSA</target>
428 <source>GOSA</source>
429 <where>
430 <clause>
431 <phrase>
432 <operator>eq</operator>
433 <id>".$id."</id>
434 </phrase>
435 </clause>
436 </where>
437 </xml>";
439 if($this->connect()){
440 $this->o_sock->write($xml_msg);
441 $str = trim($this->o_sock->read());
442 $entries = $this->xml_to_array($str);
443 if( isset($entries['XML']['HEADER']) &&
444 $entries['XML']['HEADER']=="answer" &&
445 isset($entries['XML']['ANSWER1'])){
446 return(TRUE);
447 }
448 }
449 return(FALSE);
450 }
453 /*! \brief Returns an entry from the gosaSupportQueue
454 @param Integer The ID of the entry we want to return.
455 @return Array Of the requested entry.
456 */
457 public function get_entry_by_id($id)
458 {
459 if(!is_numeric($id)){
460 trigger_error("Requires an integer as parameter.");
461 return;
462 }
463 $this->reset_error();
465 $ret = array();
466 $xml_msg = "<xml>
467 <header>gosa_query_jobdb</header>
468 <target>GOSA</target>
469 <source>GOSA</source>
470 <where>
471 <clause>
472 <phrase>
473 <operator>eq</operator>
474 <id>".$id."</id>
475 </phrase>
476 </clause>
477 </where>
478 </xml>";
479 if($this->connect()){
480 $this->o_sock->write($xml_msg);
481 $str = trim($this->o_sock->read());
482 $entries = $this->xml_to_array($str);
483 if( isset($entries['XML']['HEADER']) &&
484 $entries['XML']['HEADER']=="answer" &&
485 isset($entries['XML']['ANSWER1'])){
486 $ret = $entries['XML']['ANSWER1'];
487 }
488 }
489 return($ret);
490 }
493 /*! \brief Removes a set of entries from the GOsa support queue.
494 @param Array The IDs to remove.
495 @return Boolean True on success.
496 */
497 public function remove_entries($ids)
498 {
499 if(!is_array($ids)){
500 trigger_error("Requires an array as parameter.");
501 return;
502 }
504 $this->reset_error();
506 $ret = array();
508 $xml_msg = "<xml>
509 <header>gosa_delete_jobdb_entry</header>
510 <target>GOSA</target>
511 <source>GOSA</source>
512 <where>
513 <clause>
514 <connector>or</connector>";
515 foreach($ids as $id){
516 $xml_msg .= "<phrase>
517 <operator>eq</operator>
518 <id>".$id."</id>
519 </phrase>";
520 }
521 $xml_msg .= "</clause>
522 </where>
523 </xml>";
525 if($this->connect()){
526 $this->o_sock->write($xml_msg);
527 $str = $this->o_sock->read();
528 $entries = $this->xml_to_array($str);
529 if(isset($entries['XML']) || isset($entries['COUNT'])){
530 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::remove_entries()", $ids,"SUCCESS");
531 return(TRUE);
532 }else{
533 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::remove_entries()", $ids,"FAILED ".$this->get_error());
534 }
535 }
536 return(FALSE);
537 }
541 /*! \brief Removes an entry from the GOsa support queue.
542 @param Integer The ID of the entry we want to remove.
543 @return Boolean True on success.
544 */
545 public function remove_entry($id)
546 {
547 return($this->remove_entries(array($id)));
548 }
551 /*! \brief Parses the given xml string into an array
552 @param String XML string
553 @return Array Returns an array containing the xml structure.
554 */
555 private function xml_to_array($xml)
556 {
557 $params = array();
558 $level = array();
559 $parser = xml_parser_create_ns();
560 xml_parse_into_struct($parser, $xml, $vals, $index);
562 $err_id = xml_get_error_code($parser);
563 if($err_id){
564 xml_parser_free($parser);
565 }else{
566 xml_parser_free($parser);
568 foreach ($vals as $xml_elem) {
569 if ($xml_elem['type'] == 'open') {
570 if (array_key_exists('attributes',$xml_elem)) {
571 list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
572 } else {
573 $level[$xml_elem['level']] = $xml_elem['tag'];
574 }
575 }
576 if ($xml_elem['type'] == 'complete') {
577 $start_level = 1;
578 $php_stmt = '$params';
579 while($start_level < $xml_elem['level']) {
580 $php_stmt .= '[$level['.$start_level.']]';
581 $start_level++;
582 }
583 $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
584 @eval($php_stmt);
585 }
586 }
587 }
589 if(!isset($params['XML'])){
590 if (!array_key_exists('XML', $params)){
591 $this->set_error(_("Cannot not parse XML!"));
592 }
593 $params = array("COUNT" => 0);
594 }
596 return($params);
597 }
600 /*! \brief Updates an entry with a set of new values,
601 @param Integer The ID of the entry, we want to update.
602 @param Array The variables to update.
603 @return Boolean Returns TRUE on success.
604 */
605 public function update_entries($ids,$data)
606 {
607 $this->reset_error();
608 if(!is_array($ids)){
609 trigger_error("Requires an array as first parameter.");
610 return;
611 }
613 if(!is_array($data)){
614 trigger_error("Requires an array as second parameter.");
615 return;
616 }
618 $attr = "";
619 foreach($data as $key => $value){
620 if(is_array($value)){
621 foreach($value as $sub_value){
622 $attr.= "<$key>".strtolower($sub_value)."</$key>\n";
623 }
624 }else{
625 $attr.= "<$key>".strtolower($value)."</$key>\n";
626 }
627 }
629 $xml_msg = "<xml>
630 <header>gosa_update_status_jobdb_entry</header>
631 <target>GOSA</target>
632 <source>GOSA</source>
633 <where>
634 <clause>
635 <connector>or</connector>";
636 foreach($ids as $id){
637 $xml_msg .= "<phrase>
638 <operator>eq</operator>
639 <id>".$id."</id>
640 </phrase>";
641 }
642 $xml_msg .= "</clause>
643 </where>
644 <update>
645 ".$attr."
646 </update>
647 </xml>";
649 if($this->connect()){
651 $this->o_sock->write($xml_msg);
652 $str = trim($this->o_sock->read());
653 $entries = $this->xml_to_array($str);
654 if(isset($entries['XML'])){
655 if(isset($entries['XML']['ERROR_STRING'])) {
656 $this->set_error($entries['XML']['ERROR_STRING']);
657 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::update_entries()", $ids,"FAILED setting (".$attr.") error was ".$this->get_error());
658 return(FALSE);
659 }
660 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::update_entries()", $ids,"SUCCESS");
661 return(TRUE);
662 }
663 }
664 return(FALSE);
665 }
668 /*! \brief Returns the number of currently queued objects.
669 @return Integer
670 */
671 public function number_of_queued_entries()
672 {
673 $xml_msg ="<xml><header>gosa_count_jobdb</header><target>GOSA</target><source>GOSA</source></xml>";
674 $this->connect();
675 if($this->connect()){
676 $this->o_sock->write($xml_msg);
677 $str = trim($this->o_sock->read());
678 $entries = $this->xml_to_array($str);
679 if(isset($entries['XML'])){
680 return($entries['XML']['COUNT']);
681 }
682 }
683 return(-1);
684 }
687 public function send_data($header, $to, $data= array(), $answer_expected = FALSE)
688 {
689 $xml_message= "";
691 /* Prepare data */
692 foreach ($data as $key => $value){
693 if(is_array($value)){
694 foreach($value as $sub_value){
695 $xml_message.= "<$key>$sub_value</$key>";
696 }
697 }else{
698 $xml_message.= "<$key>$value</$key>";
699 }
700 }
702 /* Multiple targets? */
703 if (!is_array($to)){
704 $to_targets= array($to);
705 } else {
706 $to_targets= $to;
707 }
709 /* Build target strings */
710 $target ="";
711 foreach($to_targets as $to){
712 $target.= "<target>$to</target>";
713 }
715 return $this->_send("<xml><header>$header</header><source>GOSA</source>$target".$xml_message."</xml>",$answer_expected);
716 }
719 /* Allows simply appending a new DaemonEvent
720 */
721 public function append($event)
722 {
723 if(!($event instanceof DaemonEvent)){
724 return(FALSE);
725 }
727 $this->reset_error();
729 /* Add to queue if new
730 */
731 if($event->is_new()){
733 $request_answer = FALSE;
734 if($event->get_type() == SCHEDULED_EVENT){
735 $action = $event->get_schedule_action();
736 }elseif($event->get_type() == TRIGGERED_EVENT){
737 $action = $event->get_trigger_action();
738 }else{
739 trigger_error("Unknown type of queue event given.");
740 return(FALSE);
741 }
743 /* Get event informations, like targets..
744 */
745 $targets = $event->get_targets();
746 $data = $event->save();
748 /* Append an entry for each target
749 */
750 foreach($targets as $target){
751 $data['macaddress'] = $target;
752 $this->send_data($action,$target,$data,$request_answer);
754 if($this->is_error()){
755 return(FALSE);
756 }
757 }
758 return(TRUE);
759 }else{
761 /* Updated edited entry.
762 */
763 $id = $event->get_id();
764 $data = $event->save();
765 return($this->update_entries(array($id),$data));
766 }
768 return(FALSE);
769 }
772 /*! \brief Returns an array containing all queued entries.
773 @return Array All queued entries as an array.
774 */
775 public function _send($data, $answer_expected= FALSE)
776 {
777 $this->reset_error();
778 $ret = array();
780 if($this->connect()){
781 $this->o_sock->write($data);
782 if ($answer_expected){
783 $str = trim($this->o_sock->read());
784 $entries = $this->xml_to_array($str);
785 if(isset($entries['XML']) && is_array($entries['XML'])){
786 $ret = $entries;
787 if(isset($entries['XML']['ERROR_STRING'])) {
788 $this->set_error($entries['XML']['ERROR_STRING']);
789 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"FAILED ".$this->get_error());
790 }else{
791 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"SUCCESS");
792 }
793 }
794 }else{
795 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"Fire & forget, not result.! ".$this->get_error());
796 }
797 }
798 return($ret);
799 }
802 static function send($header, $to, $data= array(), $answer_expected = FALSE)
803 {
804 $xml_message= "";
806 /* Get communication object */
807 $d= new gosaSupportDaemon(TRUE,10);
809 /* Prepare data */
810 foreach ($data as $key => $value){
811 if(is_array($value)){
812 foreach($value as $sub_val){
813 $xml_message.= "<$key>$sub_value</$key>";
814 }
815 }else{
816 $xml_message.= "<$key>$value</$key>";
817 }
818 }
820 /* Multiple targets? */
821 if (!is_array($to)){
822 $to_targets= array($to);
823 } else {
824 $to_targets= $to;
825 }
827 /* Build target strings */
828 $target ="";
829 foreach($to_targets as $to){
830 $target.= "<target>$to</target>";
831 }
833 return $d->_send("<xml><header>$header</header><source>GOSA</source>$target".$xml_message."</xml>",$answer_expected);
834 }
837 /*! \brief Removes all jobs from the queue that are tiggered with a specific macAddress.
838 @param String $mac The mac address for which we want to remove all jobs.
839 */
840 function clean_queue_from_mac($mac)
841 {
842 global $config;
844 /* First of all we have to check which jobs are startet
845 * for $mac
846 */
847 $xml_msg ="<xml><header>gosa_query_jobdb</header><target>GOSA</target><source>GOSA</source><where><clause><phrase><macaddress>".$mac."</macaddress></phrase></clause></where></xml>";
849 new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac)," start cleaning.");
851 $data = $this->_send($xml_msg,TRUE);
852 if(is_array($data) && isset($data['XML'])){
853 $already_aborted = FALSE;
854 foreach($data['XML'] as $name => $entry){
855 if(preg_match("/answer[0-9]*/i",$name)){
856 $entry['STATUS'] = strtoupper($entry['STATUS']);
857 switch($entry['STATUS']){
859 case 'PROCESSING' :
861 /* Send abort event, but only once
862 */
863 if($already_aborted){
864 break;
865 }elseif(class_available("DaemonEvent_faireboot")){
866 $already_aborted = TRUE;
867 $tmp = new DaemonEvent_faireboot($config);
868 $tmp->add_targets(array($mac));
869 $tmp->set_type(TRIGGERED_EVENT);
870 if(!$this->append($tmp)){
871 msg_dialog::display(_("Error"), sprintf(_("Cannot send abort event for entry %s!"),$entry['ID']) , ERROR_DIALOG);
872 new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac),
873 "FAILED, could not send 'DaemonEvent_faireboot' for entry ID (".$entry['ID'].") - ".$this->get_error());
874 }else{
875 new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac),
876 "SUCCESS, send 'DaemonEvent_faireboot' for entry ID (".$entry['ID'].")");
877 }
878 ;break;
879 }else{
880 /* Couldn't find abort event, just remove entry */
881 }
883 case 'WAITING':
884 case 'ERROR':
885 default :
887 /* Simply remove entries from queue.
888 * Failed or waiting events, can be removed without any trouble.
889 */
890 if(!$this->remove_entries(array($entry['ID']))){
891 msg_dialog::display(_("Error"), sprintf(_("Cannot remove entry %s!"),$entry['ID']) , ERROR_DIALOG);
892 }
893 ;break;
894 }
896 }
897 }
898 }
899 }
902 static function ping($target)
903 {
904 if (tests::is_mac($target)){
905 /* Get communication object */
906 $d= new gosaSupportDaemon(TRUE,0.5);
907 $answer= $d->_send("<xml><header>gosa_ping</header><source>GOSA</source><target>$target</target></xml>", TRUE);
908 return (count($answer) ? TRUE:FALSE);
909 }
911 return (FALSE);
912 }
914 }
916 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
917 ?>