Code

f9548a12c6657a4bb99e2be759f3da5c2ac758c2
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
1 <?php
2 class workstartup extends plugin
3 {
4   /* CLI vars */
5   var $cli_summary= "Manage terminal startup options";
6   var $cli_description= "Some longer text\nfor help";
7   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* Generic terminal attributes */
10   var $bootmode= "G";
11   var $goLdapServerList= array("default");
12   var $gotoBootKernel= "default";
13   var $gotoKernelParameters= "";
14   var $gotoLdapServer= "";
15   var $gotoModules= array();
16   var $gotoAutoFs= array();
17   var $gotoFilesystem= array();
18   var $gotoTerminalPath= "";
19   var $FAIstatus= "";
20   var $FAIclass     = array();
21   var $FAIclasses   = array();
22   var $FAIclassInfo = array();
25   /* attribute list for save action */
26   var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare");
27   var $objectclasses= array("GOhard", "FAIobject");
29   /* Share */
30   var $gotoShares         = array();// Currently Share Option
31   var $gotoShare          = "";     // currently selected Share Option
32   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
33   var $gotoAvailableShares= array();// Available Shares for this account
35   /* Helper */
36   var $customParameters= "";
37   var $orig_dn= "";
38   var $ignore_account= TRUE;
40   function workstartup ($config, $dn= NULL)
41   {
42     plugin::plugin ($config, $dn);
44     /* Get arrays */
45     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
46       if (isset($this->attrs["$val"]["count"])){
47         for ($i= 0; $i<$this->attrs["count"]; $i++){
48           if (isset($this->attrs["$val"][$i])){
49             array_push($this->$val, $this->attrs["$val"][$i]);
50           }
51         }
52       }
53       sort ($this->$val);
54       $this->$val= array_unique($this->$val);
55     }
57     /* Parse Kernel Parameters to decide what boot mode is enabled */
58     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
59       $this->bootmode= "G";
60     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
61       $this->bootmode= "D";
62     } elseif ($this->gotoKernelParameters == "") {
63       $this->bootmode= "G";
64     } else {
65       $this->bootmode= "T";
66     }
67     if (preg_match("/ o /", $this->gotoKernelParameters)){
68       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
69     } else {
70       $this->customParameters= "";
71     }
73     /* Prepare Shares */
74     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
75       unset($this->attrs['gotoShare']['count']);
76       foreach($this->attrs['gotoShare'] as $share){
77         $tmp = $tmp2 = array();
78         $tmp = split("\|",$share);
79         $tmp2['server']      =$tmp[0];
80         $tmp2['name']        =$tmp[1];
81         $tmp2['mountPoint']  =$tmp[2];
82         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
83       }
84     }
86     $this->gotoShareSelections= $config->getShareList(true);
87     $this->gotoAvailableShares= $config->getShareList(false);
89     $ldap = $this->config->get_ldap_link();
90     $ldap->search("(objectClass=FAIprofile)",array("*"));
91     while($attr = $ldap->fetch()){
92       $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
93       $base =  "ou=fai,".preg_replace("/^.*ou=fai,/","",$attr['dn']);
94       $cn   = $attr['cn'][0];
95       $tmp[$cn] = $base;
96     }
98     foreach($tmp as $cn => $base){
100       $ldap->cd($base);
101       $ldap->search("(&(objectClass=*)(cn=".$cn."))",array("objectClass","cn"));
102       while($attr = $ldap->fetch()){
103   
104         if(in_array('FAIpackageList',$attr['objectClass'])){
105           $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
106           $tmp2[$cn]['FAIpackageList']['kzl']   = 'P'; 
107         }
108         if(in_array('FAItemplate',$attr['objectClass'])){
109           $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
110           $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
111         }
112         if(in_array('FAIvariable',$attr['objectClass'])){
113           $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
114           $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
115         }
116         if(in_array('FAIscript',$attr['objectClass'])){
117           $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
118           $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
119         }
120         if(in_array('FAIhook',$attr['objectClass'])){
121           $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
122           $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
123         }
124         if(in_array('FAIpartitionTable',$attr['objectClass'])){
125           $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
126           $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
127         }
128       }
129     }
131     $this->FAIclassInfo = $tmp2;
133     if(isset($this->attrs['FAIclass'])){
134       $tmp = array();
135       $tmp2 = $this->attrs['FAIclass'];
136       unset($tmp2['count']);
137       foreach($tmp2 as $class){
138         $tmp[$class] = $class;
139       }
140       $this->FAIclass = $tmp;
141     }
143     if(!is_array($this->FAIclass)){
144       $this->FAIclass = array();
145     }
148     $this->orig_dn= $this->dn;
149   }
151   function selectFriendlyClasses(){
152     $tmp=array();
153     foreach($this->FAIclasses as $class){
154       $str    = "";
155       if(isset($this->FAIclassInfo[$class])){
156         foreach($this->FAIclassInfo[$class] as $objs){
157           $str .= $objs['kzl']." "; 
158         }
159       }
160     $tmp[$class] = $class."&nbsp; [".$str."]";
161     }
162   return($tmp);
163   }
165   function execute()
166   {
167     /* Do we need to flip is_account state? */
168     if (isset($_POST['modify_state'])){
169       $this->is_account= !$this->is_account;
170     }
173     /* Do we represent a valid terminal? */
174     if (!$this->is_account && $this->parent == NULL){
175       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
176         _("This 'dn' has no terminal features.")."</b>";
177       return ($display);
178     }
180     /* Add module */
181     if (isset ($_POST['add_module'])){
182       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
183         $this->add_list ($this->gotoModules, $_POST['module']);
184       }
185     }
187     /* Delete module */
188     if (isset ($_POST['delete_module'])){
189       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
190         $this->del_list ($this->gotoModules, $_POST['modules_list']);
191       }
192     }
194     /* FAI class management */
195     
196     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
197       $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
198     }
201     if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
202       if(isset($this->FAIclass[$_POST['FAIclassSel']])){
203         unset($this->FAIclass[$_POST['FAIclassSel']]);
204       }
205     }
216     /* Show main page */
217     $smarty= get_smarty();
219     /* In this section server shares will be defined
220      * A user can select one of the given shares and a mount point
221      *  and attach this combination to his setup.
222      */
223     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
224     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
226     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
227      * This entry will be, a combination of mountPoint and sharedefinitions
228      */
229     if(isset($_POST['gotoShareAdd'])){
230       /* We assign a share to this user, if we don't know where to mount the share */
231       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
232         print_red(_("You must specify a valid mount point."));
233       }else{
234         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
235         $s_mount = $_POST['gotoShareMountPoint'];
236         /* Preparing the new assignment */
237         $this->gotoShares[$a_share['name']]=$a_share;
238         $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
239       }
240     }
242     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
243      * If there is no defined share selected, we will abort the deletion without any message
244      */
245     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
246       unset($this->gotoShares[$_POST['gotoShare']]);
247     }
249     $smarty->assign("gotoShares",$this->printOutAssignedShares());
250     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
252     /* Arrays */
253     $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
254     $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
255     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
256     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
257       $smarty->assign("$val", $this->$val);
258     }
260     /* Values */
261     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass") as $val){
262       $smarty->assign($val, $this->$val);
263       $smarty->assign($val."ACL", chkacl($this->acl, $val));
264     }
265    
266     
267     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
268     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
269     $smarty->assign("FAIclassKeys",$this->FAIclass);
271     /* Radio button group */
272     if (preg_match("/G/", $this->bootmode)) {
273       $smarty->assign("graphicalbootup", "checked");
274     } else {
275       $smarty->assign("graphicalbootup", "");
276     }
277     if (preg_match("/T/", $this->bootmode)) {
278       $smarty->assign("textbootup", "checked");
279     } else {
280       $smarty->assign("textbootup", "");
281     }
282     if (preg_match("/D/", $this->bootmode)) {
283       $smarty->assign("debugbootup", "checked");
284     } else {
285       $smarty->assign("debugbootup", "");
286     }
288     /* ACL's */
289     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
290       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
291     }
293     /* Show main page */
294     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE)));
295   }
297   function remove_from_parent()
298   {
299     $ldap= $this->config->get_ldap_link();
300     $ldap->rmdir($this->dn);
301     show_ldap_error($ldap->get_error());
302     $this->handle_post_events("remove");
303   }
306   /* Save data to object */
307   function save_object()
308   {
309     plugin::save_object();
311     /* Save group radio buttons */
312     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
313       $this->bootmode= $_POST["bootmode"];
314     }
316     /* Save kernel parameters */
317     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
318       $this->customParameters= $_POST["customParameters"];
319     }
320   }
323   /* Save to LDAP */
324   function save()
325   {
326     /* Find proper terminal path for tftp configuration
327        FIXME: This is suboptimal when the default has changed to
328        another location! */
329     if ($this->gotoTerminalPath == "default"){
330       $ldap= $this->config->get_ldap_link();
332       /* Strip relevant part from dn, keep trailing ',' */
333       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
334       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
336       /* Walk from top to base and try to load default values for
337          'gotoTerminalPath'. Abort when an entry is found. */
338       while (TRUE){
339         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
341         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
342             $this->config->current['BASE']);
343         $attrs= $ldap->fetch();
344         if (isset($attrs['gotoTerminalPath'])){
345           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
346           break;
347         }
349         /* Nothing left? */
350         if ($tmp == ""){
351           break;
352         }
353       }
354     }
356     /* Add semi automatic values */
357     // FIXME: LDAP Server may not be set here...
358     $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
359       $this->gotoTerminalPath.
360       ",ro,hard,nolock,fg,rsize=8192 ".
361       "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
363     switch ($this->bootmode){
364       case "D":
365         $this->gotoKernelParameters.= " debug";
366       break;
367       case "G":
368         $this->gotoKernelParameters.= " splash=silent";
369       break;
370     }
371     if ($this->customParameters != ""){
372       $this->gotoKernelParameters.= " o ".$this->customParameters;
373     }
375     $tmp = array();
376     foreach($this->FAIclass as $class){
377       $tmp[] = $class;
378     }
379     $this->FAIclass = $tmp;
381     plugin::save();
383     /* Add missing arrays */
384     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
385       if (isset ($this->$val) && count ($this->$val) != 0){
386     
387         $this->attrs["$val"]= array_unique($this->$val);
388       }
389       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
390     }
391     /* Strip out 'default' values */
392     if ($this->attrs['gotoLdapServer'] == "default"){
393       unset ($this->attrs['gotoLdapServer']);
394     }
396     $tmp = array();
397     foreach($this->FAIclass as $class){
398       $tmp[] = $class;
399     }
400     $this->FAIclass = $tmp;
401     /* Write back to ldap */
402     
404     $ldap= $this->config->get_ldap_link();
405     $ldap->cd($this->dn);
406     $ldap->modify($this->attrs);
407     show_ldap_error($ldap->get_error());
408     $this->handle_post_events("modify");
409   }
411   /* Add value to array, check if unique */
412   function add_list (&$array, $value)
413   {
414     if ($value != ""){
415       $array[]= $value;
416       sort($array);
417       array_unique ($array);
418     }
419   }
422   /* Delete value to array, check if unique */
423   function del_list (&$array, $list)
424   {
425     $tmp= array();
426     foreach ($array as $mod){
427       if (!in_array($mod, $list)){
428         $tmp[]= $mod;
429       }
430     }
431     $array= $tmp;
432   }
434   /* Generate ListBox frindly output for the defined shares
435    * Possibly Add or remove an attribute here,
436    */
437   function printOutAssignedShares()
438   {
439     $a_return = array();
440     if(is_array($this->gotoShares)){
441       foreach($this->gotoShares as $share){
442         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
443       }
444     }
445     return($a_return);
446   }
450 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
451 ?>