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()", "Cannot connect to si-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_kernels($release)
138 {
139 $xml_msg =
140 "<xml>".
141 "<header>gosa_get_available_kernel</header>".
142 "<source>GOSA</source>".
143 "<target>GOSA</target>".
144 "<release>".$release."</release>".
145 "</xml>";
147 $ret = array();
148 if($this->connect()){
149 $this->o_sock->write($xml_msg);
150 $str = trim($this->o_sock->read());
152 /* Check if something went wrong while reading */
153 if($this->o_sock->is_error()){
154 $this->set_error($this->o_sock->get_error());
155 return($ret);
156 }
158 $entries = $this->xml_to_array($str);
159 if(isset($entries['XML']) && is_array($entries['XML'])){
161 /* Check if returned values represent a valid answer */
162 if(isset($entries['XML'])){
163 if(isset($entries['XML']['ERROR_STRING'])) {
164 $this->set_error($entries['XML']['ERROR_STRING']);
165 new log("debug","GOsa-si",
166 get_class($this)."::".__FUNCTION__, array(),
167 "FAILED error was ".$this->get_error());
168 return($ret);
169 }
171 /* Unset header tags */
172 $ret = $entries['XML'];
173 foreach($ret as $key => $entry){
174 if(!preg_match("/^answer/i",$key)){
175 unset($ret[$key]);
176 }
177 }
178 }
179 }
180 }
181 return($ret);
182 }
185 public function FAI_get_package_sections($release)
186 {
187 $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
188 "<select>distinct section</select>".
189 "<where><clause><phrase><distribution>".$release."</distribution></phrase></clause></where></xml>";
191 $ret = array();
192 if($this->connect()){
193 $this->o_sock->write($xml_msg);
194 $str = trim($this->o_sock->read());
196 /* Check if something went wrong while reading */
197 if($this->o_sock->is_error()){
198 $this->set_error($this->o_sock->get_error());
199 return($ret);
200 }
202 $entries = $this->xml_to_array($str);
203 if(isset($entries['XML']) && is_array($entries['XML'])){
205 /* Check if returned values represent a valid answer */
206 if(isset($entries['XML'])){
207 if(isset($entries['XML']['ERROR_STRING'])) {
208 $this->set_error($entries['XML']['ERROR_STRING']);
209 new log("debug","GOsa-si",
210 get_class($this)."::".__FUNCTION__, array(),
211 "FAILED error was ".$this->get_error());
212 return($ret);
213 }
215 /* Unset header tags */
216 foreach(array("HEADER","SOURCE","TARGET","SESSION_ID") as $type){
217 if(isset($entries['XML'][$type])){
218 unset($entries['XML'][$type]);
219 }
220 }
221 $ret = $entries['XML'];
222 }
223 }
224 }
225 return($ret);
226 }
229 public function FAI_get_packages($release,$attrs,$package,$from=-1,$to=-1)
230 {
231 $this->reset_error();
232 $ret = array();
234 /* Check Parameter */
235 if(!is_array($attrs) || !count($attrs)){
236 trigger_error("Second parameter must be an array. With at least one attribute name.");
237 return($ret);
238 }
240 /* Check Parameter */
241 if(!is_array($package)){
242 trigger_error("Third parameter must be an array. With at least one attribute name.");
243 return($ret);
244 }
246 /* Create list of attributes to fetch */
247 $attr = "";
248 foreach($attrs as $at){
249 $attr.= "<select>".$at."</select>";
250 }
252 /* If no package is given, search for all */
253 if(!count($package)) $package = array("%");
255 /* Create limit tag */
256 if($from == -1){
257 $limit ="";
258 }else{
259 $limit = "<limit><from>".$from."</from><to>".$to."</to></limit>";
260 }
262 /* Create list of attributes to fetch */
263 $pkgs = "";
264 foreach($package as $pkg){
265 $pkgs .="<phrase><operator>like</operator><package>".$pkg."</package></phrase>";
266 }
268 $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
269 $attr.
270 "<where>
271 <clause><phrase><distribution>".$release."</distribution></phrase></clause>
272 <clause><connector>OR</connector>
273 ".$pkgs."
274 </clause>
275 </where>".
276 $limit.
277 "</xml>";
279 if($this->connect()){
280 $this->o_sock->write($xml_msg);
281 $str = trim($this->o_sock->read());
283 /* Check if something went wrong while reading */
284 if($this->o_sock->is_error()){
285 $this->set_error($this->o_sock->get_error());
286 return($ret);
287 }
289 $entries = $this->xml_to_array($str);
290 if(isset($entries['XML']) && is_array($entries['XML'])){
292 /* Check if returned values represent a valid answer */
293 if(isset($entries['XML'])){
294 if(isset($entries['XML']['ERROR_STRING'])) {
295 $this->set_error($entries['XML']['ERROR_STRING']);
296 new log("debug","GOsa-si",
297 get_class($this)."::".__FUNCTION__, array(),
298 "FAILED error was ".$this->get_error());
299 return($ret);
300 }
302 /* Unset header tags */
303 foreach(array("HEADER","SOURCE","TARGET","SESSION_ID") as $type){
304 if(isset($entries['XML'][$type])){
305 unset($entries['XML'][$type]);
306 }
307 }
308 $ret = $entries['XML'];
309 }
310 }
311 }
312 return($ret);
315 }
318 public function FAI_get_server($name = "")
319 {
320 $this->reset_error();
322 $xml_msg = "<xml><header>gosa_query_fai_server</header><target>GOSA</target><source>GOSA</source></xml>";
323 $ret = array();
324 if($this->connect()){
325 $this->o_sock->write($xml_msg);
326 $str = trim($this->o_sock->read());
328 /* Check if something went wrong while reading */
329 if($this->o_sock->is_error()){
330 $this->set_error($this->o_sock->get_error());
331 return($ret);
332 }
334 $entries = $this->xml_to_array($str);
335 if(isset($entries['XML']) && is_array($entries['XML'])){
337 /* Check if returned values represent a valid answer */
338 if(isset($entries['XML'])){
339 if(isset($entries['XML']['ERROR_STRING'])) {
340 $this->set_error($entries['XML']['ERROR_STRING']);
341 new log("debug","GOsa-si",
342 get_class($this)."::".__FUNCTION__, array(),
343 "FAILED error was ".$this->get_error());
344 return($ret);
345 }
347 /* Unset header tags */
348 foreach(array("HEADER","SOURCE","TARGET","SESSION_ID") as $type){
349 if(isset($entries['XML'][$type])){
350 unset($entries['XML'][$type]);
351 }
352 }
353 $ret = $entries['XML'];
354 }
355 }
356 }
357 return($ret);
358 }
361 public function FAI_get_classes($name)
362 {
363 $this->reset_error();
364 $xml_msg = "<xml><header>gosa_query_fai_release</header><target>GOSA</target><source>GOSA</source>".
365 "<where><clause><phrase><release>".$name."</release></phrase></clause></where></xml>";;
366 $ret = array();
367 if($this->connect()){
368 $this->o_sock->write($xml_msg);
369 $str = trim($this->o_sock->read());
371 /* Check if something went wrong while reading */
372 if($this->o_sock->is_error()){
373 $this->set_error($this->o_sock->get_error());
374 return($ret);
375 }
377 $entries = $this->xml_to_array($str);
378 if(isset($entries['XML']) && is_array($entries['XML'])){
380 /* Check if returned values represent a valid answer */
381 if(isset($entries['XML'])){
382 if(isset($entries['XML']['ERROR_STRING'])) {
383 $this->set_error($entries['XML']['ERROR_STRING']);
384 new log("debug","GOsa-si",
385 get_class($this)."::".__FUNCTION__, array($name),
386 "FAILED error was ".$this->get_error());
387 return($ret);
388 }
390 /* Unset header tags */
391 foreach(array("HEADER","SOURCE","TARGET","SESSION_ID") as $type){
392 if(isset($entries['XML'][$type])){
393 unset($entries['XML'][$type]);
394 }
395 }
396 $ret = $entries['XML'];
397 }
398 }
399 }
400 return($ret);
401 }
404 /*! \brief Returns an array containing all queued entries.
405 @return Array All queued entries as an array.
406 */
407 public function get_queued_entries($event_types = array("*"),$from=-1,$to=-1,$sort="timestamp DESC")
408 {
409 $this->reset_error();
410 $ret = array();
412 $tags = "";
413 foreach($event_types as $type){
414 $tags .= "<phrase><headertag>".$type."</headertag></phrase>";
415 }
416 if(count($event_types) > 1){
417 $tags = "<connector>or</connector>".$tags;
418 }
419 if(count($event_types)){
420 $tags = "<where><clause>".$tags."</clause></where>";
421 }
423 $xml_msg =
424 "<xml>
425 <header>gosa_query_jobdb</header>
426 <target>GOSA</target>
427 <source>GOSA</source>
428 ".$tags."
430 <orderby>".$sort."</orderby>";
431 if($from != -1 && $to != -1){
432 $xml_msg.= "
433 <limit>
434 <from>".$from."</from>
435 <to>".$to."</to>
436 </limit>";
437 }
438 $xml_msg.= "
439 </xml>";
441 if($this->connect()){
442 $this->o_sock->write($xml_msg);
443 $str = trim($this->o_sock->read());
445 /* Check if something went wrong while reading */
446 if($this->o_sock->is_error()){
447 $this->set_error($this->o_sock->get_error());
448 return($ret);
449 }
451 $entries = $this->xml_to_array($str);
452 if(isset($entries['XML']) && is_array($entries['XML'])){
454 /* Check if returned values represent a valid answer */
455 if(isset($entries['XML'])){
457 /* Unset header tags */
458 foreach(array("HEADER","SOURCE","TARGET") as $type){
459 unset($entries['XML'][$type]);
460 }
461 $ret = $entries['XML'];
462 }
463 }
464 }
466 /* Remove session ID. No one is interested in this... */
467 unset($ret['SESSION_ID']);
469 return($ret);
470 }
473 /*! \brief Checks if the given ids are used queue ids.
474 @param Array The ids we want to check..
475 @return Array An array containing all ids as index and TRUE/FALSE as value.
476 */
477 public function ids_exist($ids)
478 {
479 if(!is_array($ids)){
480 trigger_error("Requires an array as parameter.");
481 return;
482 }
483 $this->reset_error();
485 $ret = array();
487 $xml_msg = "<xml>
488 <header>gosa_query_jobdb</header>
489 <target>GOSA</target>
490 <source>GOSA</source>
491 <where>
492 <clause>
493 <connector>or</connector>";
494 foreach($ids as $id){
495 $xml_msg .= "<phrase>
496 <operator>eq</operator>
497 <id>".$id."</id>
498 </phrase>";
499 }
500 $xml_msg .= "</clause>
501 </where>
502 </xml>";
504 if($this->connect()){
505 $this->o_sock->write($xml_msg);
506 $str = trim($this->o_sock->read());
508 /* Check if something went wrong while reading */
509 if($this->o_sock->is_error()){
510 $this->set_error($this->o_sock->get_error());
511 return($ret);
512 }
514 $entries = $this->xml_to_array($str);
515 if(isset($entries['XML']) && is_array($entries['XML'])){
516 foreach($entries['XML'] as $entry){
517 if(is_array($entry) && array_key_exists("ID",$entry)){
518 $ret[] = $entry['ID'];
519 }
520 }
521 }
522 }
523 return($ret);
524 }
527 /*! \brief Returns an entry containing all requested ids.
528 @param Array The IDs of the entries we want to return.
529 @return Array Of the requested entries.
530 */
531 public function get_entries_by_mac($macs)
532 {
533 if(!is_array($macs)){
534 trigger_error("Requires an array as parameter.");
535 return;
536 }
537 $this->reset_error();
539 $ret = array();
541 $xml_msg = "<xml>
542 <header>gosa_query_jobdb</header>
543 <target>GOSA</target>
544 <source>GOSA</source>
545 <where>
546 <clause>
547 <connector>or</connector>";
548 foreach($macs as $mac){
549 $xml_msg .= "<phrase>
550 <operator>eq</operator>
551 <macaddress>".$mac."</macaddress>
552 </phrase>";
553 }
554 $xml_msg .= "</clause>
555 </where>
556 </xml>";
558 if($this->connect()){
559 $this->o_sock->write($xml_msg);
560 $str = trim($this->o_sock->read());
562 /* Check if something went wrong while reading */
563 if($this->o_sock->is_error()){
564 $this->set_error($this->o_sock->get_error());
565 return($ret);
566 }
568 $entries = $this->xml_to_array($str);
569 if(isset($entries['XML'])){
570 foreach($entries['XML'] as $name => $entry){
571 if(preg_match("/^ANSWER[0-9]*$/",$name)){
572 $ret[$name] = $entry;
573 }
574 }
575 }
576 }
577 return($ret);
578 }
581 /*! \brief Returns an entry containing all requested ids.
582 @param Array The IDs of the entries we want to return.
583 @return Array Of the requested entries.
584 */
585 public function get_entries_by_id($ids)
586 {
587 if(!is_array($ids)){
588 trigger_error("Requires an array as parameter.");
589 return;
590 }
591 $this->reset_error();
593 $ret = array();
595 $xml_msg = "<xml>
596 <header>gosa_query_jobdb</header>
597 <target>GOSA</target>
598 <source>GOSA</source>
599 <where>
600 <clause>
601 <connector>or</connector>";
602 foreach($ids as $id){
603 $xml_msg .= "<phrase>
604 <operator>eq</operator>
605 <id>".$id."</id>
606 </phrase>";
607 }
608 $xml_msg .= "</clause>
609 </where>
610 </xml>";
612 if($this->connect()){
613 $this->o_sock->write($xml_msg);
614 $str = trim($this->o_sock->read());
616 /* Check if something went wrong while reading */
617 if($this->o_sock->is_error()){
618 $this->set_error($this->o_sock->get_error());
619 return($ret);
620 }
622 $entries = $this->xml_to_array($str);
623 if(isset($entries['XML'])){
624 foreach($entries['XML'] as $name => $entry){
625 if(preg_match("/^ANSWER[0-9]*$/",$name)){
626 $ret[$name] = $entry;
627 }
628 }
629 }
630 }
631 return($ret);
632 }
635 /*! \brief Checks if the given id is in use.
636 @param Integer The ID of the entry.
637 @return Boolean TRUE if entry exists.
638 */
639 public function id_exists($id)
640 {
641 if(!is_numeric($id)){
642 trigger_error("Requires an integer as parameter.");
643 return;
644 }
646 $this->reset_error();
648 $xml_msg = "<xml>
649 <header>gosa_query_jobdb</header>
650 <target>GOSA</target>
651 <source>GOSA</source>
652 <where>
653 <clause>
654 <phrase>
655 <operator>eq</operator>
656 <id>".$id."</id>
657 </phrase>
658 </clause>
659 </where>
660 </xml>";
662 if($this->connect()){
663 $this->o_sock->write($xml_msg);
664 $str = trim($this->o_sock->read());
666 /* Check if something went wrong while reading */
667 if($this->o_sock->is_error()){
668 $this->set_error($this->o_sock->get_error());
669 return(FALSE);
670 }
672 $entries = $this->xml_to_array($str);
673 if( isset($entries['XML']['HEADER']) &&
674 $entries['XML']['HEADER']=="answer" &&
675 isset($entries['XML']['ANSWER1'])){
676 return(TRUE);
677 }
678 }
679 return(FALSE);
680 }
683 /*! \brief Returns an entry from the gosaSupportQueue
684 @param Integer The ID of the entry we want to return.
685 @return Array Of the requested entry.
686 */
687 public function get_entry_by_id($id)
688 {
689 if(!is_numeric($id)){
690 trigger_error("Requires an integer as parameter.");
691 return;
692 }
693 $this->reset_error();
695 $ret = array();
696 $xml_msg = "<xml>
697 <header>gosa_query_jobdb</header>
698 <target>GOSA</target>
699 <source>GOSA</source>
700 <where>
701 <clause>
702 <phrase>
703 <operator>eq</operator>
704 <id>".$id."</id>
705 </phrase>
706 </clause>
707 </where>
708 </xml>";
709 if($this->connect()){
710 $this->o_sock->write($xml_msg);
711 $str = trim($this->o_sock->read());
713 /* Check if something went wrong while reading */
714 if($this->o_sock->is_error()){
715 $this->set_error($this->o_sock->get_error());
716 return($ret);
717 }
719 $entries = $this->xml_to_array($str);
720 if( isset($entries['XML']['HEADER']) &&
721 $entries['XML']['HEADER']=="answer" &&
722 isset($entries['XML']['ANSWER1'])){
723 $ret = $entries['XML']['ANSWER1'];
724 }
725 }
726 return($ret);
727 }
730 /*! \brief Removes a set of entries from the GOsa support queue.
731 @param Array The IDs to remove.
732 @return Boolean True on success.
733 */
734 public function remove_entries($ids)
735 {
736 if(!is_array($ids)){
737 trigger_error("Requires an array as parameter.");
738 return;
739 }
741 $this->reset_error();
743 $ret = array();
745 $xml_msg = "<xml>
746 <header>gosa_delete_jobdb_entry</header>
747 <target>GOSA</target>
748 <source>GOSA</source>
749 <where>
750 <clause>
751 <connector>or</connector>";
752 foreach($ids as $id){
753 $xml_msg .= "<phrase>
754 <operator>eq</operator>
755 <id>".$id."</id>
756 </phrase>";
757 }
758 $xml_msg .= "</clause>
759 </where>
760 </xml>";
762 if($this->connect()){
763 $this->o_sock->write($xml_msg);
764 $str = $this->o_sock->read();
766 /* Check if something went wrong while reading */
767 if($this->o_sock->is_error()){
768 $this->set_error($this->o_sock->get_error());
769 return($ret);
770 }
772 $entries = $this->xml_to_array($str);
773 if(isset($entries['XML']) || isset($entries['COUNT'])){
774 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::remove_entries()", $ids,"SUCCESS");
775 return(TRUE);
776 }else{
777 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::remove_entries()", $ids,"FAILED ".$this->get_error());
778 }
779 }
780 return(FALSE);
781 }
785 /*! \brief Removes an entry from the GOsa support queue.
786 @param Integer The ID of the entry we want to remove.
787 @return Boolean True on success.
788 */
789 public function remove_entry($id)
790 {
791 return($this->remove_entries(array($id)));
792 }
795 /*! \brief Parses the given xml string into an array
796 @param String XML string
797 @return Array Returns an array containing the xml structure.
798 */
799 private function xml_to_array($xml)
800 {
801 $params = array();
802 $level = array();
803 $parser = xml_parser_create_ns();
804 xml_parse_into_struct($parser, $xml, $vals, $index);
806 $err_id = xml_get_error_code($parser);
807 if($err_id){
808 xml_parser_free($parser);
809 }else{
810 xml_parser_free($parser);
812 foreach ($vals as $xml_elem) {
813 if ($xml_elem['type'] == 'open') {
814 if (array_key_exists('attributes',$xml_elem)) {
815 list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
816 } else {
817 $level[$xml_elem['level']] = $xml_elem['tag'];
818 }
819 }
820 if ($xml_elem['type'] == 'complete') {
821 $start_level = 1;
822 $test2 = &$params;
823 while($start_level < $xml_elem['level']) {
824 $test2 = &$test2[$level[$start_level]];
825 $start_level++;
826 }
827 if(!isset($test2[$xml_elem['tag']])){
828 if(isset($xml_elem['value'])){
829 $test2[$xml_elem['tag']] = $xml_elem['value'];
830 }
831 }else{
832 if(!is_array($test2[$xml_elem['tag']])){
833 $test2[$xml_elem['tag']] = array($test2[$xml_elem['tag']]);
834 }
835 $test2[$xml_elem['tag']][] = $xml_elem['value'];
836 }
837 }
838 }
839 }
841 if(!isset($params['XML'])){
842 if (!array_key_exists('XML', $params)){
843 $this->set_error(_("Cannot not parse XML!"));
844 }
845 $params = array("COUNT" => 0);
846 }
848 return($params);
849 }
852 /*! \brief Updates an entry with a set of new values,
853 @param Integer The ID of the entry, we want to update.
854 @param Array The variables to update.
855 @return Boolean Returns TRUE on success.
856 */
857 public function update_entries($ids,$data)
858 {
859 $this->reset_error();
860 if(!is_array($ids)){
861 trigger_error("Requires an array as first parameter.");
862 return;
863 }
865 if(!is_array($data)){
866 trigger_error("Requires an array as second parameter.");
867 return;
868 }
870 $attr = "";
871 foreach($data as $key => $value){
872 $key = strtolower($key);
873 if(is_array($value)){
874 foreach($value as $sub_value){
875 $attr.= "<$key>".strtolower($sub_value)."</$key>\n";
876 }
877 }else{
878 $attr.= "<$key>".strtolower($value)."</$key>\n";
879 }
880 }
882 $xml_msg = "<xml>
883 <header>gosa_update_status_jobdb_entry</header>
884 <target>GOSA</target>
885 <source>GOSA</source>
886 <where>
887 <clause>
888 <connector>or</connector>";
889 foreach($ids as $id){
890 $xml_msg .= "<phrase>
891 <operator>eq</operator>
892 <id>".$id."</id>
893 </phrase>";
894 }
895 $xml_msg .= "</clause>
896 </where>
897 <update>
898 ".$attr."
899 </update>
900 </xml>";
902 if($this->connect()){
904 $this->o_sock->write($xml_msg);
905 $str = trim($this->o_sock->read());
907 /* Check if something went wrong while reading */
908 if($this->o_sock->is_error()){
909 $this->set_error($this->o_sock->get_error());
910 return(FALSE);
911 }
913 $entries = $this->xml_to_array($str);
914 if(isset($entries['XML'])){
915 if(isset($entries['XML']['ERROR_STRING'])) {
916 $this->set_error($entries['XML']['ERROR_STRING']);
917 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::update_entries()", $ids,"FAILED setting (".$attr.") error was ".$this->get_error());
918 return(FALSE);
919 }
920 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::update_entries()", $ids,"SUCCESS");
921 return(TRUE);
922 }
923 }
924 return(FALSE);
925 }
928 /*! \brief Returns the number of currently queued objects.
929 @return Integer
930 */
931 public function number_of_queued_entries($event_types)
932 {
933 $tags = "";
934 foreach($event_types as $type){
935 $tags .= "<phrase><headertag>".$type."</headertag></phrase>";
936 }
937 if(count($event_types) > 1){
938 $tags = "<connector>or</connector>".$tags;
939 }
940 if(count($event_types)){
941 $tags = "<where><clause>".$tags."</clause></where>";
942 }
945 $xml_msg =
946 "<xml>".
947 "<header>gosa_query_jobdb</header>".
948 "<target>GOSA</target>".
949 "<source>GOSA</source>".
950 "<select> count ID</select>".
951 $tags.
952 "</xml>";
954 $xml_msg ="<xml><header>gosa_count_jobdb</header><target>GOSA</target><source>GOSA</source></xml>";
955 $this->connect();
956 if($this->connect()){
957 $this->o_sock->write($xml_msg);
958 $str = trim($this->o_sock->read());
960 /* Check if something went wrong while reading */
961 if($this->o_sock->is_error()){
962 $this->set_error($this->o_sock->get_error());
963 return(0);
964 }
966 $entries = $this->xml_to_array($str);
967 if(isset($entries['XML'])){
968 return($entries['XML']['COUNT']);
969 }
970 }
971 return(-1);
972 }
975 public function send_data($header, $to, $data= array(), $answer_expected = FALSE)
976 {
977 $xml_message= "";
979 /* Prepare data */
980 foreach ($data as $key => $value){
981 if(is_array($value)){
982 foreach($value as $sub_value){
983 $xml_message.= "<$key>$sub_value</$key>";
984 }
985 }else{
986 $xml_message.= "<$key>$value</$key>";
987 }
988 }
990 /* Multiple targets? */
991 if (!is_array($to)){
992 $to_targets= array($to);
993 } else {
994 $to_targets= $to;
995 }
997 /* Build target strings */
998 $target ="";
999 foreach($to_targets as $to){
1000 $target.= "<target>$to</target>";
1001 }
1003 return $this->_send("<xml><header>$header</header><source>GOSA</source>$target".$xml_message."</xml>",$answer_expected);
1004 }
1007 /* Allows simply appending a new DaemonEvent
1008 */
1009 public function append($event)
1010 {
1011 if(!($event instanceof DaemonEvent)){
1012 return(FALSE);
1013 }
1015 $this->reset_error();
1017 /* Add to queue if new
1018 */
1019 if($event->is_new()){
1021 $request_answer = FALSE;
1022 if($event->get_type() == SCHEDULED_EVENT){
1023 $action = $event->get_schedule_action();
1024 }elseif($event->get_type() == TRIGGERED_EVENT){
1025 $action = $event->get_trigger_action();
1026 }else{
1027 trigger_error("Unknown type of queue event given.");
1028 return(FALSE);
1029 }
1031 /* Get event informations, like targets..
1032 */
1033 $targets = $event->get_targets();
1034 $data = $event->save();
1036 /* Append an entry for each target
1037 */
1038 foreach($targets as $target){
1039 $data['macaddress'] = $target;
1040 $this->send_data($action,$target,$data,$request_answer);
1042 if($this->is_error()){
1043 return(FALSE);
1044 }
1045 }
1046 return(TRUE);
1047 }else{
1049 /* Updated edited entry.
1050 */
1051 $id = $event->get_id();
1052 $data = $event->save();
1053 return($this->update_entries(array($id),$data));
1054 }
1056 return(FALSE);
1057 }
1060 /*! \brief Returns an array containing all queued entries.
1061 @return Array All queued entries as an array.
1062 */
1063 public function _send($data, $answer_expected= FALSE)
1064 {
1065 $this->reset_error();
1066 $ret = array();
1068 if($this->connect()){
1069 $this->o_sock->write($data);
1070 if ($answer_expected){
1071 $str = trim($this->o_sock->read());
1073 /* Check if something went wrong while reading */
1074 if($this->o_sock->is_error()){
1075 $this->set_error($this->o_sock->get_error());
1076 return($ret);
1077 }
1079 $entries = $this->xml_to_array($str);
1080 if(isset($entries['XML']) && is_array($entries['XML'])){
1081 $ret = $entries;
1082 if(isset($entries['XML']['ERROR_STRING'])) {
1083 $this->set_error($entries['XML']['ERROR_STRING']);
1084 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"FAILED ".$this->get_error());
1085 }elseif(isset($entries['XML']['ERROR'])){
1086 $this->set_error($entries['XML']['ERROR']);
1087 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"FAILED ".$this->get_error());
1088 }else{
1089 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"SUCCESS");
1090 }
1091 }
1092 }else{
1093 new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::_send()", array($data=>$data),"Fire & forget, not result.! ".$this->get_error());
1094 }
1095 }
1096 return($ret);
1097 }
1100 static function send($header, $to, $data= array(), $answer_expected = FALSE)
1101 {
1102 $xml_message= "";
1104 /* Get communication object */
1105 $d= new gosaSupportDaemon(TRUE,10);
1107 /* Prepare data */
1108 foreach ($data as $key => $value){
1109 if(is_array($value)){
1110 foreach($value as $sub_val){
1111 $xml_message.= "<$key>$sub_value</$key>";
1112 }
1113 }else{
1114 $xml_message.= "<$key>$value</$key>";
1115 }
1116 }
1118 /* Multiple targets? */
1119 if (!is_array($to)){
1120 $to_targets= array($to);
1121 } else {
1122 $to_targets= $to;
1123 }
1125 /* Build target strings */
1126 $target ="";
1127 foreach($to_targets as $to){
1128 $target.= "<target>$to</target>";
1129 }
1131 return $d->_send("<xml><header>$header</header><source>GOSA</source>$target".$xml_message."</xml>",$answer_expected);
1132 }
1135 /*! \brief Removes all jobs from the queue that are tiggered with a specific macAddress.
1136 @param String $mac The mac address for which we want to remove all jobs.
1137 */
1138 function clean_queue_from_mac($mac)
1139 {
1140 global $config;
1142 /* First of all we have to check which jobs are startet
1143 * for $mac
1144 */
1145 $xml_msg ="<xml><header>gosa_query_jobdb</header><target>GOSA</target><source>GOSA</source><where><clause><phrase><macaddress>".$mac."</macaddress></phrase></clause></where></xml>";
1147 new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac)," start cleaning.");
1149 $data = $this->_send($xml_msg,TRUE);
1150 if(is_array($data) && isset($data['XML'])){
1151 $already_aborted = FALSE;
1152 foreach($data['XML'] as $name => $entry){
1153 if(preg_match("/answer[0-9]*/i",$name)){
1154 $entry['STATUS'] = strtoupper($entry['STATUS']);
1155 switch($entry['STATUS']){
1157 case 'PROCESSING' :
1159 /* Send abort event, but only once
1160 */
1161 if($already_aborted){
1162 break;
1163 }elseif(class_available("DaemonEvent_faireboot")){
1164 $already_aborted = TRUE;
1165 $tmp = new DaemonEvent_faireboot($config);
1166 $tmp->add_targets(array($mac));
1167 $tmp->set_type(TRIGGERED_EVENT);
1168 if(!$this->append($tmp)){
1169 msg_dialog::display(_("Error"), sprintf(_("Cannot send abort event for entry %s!"),$entry['ID']) , ERROR_DIALOG);
1170 new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac),
1171 "FAILED, could not send 'DaemonEvent_faireboot' for entry ID (".$entry['ID'].") - ".$this->get_error());
1172 }else{
1173 new log("debug","DaemonEvent ", "gosaSupportDaemon::clean_queue_from_mac()", array($mac => $mac),
1174 "SUCCESS, send 'DaemonEvent_faireboot' for entry ID (".$entry['ID'].")");
1175 }
1176 ;break;
1177 }else{
1178 /* Couldn't find abort event, just remove entry */
1179 }
1181 case 'WAITING':
1182 case 'ERROR':
1183 default :
1185 /* Simply remove entries from queue.
1186 * Failed or waiting events, can be removed without any trouble.
1187 */
1188 if(!$this->remove_entries(array($entry['ID']))){
1189 msg_dialog::display(_("Error"), sprintf(_("Cannot remove entry %s!"),$entry['ID']) , ERROR_DIALOG);
1190 }
1191 ;break;
1192 }
1194 }
1195 }
1196 }
1197 }
1200 static function ping($target)
1201 {
1202 if (tests::is_mac($target)){
1203 /* Get communication object */
1204 $d= new gosaSupportDaemon(TRUE,0.5);
1205 $answer= $d->_send("<xml><header>gosa_ping</header><source>GOSA</source><target>$target</target></xml>", TRUE);
1206 return (count($answer) ? TRUE:FALSE);
1207 }
1208 return (FALSE);
1209 }
1213 /*! \brief Returns a list of all configured principals.
1214 (Uses the GOsa support daemon instead of the ldap database.)
1215 @return Array A list containing the names of all configured principals.
1216 */
1217 public function krb5_list_principals($server)
1218 {
1219 $res = array();
1221 /* Check if the given server is a valid mac address
1222 */
1223 if(!tests::is_mac($server)){
1224 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1225 return($ret);
1226 }
1228 /* Prepare request event
1229 */
1230 $xml_msg =
1231 "<xml>".
1232 "<header>gosa_krb5_list_principals</header>".
1233 "<source>GOSA</source>".
1234 "<target>".$server."</target>".
1235 "</xml>";
1237 $tmp = $this->_send($xml_msg,TRUE);
1238 if(isset($tmp['XML']['PRINCIPAL'])){
1239 return($tmp['XML']['PRINCIPAL']);
1240 }else{
1241 return($res);
1242 }
1243 }
1246 /*! \brief Returns the configuration settings for a given principal name.
1247 (Uses the GOsa support daemon instead of the ldap database.)
1248 @pram String The name of the requested principal. (e.g. peter@EXAMPLE.DE)
1249 @return Array A list containing the names of all configured principals.
1250 */
1251 public function krb5_get_principal($server,$name)
1252 {
1253 $ret = array();
1255 /* Check if the given name is a valid request value
1256 */
1257 if(!is_string($name) || empty($name)){
1258 trigger_error("The given principal name is not of type string or it is empty.");
1259 return($ret);
1260 }
1262 /* Check if the given server is a valid mac address
1263 */
1264 if(!tests::is_mac($server)){
1265 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1266 return($ret);
1267 }
1269 /* Prepare request event
1270 */
1271 $xml_msg =
1272 "<xml>".
1273 "<header>gosa_krb5_get_principal</header>".
1274 "<principal>".$name."</principal>".
1275 "<source>GOSA</source>".
1276 "<target>".$server."</target>".
1277 "</xml>";
1279 $res = $this->_send($xml_msg,TRUE);
1280 if(isset($res['XML'])){
1281 return($res['XML']);
1282 }else{
1283 return($ret);
1284 }
1285 }
1288 /*! \brief Creates a given principal with a set of configuration settings.
1289 For a list of configurable attributes have a look at 'krb5_get_principal()'.
1290 (Uses the GOsa support daemon instead of the ldap database.)
1291 @pram String The name of the principal to update. (e.g. peter@EXAMPLE.DE)
1292 @return Boolean TRUE on success else FALSE.
1293 */
1294 public function krb5_add_principal($server,$name,$values)
1295 {
1296 $ret = FALSE;
1298 /* Check if the given name is a valid request value
1299 */
1300 if(!is_string($name) || empty($name)){
1301 trigger_error("The given principal name is not of type string or it is empty.");
1302 return($ret);
1303 }
1304 if(!is_array($values) || !count($values)){
1305 trigger_error("No valid update settings given. The parameter must be of type array and must contain at least one entry");
1306 return($ret);
1307 }
1309 /* Check if the given server is a valid mac address
1310 */
1311 if(!tests::is_mac($server)){
1312 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1313 return($ret);
1314 }
1316 $attrs = "";
1317 foreach($values as $key => $value){
1318 if(empty($key) || is_numeric($key)){
1319 trigger_error("Invalid configuration attribute given '".$key."=".$value."'.");
1320 return($ret);
1321 }
1322 $key = strtolower($key);
1323 if(is_array($value)){
1324 foreach($value as $val){
1325 $attrs.= "<$key>$val</$key>\n";
1326 }
1327 }else{
1328 $attrs.= "<$key>$value</$key>\n";
1329 }
1330 }
1332 /* Prepare request event
1333 */
1334 $xml_msg =
1335 "<xml>".
1336 "<header>gosa_krb5_create_principal</header>".
1337 "<principal>".$name."</principal>".
1338 $attrs.
1339 "<source>GOSA</source>".
1340 "<target>".$server."</target>".
1341 "</xml>";
1343 return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
1344 }
1347 /*! \brief Updates a given principal with a set of configuration settings.
1348 For a list of configurable attributes have a look at 'krb5_get_principal()'.
1349 (Uses the GOsa support daemon instead of the ldap database.)
1350 @pram String The name of the principal to update. (e.g. peter@EXAMPLE.DE)
1351 @return Boolean TRUE on success else FALSE.
1352 */
1353 public function krb5_set_principal($server,$name,$values)
1354 {
1355 $ret = FALSE;
1357 /* Check if the given name is a valid request value
1358 */
1359 if(!is_string($name) || empty($name)){
1360 trigger_error("The given principal name is not of type string or it is empty.");
1361 return($ret);
1362 }
1363 if(!is_array($values) || !count($values)){
1364 trigger_error("No valid update settings given. The parameter must be of type array and must contain at least one entry");
1365 return($ret);
1366 }
1368 /* Check if the given server is a valid mac address
1369 */
1370 if(!tests::is_mac($server)){
1371 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1372 return($ret);
1373 }
1375 $attrs = "";
1376 foreach($values as $key => $value){
1377 if(empty($key) || is_numeric($key)){
1378 trigger_error("Invalid configuration attribute given '".$key."=".$value."'.");
1379 return($ret);
1380 }
1381 $key = strtolower($key);
1382 if(is_array($value)){
1383 foreach($value as $val){
1384 $attrs.= "<$key>$val</$key>\n";
1385 }
1386 }else{
1387 $attrs.= "<$key>$value</$key>\n";
1388 }
1389 }
1391 /* Prepare request event
1392 */
1393 $xml_msg =
1394 "<xml>".
1395 "<header>gosa_krb5_modify_principal</header>".
1396 "<principal>".$name."</principal>".
1397 $attrs.
1398 "<source>GOSA</source>".
1399 "<target>".$server."</target>".
1400 "</xml>";
1402 return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
1403 }
1406 /*! \brief Removes the given principal.
1407 (Uses the GOsa support daemon instead of the ldap database.)
1408 @pram String The name of the principal. (e.g. peter@EXAMPLE.DE)
1409 @return Boollean TRUE on success else FALSE
1410 */
1411 public function krb5_del_principal($server,$name)
1412 {
1413 $ret = FALSE;
1415 /* Check if the given name is a valid request value
1416 */
1417 if(!is_string($name) || empty($name)){
1418 trigger_error("The given principal name is not of type string or it is empty.");
1419 return($ret);
1420 }
1422 /* Check if the given server is a valid mac address
1423 */
1424 if(!tests::is_mac($server)){
1425 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1426 return($ret);
1427 }
1429 /* Prepare request event
1430 */
1431 $xml_msg =
1432 "<xml>".
1433 "<header>gosa_krb5_del_principal</header>".
1434 "<principal>".$name."</principal>".
1435 "<source>GOSA</source>".
1436 "<target>".$server."</target>".
1437 "</xml>";
1439 return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
1440 }
1443 /*! \brief Returns a list of configured password policies.
1444 (Uses the GOsa support daemon instead of the ldap database.)
1445 @return Array A list of all configured password policies.
1446 */
1447 public function krb5_list_policies($server)
1448 {
1449 $res = array();
1451 /* Check if the given server is a valid mac address
1452 */
1453 if(!tests::is_mac($server)){
1454 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1455 return($ret);
1456 }
1458 /* Prepare request event
1459 */
1460 $xml_msg =
1461 "<xml>".
1462 "<header>gosa_krb5_list_policies</header>".
1463 "<source>GOSA</source>".
1464 "<target>".$server."</target>".
1465 "</xml>";
1467 $res = $this->_send($xml_msg,TRUE);
1469 /* Check if there are results for POLICY
1470 */
1471 if(isset($res['XML']['POLICY'])){
1473 /* Ensure that we return an array
1474 */
1475 $tmp = $res['XML']['POLICY'];
1476 if(!is_array($tmp)){
1477 $tmp = array($tmp);
1478 }
1479 return($tmp);
1480 }else{
1481 return(array());
1482 }
1483 }
1486 /*! \brief Returns a list of configured password policies.
1487 (Uses the GOsa support daemon instead of the ldap database.)
1488 @return Array The policy settings for the given policy name.
1489 */
1490 public function krb5_get_policy($server,$name)
1491 {
1492 $res = array();
1494 /* Check if the given name is a valid request value
1495 */
1496 if(!is_string($name) || empty($name)){
1497 trigger_error("The given policy name is not of type string or it is empty.");
1498 return($ret);
1499 }
1501 /* Check if the given server is a valid mac address
1502 */
1503 if(!tests::is_mac($server)){
1504 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1505 return($ret);
1506 }
1508 /* Prepare request event
1509 */
1510 $xml_msg =
1511 "<xml>".
1512 "<header>gosa_krb5_get_policy</header>".
1513 "<policy>".$name."</policy>".
1514 "<source>GOSA</source>".
1515 "<target>".$server."</target>".
1516 "</xml>";
1518 /* Possible attributes */
1519 $attrs = array("MASK","POLICY","PW_HISTORY_NUM","PW_MAX_LIFE",
1520 "PW_MIN_CLASSES","PW_MIN_LENGTH","PW_MIN_LIFE","POLICY_REFCNT");
1523 $tmp = $this->_send($xml_msg,TRUE);
1524 if(isset($tmp['XML'])){
1525 foreach($attrs as $attr){
1526 if(isset($tmp['XML'][$attr])){
1527 $ret[$attr] = $tmp['XML'][$attr];
1528 }else{
1529 $ret[$attr] = "";
1530 }
1531 }
1532 }
1533 return($ret);
1534 }
1537 /*! \brief Creates a new policy with a given set of configuration settings.
1538 For a list of configurable attributes have a look at 'krb5_get_policy()'.
1539 (Uses the GOsa support daemon instead of the ldap database.)
1540 @pram String The name of the policy to update.
1541 @pram Array The attributes to update
1542 @return Boolean TRUE on success else FALSE.
1543 */
1544 public function krb5_add_policy($server,$name,$values)
1545 {
1546 $ret = FALSE;
1548 /* Check if the given name is a valid request value
1549 */
1550 if(!is_string($name) || empty($name)){
1551 trigger_error("The given policy name is not of type string or it is empty.");
1552 return($ret);
1553 }
1554 if(!is_array($values) || !count($values)){
1555 trigger_error("No valid policy settings given. The parameter must be of type array and must contain at least one entry");
1556 return($ret);
1557 }
1559 /* Check if the given server is a valid mac address
1560 */
1561 if(!tests::is_mac($server)){
1562 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1563 return($ret);
1564 }
1567 /* Transform array into <xml>
1568 */
1569 $attrs = "";
1570 foreach($values as $id => $value){
1571 if(empty($id) || is_numeric($id)){
1572 trigger_error("Invalid policy configuration attribute given '".$id."=".$value."'.");
1573 return($ret);
1574 }
1575 $id = strtolower($id);
1576 $attrs.= "<$id>$value</$id>\n";
1577 }
1579 /* Prepare request event
1580 */
1581 $xml_msg =
1582 "<xml>".
1583 "<header>gosa_krb5_create_policy</header>".
1584 "<policy>".$name."</policy>".
1585 $attrs.
1586 "<source>GOSA</source>".
1587 "<target>".$server."</target>".
1588 "</xml>";
1590 return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
1591 }
1594 /*! \brief Updates a given policy with a set of configuration settings.
1595 For a list of configurable attributes have a look at 'krb5_get_policy()'.
1596 (Uses the GOsa support daemon instead of the ldap database.)
1597 @pram String The name of the policy to update.
1598 @return Boolean TRUE on success else FALSE.
1599 */
1600 public function krb5_set_policy($server,$name,$values)
1601 {
1602 $ret = FALSE;
1604 /* Check if the given name is a valid request value
1605 */
1606 if(!is_string($name) || empty($name)){
1607 trigger_error("The given policy name is not of type string or it is empty.");
1608 return($ret);
1609 }
1610 if(!is_array($values) || !count($values)){
1611 trigger_error("No valid policy settings given. The parameter must be of type array and must contain at least one entry");
1612 return($ret);
1613 }
1615 /* Check if the given server is a valid mac address
1616 */
1617 if(!tests::is_mac($server)){
1618 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1619 return($ret);
1620 }
1622 /* Transform array into <xml>
1623 */
1624 $attrs = "";
1625 foreach($values as $id => $value){
1626 if(preg_match("/^policy$/i",$id)) continue;
1627 if(empty($id) || is_numeric($id)){
1628 trigger_error("Invalid policy configuration attribute given '".$id."=".$value."'.");
1629 return($ret);
1630 }
1631 $id = strtolower($id);
1632 $attrs.= "<$id>$value</$id>\n";
1633 }
1635 /* Prepare request event
1636 */
1637 $xml_msg =
1638 "<xml>".
1639 "<header>gosa_krb5_modify_policy</header>".
1640 "<policy>".$name."</policy>".
1641 $attrs.
1642 "<source>GOSA</source>".
1643 "<target>".$server."</target>".
1644 "</xml>";
1646 return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
1647 }
1650 /*! \brief Removes the given password policy.
1651 (Uses the GOsa support daemon instead of the ldap database.)
1652 @return Boolean TRUE on success else FALSE
1653 */
1654 public function krb5_del_policy($server,$name)
1655 {
1656 $ret = FALSE;
1658 /* Check if the given server is a valid mac address
1659 */
1660 if(!tests::is_mac($server)){
1661 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1662 return($ret);
1663 }
1665 /* Check if the given name is a valid request value
1666 */
1667 if(!is_string($name) || empty($name)){
1668 trigger_error("The given policy name is not of type string or it is empty.");
1669 return($ret);
1670 }
1672 /* Prepare request event
1673 */
1674 $xml_msg =
1675 "<xml>".
1676 "<header>gosa_krb5_del_policy</header>".
1677 "<policy>".$name."</policy>".
1678 "<source>GOSA</source>".
1679 "<target>".$server."</target>".
1680 "</xml>";
1681 return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
1682 }
1685 /*! \brief Sets the password of for the given principal.
1686 (Uses the GOsa support daemon instead of the ldap database.)
1687 @param String The servers mac
1688 @param String The principals name
1689 @param String $the new password.
1690 @return Boolean TRUE on success else FALSE
1691 */
1692 public function krb5_set_password($server,$name,$password)
1693 {
1694 $ret = FALSE;
1696 /* Check if the given server is a valid mac address
1697 */
1698 if(!tests::is_mac($server)){
1699 trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
1700 return($ret);
1701 }
1703 /* Check if the given name is a valid request value
1704 */
1705 if(!is_string($name) || empty($name)){
1706 trigger_error("The given principal name is not of type string or it is empty.");
1707 return($ret);
1708 }
1710 /* Prepare request event
1711 */
1712 $xml_msg =
1713 "<xml>".
1714 "<header>gosa_krb5_set_password</header>".
1715 "<principal>".$name."</principal>".
1716 "<password>".$password."</password>".
1717 "<source>GOSA</source>".
1718 "<target>".$server."</target>".
1719 "</xml>";
1720 return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
1721 }
1724 /*! \brief Returns log file informations for a given mac address
1725 @param $mac The mac address to fetch logs for.
1726 @retrun Array A Multidimensional array containing log infos.
1727 MAC_00_01_6C_9D_B9_FA['install_20080311_090900'][0]=debconf.log
1728 MAC_00_01_6C_9D_B9_FA['install_20080311_090900'][1]=syslog.log
1729 install_20080313_144450 ...
1730 */
1731 public function get_log_info_for_mac($mac)
1732 {
1733 $xml_msg = "
1734 <xml>
1735 <header>gosa_show_log_by_mac</header>
1736 <target>GOSA</target>
1737 <source>GOSA</source>
1738 <mac>".$mac."</mac>
1739 </xml>";
1741 $res = $this->_send($xml_msg,TRUE);
1742 $ret = array();
1743 if(isset($res['XML'])){
1745 /* Filter all entry that look like this
1746 MAC_00_01_6C_9D_B9_FA
1747 */
1748 foreach($res['XML'] as $name => $entry){
1749 if(preg_match("/^MAC/",$name)){
1751 /* Get list of available log files
1752 */
1753 foreach($entry as $log_date){
1754 $xml_msg2 = "<xml>
1755 <header>gosa_show_log_files_by_date_and_mac</header>
1756 <target>GOSA</target>
1757 <source>GOSA</source>
1758 <date>".$log_date."</date>
1759 <mac>".$mac."</mac>
1760 </xml>";
1762 $ret[$mac][$log_date] = array();
1763 $res = $this->_send($xml_msg2,TRUE);
1764 $ret[$mac][$log_date]['DATE_STR'] = $log_date;
1765 $ret[$mac][$log_date]['REAL_DATE'] = strtotime(preg_replace("/[^0-9]*/","",$log_date));
1766 if(isset($res['XML']['SHOW_LOG_FILES_BY_DATE_AND_MAC'])){
1767 $ret[$mac][$log_date]['FILES'] = $res['XML']['SHOW_LOG_FILES_BY_DATE_AND_MAC'];
1768 }
1769 }
1770 }
1771 }
1772 }
1773 return($ret);
1774 }
1776 public function get_log_file($mac,$date,$file)
1777 {
1778 $xml_msg ="
1779 <xml>
1780 <header>gosa_get_log_file_by_date_and_mac</header>
1781 <target>GOSA</target>
1782 <source>GOSA</source>
1783 <date>".$date."</date>
1784 <mac>".$mac."</mac>
1785 <log_file>".$file."</log_file>
1786 </xml>";
1788 $res = $this->_send($xml_msg,TRUE);
1789 if(isset($res['XML'][strtoupper($file)])){
1790 return(base64_decode($res['XML'][strtoupper($file)]));
1791 }
1792 return("");
1793 }
1794 }
1796 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1797 ?>