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();
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 $this->members[$attrs['cn'][0]]= $attrs['macAddress'][0];
27 }
28 }
29 }
31 /* Include config object */
32 $this->config= $config;
33 }
35 function execute()
36 {
38 /* Watch for events */
39 if (isset($_POST['action'])){
40 $macaddresses="";
41 $names="";
42 foreach ($this->members as $cn => $macAddress){
43 $macaddresses.= "$macAddress ";
44 $names.= "$cn ";
45 }
47 switch($_POST['saction']){
48 case 'wake':
49 $cmd= $this->search($this->config->data['TABS'], "terminfo", "WAKECMD");
50 if ($cmd == ""){
51 print_red(_("No WAKECMD definition found in your gosa.conf"));
52 } else {
53 exec ($cmd." ".$macaddresses, $dummy, $retval);
54 if ($retval != 0){
55 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
56 }
57 }
58 break;
60 case 'reboot':
61 $cmd= $this->search($this->config->data['TABS'], "terminfo", "REBOOTCMD");
62 if ($cmd == ""){
63 print_red(_("No REBOOTCMD definition found in your gosa.conf"));
64 } else {
65 exec ($cmd." ".$names, $dummy, $retval);
66 if ($retval != 0){
67 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
68 }
69 }
70 break;
72 case 'halt':
73 $cmd= $this->search($this->config->data['TABS'], "terminfo", "HALTCMD");
74 if ($cmd == ""){
75 print_red(_("No HALTCMD definition found in your gosa.conf"));
76 } else {
77 exec ($cmd." ".$names, $dummy, $retval);
78 if ($retval != 0){
79 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
80 }
81 }
82 break;
83 }
84 }
88 /* Set government mode */
89 $smarty= get_smarty();
91 $smarty->assign("actions", array("wake" => _("Wake up"), "halt" => _("Switch off"), "reboot" => _("Reboot")));
92 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
94 /* Show main page */
95 return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE)));
96 }
98 }
101 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
102 ?>