1cf3899b0a97ba9c5c67a0b894cfa7fb8bcb297d
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 = "";
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 $gotoBootKernels = array();
22 /* attribute list for save action */
23 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
24 var $objectclasses = array("GOhard", "FAIobject");
26 /* Share */
27 var $gotoShares = array();// Currently Share Option
28 var $gotoShare = ""; // currently selected Share Option
29 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
30 var $gotoAvailableShares= array();// Available Shares for this account
32 /* Helper */
33 var $customParameters = "";
34 var $orig_dn = "";
35 var $ignore_account = TRUE;
37 /* FAI class selection */
38 var $FAIclass = array();
39 var $FAIclasses = array();
40 var $FAIclassInfo = array();
41 var $FAIrelease = "";
42 var $FAIdebianMirror = "auto";
44 /* Contains all possible server/release/class settings */
45 var $FAIServRepConfig = array();
47 function workstartup ($config, $dn= NULL)
48 {
49 plugin::plugin ($config, $dn);
51 /* Creating a list of valid Mirrors
52 * none will not be saved to ldap.
53 */
54 $ldap = $this->config->get_ldap_link();
55 $ldap->cd($this->config->current['BASE']);
57 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
58 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
60 /* Search all FAI objects */
61 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
62 /* Sort all entries, and attach elementtype.
63 * To be able to show the types in the listbox.
64 */
65 while($attr = $ldap->fetch()){
66 $cn = $attr['cn'][0];
68 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
70 if(in_array('FAIpackageList',$attr['objectClass'])){
71 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
72 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
73 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
74 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
75 }
76 if(in_array('FAItemplate',$attr['objectClass'])){
77 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
78 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
79 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
80 }
81 if(in_array('FAIvariable',$attr['objectClass'])){
82 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
83 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
84 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
85 }
86 if(in_array('FAIscript',$attr['objectClass'])){
87 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
88 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
89 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
90 }
91 if(in_array('FAIhook',$attr['objectClass'])){
92 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
93 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
94 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
95 }
96 if(in_array('FAIpartitionTable',$attr['objectClass'])){
97 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
98 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
99 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
100 }
101 if(in_array('FAIprofile',$attr['objectClass'])){
102 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
103 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
104 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
105 }
106 }
107 if(is_array($this->FAIclasses)){
108 natcasesort($this->FAIclasses);
109 }
111 $this->FAIclassInfo = $tmp2;
114 /* Build up an array like this one :
115 [$url]['SERVER'] = 'srv1-002';
116 [$url]['RELEASE']['siga/rc9.0.2']
117 ['SECTIONS'][0] "main";
118 ['SECTIONS'][1] "non-free";
119 [$url]['RELEASE']['siga/rc9.0.2']
120 ['PACKAGES'][0] "pkg1";
121 ['PACKAGES'][1] "postfix";
122 */
124 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
125 $test = array();
126 while($attr = $ldap->fetch()){
127 if(isset($attr['FAIrepository'])){
129 unset($attr['FAIrepository']['count']);
131 foreach($attr['FAIrepository'] as $rep){
132 $tmp = split("\|",$rep);
134 if(count($tmp)==4){
135 $sections = split(",",$tmp[3]);
136 $release = $tmp[2];
137 $server = $tmp[1];
138 $url = $tmp[0];
140 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
142 /* Result will be cached
143 */
144 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
145 $test[$url]['SERVER'] = $server;
147 /* auto gets all releases/classes
148 */
149 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
150 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
151 }
152 }
153 }
154 }
155 $this->FAIServRepConfig =$test;
157 /* Get arrays */
158 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
159 if (isset($this->attrs["$val"]["count"])){
160 for ($i= 0; $i<$this->attrs["count"]; $i++){
161 if (isset($this->attrs["$val"][$i])){
162 array_push($this->$val, $this->attrs["$val"][$i]);
163 }
164 }
165 }
166 sort ($this->$val);
167 $this->$val= array_unique($this->$val);
168 }
170 /* Parse Kernel Parameters to decide what boot mode is enabled */
171 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
172 $this->bootmode= "G";
173 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
174 $this->bootmode= "D";
175 } elseif ($this->gotoKernelParameters == "") {
176 $this->bootmode= "G";
177 } else {
178 $this->bootmode= "T";
179 }
180 if (preg_match("/ o /", $this->gotoKernelParameters)){
181 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
182 } else {
183 $this->customParameters= "";
184 }
186 /* Prepare Shares */
187 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
188 unset($this->attrs['gotoShare']['count']);
189 foreach($this->attrs['gotoShare'] as $share){
190 $tmp = $tmp2 = array();
191 $tmp = split("\|",$share);
192 $tmp2['server'] =$tmp[0];
193 $tmp2['name'] =$tmp[1];
194 $tmp2['mountPoint'] =$tmp[2];
195 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
196 }
197 }
199 $this->gotoShareSelections= $config->getShareList(true);
200 $this->gotoAvailableShares= $config->getShareList(false);
201 $tmp2 = array();
203 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
204 $tmp = array();
205 $tmp = split(" ",$this->FAIclass);
206 $tmp2 =array();
208 foreach($tmp as $class){
209 if( ":" == $class[0] ) {
210 $this->FAIrelease = substr( $class, 1 );
211 }
212 else
213 $tmp2[$class] = $class;
214 }
215 $this->FAIclass = $tmp2;
216 }
218 if(!is_array($this->FAIclass)){
219 $this->FAIclass =array();
220 }
222 $this->orig_dn= $this->dn;
224 /* Handle inheritance value "default" */
225 $this->gotoBootKernels= array("%default%" => '['._("inherited").']');
227 /* Get list of boot kernels */
228 if (isset($this->config->data['TABS'])){
229 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
231 if (!check_command($command)){
232 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
233 get_class($this));
234 } else {
235 $fh= popen($command, "r");
236 while (!feof($fh)) {
237 $buffer= trim(fgets($fh, 256));
239 if ($buffer != ""){
240 $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
241 }
242 }
243 pclose($fh);
244 ksort($this->gotoBootKernels);
245 }
247 }
249 }
252 /* This class is called by the contrucktor ONLY.
253 * It return the available classes for each
254 * Server / Release combination ...
255 * (Release specifies which classes are available)
256 */
257 function getAvailableClassesForThisRelease($release)
258 {
259 /* There could be more than one server providing this release,
260 so use cached result if available
261 */
262 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
263 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
264 }
266 /* Create cache with all classes
267 */
268 if((!isset($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
269 (!is_array($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
270 (count($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES']) ==0 )){
272 /* Get ldap connection */
273 $ldap = $this->config->get_ldap_link();
274 $ldap->cd($this->config->current['BASE']);
276 /* Get possible classes ...
277 This would be faste with some kind of caching ...
278 */
279 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn"),true);
280 /* Sort all entries, and attach elementtype.
281 * To be able to show the types in the listbox.
282 */
283 while($attr = $ldap->fetch()){
284 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
285 }
286 }
288 /* Walk through cache and get out what we need.
289 *
290 * Function od : "$this->generateDNSyn($release)"
291 * It returns an array like this one :
292 * array("ou=packges,ou=rc0.9.2,ou=siga,",
293 * "ou=scripts.. "
294 * ...);
295 * This helps us to select the correct classes for each release.
296 * It prevents errors like: 'siga' is selected as release, but all classes
297 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
298 */
299 $tmp2 = $this->generateDNSyn($release) ;
300 $test2 = array();
301 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
302 foreach($tmp2 as $dns){
303 if(preg_match("/".$dns."/",$attr['dn'])){
304 $test2[$attr['cn'][0]] = $attr['cn'][0];
305 }
306 }
307 }
308 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
309 return($test2);
310 }
313 /* Create array to display available classes/profiles in a selectbox
314 * This function only displays the available classes.
315 * If a class is available is defined by these facts :
316 * 1. Is this class available for the selected release ?
317 * - if it is available, check if the release is available for the selected server
318 * (done by $this->getFAIreleases())
319 * 2. Is this class currently not assigned to $this->FAIclass
320 */
321 function selectFriendlyClasses(){
322 $tmp=array();
324 /* check if the current release exists,
325 else select the first one ..
326 */
327 $tmp2 = $this->getFAIreleases();
328 if(!in_array($this->FAIrelease, $tmp2)){
329 $this->FAIrelease = key($tmp2);
330 }
332 /* Get all Packages for this server/release combination
333 */
334 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
335 $pkgs = array();
336 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
337 }else{
338 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
339 }
341 /* Check each and every single class name
342 */
343 foreach($pkgs as $pkg){
345 /* Class already assigned to the classes list ?
346 * If not ... go on
347 */
348 if(!in_array($pkg,$this->FAIclass)){
350 /* Create the displayed list entry value
351 HKLMOP [-Pl P V T-] or something like that
352 */
353 $str = "";
354 foreach($this->FAIclassInfo[$pkg] as $entry){
355 if(isset($entry['kzl'])){
356 $str .= $entry['kzl']." ";
357 }
358 }
360 /* Append class if everyting was fine
361 */
362 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
363 }
364 }
365 /* Just sort and return new classes list ...
366 ( possibly we should cache the result ... )
367 */
368 natcasesort ($tmp);
369 return($tmp);
370 }
372 function check()
373 {
374 $messages = array();
376 /* Call common method to give check the hook */
377 $messages= plugin::check();
379 /* If there are packages selected, but no mirror show error */
380 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
381 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
382 }
384 return($messages);
385 }
387 function execute()
388 {
390 /* Call parent execute */
391 plugin::execute();
393 /* Do we need to flip is_account state? */
394 if (isset($_POST['modify_state'])){
395 $this->is_account= !$this->is_account;
396 }
398 /* Do we represent a valid terminal? */
399 if (!$this->is_account && $this->parent == NULL){
400 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
401 _("This 'dn' has no terminal features.")."</b>";
402 return ($display);
403 }
405 /* Add module */
406 if (isset ($_POST['add_module'])){
407 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
408 $this->add_list ($this->gotoModules, $_POST['module']);
409 }
410 }
412 /* Delete module */
413 if (isset ($_POST['delete_module'])){
414 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
415 $this->del_list ($this->gotoModules, $_POST['modules_list']);
416 }
417 }
419 /* FAI class management */
420 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
421 $found = 0 ;
423 /* If this new class/profile will attach a second partition table
424 * to our list of classes, abort and show a message.
425 */
426 foreach($this->FAIclass as $name){
427 if(isset($this->FAIclassInfo[$name])){
428 foreach($this->FAIclassInfo[$name] as $atr){
429 if(isset($atr['obj'])){
430 if($atr['obj'] == "FAIpartitionTable"){
431 $found ++ ;
432 }
433 }
434 }
435 }
436 }
438 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
439 print_red(_("There is already a profile in your selection that contain partition table configurations."));
440 }else{
441 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
442 }
443 }
445 $sort = false;
446 foreach($_POST as $name => $val){
448 $sort_type = false;
449 if((preg_match("/sort_up/",$name))&&(!$sort)){
450 $sort_type = "sort_up_";
451 }
452 if((preg_match("/sort_down/",$name))&&(!$sort)){
453 $sort_type = "sort_down_";
454 }
456 if(($sort_type)&&(!$sort)){
457 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
458 $sort = true;
460 $last = -1;
461 $change_down = -1;
463 /* Create array with numeric index */
464 $tmp = array();
465 foreach($this->FAIclass as $class){
466 $tmp [] = $class;
467 }
469 /* Walk trough array */
470 foreach($tmp as $key => $faiName){
471 if($faiName == $value){
472 if($sort_type == "sort_up_"){
473 if($last != -1){
474 $change_down= $last;
475 }
476 }else{
477 if(isset($tmp[$key+1])){
478 $change_down = $key;
479 }
480 }
481 }
482 $last = $key;
483 }
485 $tmp2 = array();
486 $skip = false;
488 foreach($tmp as $ky => $vl){
490 if($ky == $change_down){
491 $skip = $vl;
492 }else{
493 $tmp2[$vl] = $vl;
494 }
495 if(($skip != false)&&($ky != $change_down)){
496 $tmp2[$skip] = $skip;
497 $skip =false;
498 }
499 }
500 $this->FAIclass = $tmp2;
501 }
503 if(preg_match("/fai_remove/i",$name)){
504 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
505 unset($this->FAIclass[$value]);
506 }
507 }
509 /* Delete selected class from our list */
510 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
511 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
512 unset($this->FAIclass[$_POST['FAIclassSel']]);
513 }
514 }
516 /* Show main page */
517 $smarty= get_smarty();
518 $smarty->assign("SelectBoxLdapServer","");
520 /* In this section server shares will be defined
521 * A user can select one of the given shares and a mount point
522 * and attach this combination to his setup.
523 */
524 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
525 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
527 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
528 * This entry will be, a combination of mountPoint and sharedefinitions
529 */
530 if(isset($_POST['gotoShareAdd'])){
531 /* We assign a share to this user, if we don't know where to mount the share */
532 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
533 print_red(_("You must specify a valid mount point."));
534 }else{
535 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
536 $s_mount = $_POST['gotoShareMountPoint'];
537 /* Preparing the new assignment */
538 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
539 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
540 }
541 }
543 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
544 * If there is no defined share selected, we will abort the deletion without any message
545 */
546 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
547 unset($this->gotoShares[$_POST['gotoShare']]);
548 }
550 $smarty->assign("gotoShares",$this->printOutAssignedShares());
551 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
552 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
554 /* Arrays */
555 $tmp = $this->config->data['SERVERS']['LDAP'];
557 /* Create divSelectBox for ldap server selection
558 */
559 $SelectBoxLdapServer = new divSelectBox("LdapServer");
560 $SelectBoxLdapServer->SetHeight(130);
562 /* Set first entry as selected, if $this->gotoLdapServer is empty
563 * or given entry is no longer available ...
564 */
565 $found = false;
566 foreach($tmp as $server){
567 if($this->gotoLdapServer==$server){
568 $found = true;
569 }
570 }
572 /* Add Entries
573 */
574 foreach($tmp as $server){
575 $use ="";
576 if(($this->gotoLdapServer == $server) || ($found == false)) {
577 $found = true;
578 $use = " checked ";
579 };
581 $SelectBoxLdapServer->AddEntry(
582 array(
583 array("string"=>$server),
584 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$server."' ".$use.">",
585 "attach"=>"style='border-right:0px;'")
586 ));
587 }
589 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
591 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
592 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
593 $smarty->assign("$val", $this->$val);
594 }
596 /* Values */
597 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
598 $smarty->assign($val, $this->$val);
599 $smarty->assign($val."ACL", chkacl($this->acl, $val));
600 }
602 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
603 $smarty->assign("FAIreleases",$this->getFAIreleases());
604 $smarty->assign("FAIrelease",$this->FAIrelease);
605 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
606 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
607 $smarty->assign("FAIclassKeys",$this->FAIclass);
609 $div = new divSelectBox("WSFAIscriptClasses");
610 $div -> SetHeight("110");
611 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
612 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
613 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
614 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
616 $i = 1;
617 foreach($this->FAIclass as $class){
618 if($i==1){
619 $str = $str_empty.$str_down.$str_remove;
620 }elseif($i == count($this->FAIclass)){
621 $str = $str_up.$str_empty.$str_remove;
622 }else{
623 $str = $str_up.$str_down.$str_remove;
624 }
625 $i ++ ;
627 $div->AddEntry(array(
628 array("string"=>$class),
629 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
630 ));
631 }
633 $smarty->assign("FAIScriptlist",$div->DrawList());
635 /* Radio button group */
636 if (preg_match("/G/", $this->bootmode)) {
637 $smarty->assign("graphicalbootup", "checked");
638 } else {
639 $smarty->assign("graphicalbootup", "");
640 }
641 if (preg_match("/T/", $this->bootmode)) {
642 $smarty->assign("textbootup", "checked");
643 } else {
644 $smarty->assign("textbootup", "");
645 }
646 if (preg_match("/D/", $this->bootmode)) {
647 $smarty->assign("debugbootup", "checked");
648 } else {
649 $smarty->assign("debugbootup", "");
650 }
652 /* ACL's */
653 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
654 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
655 }
657 /* Show main page */
658 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
659 }
661 function remove_from_parent()
662 {
663 $this->handle_post_events("remove");
664 }
666 function generateDNSyn($release)
667 {
668 $str = "";
669 $tmp = split("\/",$release);
670 $tmp = array_reverse($tmp);
672 $base = ",ou=fai,";
674 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
676 foreach($tmp as $departmentname){
678 $str .= ",ou=".$departmentname;
679 }
680 $ret = array();
681 foreach($arr as $ar){
682 $ret[] = ",ou=".$ar.$str.$base;
683 }
684 return($ret);
685 }
687 function getFAIdebianMirrors()
688 {
689 $ret = array();
690 $ret['auto']=_("automatic");
691 $secs = array();
693 /* Walk through all available servers
694 and check if they support the currently selected classes
695 if not, dont't add them to our list
696 */
697 foreach($this->FAIServRepConfig as $mirror => $rest){
699 $use = false;
701 if(count($this->FAIclass) == 0){
702 $use = true;
703 }else{
704 $tmp = $this->getFAIreleases();
705 foreach($tmp as $release){
706 if(isset($rest['RELEASE'][$release])){
707 $use =true;
708 }
709 }
710 }
712 /* If current server, doesn't support this class
713 remove it from list
714 */
715 if($use){
716 $ret[$mirror] = $mirror;
717 }
718 }
719 return($ret);
720 }
722 function getFAIreleases()
723 {
724 $ret = array();
726 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
727 $this->FAIdebianMirror = "auto";
728 }
730 $errorClasses = "";
732 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
733 $use = true;
735 if(!count($this->FAIclass) == 0){
736 foreach($this->FAIclass as $class){
737 if(!in_array($class, $sections['PACKAGES'])){
738 $use = false;
739 $errorClasses[$class] = $class;
740 }else{
741 if(isset($errorClasses[$class])){
742 unset($errorClasses[$class]);
743 }
744 }
745 }
746 }
747 if($use){
748 $ret[$release]=$release;
749 }
750 }
751 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
753 $eClasses = " ";
754 foreach($errorClasses as $class){
755 $eClasses .= $class." ";
756 }
758 print_red(sprintf(_("Can't resolve one or more of the given FAIclass(es) [%s] in FAI server '%s'. Server was reset to 'auto'."),$eClasses, $this->FAIdebianMirror));
759 $this->FAIdebianMirror = "auto";
760 return($this->getFAIreleases());
761 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
763 $eClasses = " ";
764 foreach($errorClasses as $class){
765 $eClasses .= $class." ";
766 }
768 $this->FAIclass= array();
769 print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. !All classes have been removed from this account, press cancel if you don't want this to be saved."),$eClasses));
770 }
771 return($ret);
772 }
774 /* Save data to object */
775 function save_object()
776 {
777 plugin::save_object();
779 /* Save group radio buttons */
780 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
781 $this->bootmode= $_POST["bootmode"];
782 }
784 /* Save kernel parameters */
785 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
786 $this->customParameters= $_POST["customParameters"];
787 }
788 }
791 /* Save to LDAP */
792 function save()
793 {
795 /* Depending on the baseobject (Ogroup / WS) we
796 * use another set of objectClasses
797 * In case of WS itself, we use "array("GOhard", "FAIobject");"
798 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
799 */
800 if(isset($this->parent->by_object['ogroup'])){
801 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
802 }elseif(isset($this->parent->by_object['workgeneric'])){
803 $this->objectclasses = array("GOhard", "FAIobject");
804 }elseif(isset($this->parent->by_object['servgeneric'])){
805 $this->objectclasses = array("GOhard", "FAIobject");
806 }else{
807 print "Object Type Configuration : unknown";
808 exit();
809 }
811 /* Find proper terminal path for tftp configuration
812 FIXME: This is suboptimal when the default has changed to
813 another location! */
814 if ($this->gotoTerminalPath == "default"){
815 $ldap= $this->config->get_ldap_link();
817 /* Strip relevant part from dn, keep trailing ',' */
818 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
819 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
821 /* Walk from top to base and try to load default values for
822 'gotoTerminalPath'. Abort when an entry is found. */
823 while (TRUE){
824 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
826 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
827 $this->config->current['BASE'], array('gotoTerminalPath'));
828 $attrs= $ldap->fetch();
829 if (isset($attrs['gotoTerminalPath'])){
830 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
831 break;
832 }
834 /* Nothing left? */
835 if ($tmp == ""){
836 break;
837 }
838 }
839 }
841 /* Add semi automatic values */
842 // FIXME: LDAP Server may not be set here...
843 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
845 switch ($this->bootmode){
846 case "D":
847 $this->gotoKernelParameters.= " debug";
848 break;
849 case "G":
850 $this->gotoKernelParameters.= " splash=silent";
851 break;
852 }
853 if ($this->customParameters != ""){
854 $this->gotoKernelParameters.= " o ".$this->customParameters;
855 }
857 plugin::save();
859 unset( $this->attrs['FAIrelease'] );
861 $str = "";
862 foreach($this->FAIclass as $class){
863 $str .= $class." ";
864 }
865 $str .= ":" . $this->FAIrelease;
866 $this->attrs['FAIclass']= "";
867 $this->attrs['FAIclass']= trim($str);
869 if(empty($this->attrs['FAIclass'])){
870 $this->attrs['FAIclass'] = array();
871 }
873 /* Add missing arrays */
874 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
875 if (isset ($this->$val) && count ($this->$val) != 0){
877 $this->attrs["$val"]= array_unique($this->$val);
878 }
879 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
880 }
881 /* Strip out 'default' values */
882 if ($this->attrs['gotoLdapServer'] == "default"){
883 $this->attrs['gotoLdapServer']= array();
884 }
885 if ($this->attrs['gotoBootKernel'] == "%default%"){
886 $this->attrs['gotoBootKernel']= array();
887 }
889 /* if mirror == none stop saving this attribute */
890 if($this->FAIdebianMirror == "none"){
891 $this->FAIdebianMirror = "";
892 }
894 /* Remove FAI objects if no FAI class is selected */
895 if(count($this->FAIclass)==0){
896 $tmp = array();
897 foreach($this->attrs['objectClass'] as $class){
898 if($class != "FAIobject"){
899 $tmp[] = $class;
900 }
901 }
902 $this->attrs['objectClass'] = $tmp;
903 $this->attrs['FAIclass'] = array();
904 $this->attrs['FAIdebianMirror'] = array();
905 }
907 /* prepare share settings */
908 $tmp = array();
909 foreach($this->gotoShares as $name => $settings){
910 $tmp2= split("\|",$name);
911 $name = $tmp2[0];
912 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
913 }
914 $this->attrs['gotoShare']=$tmp;
916 $ldap= $this->config->get_ldap_link();
917 $ldap->cd($this->dn);
918 $this->cleanup();
919 $ldap->modify ($this->attrs);
921 show_ldap_error($ldap->get_error());
922 $this->handle_post_events("modify");
923 }
925 /* Add value to array, check if unique */
926 function add_list (&$array, $value)
927 {
928 if ($value != ""){
929 $array[]= $value;
930 sort($array);
931 array_unique ($array);
932 }
933 }
936 /* Delete value to array, check if unique */
937 function del_list (&$array, $list)
938 {
939 $tmp= array();
940 foreach ($array as $mod){
941 if (!in_array($mod, $list)){
942 $tmp[]= $mod;
943 }
944 }
945 $array= $tmp;
946 }
948 /* Generate ListBox frindly output for the defined shares
949 * Possibly Add or remove an attribute here,
950 */
951 function printOutAssignedShares()
952 {
953 $a_return = array();
954 if(is_array($this->gotoShares)){
955 foreach($this->gotoShares as $share){
956 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
957 }
958 }
959 return($a_return);
960 }
962 }
964 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
965 ?>