54929b931d63b9f440502c39f5f141f4a7b26f3b
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("default");
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 /* Get list of boot kernels */
225 if (isset($this->config->data['TABS'])){
226 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
228 if (!check_command($command)){
229 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
230 get_class($this));
231 } else {
232 $fh= popen($command, "r");
233 while (!feof($fh)) {
234 $buffer= fgets($fh, 256);
235 $this->gotoBootKernels[]= $buffer;
236 }
237 pclose($fh);
238 sort($this->gotoBootKernels);
239 }
241 }
242 }
245 /* This class is called by the contrucktor ONLY.
246 * It return the available classes for each
247 * Server / Release combination ...
248 * (Release specifies which classes are available)
249 */
250 function getAvailableClassesForThisRelease($release)
251 {
252 /* There could be more than one server providing this release,
253 so use cached result if available
254 */
255 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
256 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
257 }
259 /* Create cache with all classes
260 */
261 if((!isset($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
262 (!is_array($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
263 (count($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES']) ==0 )){
265 /* Get ldap connection */
266 $ldap = $this->config->get_ldap_link();
267 $ldap->cd($this->config->current['BASE']);
269 /* Get possible classes ...
270 This would be faste with some kind of caching ...
271 */
272 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn"),true);
273 /* Sort all entries, and attach elementtype.
274 * To be able to show the types in the listbox.
275 */
276 while($attr = $ldap->fetch()){
277 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
278 }
279 }
281 /* Walk through cache and get out what we need.
282 *
283 * Function od : "$this->generateDNSyn($release)"
284 * It returns an array like this one :
285 * array("ou=packges,ou=rc0.9.2,ou=siga,",
286 * "ou=scripts.. "
287 * ...);
288 * This helps us to select the correct classes for each release.
289 * It prevents errors like: 'siga' is selected as release, but all classes
290 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
291 */
292 $tmp2 = $this->generateDNSyn($release) ;
293 $test2 = array();
294 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
295 foreach($tmp2 as $dns){
296 if(preg_match("/".$dns."/",$attr['dn'])){
297 $test2[$attr['cn'][0]] = $attr['cn'][0];
298 }
299 }
300 }
301 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
302 return($test2);
303 }
306 /* Create array to display available classes/profiles in a selectbox
307 * This function only displays the available classes.
308 * If a class is available is defined by these facts :
309 * 1. Is this class available for the selected release ?
310 * - if it is available, check if the release is available for the selected server
311 * (done by $this->getFAIreleases())
312 * 2. Is this class currently not assigned to $this->FAIclass
313 */
314 function selectFriendlyClasses(){
315 $tmp=array();
317 /* check if the current release exists,
318 else select the first one ..
319 */
320 $tmp2 = $this->getFAIreleases();
321 if(!in_array($this->FAIrelease, $tmp2)){
322 $this->FAIrelease = key($tmp2);
323 }
325 /* Get all Packages for this server/release combination
326 */
327 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
328 $pkgs = array();
329 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
330 }else{
331 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
332 }
334 /* Check each and every single class name
335 */
336 foreach($pkgs as $pkg){
338 /* Class already assigned to the classes list ?
339 * If not ... go on
340 */
341 if(!in_array($pkg,$this->FAIclass)){
343 /* Create the displayed list entry value
344 HKLMOP [-Pl P V T-] or something like that
345 */
346 $str = "";
347 foreach($this->FAIclassInfo[$pkg] as $entry){
348 if(isset($entry['kzl'])){
349 $str .= $entry['kzl']." ";
350 }
351 }
353 /* Append class if everyting was fine
354 */
355 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
356 }
357 }
358 /* Just sort and return new classes list ...
359 ( possibly we should cache the result ... )
360 */
361 natcasesort ($tmp);
362 return($tmp);
363 }
365 function check()
366 {
367 $messages = array();
369 /* Call common method to give check the hook */
370 $messages= plugin::check();
372 /* If there are packages selected, but no mirror show error */
373 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
374 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
375 }
377 return($messages);
378 }
380 function execute()
381 {
383 /* Call parent execute */
384 plugin::execute();
386 /* Do we need to flip is_account state? */
387 if (isset($_POST['modify_state'])){
388 $this->is_account= !$this->is_account;
389 }
391 /* Do we represent a valid terminal? */
392 if (!$this->is_account && $this->parent == NULL){
393 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
394 _("This 'dn' has no terminal features.")."</b>";
395 return ($display);
396 }
398 /* Add module */
399 if (isset ($_POST['add_module'])){
400 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
401 $this->add_list ($this->gotoModules, $_POST['module']);
402 }
403 }
405 /* Delete module */
406 if (isset ($_POST['delete_module'])){
407 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
408 $this->del_list ($this->gotoModules, $_POST['modules_list']);
409 }
410 }
412 /* FAI class management */
413 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
414 $found = 0 ;
416 /* If this new class/profile will attach a second partition table
417 * to our list of classes, abort and show a message.
418 */
419 foreach($this->FAIclass as $name){
420 if(isset($this->FAIclassInfo[$name])){
421 foreach($this->FAIclassInfo[$name] as $atr){
422 if(isset($atr['obj'])){
423 if($atr['obj'] == "FAIpartitionTable"){
424 $found ++ ;
425 }
426 }
427 }
428 }
429 }
431 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
432 print_red(_("There is already a profile in your selection that contain partition table configurations."));
433 }else{
434 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
435 }
436 }
438 $sort = false;
439 foreach($_POST as $name => $val){
441 $sort_type = false;
442 if((preg_match("/sort_up/",$name))&&(!$sort)){
443 $sort_type = "sort_up_";
444 }
445 if((preg_match("/sort_down/",$name))&&(!$sort)){
446 $sort_type = "sort_down_";
447 }
449 if(($sort_type)&&(!$sort)){
450 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
451 $sort = true;
453 $last = -1;
454 $change_down = -1;
456 /* Create array with numeric index */
457 $tmp = array();
458 foreach($this->FAIclass as $class){
459 $tmp [] = $class;
460 }
462 /* Walk trough array */
463 foreach($tmp as $key => $faiName){
464 if($faiName == $value){
465 if($sort_type == "sort_up_"){
466 if($last != -1){
467 $change_down= $last;
468 }
469 }else{
470 if(isset($tmp[$key+1])){
471 $change_down = $key;
472 }
473 }
474 }
475 $last = $key;
476 }
478 $tmp2 = array();
479 $skip = false;
481 foreach($tmp as $ky => $vl){
483 if($ky == $change_down){
484 $skip = $vl;
485 }else{
486 $tmp2[$vl] = $vl;
487 }
488 if(($skip != false)&&($ky != $change_down)){
489 $tmp2[$skip] = $skip;
490 $skip =false;
491 }
492 }
493 $this->FAIclass = $tmp2;
494 }
496 if(preg_match("/fai_remove/i",$name)){
497 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
498 unset($this->FAIclass[$value]);
499 }
500 }
502 /* Delete selected class from our list */
503 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
504 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
505 unset($this->FAIclass[$_POST['FAIclassSel']]);
506 }
507 }
509 /* Show main page */
510 $smarty= get_smarty();
511 $smarty->assign("SelectBoxLdapServer","");
513 /* In this section server shares will be defined
514 * A user can select one of the given shares and a mount point
515 * and attach this combination to his setup.
516 */
517 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
518 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
520 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
521 * This entry will be, a combination of mountPoint and sharedefinitions
522 */
523 if(isset($_POST['gotoShareAdd'])){
524 /* We assign a share to this user, if we don't know where to mount the share */
525 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
526 print_red(_("You must specify a valid mount point."));
527 }else{
528 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
529 $s_mount = $_POST['gotoShareMountPoint'];
530 /* Preparing the new assignment */
531 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
532 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
533 }
534 }
536 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
537 * If there is no defined share selected, we will abort the deletion without any message
538 */
539 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
540 unset($this->gotoShares[$_POST['gotoShare']]);
541 }
543 $smarty->assign("gotoShares",$this->printOutAssignedShares());
544 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
545 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
547 /* Arrays */
548 $tmp = $this->config->data['SERVERS']['LDAP'];
550 /* Create divSelectBox for ldap server selection
551 */
552 $SelectBoxLdapServer = new divSelectBox("LdapServer");
553 $SelectBoxLdapServer->SetHeight(80);
555 /* Set first entry as selected, if $this->gotoLdapServer is empty
556 * or given entry is no longer available ...
557 */
558 $found = false;
559 foreach($tmp as $server){
560 if($this->gotoLdapServer==$server){
561 $found = true;
562 }
563 }
565 /* Add Entries
566 */
567 foreach($tmp as $server){
568 $use ="";
569 if(($this->gotoLdapServer == $server) || ($found == false)) {
570 $found = true;
571 $use = " checked ";
572 };
574 $SelectBoxLdapServer->AddEntry(
575 array(
576 array("string"=>$server),
577 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$server."' ".$use.">",
578 "attach"=>"style='border-right:0px;'")
579 ));
580 }
582 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
584 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
585 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
586 $smarty->assign("$val", $this->$val);
587 }
589 /* Values */
590 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
591 $smarty->assign($val, $this->$val);
592 $smarty->assign($val."ACL", chkacl($this->acl, $val));
593 }
595 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
596 $smarty->assign("FAIreleases",$this->getFAIreleases());
597 $smarty->assign("FAIrelease",$this->FAIrelease);
598 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
599 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
600 $smarty->assign("FAIclassKeys",$this->FAIclass);
602 $div = new divSelectBox("WSFAIscriptClasses");
603 $div -> SetHeight("110");
604 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
605 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
606 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
607 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
609 $i = 1;
610 foreach($this->FAIclass as $class){
611 if($i==1){
612 $str = $str_empty.$str_down.$str_remove;
613 }elseif($i == count($this->FAIclass)){
614 $str = $str_up.$str_empty.$str_remove;
615 }else{
616 $str = $str_up.$str_down.$str_remove;
617 }
618 $i ++ ;
620 $div->AddEntry(array(
621 array("string"=>$class),
622 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
623 ));
624 }
626 $smarty->assign("FAIScriptlist",$div->DrawList());
628 /* Radio button group */
629 if (preg_match("/G/", $this->bootmode)) {
630 $smarty->assign("graphicalbootup", "checked");
631 } else {
632 $smarty->assign("graphicalbootup", "");
633 }
634 if (preg_match("/T/", $this->bootmode)) {
635 $smarty->assign("textbootup", "checked");
636 } else {
637 $smarty->assign("textbootup", "");
638 }
639 if (preg_match("/D/", $this->bootmode)) {
640 $smarty->assign("debugbootup", "checked");
641 } else {
642 $smarty->assign("debugbootup", "");
643 }
645 /* ACL's */
646 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
647 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
648 }
650 /* Show main page */
651 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
652 }
654 function remove_from_parent()
655 {
656 $this->handle_post_events("remove");
657 }
659 function generateDNSyn($release)
660 {
661 $str = "";
662 $tmp = split("\/",$release);
663 $tmp = array_reverse($tmp);
665 $base = ",ou=fai,";
667 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
669 foreach($tmp as $departmentname){
671 $str .= ",ou=".$departmentname;
672 }
673 $ret = array();
674 foreach($arr as $ar){
675 $ret[] = ",ou=".$ar.$str.$base;
676 }
677 return($ret);
678 }
680 function getFAIdebianMirrors()
681 {
682 $ret = array();
683 $ret['auto']=_("automatic");
684 $secs = array();
686 /* Walk through all available servers
687 and check if they support the currently selected classes
688 if not, dont't add them to our list
689 */
690 foreach($this->FAIServRepConfig as $mirror => $rest){
692 $use = false;
694 if(count($this->FAIclass) == 0){
695 $use = true;
696 }else{
697 $tmp = $this->getFAIreleases();
698 foreach($tmp as $release){
699 if(isset($rest['RELEASE'][$release])){
700 $use =true;
701 }
702 }
703 }
705 /* If current server, doesn't support this class
706 remove it from list
707 */
708 if($use){
709 $ret[$mirror] = $mirror;
710 }
711 }
712 return($ret);
713 }
715 function getFAIreleases()
716 {
717 $ret = array();
719 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
720 $this->FAIdebianMirror = "auto";
721 }
723 $errorClasses = "";
725 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
726 $use = true;
728 if(!count($this->FAIclass) == 0){
729 foreach($this->FAIclass as $class){
730 if(!in_array($class, $sections['PACKAGES'])){
731 $use = false;
732 $errorClasses[$class] = $class;
733 }else{
734 if(isset($errorClasses[$class])){
735 unset($errorClasses[$class]);
736 }
737 }
738 }
739 }
740 if($use){
741 $ret[$release]=$release;
742 }
743 }
744 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
746 $eClasses = " ";
747 foreach($errorClasses as $class){
748 $eClasses .= $class." ";
749 }
751 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));
752 $this->FAIdebianMirror = "auto";
753 return($this->getFAIreleases());
754 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
756 $eClasses = " ";
757 foreach($errorClasses as $class){
758 $eClasses .= $class." ";
759 }
761 $this->FAIclass= array();
762 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));
763 }
764 return($ret);
765 }
767 /* Save data to object */
768 function save_object()
769 {
770 plugin::save_object();
772 /* Save group radio buttons */
773 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
774 $this->bootmode= $_POST["bootmode"];
775 }
777 /* Save kernel parameters */
778 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
779 $this->customParameters= $_POST["customParameters"];
780 }
781 }
784 /* Save to LDAP */
785 function save()
786 {
788 /* Depending on the baseobject (Ogroup / WS) we
789 * use another set of objectClasses
790 * In case of WS itself, we use "array("GOhard", "FAIobject");"
791 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
792 */
793 if(isset($this->parent->by_object['ogroup'])){
794 $this->objectclasses = array("gotoWorkstationTemplate","GOhard", "FAIobject");
795 }elseif(isset($this->parent->by_object['workgeneric'])){
796 $this->objectclasses = array("GOhard", "FAIobject");
797 }else{
798 print "Object Type Configuration : unknown";
799 exit();
800 }
802 /* Find proper terminal path for tftp configuration
803 FIXME: This is suboptimal when the default has changed to
804 another location! */
805 if ($this->gotoTerminalPath == "default"){
806 $ldap= $this->config->get_ldap_link();
808 /* Strip relevant part from dn, keep trailing ',' */
809 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
810 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
812 /* Walk from top to base and try to load default values for
813 'gotoTerminalPath'. Abort when an entry is found. */
814 while (TRUE){
815 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
817 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
818 $this->config->current['BASE']);
819 $attrs= $ldap->fetch();
820 if (isset($attrs['gotoTerminalPath'])){
821 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
822 break;
823 }
825 /* Nothing left? */
826 if ($tmp == ""){
827 break;
828 }
829 }
830 }
832 /* Add semi automatic values */
833 // FIXME: LDAP Server may not be set here...
834 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
836 switch ($this->bootmode){
837 case "D":
838 $this->gotoKernelParameters.= " debug";
839 break;
840 case "G":
841 $this->gotoKernelParameters.= " splash=silent";
842 break;
843 }
844 if ($this->customParameters != ""){
845 $this->gotoKernelParameters.= " o ".$this->customParameters;
846 }
848 plugin::save();
850 unset( $this->attrs['FAIrelease'] );
852 $str = "";
853 foreach($this->FAIclass as $class){
854 $str .= $class." ";
855 }
856 $str .= ":" . $this->FAIrelease;
857 $this->attrs['FAIclass']= "";
858 $this->attrs['FAIclass']= trim($str);
860 if(empty($this->attrs['FAIclass'])){
861 $this->attrs['FAIclass'] = array();
862 }
864 /* Add missing arrays */
865 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
866 if (isset ($this->$val) && count ($this->$val) != 0){
868 $this->attrs["$val"]= array_unique($this->$val);
869 }
870 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
871 }
872 /* Strip out 'default' values */
873 if ($this->attrs['gotoLdapServer'] == "default"){
874 unset ($this->attrs['gotoLdapServer']);
875 }
877 /* if mirror == none stop saving this attribute */
878 if($this->FAIdebianMirror == "none"){
879 $this->FAIdebianMirror = "";
880 }
882 if((count($this->attrs['FAIclass'])==0)&&(empty($this->FAIdebianMirror))){
883 $tmp = array();
884 foreach($this->attrs['objectClass'] as $class){
885 if($class != "FAIobject"){
886 $tmp[] = $class;
887 }
888 }
889 $this->attrs['objectClass'] = $tmp;
890 $this->attrs['FAIclass'] = array();
891 $this->attrs['FAIdebianMirror'] = array();
892 }
894 /* prepare share settings */
895 $tmp = array();
896 foreach($this->gotoShares as $name => $settings){
897 $tmp2= split("\|",$name);
898 $name = $tmp2[0];
899 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
900 }
901 $this->attrs['gotoShare']=$tmp;
903 $ldap= $this->config->get_ldap_link();
904 $ldap->cd($this->dn);
905 $this->cleanup();
906 $ldap->modify ($this->attrs);
908 show_ldap_error($ldap->get_error());
909 $this->handle_post_events("modify");
910 }
912 /* Add value to array, check if unique */
913 function add_list (&$array, $value)
914 {
915 if ($value != ""){
916 $array[]= $value;
917 sort($array);
918 array_unique ($array);
919 }
920 }
923 /* Delete value to array, check if unique */
924 function del_list (&$array, $list)
925 {
926 $tmp= array();
927 foreach ($array as $mod){
928 if (!in_array($mod, $list)){
929 $tmp[]= $mod;
930 }
931 }
932 $array= $tmp;
933 }
935 /* Generate ListBox frindly output for the defined shares
936 * Possibly Add or remove an attribute here,
937 */
938 function printOutAssignedShares()
939 {
940 $a_return = array();
941 if(is_array($this->gotoShares)){
942 foreach($this->gotoShares as $share){
943 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
944 }
945 }
946 return($a_return);
947 }
949 }
951 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
952 ?>