Code

Added anyway edit to fai class
[gosa.git] / plugins / admin / ogroups / class_termgroup.inc
1 <?php
3 class termgroup extends plugin
4 {
5   /* attribute list for save action */
6   var $attributes= array();
7   var $objectclasses= array();
9   var $members= array();
11   function termgroup ($config, $dn= NULL)
12   {
13     plugin::plugin($config, $dn);
14     $ldap= $config->get_ldap_link();
16     
17     /* We're only interested in the terminal members here, evaluate
18        these... */
19     for ($i= 0; $i<$this->attrs['member']['count']; $i++){
20       $member= $this->attrs['member'][$i];
21       $ldap->cat($member);
22       if (preg_match("/success/i", $ldap->error)){
23         $attrs = $ldap->fetch();
24         if (in_array("gotoTerminal", $attrs['objectClass']) ||
25             in_array("gotoWorkstation", $attrs['objectClass'])){
26           if (isset($attrs['macAddress'])){
27             $this->members[$attrs['cn'][0]]= $attrs['macAddress'][0];
28           } else {
29             $this->members[$attrs['cn'][0]]= "";
30           }
31         }
32       }
33     }
35     /* Include config object */
36     $this->config= $config;
37   }
39   function check()
40   {
41   }
43   function execute()
44   {
45         /* Call parent execute */
46         plugin::execute();
49     /* Watch for events */
50     if (isset($_POST['action'])){
51       $macaddresses="";
52       $names="";
53       foreach ($this->members as $cn => $macAddress){
54         $macaddresses.= "$macAddress ";
55         $names.= "$cn ";
56       }
58       switch($_POST['saction']){
59         case 'wake':
60           $cmd= search_config($this->config->data['TABS'], "terminfo", "WAKECMD");
61           if ($cmd == ""){
62             print_red(_("No WAKECMD definition found in your gosa.conf"));
63           } else {
64             exec ($cmd." ".$macaddresses, $dummy, $retval);
65             if ($retval != 0){
66               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
67             }
68           }
69           break;
71         case 'reboot':
72           $cmd= search_config($this->config->data['TABS'], "terminfo", "REBOOTCMD");
73           if ($cmd == ""){
74             print_red(_("No REBOOTCMD definition found in your gosa.conf"));
75           } else {
76             exec ($cmd." ".$names, $dummy, $retval);
77             if ($retval != 0){
78               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
79             }
80           }
81           break;
83         case 'halt':
84           $cmd= search_config($this->config->data['TABS'], "terminfo", "HALTCMD");
85           if ($cmd == ""){
86             print_red(_("No HALTCMD definition found in your gosa.conf"));
87           } else {
88             exec ($cmd." ".$names, $dummy, $retval);
89             if ($retval != 0){
90               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
91             }
92           }
93           break;
94       }
95     }
96  
98     
99     /* Set government mode */
100     $smarty= get_smarty();
102     $smarty->assign("actions", array("wake" => _("Wake up"), "halt" => _("Switch off"), "reboot" => _("Reboot")));
103     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
105     /* Show main page */
106     return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE)));
107   }
112 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
113 ?>