Code

Added ogroup acls
[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;
21   var $mapActions         = array("reboot"          => "",
22                             "instant_update"  => "softupdate",
23                             "update"          => "sceduledupdate",
24                             "reinstall"       => "install",
25                             "rescan"          => "",
26                             "memcheck"        => "memcheck",
27                             "sysinfo"         => "sysinfo");
30   function termgroup ($config, $dn= NULL)
31   {
32     /***************
33       Some  initialisations
34      ***************/
36     plugin::plugin($config, $dn);
38     $ldap= $config->get_ldap_link();
40     $this->is_account = true;
41     $ui               = get_userinfo();
42     $acl              = get_permissions ($this->dn, $ui->subtreeACL);
43     $this->acl        = get_module_permission($acl, "group", $this->dn);
45     $this->modes["active"]= _("Activated");
46     $this->modes["locked"]= _("Locked");
47 //    $this->modes["memcheck"]= _("Memory test");
48 //    $this->modes["sysinfo"]= _("System analysis");
50     $this->orig_dn =    $this->dn;
52     /*************** 
53       Get mac addresses from member objects  
54      ***************/
56     /* We're only interested in the terminal members here, evaluate
57        these... */
58     if(isset($this->attrs['member'])){
59       for ($i= 0; $i<$this->attrs['member']['count']; $i++){
60         $member= $this->attrs['member'][$i];
61         $ldap->cat($member, array('objectClass', 'macAddress', 'cn'));
62         if (preg_match("/success/i", $ldap->error)){
63           $attrs = $ldap->fetch();
64           if (in_array("gotoTerminal", $attrs['objectClass']) ||
65               in_array("gotoWorkstation", $attrs['objectClass'])){
66             if (isset($attrs['macAddress'])){
67               $this->members[$attrs['cn'][0]]= $attrs['macAddress'][0];
68             } else {
69               $this->members[$attrs['cn'][0]]= "";
70             }
71           }
72         }
73       }
74     }
76     /*************** 
77       Perpare NTP settings 
78      ***************/
80     /* Create used ntp server array */
81     $this->gotoNtpServer= array();
82     if(isset($this->attrs['gotoNtpServer'])){
83       $this->inheritTimeServer = false;
84       unset($this->attrs['gotoNtpServer']['count']);
85       foreach($this->attrs['gotoNtpServer'] as $server){
86         $this->gotoNtpServer[$server] = $server;
87       }
88     }
90     /* Set inherit checkbox state */
91     if(in_array("default",$this->gotoNtpServer)){
92       $this->inheritTimeServer = true;
93       $this->gotoNtpServer=array();
94     }
96     /* Create available ntp options */
97     $this->gotoNtpServers = $this->config->data['SERVERS']['NTP'];
98     foreach($this->gotoNtpServers as $key => $server){
99       if($server == "default"){
100         unset($this->gotoNtpServers[$key]);
101       }
102     }
105   }
107   function check()
108   {
109      /* Call common method to give check the hook */
110     $message= plugin::check();
112     if (chkacl($this->acl, "create") != ""){
113       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
114     }
116     /* Check for valid ntpServer selection */
117     if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
118       $message[]= _("There must be at least one NTP server selected.");
119     }
120     return($message);
121   }
123   function remove_from_parent()
124   {
125     /* Workstation startup is using gotoWorkstationTemplate too,
126         if we remove this oc all other not manged attributes will cause errors */
127     if(isset($this->attrs['gotoKernelParameters'])){
128       $this->objectclasses = array();
129     }
131     /* Remove acc */
132     plugin::remove_from_parent();
133     $ldap = $this->config->get_ldap_link();
134     $ldap->cd($this->orig_dn);
135     $ldap->modify($this->attrs);
136     $this->handle_post_events("remove");
137   }
139   function execute()
140   {
141     /* Call parent execute */
142     plugin::execute();
145     /*************** 
146       Handle requested action
147      ***************/
149     /* Watch for events */
150     if (isset($_POST['action'])){
151       $macaddresses="";
152       $names="";
153       foreach ($this->members as $cn => $macAddress){
154         $macaddresses.= "$macAddress ";
155         $names.= "$cn ";
156       }
158       if (isset($_POST['action'])){
159         $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
161         if ($cmd == ""){
162           print_red(_("No ACTIONCMD definition found in your gosa.conf"));
163         } else {
164           exec ($cmd." ".$macaddresses." ".escapeshellarg($_POST['saction']), $dummy, $retval);
165           if ($retval != 0){
166             print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
167           } else {
168             $this->didAction= TRUE;
170             /* Get dns from member objects. Create ldap object  */
171             $member = $this->parent->by_object['ogroup']->member;
172             $ldap = $this->config->get_ldap_link();
173             $ldap->cd($this->config->current['BASE']);
175             /* walk trough members and add FAIstate */ 
176             foreach($member as $dn =>  $object){
178               /* Get object */
179               $ldap->cat($dn,array("objectClass"));
180               $res                = $ldap->fetch();
181               $attrs              = array();
183               /* Add FAI state */
184               $attrs['FAIstate']  = "";
185               if(isset($this->mapActions[$_POST['saction']])){
186                 $attrs['FAIstate'] = $this->mapActions[$_POST ['saction']];
187               }
189               /* Fix objectClass index */
190               for($i = 0; $i < $res['objectClass']['count'] ; $i ++){
191                 $attrs['objectClass'][] = $res['objectClass'][$i];
192               }
194               /* Check if we must add the objectClass */
195               if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
196                 $attrs['objectClass'][] = "FAIobject";
197               }
199               if($attrs['FAIstate'] == ""){
200                 $attrs['FAIstate'] = array();
201               }
203               $ldap->cd($dn);
204               $ldap->modify($attrs);
205               show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/generic (FAIstate) with dn '%s' failed."),$dn));
206             }
207             $this->didAction= TRUE;
208           }
209         }
210       }
211     }
214     /*************** 
215       Add remove NTP server
216      ***************/
218     /* Add new ntp Server to our list */
219     if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers']))){
220       $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
221     }
223     /* Delete selected NtpServer for list of used servers  */
224     if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected']))){
225       foreach($_POST['gotoNtpServerSelected'] as $name){
226         unset($this->gotoNtpServer[$name]);
227       }
228     }
231     /*************** 
232       Prepare smarty 
233      ***************/
235     /* Set government mode */
236     $smarty= get_smarty();
238     foreach($this->attributes as $attr){
239       $smarty->assign($attr,      $this->$attr);
240       $smarty->assign($attr."ACL",chkacl($this->acl,$this->$attr));
241     }
243     /* Variables */
244     foreach(array("gotoMode","gotoNtpServer") as $val){
245       $smarty->assign($val."_select", $this->$val);
246       $smarty->assign($val."ACL", chkacl($this->acl, $val));
247     }
249     $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
250           "instant_update" => _("Instant update"),
251           "update" => _("Scheduled update"),
252           "reinstall" => _("Reinstall"),
253           "rescan" => _("Rescan hardware"),
254           "memcheck" => _("Memory test"),
255           "sysinfo"  => _("System analysis")));
257     $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
258     $smarty->assign("modes", $this->modes);
259     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
261     $tmp = array();
262     foreach($this->gotoNtpServers as $server){
263       if(!in_array($server,$this->gotoNtpServer)){
264         $tmp[$server] = $server;
265       }
266     }
268     $smarty->assign("gotoNtpServers",$tmp); 
269     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']); 
270     $smarty->assign("gotoSyslogServer_select", $this->gotoSyslogServer); 
272     /* Show main page */
273     return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE)));
274   }
276   function save_object()
277   {
278     plugin::save_object();  
279     /* Set inherit mode */
280     if(isset($_POST['workgeneric_posted'])){
281       if(isset($_POST["inheritTimeServer"])){
282         $this->inheritTimeServer = true;
283       }else{
284         $this->inheritTimeServer = false;
285       }
286     }
287   }
289   /* Save to LDAP */
290   function save()
291   {
292     plugin::save();
294     /***************
295       Prepare special vars 
296      ***************/
298     /* Unset some special vars ... */
299     foreach (array("gotoSyslogServer") as $val){
300       if ($this->attrs[$val] == "default"){
301         $this->attrs[$val]= array();
302       }
303     }
305     /* Update ntp server settings */
306     if($this->inheritTimeServer){
307       $this->attrs['gotoNtpServer'] = "default";
308     }else{
309       /* Set ntpServers */
310       $this->attrs['gotoNtpServer'] = array();
311       foreach($this->gotoNtpServer as $server){
312         $this->attrs['gotoNtpServer'][] = $server;
313       }
314     }
317     /***************
318       Write to ldap 
319      ***************/
321     /* Write back to ldap */
322     $ldap= $this->config->get_ldap_link();
323     $ldap->cd($this->dn);
324     $this->cleanup();
325     $ldap->modify ($this->attrs);
327     if(!$this->didAction){
328       $this->handle_post_events("modify");
329     }
330     show_ldap_error($ldap->get_error(), _("Saving workstation failed"));
332   }
333   
334   function plInfo()
335   {
336     return (array(
337           "plShortName"   => _("System"),
338           "plDescription" => _("System group"),
339           "plSelfModify"  => FALSE,
340           "plDepends"     => array(),
341           "plPriority"    => 0,
342           "plSection"     => array("administration"),
343           "plCategory"    => array("ogroups"),
344           "plProvidedAcls"=> array(
345             "gotoMode"          => _("Mode"),     
346             "gotoSyslogServer"  => _("Syslog server"), 
347             "FAIstate"          => _("Action flag"), 
348             "gotoNtpServer"     => _("Ntp server"))
349           ));
350   }
356 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
357 ?>