35b521d49017d7f58a3f8469f8eff43db334b6b1
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 /* Call parent execute */
89 plugin::execute();
91 /* Do we need to flip is_account state? */
92 if (isset($_POST['modify_state'])){
93 $this->is_account= !$this->is_account;
94 }
96 /* Do we represent a valid terminal? */
97 if (!$this->is_account && $this->parent == NULL){
98 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
99 _("This 'dn' has no terminal features.")."</b>";
100 return ($display);
101 }
103 /* Add module */
104 if (isset ($_POST['add_module'])){
105 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
106 $this->add_list ($this->gotoModules, $_POST['module']);
107 }
108 }
110 /* Delete module */
111 if (isset ($_POST['delete_module'])){
112 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
113 $this->del_list ($this->gotoModules, $_POST['modules_list']);
114 }
115 }
117 /* Show main page */
118 $smarty= get_smarty();
121 /* In this section server shares will be defined
122 * A user can select one of the given shares and a mount point
123 * and attach this combination to his setup.
124 */
125 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
126 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
128 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
129 * This entry will be, a combination of mountPoint and sharedefinitions
130 */
131 if(isset($_POST['gotoShareAdd'])){
132 /* We assign a share to this user, if we don't know where to mount the share */
133 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
134 print_red(_("You must specify a valid mount point."));
135 }else{
136 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
137 $s_mount = $_POST['gotoShareMountPoint'];
138 /* Preparing the new assignment */
139 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
140 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
141 }
142 }
144 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
145 * If there is no defined share selected, we will abort the deletion without any message
146 */
147 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
148 unset($this->gotoShares[$_POST['gotoShare']]);
149 }
151 $smarty->assign("gotoShares",$this->printOutAssignedShares());
152 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
154 /* Arrays */
155 $tmp = $this->config->data['SERVERS']['LDAP'];
157 /* Create divSelectBox for ldap server selection
158 */
159 $SelectBoxLdapServer = new divSelectBox("LdapServer");
160 $SelectBoxLdapServer->SetHeight(80);
162 /* Set first entry as selected, if $this->gotoLdapServer is empty
163 * or given entry is no longer available ...
164 */
165 $found = false;
166 foreach($tmp as $server){
167 if($this->gotoLdapServer==$server){
168 $found = true;
169 }
170 }
172 /* Add Entries
173 */
174 foreach($tmp as $server){
175 $use ="";
176 if(($this->gotoLdapServer == $server) || ($found == false)) {
177 $found = true;
178 $use = " checked ";
179 };
181 $SelectBoxLdapServer->AddEntry(
182 array(
183 array("string"=>$server),
184 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$server."' ".$use.">",
185 "attach"=>"style='border-right:0px;'")
186 ));
187 }
189 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
191 $smarty->assign("gotoShareACL", chkacl($this->acl, "gotoShareACL"));
192 foreach (array("gotoModules" ) as $val){
193 $smarty->assign("$val", $this->$val);
194 }
196 /* Values */
197 foreach(array("gotoBootKernel", "customParameters") as $val){
198 $smarty->assign($val, $this->$val);
199 $smarty->assign($val."ACL", chkacl($this->acl, $val));
200 }
202 /* Radio button group */
203 if (preg_match("/G/", $this->bootmode)) {
204 $smarty->assign("graphicalbootup", "checked");
205 } else {
206 $smarty->assign("graphicalbootup", "");
207 }
208 if (preg_match("/T/", $this->bootmode)) {
209 $smarty->assign("textbootup", "checked");
210 } else {
211 $smarty->assign("textbootup", "");
212 }
213 if (preg_match("/D/", $this->bootmode)) {
214 $smarty->assign("debugbootup", "checked");
215 } else {
216 $smarty->assign("debugbootup", "");
217 }
219 /* ACL's */
220 foreach (array("gotoKernelParameters", "gotoModules") as $value){
221 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
222 }
224 /* Show main page */
225 return($smarty->fetch (get_template_path('terminalStartup.tpl', TRUE)));
226 }
228 function remove_from_parent()
229 {
230 $this->handle_post_events("remove");
231 }
234 /* Save data to object */
235 function save_object()
236 {
237 plugin::save_object();
239 /* Save group radio buttons */
240 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
241 $this->bootmode= $_POST["bootmode"];
242 }
244 /* Save kernel parameters */
245 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
246 $this->customParameters= $_POST["customParameters"];
247 }
248 }
251 /* Save to LDAP */
252 function save()
253 {
254 /* Find proper terminal path for tftp configuration
255 FIXME: This is suboptimal when the default has changed to
256 another location! */
257 if ($this->gotoTerminalPath == "default"){
258 $ldap= $this->config->get_ldap_link();
260 /* Strip relevant part from dn, keep trailing ',' */
261 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
262 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
264 /* Walk from top to base and try to load default values for
265 'gotoTerminalPath'. Abort when an entry is found. */
266 while (TRUE){
267 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
269 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
270 $this->config->current['BASE']);
271 $attrs= $ldap->fetch();
272 if (isset($attrs['gotoTerminalPath'])){
273 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
274 break;
275 }
277 /* Nothing left? */
278 if ($tmp == ""){
279 break;
280 }
281 }
282 }
284 /* Add semi automatic values */
285 // FIXME: LDAP Server may not be set here...
286 $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
287 $this->gotoTerminalPath.
288 ",ro,hard,nolock,fg,rsize=8192 ".
289 "ip=::::::dhcp ldap=".base64_encode($this->gotoLdapServer);
291 switch ($this->bootmode){
292 case "D":
293 $this->gotoKernelParameters.= " debug";
294 break;
295 case "G":
296 $this->gotoKernelParameters.= " splash=silent";
297 break;
298 }
299 if ($this->customParameters != ""){
300 $this->gotoKernelParameters.= " o ".$this->customParameters;
301 }
303 plugin::save();
305 /* Add missing arrays */
306 foreach (array("gotoModules") as $val){
307 if (isset ($this->$val) && count ($this->$val) != 0){
309 $this->attrs["$val"]= array_unique($this->$val);
310 }
311 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
312 }
314 /* Strip out 'default' values */
315 if ($this->attrs['gotoLdapServer'] == "default"){
316 unset ($this->attrs['gotoLdapServer']);
317 }
319 /* prepare share settings */
320 $tmp = array();
321 foreach($this->gotoShares as $name => $settings){
322 $tmp2 = split("\|",$name);
323 $name = $tmp2[0];
324 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
325 }
326 $this->attrs['gotoShare']=$tmp;
328 /* Write back to ldap */
329 $ldap= $this->config->get_ldap_link();
330 $ldap->cd($this->dn);
331 $this->cleanup();
332 $ldap->modify ($this->attrs);
334 show_ldap_error($ldap->get_error());
335 $this->handle_post_events("modify");
336 }
338 /* Add value to array, check if unique */
339 function add_list (&$array, $value)
340 {
341 if ($value != ""){
342 $array[]= $value;
343 sort($array);
344 array_unique ($array);
345 }
346 }
349 /* Delete value to array, check if unique */
350 function del_list (&$array, $list)
351 {
352 $tmp= array();
353 foreach ($array as $mod){
354 if (!in_array($mod, $list)){
355 $tmp[]= $mod;
356 }
357 }
358 $array= $tmp;
359 }
361 /* Generate ListBox frindly output for the defined shares
362 * Possibly Add or remove an attribute here,
363 */
364 function printOutAssignedShares()
365 {
366 $a_return = array();
367 if(is_array($this->gotoShares)){
368 foreach($this->gotoShares as $share){
369 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
370 }
371 }
372 return($a_return);
373 }
376 }
378 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
379 ?>