Code

reworked printer ppd selection
[gosa.git] / plugins / admin / systems / class_terminalStartup.inc
1 <?php
2 class termstartup 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 $gotoTerminalPath= "";
18   /* Share */
19   var $gotoShares         = array();// Currently Share Option
20   var $gotoShare          = "";     // currently selected Share Option
21   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
22   var $gotoAvailableShares= array();// Available Shares for this account
25   /* attribute list for save action */
26   var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters");
27   var $objectclasses= array("GOhard");
29   /* Helper */
30   var $customParameters= "";
31   var $orig_dn= "";
32   var $ignore_account= TRUE;
34   function termstartup ($config, $dn= NULL)
35   {
36     plugin::plugin ($config, $dn);
38     /* Get arrays */
39     foreach (array("gotoModules") as $val){
40       if (isset($this->attrs["$val"]["count"])){
41         for ($i= 0; $i<$this->attrs["count"]; $i++){
42           if (isset($this->attrs["$val"][$i])){
43             array_push($this->$val, $this->attrs["$val"][$i]);
44           }
45         }
46       }
47       sort ($this->$val);
48       $this->$val= array_unique($this->$val);
49     }
51     /* Parse Kernel Parameters to decide what boot mode is enabled */
52     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
53       $this->bootmode= "G";
54     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
55       $this->bootmode= "D";
56     } elseif ($this->gotoKernelParameters == "") {
57       $this->bootmode= "G";
58     } else {
59       $this->bootmode= "T";
60     }
61     if (preg_match("/ o /", $this->gotoKernelParameters)){
62       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
63     } else {
64       $this->customParameters= "";
65     }
67     /* Prepare Shares */
68     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
69       unset($this->attrs['gotoShare']['count']);
70       foreach($this->attrs['gotoShare'] as $share){
71         $tmp = $tmp2 = array();
72         $tmp = split("\|",$share);
73         $tmp2['server']      =$tmp[0];
74         $tmp2['name']        =$tmp[1];
75         $tmp2['mountPoint']  =$tmp[2];
76         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
77       }
78     }
80     $this->gotoShareSelections= $config->getShareList(true);
81     $this->gotoAvailableShares= $config->getShareList(false);
83     $this->orig_dn= $this->dn;
84   }
86   function execute()
87   {
88     /* Do we need to flip is_account state? */
89     if (isset($_POST['modify_state'])){
90       $this->is_account= !$this->is_account;
91     }
93     /* Do we represent a valid terminal? */
94     if (!$this->is_account && $this->parent == NULL){
95       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
96         _("This 'dn' has no terminal features.")."</b>";
97       return ($display);
98     }
100     /* Add module */
101     if (isset ($_POST['add_module'])){
102       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
103         $this->add_list ($this->gotoModules, $_POST['module']);
104       }
105     }
107     /* Delete module */
108     if (isset ($_POST['delete_module'])){
109       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
110         $this->del_list ($this->gotoModules, $_POST['modules_list']);
111       }
112     }
114     /* Show main page */
115     $smarty= get_smarty();
118        /* In this section server shares will be defined
119      * A user can select one of the given shares and a mount point
120      *  and attach this combination to his setup.
121      */
122     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
123     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
125     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
126      * This entry will be, a combination of mountPoint and sharedefinitions
127      */
128     if(isset($_POST['gotoShareAdd'])){
129       /* We assign a share to this user, if we don't know where to mount the share */
130       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
131         print_red(_("You must specify a valid mount point."));
132       }else{
133         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
134         $s_mount = $_POST['gotoShareMountPoint'];
135         /* Preparing the new assignment */
136         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
137         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
138       }
139     }
141     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
142      * If there is no defined share selected, we will abort the deletion without any message
143      */
144     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
145       unset($this->gotoShares[$_POST['gotoShare']]);
146     }
148     $smarty->assign("gotoShares",$this->printOutAssignedShares());
149     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
153     /* Arrays */
154     $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
155     $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
156     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
157     $smarty->assign("gotoShareACL", chkacl($this->acl, "gotoShareACL"));
158     foreach (array("gotoModules" ) as $val){
159       $smarty->assign("$val", $this->$val);
160     }
162     /* Values */
163     foreach(array("gotoBootKernel", "customParameters") as $val){
164       $smarty->assign($val, $this->$val);
165       $smarty->assign($val."ACL", chkacl($this->acl, $val));
166     }
168     /* Radio button group */
169     if (preg_match("/G/", $this->bootmode)) {
170       $smarty->assign("graphicalbootup", "checked");
171     } else {
172       $smarty->assign("graphicalbootup", "");
173     }
174     if (preg_match("/T/", $this->bootmode)) {
175       $smarty->assign("textbootup", "checked");
176     } else {
177       $smarty->assign("textbootup", "");
178     }
179     if (preg_match("/D/", $this->bootmode)) {
180       $smarty->assign("debugbootup", "checked");
181     } else {
182       $smarty->assign("debugbootup", "");
183     }
185     /* ACL's */
186     foreach (array("gotoKernelParameters", "gotoModules") as $value){
187       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
188     }
190     /* Show main page */
191     return($smarty->fetch (get_template_path('terminalStartup.tpl', TRUE)));
192   }
194   function remove_from_parent()
195   {
196     $ldap= $this->config->get_ldap_link();
197     $ldap->rmdir($this->dn);
198     show_ldap_error($ldap->get_error());
199     $this->handle_post_events("remove");
200   }
203   /* Save data to object */
204   function save_object()
205   {
206     plugin::save_object();
208     /* Save group radio buttons */
209     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
210       $this->bootmode= $_POST["bootmode"];
211     }
213     /* Save kernel parameters */
214     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
215       $this->customParameters= $_POST["customParameters"];
216     }
217   }
220   /* Save to LDAP */
221   function save()
222   {
223     /* Find proper terminal path for tftp configuration
224        FIXME: This is suboptimal when the default has changed to
225        another location! */
226     if ($this->gotoTerminalPath == "default"){
227       $ldap= $this->config->get_ldap_link();
229       /* Strip relevant part from dn, keep trailing ',' */
230       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
231       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
233       /* Walk from top to base and try to load default values for
234          'gotoTerminalPath'. Abort when an entry is found. */
235       while (TRUE){
236         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
238         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
239             $this->config->current['BASE']);
240         $attrs= $ldap->fetch();
241         if (isset($attrs['gotoTerminalPath'])){
242           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
243           break;
244         }
246         /* Nothing left? */
247         if ($tmp == ""){
248           break;
249         }
250       }
251     }
253     /* Add semi automatic values */
254     // FIXME: LDAP Server may not be set here...
255     $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
256       $this->gotoTerminalPath.
257       ",ro,hard,nolock,fg,rsize=8192 ".
258       "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
260     switch ($this->bootmode){
261       case "D":
262         $this->gotoKernelParameters.= " debug";
263       break;
264       case "G":
265         $this->gotoKernelParameters.= " splash=silent";
266       break;
267     }
268     if ($this->customParameters != ""){
269       $this->gotoKernelParameters.= " o ".$this->customParameters;
270     }
272     plugin::save();
274     /* Add missing arrays */
275     foreach (array("gotoModules") as $val){
276       if (isset ($this->$val) && count ($this->$val) != 0){
277     
278         $this->attrs["$val"]= array_unique($this->$val);
279       }
280       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
281     }
283     /* Strip out 'default' values */
284     if ($this->attrs['gotoLdapServer'] == "default"){
285       unset ($this->attrs['gotoLdapServer']);
286     }
288      /* prepare share settings */
289     $tmp = array();
290     foreach($this->gotoShares as $name => $settings){
291       $tmp2 = split("\|",$name);
292       $name = $tmp2[0];
293       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
294     }
295     $this->attrs['gotoShare']=$tmp;
297     /* Write back to ldap */
298     $ldap= $this->config->get_ldap_link();
299     $ldap->cd($this->dn);
300     $ldap->modify($this->attrs);
301     show_ldap_error($ldap->get_error());
302     $this->handle_post_events("modify");
303   }
305   /* Add value to array, check if unique */
306   function add_list (&$array, $value)
307   {
308     if ($value != ""){
309       $array[]= $value;
310       sort($array);
311       array_unique ($array);
312     }
313   }
316   /* Delete value to array, check if unique */
317   function del_list (&$array, $list)
318   {
319     $tmp= array();
320     foreach ($array as $mod){
321       if (!in_array($mod, $list)){
322         $tmp[]= $mod;
323       }
324     }
325     $array= $tmp;
326   }
328    /* Generate ListBox frindly output for the defined shares
329    * Possibly Add or remove an attribute here,
330    */
331   function printOutAssignedShares()
332   {
333     $a_return = array();
334     if(is_array($this->gotoShares)){
335       foreach($this->gotoShares as $share){
336         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
337       }
338     }
339     return($a_return);
340   }
345 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
346 ?>