Code

next 4 classes
[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 $gotoAutoFs= array();
17   var $gotoFilesystem= array();
18   var $gotoTerminalPath= "";
20   /* attribute list for save action */
21   var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters");
22   var $objectclasses= array("GOhard");
24   /* Helper */
25   var $customParameters= "";
26   var $orig_dn= "";
29   function termstartup ($config, $dn= NULL)
30   {
31     plugin::plugin ($config, $dn);
33     /* Get arrays */
34     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
35       if (isset($this->attrs["$val"]["count"])){
36         for ($i= 0; $i<$this->attrs["count"]; $i++){
37           if (isset($this->attrs["$val"][$i])){
38             array_push($this->$val, $this->attrs["$val"][$i]);
39           }
40         }
41       }
42       sort ($this->$val);
43       $this->$val= array_unique($this->$val);
44     }
46     /* Parse Kernel Parameters to decide what boot mode is enabled */
47     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
48       $this->bootmode= "G";
49     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
50       $this->bootmode= "D";
51     } elseif ($this->gotoKernelParameters == "") {
52       $this->bootmode= "G";
53     } else {
54       $this->bootmode= "T";
55     }
56     if (preg_match("/ o /", $this->gotoKernelParameters)){
57       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
58     } else {
59       $this->customParameters= "";
60     }
62     $this->orig_dn= $this->dn;
63   }
65   function execute()
66   {
67     /* Do we need to flip is_account state? */
68     if (isset($_POST['modify_state'])){
69       $this->is_account= !$this->is_account;
70     }
72     /* Do we represent a valid terminal? */
73     if (!$this->is_account && $this->parent == NULL){
74       $display= "<img src=\"images/stop.png\" align=middle>&nbsp;<b>".
75         _("This 'dn' has no terminal features.")."</b>";
76       return ($display);
77     }
79     /* Add module */
80     if (isset ($_POST['add_module'])){
81       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
82         $this->add_list ($this->gotoModules, $_POST['module']);
83       }
84     }
86     /* Delete module */
87     if (isset ($_POST['delete_module'])){
88       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
89         $this->del_list ($this->gotoModules, $_POST['modules_list']);
90       }
91     }
93     /* Add autofs */
94     if (isset ($_POST['add_autofs'])){
95       if ($_POST['autofs'] != "" && chkacl ($this->acl, "gotoAutoFs") == ""){
96         $this->add_list ($this->gotoAutoFs, $_POST['autofs']);
97       }
98     }
100     /* Delete autofs */
101     if (isset ($_POST['delete_autofs'])){
102       if (count($_POST['autofs_list']) && chkacl ($this->acl, "gotoAutoFs") == ""){
103         $this->del_list ($this->gotoAutoFs, $_POST['autofs_list']);
104       }
105     }
107     /* Add filesystem */
108     if (isset ($_POST['add_fs'])){
109       if ($_POST['fstab'] != "" && chkacl ($this->acl, "gotoFilesystem") == ""){
110         $this->add_list ($this->gotoFilesystem, $_POST['fstab']);
111       }
112     }
114     /* Delete filesystem */
115     if (isset ($_POST['delete_fs'])){
116       if (count($_POST['fstab_list']) && chkacl ($this->acl, "gotoFilesystem") == ""){
117         $this->del_list ($this->gotoFilesystem, $_POST['fstab_list']);
118       }
119     }
121     /* Show main page */
122     $smarty= get_smarty();
124     /* Arrays */
125     $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
126     $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
127     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
128     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
129       $smarty->assign("$val", $this->$val);
130     }
132     /* Values */
133     foreach(array("gotoBootKernel", "customParameters") as $val){
134       $smarty->assign($val, $this->$val);
135       $smarty->assign($val."ACL", chkacl($this->acl, $val));
136     }
138     /* Radio button group */
139     if (preg_match("/G/", $this->bootmode)) {
140       $smarty->assign("graphicalbootup", "checked");
141     } else {
142       $smarty->assign("graphicalbootup", "");
143     }
144     if (preg_match("/T/", $this->bootmode)) {
145       $smarty->assign("textbootup", "checked");
146     } else {
147       $smarty->assign("textbootup", "");
148     }
149     if (preg_match("/D/", $this->bootmode)) {
150       $smarty->assign("debugbootup", "checked");
151     } else {
152       $smarty->assign("debugbootup", "");
153     }
155     /* ACL's */
156     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem") as $value){
157       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
158     }
160     /* Show main page */
161     return($smarty->fetch (get_template_path('startup.tpl', TRUE)));
162   }
164   function remove_from_parent()
165   {
166     $ldap= $this->config->get_ldap_link();
167     $ldap->rmdir($this->dn);
168     show_ldap_error($ldap->get_error());
169     $this->handle_post_events("remove");
170   }
173   /* Save data to object */
174   function save_object()
175   {
176     plugin::save_object();
178     /* Save group radio buttons */
179     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
180       $this->bootmode= $_POST["bootmode"];
181     }
183     /* Save kernel parameters */
184     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
185       $this->customParameters= $_POST["customParameters"];
186     }
187   }
190   /* Save to LDAP */
191   function save()
192   {
193     /* Find proper terminal path for tftp configuration
194        FIXME: This is suboptimal when the default has changed to
195        another location! */
196     if ($this->gotoTerminalPath == "default"){
197       $ldap= $this->config->get_ldap_link();
199       /* Strip relevant part from dn, keep trailing ',' */
200       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
201       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
203       /* Walk from top to base and try to load default values for
204          'gotoTerminalPath'. Abort when an entry is found. */
205       while (TRUE){
206         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
208         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
209             $this->config->current['BASE']);
210         $attrs= $ldap->fetch();
211         if (isset($attrs['gotoTerminalPath'])){
212           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
213           break;
214         }
216         /* Nothing left? */
217         if ($tmp == ""){
218           break;
219         }
220       }
221     }
223     /* Add semi automatic values */
224     // FIXME: LDAP Server may not be set here...
225     $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
226       $this->gotoTerminalPath.
227       ",ro,hard,nolock,fg,rsize=8192 ".
228       "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
230     switch ($this->bootmode){
231       case "D":
232         $this->gotoKernelParameters.= " debug";
233       break;
234       case "G":
235         $this->gotoKernelParameters.= " splash=silent";
236       break;
237     }
238     if ($this->customParameters != ""){
239       $this->gotoKernelParameters.= " o ".$this->customParameters;
240     }
242     plugin::save();
244     /* Add missing arrays */
245     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
246       if (isset ($this->$val) && count ($this->$val) != 0){
247         $this->attrs["$val"]= array_unique($this->$val);
248       }
249     }
251     /* Strip out 'default' values */
252     if ($this->attrs['gotoLdapServer'] == "default"){
253       unset ($this->attrs['gotoLdapServer']);
254     }
256     /* Write back to ldap */
257     $ldap= $this->config->get_ldap_link();
258     $ldap->cd($this->dn);
259     $ldap->modify($this->attrs);
260     show_ldap_error($ldap->get_error());
261     $this->handle_post_events("modify");
262   }
264   /* Add value to array, check if unique */
265   function add_list (&$array, $value)
266   {
267     if ($value != ""){
268       $array[]= $value;
269       sort($array);
270       array_unique ($array);
271     }
272   }
275   /* Delete value to array, check if unique */
276   function del_list (&$array, $list)
277   {
278     $tmp= array();
279     foreach ($array as $mod){
280       if (!in_array($mod, $list)){
281         $tmp[]= $mod;
282       }
283     }
284     $array= $tmp;
285   }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>