e6b415d376670c8e47f4e256c2f2949f63b3146a
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();
23 var $FAIdebianMirror = array();
26 /* attribute list for save action */
27 var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror");
28 var $objectclasses= array("GOhard", "FAIobject");
30 /* Share */
31 var $gotoShares = array();// Currently Share Option
32 var $gotoShare = ""; // currently selected Share Option
33 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
34 var $gotoAvailableShares= array();// Available Shares for this account
36 /* Helper */
37 var $customParameters= "";
38 var $orig_dn= "";
39 var $ignore_account= TRUE;
40 var $FAIdebianMirrors = array();
42 function workstartup ($config, $dn= NULL)
43 {
44 plugin::plugin ($config, $dn);
46 $this->FAIdebianMirrors= array("none"=>_("none"));
47 $ldap = $this->config->get_ldap_link();
48 $ldap->search("(objectClass=FAIrepository)",array("FAIdebianMirror"));
49 while($attr = $ldap->fetch()){
50 if(isset($attr['FAIdebianMirror'])){
51 $this->FAIdebianMirrors[$attr['FAIdebianMirror'][0]]=$attr['FAIdebianMirror'][0];
52 }
53 }
56 /* Get arrays */
57 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
58 if (isset($this->attrs["$val"]["count"])){
59 for ($i= 0; $i<$this->attrs["count"]; $i++){
60 if (isset($this->attrs["$val"][$i])){
61 array_push($this->$val, $this->attrs["$val"][$i]);
62 }
63 }
64 }
65 sort ($this->$val);
66 $this->$val= array_unique($this->$val);
67 }
69 /* Parse Kernel Parameters to decide what boot mode is enabled */
70 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
71 $this->bootmode= "G";
72 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
73 $this->bootmode= "D";
74 } elseif ($this->gotoKernelParameters == "") {
75 $this->bootmode= "G";
76 } else {
77 $this->bootmode= "T";
78 }
79 if (preg_match("/ o /", $this->gotoKernelParameters)){
80 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
81 } else {
82 $this->customParameters= "";
83 }
85 /* Prepare Shares */
86 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
87 unset($this->attrs['gotoShare']['count']);
88 foreach($this->attrs['gotoShare'] as $share){
89 $tmp = $tmp2 = array();
90 $tmp = split("\|",$share);
91 $tmp2['server'] =$tmp[0];
92 $tmp2['name'] =$tmp[1];
93 $tmp2['mountPoint'] =$tmp[2];
94 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
95 }
96 }
98 $this->gotoShareSelections= $config->getShareList(true);
99 $this->gotoAvailableShares= $config->getShareList(false);
100 $tmp2 = array();
102 //$ldap->cd($base);
103 $ldap = $this->config->get_ldap_link();
104 $ldap->cd($this->config->current['BASE']);
105 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)
106 (objectClass=FAIvariable)(objectClass=FAIscript')(objectClass=FAIhook)
107 (objectClass=FAIpartitionTable))",array("objectClass","cn"),true);
108 $test_dns = array();
109 while($attr = $ldap->fetch()){
110 $cn = $attr['cn'][0];
111 if(in_array('FAIpackageList',$attr['objectClass'])){
112 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
113 $tmp2[$cn]['FAIpackageList']['kzl'] = 'P';
114 $tmp2[$cn]['FAIpackageList']['dn'] = $attr['dn'];
115 $test_dns[$cn]=$attr['dn'];
116 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
117 }
118 if(in_array('FAItemplate',$attr['objectClass'])){
119 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
120 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
121 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
122 }
123 if(in_array('FAIvariable',$attr['objectClass'])){
124 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
125 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
126 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
127 }
128 if(in_array('FAIscript',$attr['objectClass'])){
129 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
130 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
131 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
132 }
133 if(in_array('FAIhook',$attr['objectClass'])){
134 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
135 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
136 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
137 }
138 if(in_array('FAIpartitionTable',$attr['objectClass'])){
139 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
140 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
141 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
142 }
143 }
145 foreach($test_dns as $cn => $dn){
146 $entry = $ldap->cat($dn);
147 $attr = $ldap->fetch();
148 $mirror = $attr['FAIdebianMirror'][0];
149 $tmp2[$cn]['FAIpackageList']['mirror']= $mirror;
150 }
152 $this->FAIclassInfo = $tmp2;
154 if(isset($this->attrs['FAIclass'])){
155 $tmp = array();
156 $tmp2 = $this->attrs['FAIclass'];
157 unset($tmp2['count']);
158 foreach($tmp2 as $class){
159 $tmp[$class] = $class;
160 }
161 $this->FAIclass = $tmp;
162 }
164 if(!is_array($this->FAIclass)){
165 $this->FAIclass = array();
166 }
169 $this->orig_dn= $this->dn;
170 }
172 function selectFriendlyClasses(){
173 $tmp=array();
174 foreach($this->FAIclasses as $class){
175 $str = "";
176 $skip = false;
177 if(isset($this->FAIclassInfo[$class])){
178 foreach($this->FAIclassInfo[$class] as $objs){
179 $str .= $objs['kzl']." ";
180 }
181 }
182 $tmp[$class] = $class." [".$str."]";
183 }
184 return($tmp);
185 }
187 function check()
188 {
189 $messages = array();
191 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
192 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
193 }
194 return($messages);
195 }
197 function execute()
198 {
199 /* Do we need to flip is_account state? */
200 if (isset($_POST['modify_state'])){
201 $this->is_account= !$this->is_account;
202 }
205 /* Do we represent a valid terminal? */
206 if (!$this->is_account && $this->parent == NULL){
207 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
208 _("This 'dn' has no terminal features.")."</b>";
209 return ($display);
210 }
212 /* Add module */
213 if (isset ($_POST['add_module'])){
214 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
215 $this->add_list ($this->gotoModules, $_POST['module']);
216 }
217 }
219 /* Delete module */
220 if (isset ($_POST['delete_module'])){
221 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
222 $this->del_list ($this->gotoModules, $_POST['modules_list']);
223 }
224 }
226 /* FAI class management */
227 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
229 $found = 0 ;
231 foreach($this->FAIclass as $name){
232 if(isset($this->FAIclassInfo[$name])){
233 foreach($this->FAIclassInfo[$name] as $atr){
234 if($atr['obj'] == "FAIpartitionTable"){
235 $found ++ ;
236 }
237 }
238 }
239 }
241 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpackageList']))&&($found>0)){
242 print_red(_("There is already a profile in your selection that contain partition table configuratons."));
243 }else{
244 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
245 }
246 }
248 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
249 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
250 unset($this->FAIclass[$_POST['FAIclassSel']]);
251 }
252 }
254 /* Show main page */
255 $smarty= get_smarty();
257 /* In this section server shares will be defined
258 * A user can select one of the given shares and a mount point
259 * and attach this combination to his setup.
260 */
261 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
262 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
264 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
265 * This entry will be, a combination of mountPoint and sharedefinitions
266 */
267 if(isset($_POST['gotoShareAdd'])){
268 /* We assign a share to this user, if we don't know where to mount the share */
269 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
270 print_red(_("You must specify a valid mount point."));
271 }else{
272 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
273 $s_mount = $_POST['gotoShareMountPoint'];
274 /* Preparing the new assignment */
275 $this->gotoShares[$a_share['name']]=$a_share;
276 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
277 }
278 }
280 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
281 * If there is no defined share selected, we will abort the deletion without any message
282 */
283 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
284 unset($this->gotoShares[$_POST['gotoShare']]);
285 }
287 $smarty->assign("gotoShares",$this->printOutAssignedShares());
288 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
290 /* Arrays */
291 $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
292 $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
293 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
294 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
295 $smarty->assign("$val", $this->$val);
296 }
298 /* Values */
299 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror") as $val){
300 $smarty->assign($val, $this->$val);
301 $smarty->assign($val."ACL", chkacl($this->acl, $val));
302 }
305 $smarty->assign("FAIdebianMirrors",$this->FAIdebianMirrors);
306 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
307 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
308 $smarty->assign("FAIclassKeys",$this->FAIclass);
310 /* Radio button group */
311 if (preg_match("/G/", $this->bootmode)) {
312 $smarty->assign("graphicalbootup", "checked");
313 } else {
314 $smarty->assign("graphicalbootup", "");
315 }
316 if (preg_match("/T/", $this->bootmode)) {
317 $smarty->assign("textbootup", "checked");
318 } else {
319 $smarty->assign("textbootup", "");
320 }
321 if (preg_match("/D/", $this->bootmode)) {
322 $smarty->assign("debugbootup", "checked");
323 } else {
324 $smarty->assign("debugbootup", "");
325 }
327 /* ACL's */
328 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
329 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
330 }
332 /* Show main page */
333 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE)));
334 }
336 function remove_from_parent()
337 {
338 $ldap= $this->config->get_ldap_link();
339 $ldap->rmdir($this->dn);
340 show_ldap_error($ldap->get_error());
341 $this->handle_post_events("remove");
342 }
345 /* Save data to object */
346 function save_object()
347 {
348 plugin::save_object();
350 /* Save group radio buttons */
351 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
352 $this->bootmode= $_POST["bootmode"];
353 }
355 /* Save kernel parameters */
356 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
357 $this->customParameters= $_POST["customParameters"];
358 }
359 }
362 /* Save to LDAP */
363 function save()
364 {
365 /* Find proper terminal path for tftp configuration
366 FIXME: This is suboptimal when the default has changed to
367 another location! */
368 if ($this->gotoTerminalPath == "default"){
369 $ldap= $this->config->get_ldap_link();
371 /* Strip relevant part from dn, keep trailing ',' */
372 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
373 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
375 /* Walk from top to base and try to load default values for
376 'gotoTerminalPath'. Abort when an entry is found. */
377 while (TRUE){
378 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
380 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
381 $this->config->current['BASE']);
382 $attrs= $ldap->fetch();
383 if (isset($attrs['gotoTerminalPath'])){
384 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
385 break;
386 }
388 /* Nothing left? */
389 if ($tmp == ""){
390 break;
391 }
392 }
393 }
395 /* Add semi automatic values */
396 // FIXME: LDAP Server may not be set here...
397 $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
398 $this->gotoTerminalPath.
399 ",ro,hard,nolock,fg,rsize=8192 ".
400 "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
402 switch ($this->bootmode){
403 case "D":
404 $this->gotoKernelParameters.= " debug";
405 break;
406 case "G":
407 $this->gotoKernelParameters.= " splash=silent";
408 break;
409 }
410 if ($this->customParameters != ""){
411 $this->gotoKernelParameters.= " o ".$this->customParameters;
412 }
414 $tmp = array();
415 foreach($this->FAIclass as $class){
416 $tmp[] = $class;
417 }
418 $this->FAIclass = $tmp;
420 plugin::save();
422 /* Add missing arrays */
423 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
424 if (isset ($this->$val) && count ($this->$val) != 0){
426 $this->attrs["$val"]= array_unique($this->$val);
427 }
428 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
429 }
430 /* Strip out 'default' values */
431 if ($this->attrs['gotoLdapServer'] == "default"){
432 unset ($this->attrs['gotoLdapServer']);
433 }
435 $tmp = array();
436 foreach($this->FAIclass as $class){
437 $tmp[] = $class;
438 }
439 $this->attrs['FAIclass'] = $tmp;
440 /* Write back to ldap */
442 if($this->FAIdebianMirror == "none"){
443 $this->FAIdebianMirror = "";
444 }
446 if((count($this->attrs['FAIclass'])==0)&&(empty($this->FAIdebianMirror))){
447 $tmp = array();
448 foreach($this->attrs['objectClass'] as $class){
449 if($class != "FAIobject"){
450 $tmp[] = $class;
451 }
452 }
453 $this->attrs['objectClass'] = $tmp;
454 $this->attrs['FAIclass'] = array();;
455 $this->attrs['FAIdebianMirror'] = array();;
456 }
458 $ldap= $this->config->get_ldap_link();
459 $ldap->cd($this->dn);
460 $ldap->modify($this->attrs);
461 show_ldap_error($ldap->get_error());
462 $this->handle_post_events("modify");
463 }
465 /* Add value to array, check if unique */
466 function add_list (&$array, $value)
467 {
468 if ($value != ""){
469 $array[]= $value;
470 sort($array);
471 array_unique ($array);
472 }
473 }
476 /* Delete value to array, check if unique */
477 function del_list (&$array, $list)
478 {
479 $tmp= array();
480 foreach ($array as $mod){
481 if (!in_array($mod, $list)){
482 $tmp[]= $mod;
483 }
484 }
485 $array= $tmp;
486 }
488 /* Generate ListBox frindly output for the defined shares
489 * Possibly Add or remove an attribute here,
490 */
491 function printOutAssignedShares()
492 {
493 $a_return = array();
494 if(is_array($this->gotoShares)){
495 foreach($this->gotoShares as $share){
496 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
497 }
498 }
499 return($a_return);
500 }
502 }
504 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
505 ?>