Code

b7219b48e552423a2334972c53bcea660cabbf09
[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();
48     /* Watch for events */
49     if (isset($_POST['action'])){
50       $macaddresses="";
51       $names="";
52       foreach ($this->members as $cn => $macAddress){
53         $macaddresses.= "$macAddress ";
54         $names.= "$cn ";
55       }
57       switch($_POST['saction']){
58         case 'wake':
59           $cmd= search_config($this->config->data['TABS'], "terminfo", "WAKECMD");
60           if ($cmd == ""){
61             print_red(_("No WAKECMD definition found in your gosa.conf"));
62           } else {
63             exec ($cmd." ".$macaddresses, $dummy, $retval);
64             if ($retval != 0){
65               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
66             }
67           }
68           break;
70         case 'reboot':
71           $cmd= search_config($this->config->data['TABS'], "terminfo", "REBOOTCMD");
72           if ($cmd == ""){
73             print_red(_("No REBOOTCMD definition found in your gosa.conf"));
74           } else {
75             exec ($cmd." ".$names, $dummy, $retval);
76             if ($retval != 0){
77               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
78             }
79           }
80           break;
82         case 'halt':
83           $cmd= search_config($this->config->data['TABS'], "terminfo", "HALTCMD");
84           if ($cmd == ""){
85             print_red(_("No HALTCMD definition found in your gosa.conf"));
86           } else {
87             exec ($cmd." ".$names, $dummy, $retval);
88             if ($retval != 0){
89               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
90             }
91           }
92           break;
93       }
94     }
95  
97     
98     /* Set government mode */
99     $smarty= get_smarty();
101     $smarty->assign("actions", array("wake" => _("Wake up"), "halt" => _("Switch off"), "reboot" => _("Reboot")));
102     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
104     /* Show main page */
105     return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE)));
106   }
111 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
112 ?>