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=center> <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 }
154 $smarty->assign("gotoKernelParameters", chkacl($this->acl, "gotoKernelParameters"));
156 /* Show main page */
157 return($smarty->fetch (get_template_path('startup.tpl', TRUE)));
158 }
160 function remove_from_parent()
161 {
162 $ldap= $this->config->get_ldap_link();
163 $ldap->rmdir($this->dn);
164 show_ldap_error($ldap->get_error());
165 $this->handle_post_events("remove");
166 }
169 /* Save data to object */
170 function save_object()
171 {
172 plugin::save_object();
174 /* Save group radio buttons */
175 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
176 $this->bootmode= $_POST["bootmode"];
177 }
179 /* Save kernel parameters */
180 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
181 $this->customParameters= $_POST["customParameters"];
182 }
183 }
186 /* Save to LDAP */
187 function save()
188 {
189 /* Find proper terminal path for tftp configuration
190 FIXME: This is suboptimal when the default has changed to
191 another location! */
192 if ($this->gotoTerminalPath == "default"){
193 $ldap= $this->config->get_ldap_link();
195 /* Strip relevant part from dn, keep trailing ',' */
196 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
197 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
199 /* Walk from top to base and try to load default values for
200 'gotoTerminalPath'. Abort when an entry is found. */
201 while (TRUE){
202 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
204 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
205 $this->config->current['BASE']);
206 $attrs= $ldap->fetch();
207 if (isset($attrs['gotoTerminalPath'])){
208 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
209 break;
210 }
212 /* Nothing left? */
213 if ($tmp == ""){
214 break;
215 }
216 }
217 }
219 /* Add semi automatic values */
220 // FIXME: LDAP Server may not be set here...
221 $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
222 $this->gotoTerminalPath.
223 ",ro,hard,nolock,fg,rsize=8192 ".
224 "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
226 switch ($this->bootmode){
227 case "D":
228 $this->gotoKernelParameters.= " debug";
229 break;
230 case "G":
231 $this->gotoKernelParameters.= " splash=silent";
232 break;
233 }
234 if ($this->customParameters != ""){
235 $this->gotoKernelParameters.= " o ".$this->customParameters;
236 }
238 plugin::save();
240 /* Add missing arrays */
241 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
242 if (isset ($this->$val) && count ($this->$val) != 0){
243 $this->attrs["$val"]= array_unique($this->$val);
244 }
245 }
247 /* Strip out 'default' values */
248 if ($this->attrs['gotoLdapServer'] == "default"){
249 unset ($this->attrs['gotoLdapServer']);
250 }
252 /* Write back to ldap */
253 $ldap= $this->config->get_ldap_link();
254 $ldap->cd($this->dn);
255 $ldap->modify($this->attrs);
256 show_ldap_error($ldap->get_error());
257 $this->handle_post_events("modify");
258 }
260 /* Add value to array, check if unique */
261 function add_list (&$array, $value)
262 {
263 if ($value != ""){
264 $array[]= $value;
265 sort($array);
266 array_unique ($array);
267 }
268 }
271 /* Delete value to array, check if unique */
272 function del_list (&$array, $list)
273 {
274 $tmp= array();
275 foreach ($array as $mod){
276 if (!in_array($mod, $list)){
277 $tmp[]= $mod;
278 }
279 }
280 $array= $tmp;
281 }
284 }
286 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
287 ?>