Code

b994a16c5eb57960260bd7df5516e0540ca23a71
[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     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
197       $found = 0 ; 
199       foreach($this->FAIclass as $name){
200         if(isset($this->FAIclassInfo[$name])){
201           foreach($this->FAIclassInfo[$name] as $atr){
202             if($atr['obj'] == "FAIpartitionTable"){
203               $found ++ ; 
204             }
205           }
206         }
207       }
209       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpackageList']))&&($found>0)){
210         print_red(_("There is already a profile in your selection that contain partition table configuratons."));
211       }else{
212         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
213       }
214     }
216     if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
217       if(isset($this->FAIclass[$_POST['FAIclassSel']])){
218         unset($this->FAIclass[$_POST['FAIclassSel']]);
219       }
220     }
222     /* Show main page */
223     $smarty= get_smarty();
225     /* In this section server shares will be defined
226      * A user can select one of the given shares and a mount point
227      *  and attach this combination to his setup.
228      */
229     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
230     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
232     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
233      * This entry will be, a combination of mountPoint and sharedefinitions
234      */
235     if(isset($_POST['gotoShareAdd'])){
236       /* We assign a share to this user, if we don't know where to mount the share */
237       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
238         print_red(_("You must specify a valid mount point."));
239       }else{
240         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
241         $s_mount = $_POST['gotoShareMountPoint'];
242         /* Preparing the new assignment */
243         $this->gotoShares[$a_share['name']]=$a_share;
244         $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
245       }
246     }
248     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
249      * If there is no defined share selected, we will abort the deletion without any message
250      */
251     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
252       unset($this->gotoShares[$_POST['gotoShare']]);
253     }
255     $smarty->assign("gotoShares",$this->printOutAssignedShares());
256     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
258     /* Arrays */
259     $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
260     $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
261     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
262     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
263       $smarty->assign("$val", $this->$val);
264     }
266     /* Values */
267     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass") as $val){
268       $smarty->assign($val, $this->$val);
269       $smarty->assign($val."ACL", chkacl($this->acl, $val));
270     }
271    
272     
273     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
274     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
275     $smarty->assign("FAIclassKeys",$this->FAIclass);
277     /* Radio button group */
278     if (preg_match("/G/", $this->bootmode)) {
279       $smarty->assign("graphicalbootup", "checked");
280     } else {
281       $smarty->assign("graphicalbootup", "");
282     }
283     if (preg_match("/T/", $this->bootmode)) {
284       $smarty->assign("textbootup", "checked");
285     } else {
286       $smarty->assign("textbootup", "");
287     }
288     if (preg_match("/D/", $this->bootmode)) {
289       $smarty->assign("debugbootup", "checked");
290     } else {
291       $smarty->assign("debugbootup", "");
292     }
294     /* ACL's */
295     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
296       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
297     }
299     /* Show main page */
300     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE)));
301   }
303   function remove_from_parent()
304   {
305     $ldap= $this->config->get_ldap_link();
306     $ldap->rmdir($this->dn);
307     show_ldap_error($ldap->get_error());
308     $this->handle_post_events("remove");
309   }
312   /* Save data to object */
313   function save_object()
314   {
315     plugin::save_object();
317     /* Save group radio buttons */
318     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
319       $this->bootmode= $_POST["bootmode"];
320     }
322     /* Save kernel parameters */
323     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
324       $this->customParameters= $_POST["customParameters"];
325     }
326   }
329   /* Save to LDAP */
330   function save()
331   {
332     /* Find proper terminal path for tftp configuration
333        FIXME: This is suboptimal when the default has changed to
334        another location! */
335     if ($this->gotoTerminalPath == "default"){
336       $ldap= $this->config->get_ldap_link();
338       /* Strip relevant part from dn, keep trailing ',' */
339       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
340       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
342       /* Walk from top to base and try to load default values for
343          'gotoTerminalPath'. Abort when an entry is found. */
344       while (TRUE){
345         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
347         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
348             $this->config->current['BASE']);
349         $attrs= $ldap->fetch();
350         if (isset($attrs['gotoTerminalPath'])){
351           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
352           break;
353         }
355         /* Nothing left? */
356         if ($tmp == ""){
357           break;
358         }
359       }
360     }
362     /* Add semi automatic values */
363     // FIXME: LDAP Server may not be set here...
364     $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
365       $this->gotoTerminalPath.
366       ",ro,hard,nolock,fg,rsize=8192 ".
367       "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
369     switch ($this->bootmode){
370       case "D":
371         $this->gotoKernelParameters.= " debug";
372       break;
373       case "G":
374         $this->gotoKernelParameters.= " splash=silent";
375       break;
376     }
377     if ($this->customParameters != ""){
378       $this->gotoKernelParameters.= " o ".$this->customParameters;
379     }
381     $tmp = array();
382     foreach($this->FAIclass as $class){
383       $tmp[] = $class;
384     }
385     $this->FAIclass = $tmp;
387     plugin::save();
389     /* Add missing arrays */
390     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
391       if (isset ($this->$val) && count ($this->$val) != 0){
392     
393         $this->attrs["$val"]= array_unique($this->$val);
394       }
395       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
396     }
397     /* Strip out 'default' values */
398     if ($this->attrs['gotoLdapServer'] == "default"){
399       unset ($this->attrs['gotoLdapServer']);
400     }
402     $tmp = array();
403     foreach($this->FAIclass as $class){
404       $tmp[] = $class;
405     }
406     $this->attrs['FAIclass'] = $tmp;
407     /* Write back to ldap */
408    
409     if(count($this->attrs['FAIclass'])==0){
410       $tmp = array();
411       foreach($this->attrs['objectClass'] as $class){
412         if($class != "FAIobject"){
413           $tmp[] = $class;
414         }
415       }
416       $this->attrs['objectClass'] = $tmp;
417       $this->attrs['FAIclass'] = array();;
418     }
419  
421     $ldap= $this->config->get_ldap_link();
422     $ldap->cd($this->dn);
423     $ldap->modify($this->attrs);
424     show_ldap_error($ldap->get_error());
425     $this->handle_post_events("modify");
426   }
428   /* Add value to array, check if unique */
429   function add_list (&$array, $value)
430   {
431     if ($value != ""){
432       $array[]= $value;
433       sort($array);
434       array_unique ($array);
435     }
436   }
439   /* Delete value to array, check if unique */
440   function del_list (&$array, $list)
441   {
442     $tmp= array();
443     foreach ($array as $mod){
444       if (!in_array($mod, $list)){
445         $tmp[]= $mod;
446       }
447     }
448     $array= $tmp;
449   }
451   /* Generate ListBox frindly output for the defined shares
452    * Possibly Add or remove an attribute here,
453    */
454   function printOutAssignedShares()
455   {
456     $a_return = array();
457     if(is_array($this->gotoShares)){
458       foreach($this->gotoShares as $share){
459         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
460       }
461     }
462     return($a_return);
463   }
467 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
468 ?>