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