Code

49d099202667cf6422bb458a4f4a3e1791f3ad2a
[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("gotoMode","gotoSyslogServer", "gotoNtpServer");
7   var $objectclasses= array("gotoWorkstationTemplate");
9   var $members= array();
11   var $gotoMode           = "locked";
12   var $gotoSyslogServer   = "";
13   var $gotoNtpServer      = array();
14   var $gotoNtpServers     = array();
15   var $modes              = array();
16   var $inheritTimeServer  = true;
17   var $acl                ;
18   var $is_account                 = true; 
19   var $orig_dn                = "";
20   var $didAction                  = FALSE;
23   function termgroup ($config, $dn= NULL)
24   {
25     /***************
26       Some  initialisations
27      ***************/
29     plugin::plugin($config, $dn);
31     $ldap= $config->get_ldap_link();
33     $this->is_account = true;
34     $ui               = get_userinfo();
35     $acl              = get_permissions ($this->dn, $ui->subtreeACL);
36     $this->acl        = get_module_permission($acl, "group", $this->dn);
38     $this->modes["active"]= _("Activated");
39     $this->modes["locked"]= _("Locked");
40     $this->modes["memcheck"]= _("Memory test");
41     $this->modes["sysinfo"]= _("System analysis");
43     $this->orig_dn =    $this->dn;
45     /*************** 
46       Get mac addresses from member objects  
47      ***************/
49     /* We're only interested in the terminal members here, evaluate
50        these... */
51     if(isset($this->attrs['member'])){
52       for ($i= 0; $i<$this->attrs['member']['count']; $i++){
53         $member= $this->attrs['member'][$i];
54         $ldap->cat($member, array('objectClass', 'macAddress', 'cn'));
55         if (preg_match("/success/i", $ldap->error)){
56           $attrs = $ldap->fetch();
57           if (in_array("gotoTerminal", $attrs['objectClass']) ||
58               in_array("gotoWorkstation", $attrs['objectClass'])){
59             if (isset($attrs['macAddress'])){
60               $this->members[$attrs['cn'][0]]= $attrs['macAddress'][0];
61             } else {
62               $this->members[$attrs['cn'][0]]= "";
63             }
64           }
65         }
66       }
67     }
69     /*************** 
70       Perpare NTP settings 
71      ***************/
73     /* Create used ntp server array */
74     $this->gotoNtpServer= array();
75     if(isset($this->attrs['gotoNtpServer'])){
76       $this->inheritTimeServer = false;
77       unset($this->attrs['gotoNtpServer']['count']);
78       foreach($this->attrs['gotoNtpServer'] as $server){
79         $this->gotoNtpServer[$server] = $server;
80       }
81     }
83     /* Set inherit checkbox state */
84     if(in_array("default",$this->gotoNtpServer)){
85       $this->inheritTimeServer = true;
86       $this->gotoNtpServer=array();
87     }
89     /* Create available ntp options */
90     $this->gotoNtpServers = $this->config->data['SERVERS']['NTP'];
91     foreach($this->gotoNtpServers as $key => $server){
92       if($server == "default"){
93         unset($this->gotoNtpServers[$key]);
94       }
95     }
98   }
100   function check()
101   {
102      /* Call common method to give check the hook */
103     $message= plugin::check();
105     if (chkacl($this->acl, "create") != ""){
106       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
107     }
109     /* Check for valid ntpServer selection */
110     if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
111       $message[]= _("There must be at least one NTP server selected, or the inherit mode activated.");
112     }
113     return($message);
114   }
116   function remove_from_parent()
117   {
118     /* Workstation startup is using gotoWorkstationTemplate too,
119         if we remove this oc all other not manged attributes will cause errors */
120     if(isset($this->attrs['gotoKernelParameters'])){
121       $this->objectclasses = array();
122     }
124     /* Remove acc */
125     plugin::remove_from_parent();
126     $ldap = $this->config->get_ldap_link();
127     $ldap->cd($this->orig_dn);
128     $ldap->modify($this->attrs);
129     $this->handle_post_events("remove");
130   }
132   function execute()
133   {
134     /* Call parent execute */
135     plugin::execute();
138     /*************** 
139       Handle requested action
140      ***************/
142     /* Watch for events */
143     if (isset($_POST['action'])){
144       $macaddresses="";
145       $names="";
146       foreach ($this->members as $cn => $macAddress){
147         $macaddresses.= "$macAddress ";
148         $names.= "$cn ";
149       }
151       if (isset($_POST['action'])){
152         $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
153         if ($cmd == ""){
154           print_red(_("No ACTIONCMD definition found in your gosa.conf"));
155         } else {
156           exec ($cmd." ".$macaddresses." ".escapeshellarg($_POST['saction']), $dummy, $retval);
157           if ($retval != 0){
158             print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
159           } else {
160             $this->didAction= TRUE;
161           }
162         }
163       }
164     }
167     /*************** 
168       Add remove NTP server
169      ***************/
171     /* Add new ntp Server to our list */
172     if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers']))){
173       $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
174     }
176     /* Delete selected NtpServer for list of used servers  */
177     if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected']))){
178       foreach($_POST['gotoNtpServerSelected'] as $name){
179         unset($this->gotoNtpServer[$name]);
180       }
181     }
184     /*************** 
185       Prepare smarty 
186      ***************/
188     /* Set government mode */
189     $smarty= get_smarty();
191     foreach($this->attributes as $attr){
192       $smarty->assign($attr,      $this->$attr);
193       $smarty->assign($attr."ACL",chkacl($this->acl,$this->$attr));
194     }
196     /* Variables */
197     foreach(array("gotoMode","gotoNtpServer") as $val){
198       $smarty->assign($val."_select", $this->$val);
199       $smarty->assign($val."ACL", chkacl($this->acl, $val));
200     }
202     /* Check if workstation is online */
203     $smarty->assign("actions", array(
204           "halt" =>             _("Switch off"), 
205           "reboot" =>           _("Reboot"),
206           "instant_update" =>   _("Instant update"),
207           "update" =>           _("Scheduled update"),
208           "reinstall" =>        _("Reinstall"),
209           "rescan" =>           _("Rescan hardware")));
211     $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
212     $smarty->assign("modes", $this->modes);
213     $smarty->assign("actions", array("wake" => _("Wake up"), "halt" => _("Switch off"), "reboot" => _("Reboot")));
214     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
215     $smarty->assign("gotoNtpServers",$this->gotoNtpServers); 
216     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']); 
217     $smarty->assign("gotoSyslogServer_select", $this->gotoSyslogServer); 
219     /* Show main page */
220     return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE)));
221   }
223   function save_object()
224   {
225     plugin::save_object();  
226     /* Set inherit mode */
227     if(isset($_POST['workgeneric_posted'])){
228       if(isset($_POST["inheritTimeServer"])){
229         $this->inheritTimeServer = true;
230       }else{
231         $this->inheritTimeServer = false;
232       }
233     }
234   }
236   /* Save to LDAP */
237   function save()
238   {
239     plugin::save();
241     /***************
242       Prepare special vars 
243      ***************/
245     /* Unset some special vars ... */
246     foreach (array("gotoSyslogServer") as $val){
247       if ($this->attrs[$val] == "default"){
248         $this->attrs[$val]= array();
249       }
250     }
252     /* Update ntp server settings */
253     if($this->inheritTimeServer){
254       $this->attrs['gotoNtpServer'] = "default";
255     }else{
256       /* Set ntpServers */
257       $this->attrs['gotoNtpServer'] = array();
258       foreach($this->gotoNtpServer as $server){
259         $this->attrs['gotoNtpServer'][] = $server;
260       }
261     }
264     /***************
265       Write to ldap 
266      ***************/
268     /* Write back to ldap */
269     $ldap= $this->config->get_ldap_link();
270     if ($this->orig_dn == 'new'){
271       $ldap->cd($this->config->current['BASE']);
272       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
273       $ldap->cd($this->dn);
274       $ldap->add($this->attrs);
275       if(!$this->didAction){
276         $this->handle_post_events("add");
277       }
278     } else {
279       if ($this->orig_dn != $this->dn){
280         $this->move($this->orig_dn, $this->dn);
281       }
282       $ldap->cd($this->dn);
283       $this->cleanup();
284       $ldap->modify ($this->attrs);
286       if(!$this->didAction){
287         $this->handle_post_events("modify");
288       }
289     }
290     show_ldap_error($ldap->get_error(), _("Saving workstation failed"));
291   }
294 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
295 ?>