Code

eaf51fb6df1ae1c6aee00c199a032bbe4aea4863
[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     $tmp = array();
90     $ldap = $this->config->get_ldap_link();
91     $ldap->cd($this->config->current['BASE']);
92     $ldap->search("(objectClass=FAIprofile)",array("cn"));
93     while($attr = $ldap->fetch()){
94       $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
95       $base =  "ou=fai,".preg_replace("/^.*ou=fai,/","",$attr['dn']);
96       $cn   = $attr['cn'][0];
97       $tmp[$cn] = $base;
98     }
101     $tmp2 = array();
102   
103     foreach($tmp as $cn => $base){
105       $ldap->cd($base);
106       $ldap->search("(&(objectClass=*)(cn=".$cn."))",array("objectClass","cn"));
107       while($attr = $ldap->fetch()){
108   
109         if(in_array('FAIpackageList',$attr['objectClass'])){
110           $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
111           $tmp2[$cn]['FAIpackageList']['kzl']   = 'P'; 
112         }
113         if(in_array('FAItemplate',$attr['objectClass'])){
114           $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
115           $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
116         }
117         if(in_array('FAIvariable',$attr['objectClass'])){
118           $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
119           $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
120         }
121         if(in_array('FAIscript',$attr['objectClass'])){
122           $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
123           $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
124         }
125         if(in_array('FAIhook',$attr['objectClass'])){
126           $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
127           $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
128         }
129         if(in_array('FAIpartitionTable',$attr['objectClass'])){
130           $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
131           $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
132         }
133       }
134     }
136     $this->FAIclassInfo = $tmp2;
138     if(isset($this->attrs['FAIclass'])){
139       $tmp = array();
140       $tmp2 = $this->attrs['FAIclass'];
141       unset($tmp2['count']);
142       foreach($tmp2 as $class){
143         $tmp[$class] = $class;
144       }
145       $this->FAIclass = $tmp;
146     }
148     if(!is_array($this->FAIclass)){
149       $this->FAIclass = array();
150     }
153     $this->orig_dn= $this->dn;
154   }
156   function selectFriendlyClasses(){
157     $tmp=array();
158     foreach($this->FAIclasses as $class){
159       $str    = "";
160       if(isset($this->FAIclassInfo[$class])){
161         foreach($this->FAIclassInfo[$class] as $objs){
162           $str .= $objs['kzl']." "; 
163         }
164       }
165     $tmp[$class] = $class."&nbsp; [".$str."]";
166     }
167   return($tmp);
168   }
170   function execute()
171   {
172     /* Do we need to flip is_account state? */
173     if (isset($_POST['modify_state'])){
174       $this->is_account= !$this->is_account;
175     }
178     /* Do we represent a valid terminal? */
179     if (!$this->is_account && $this->parent == NULL){
180       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
181         _("This 'dn' has no terminal features.")."</b>";
182       return ($display);
183     }
185     /* Add module */
186     if (isset ($_POST['add_module'])){
187       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
188         $this->add_list ($this->gotoModules, $_POST['module']);
189       }
190     }
192     /* Delete module */
193     if (isset ($_POST['delete_module'])){
194       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
195         $this->del_list ($this->gotoModules, $_POST['modules_list']);
196       }
197     }
199     /* FAI class management */
200     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
202       $found = 0 ; 
204       foreach($this->FAIclass as $name){
205         if(isset($this->FAIclassInfo[$name])){
206           foreach($this->FAIclassInfo[$name] as $atr){
207             if($atr['obj'] == "FAIpartitionTable"){
208               $found ++ ; 
209             }
210           }
211         }
212       }
214       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpackageList']))&&($found>0)){
215         print_red(_("There is already a profile in your selection that contain partition table configuratons."));
216       }else{
217         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
218       }
219     }
221     if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
222       if(isset($this->FAIclass[$_POST['FAIclassSel']])){
223         unset($this->FAIclass[$_POST['FAIclassSel']]);
224       }
225     }
227     /* Show main page */
228     $smarty= get_smarty();
230     /* In this section server shares will be defined
231      * A user can select one of the given shares and a mount point
232      *  and attach this combination to his setup.
233      */
234     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
235     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
237     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
238      * This entry will be, a combination of mountPoint and sharedefinitions
239      */
240     if(isset($_POST['gotoShareAdd'])){
241       /* We assign a share to this user, if we don't know where to mount the share */
242       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
243         print_red(_("You must specify a valid mount point."));
244       }else{
245         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
246         $s_mount = $_POST['gotoShareMountPoint'];
247         /* Preparing the new assignment */
248         $this->gotoShares[$a_share['name']]=$a_share;
249         $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
250       }
251     }
253     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
254      * If there is no defined share selected, we will abort the deletion without any message
255      */
256     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
257       unset($this->gotoShares[$_POST['gotoShare']]);
258     }
260     $smarty->assign("gotoShares",$this->printOutAssignedShares());
261     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
263     /* Arrays */
264     $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
265     $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
266     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
267     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
268       $smarty->assign("$val", $this->$val);
269     }
271     /* Values */
272     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass") as $val){
273       $smarty->assign($val, $this->$val);
274       $smarty->assign($val."ACL", chkacl($this->acl, $val));
275     }
276    
277     
278     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
279     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
280     $smarty->assign("FAIclassKeys",$this->FAIclass);
282     /* Radio button group */
283     if (preg_match("/G/", $this->bootmode)) {
284       $smarty->assign("graphicalbootup", "checked");
285     } else {
286       $smarty->assign("graphicalbootup", "");
287     }
288     if (preg_match("/T/", $this->bootmode)) {
289       $smarty->assign("textbootup", "checked");
290     } else {
291       $smarty->assign("textbootup", "");
292     }
293     if (preg_match("/D/", $this->bootmode)) {
294       $smarty->assign("debugbootup", "checked");
295     } else {
296       $smarty->assign("debugbootup", "");
297     }
299     /* ACL's */
300     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
301       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
302     }
304     /* Show main page */
305     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE)));
306   }
308   function remove_from_parent()
309   {
310     $ldap= $this->config->get_ldap_link();
311     $ldap->rmdir($this->dn);
312     show_ldap_error($ldap->get_error());
313     $this->handle_post_events("remove");
314   }
317   /* Save data to object */
318   function save_object()
319   {
320     plugin::save_object();
322     /* Save group radio buttons */
323     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
324       $this->bootmode= $_POST["bootmode"];
325     }
327     /* Save kernel parameters */
328     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
329       $this->customParameters= $_POST["customParameters"];
330     }
331   }
334   /* Save to LDAP */
335   function save()
336   {
337     /* Find proper terminal path for tftp configuration
338        FIXME: This is suboptimal when the default has changed to
339        another location! */
340     if ($this->gotoTerminalPath == "default"){
341       $ldap= $this->config->get_ldap_link();
343       /* Strip relevant part from dn, keep trailing ',' */
344       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
345       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
347       /* Walk from top to base and try to load default values for
348          'gotoTerminalPath'. Abort when an entry is found. */
349       while (TRUE){
350         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
352         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
353             $this->config->current['BASE']);
354         $attrs= $ldap->fetch();
355         if (isset($attrs['gotoTerminalPath'])){
356           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
357           break;
358         }
360         /* Nothing left? */
361         if ($tmp == ""){
362           break;
363         }
364       }
365     }
367     /* Add semi automatic values */
368     // FIXME: LDAP Server may not be set here...
369     $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
370       $this->gotoTerminalPath.
371       ",ro,hard,nolock,fg,rsize=8192 ".
372       "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
374     switch ($this->bootmode){
375       case "D":
376         $this->gotoKernelParameters.= " debug";
377       break;
378       case "G":
379         $this->gotoKernelParameters.= " splash=silent";
380       break;
381     }
382     if ($this->customParameters != ""){
383       $this->gotoKernelParameters.= " o ".$this->customParameters;
384     }
386     $tmp = array();
387     foreach($this->FAIclass as $class){
388       $tmp[] = $class;
389     }
390     $this->FAIclass = $tmp;
392     plugin::save();
394     /* Add missing arrays */
395     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
396       if (isset ($this->$val) && count ($this->$val) != 0){
397     
398         $this->attrs["$val"]= array_unique($this->$val);
399       }
400       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
401     }
402     /* Strip out 'default' values */
403     if ($this->attrs['gotoLdapServer'] == "default"){
404       unset ($this->attrs['gotoLdapServer']);
405     }
407     $tmp = array();
408     foreach($this->FAIclass as $class){
409       $tmp[] = $class;
410     }
411     $this->attrs['FAIclass'] = $tmp;
412     /* Write back to ldap */
413    
414     if(count($this->attrs['FAIclass'])==0){
415       $tmp = array();
416       foreach($this->attrs['objectClass'] as $class){
417         if($class != "FAIobject"){
418           $tmp[] = $class;
419         }
420       }
421       $this->attrs['objectClass'] = $tmp;
422       $this->attrs['FAIclass'] = array();;
423     }
424  
426     $ldap= $this->config->get_ldap_link();
427     $ldap->cd($this->dn);
428     $ldap->modify($this->attrs);
429     show_ldap_error($ldap->get_error());
430     $this->handle_post_events("modify");
431   }
433   /* Add value to array, check if unique */
434   function add_list (&$array, $value)
435   {
436     if ($value != ""){
437       $array[]= $value;
438       sort($array);
439       array_unique ($array);
440     }
441   }
444   /* Delete value to array, check if unique */
445   function del_list (&$array, $list)
446   {
447     $tmp= array();
448     foreach ($array as $mod){
449       if (!in_array($mod, $list)){
450         $tmp[]= $mod;
451       }
452     }
453     $array= $tmp;
454   }
456   /* Generate ListBox frindly output for the defined shares
457    * Possibly Add or remove an attribute here,
458    */
459   function printOutAssignedShares()
460   {
461     $a_return = array();
462     if(is_array($this->gotoShares)){
463       foreach($this->gotoShares as $share){
464         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
465       }
466     }
467     return($a_return);
468   }
472 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
473 ?>