3c587552768ecf594a36000acaafaf6775eed7c2
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 = "default-inherited";
13 var $gotoKernelParameters = "";
14 var $gotoLdapServer = "default-inherited";
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 var $unresolved_classes = array();
47 /* FAI class selection */
48 var $InheritedFAIclass = array();
49 var $InheritedFAIrelease = "";
50 var $InheritedFAIdebianMirror = "auto";
52 /* Contains all possible server/release/class settings */
53 var $FAIServRepConfig = array();
55 var $CopyPasteVars = array("gotoModules","gotoShares");
57 var $fai_activated = FALSE;
59 function workstartup ($config, $dn= NULL, $parent= NULL)
60 {
61 /* Check if FAI is active */
62 $tmp = search_config($config->data,"faiManagement","CLASS");
63 if(!empty($tmp)){
64 $this->fai_activated = TRUE;
65 }else{
66 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
67 $this->objectclasses = array("GOhard");
68 }
70 plugin::plugin ($config, $dn, $parent);
72 /* Creating a list of valid Mirrors
73 * none will not be saved to ldap.
74 */
75 $ldap = $this->config->get_ldap_link();
76 $ldap->cd($this->config->current['BASE']);
78 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
79 $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
80 }
83 /* FAI Initialization
84 Skip this if FAI is not activated
85 */
86 if($this->fai_activated) {
88 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
89 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
91 /* Search all FAI objects */
92 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
93 /* Sort all entries, and attach elementtype.
94 * To be able to show the types in the listbox.
95 */
96 while($attr = $ldap->fetch()){
97 $cn = $attr['cn'][0];
99 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
101 if(in_array('FAIpackageList',$attr['objectClass'])){
102 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
103 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
104 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
105 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
106 }
107 if(in_array('FAItemplate',$attr['objectClass'])){
108 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
109 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
110 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
111 }
112 if(in_array('FAIvariable',$attr['objectClass'])){
113 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
114 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
115 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
116 }
117 if(in_array('FAIscript',$attr['objectClass'])){
118 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
119 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
120 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
121 }
122 if(in_array('FAIhook',$attr['objectClass'])){
123 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
124 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
125 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
126 }
127 if(in_array('FAIpartitionTable',$attr['objectClass'])){
128 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
129 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
130 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
131 }
132 if(in_array('FAIprofile',$attr['objectClass'])){
133 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
134 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
135 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
136 }
137 }
138 if(is_array($this->FAIclasses)){
139 natcasesort($this->FAIclasses);
140 }
142 if(isset($tmp2)){
143 $this->FAIclassInfo = $tmp2;
144 } else {
145 $this->FAIclassInfo = array();
146 }
148 /* Build up an array like this one :
149 [$url]['SERVER'] = 'srv1-002';
150 [$url]['RELEASE']['siga/rc9.0.2']
151 ['SECTIONS'][0] "main";
152 ['SECTIONS'][1] "non-free";
153 [$url]['RELEASE']['siga/rc9.0.2']
154 ['PACKAGES'][0] "pkg1";
155 ['PACKAGES'][1] "postfix";
156 */
158 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
159 $test = array();
160 while($attr = $ldap->fetch()){
161 if(isset($attr['FAIrepository'])){
163 unset($attr['FAIrepository']['count']);
165 foreach($attr['FAIrepository'] as $rep){
166 $tmp = split("\|",$rep);
168 if(count($tmp)==4){
169 $sections = split(",",$tmp[3]);
170 $release = $tmp[2];
171 $server = $tmp[1];
172 $url = $tmp[0];
174 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
176 /* Result will be cached
177 */
178 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
179 $test[$url]['SERVER'] = $server;
181 /* auto gets all releases/classes
182 */
183 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
184 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
185 }
186 }
187 }
188 }
190 /* Add possible elements from hook */
191 $lines= $this->GetHookElements();
192 foreach ($lines as $hline){
193 $entries= split(";", $hline);
194 if (isset($entries[1]) && !isset($test[$entries[1]])){
195 $test[$entries[1]]['RELEASE']= array();
197 /* Split releases */
198 if (isset($entries[2])){
199 $releases= split(",", $entries[2]);
201 foreach ($releases as $release){
202 $rname= preg_replace('/:.*$/', '', $release);
203 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
204 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
205 $test[$entries[1]]['RELEASE'][$rname]= array();
206 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
207 foreach ($classes as $class){
208 if ($class != ""){
209 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
210 }
211 }
212 }
213 }
214 }
215 }
217 $this->FAIServRepConfig= $test;
219 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
220 $tmp = array();
221 $tmp = split(" ",$this->FAIclass);
222 $tmp2 =array();
224 foreach($tmp as $class){
225 if( ":" == $class[0] ) {
226 $this->FAIrelease = substr( $class, 1 );
227 }
228 else
229 $tmp2[$class] = $class;
230 }
231 $this->FAIclass = $tmp2;
232 }
234 if(!is_array($this->FAIclass)){
235 $this->FAIclass =array();
236 }
237 }// END of FAI initialization stuff
240 /* Get arrays */
241 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
242 if (isset($this->attrs["$val"]["count"])){
243 for ($i= 0; $i<$this->attrs["count"]; $i++){
244 if (isset($this->attrs["$val"][$i])){
245 array_push($this->$val, $this->attrs["$val"][$i]);
246 }
247 }
248 }
249 sort ($this->$val);
250 $this->$val= array_unique($this->$val);
251 }
253 /* Parse Kernel Parameters to decide what boot mode is enabled */
254 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
255 $this->bootmode= "G";
256 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
257 $this->bootmode= "D";
258 } elseif ($this->gotoKernelParameters == "") {
259 $this->bootmode= "G";
260 } else {
261 $this->bootmode= "T";
262 }
263 if (preg_match("/ o /", $this->gotoKernelParameters)){
264 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
265 } else {
266 $this->customParameters= "";
267 }
269 /* Prepare Shares */
270 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
271 unset($this->attrs['gotoShare']['count']);
272 foreach($this->attrs['gotoShare'] as $share){
273 $tmp = $tmp2 = array();
274 $tmp = split("\|",$share);
275 $tmp2['server'] =$tmp[0];
276 $tmp2['name'] =$tmp[1];
277 $tmp2['mountPoint'] =$tmp[2];
278 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
279 }
280 }
282 $this->gotoShareSelections= $config->getShareList(true);
283 $this->gotoAvailableShares= $config->getShareList(false);
284 $tmp2 = array();
287 $this->orig_dn= $this->dn;
289 /* Handle inheritance value "default" */
290 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
292 /* Load hardware list */
293 $ldap= $this->config->get_ldap_link();
294 $ldap->cd($this->config->current['BASE']);
295 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
296 if ($ldap->count() == 1){
298 if($this->fai_activated){
299 $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
300 }else{
301 $map= array("gotoLdapServer");
302 }
303 $attrs= $ldap->fetch();
305 foreach ($map as $name){
306 if (!isset($attrs[$name][0])){
307 continue;
308 }
310 switch ($name){
311 case 'gotoLdapServer':
312 $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
313 break;
315 case 'gotoBootKernel':
316 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
317 break;
319 case 'FAIclass':
320 $str = split(":",$attrs[$name][0]);
321 $this->InheritedFAIclass = split("\ ",trim($str[0]));
322 $this->InheritedFAIrelease = trim($str[1]);
323 break;
325 case 'FAIdebianMirror':
326 $this->InheritedFAIdebianMirror = $attrs[$name][0];
327 break;
328 }
329 }
330 }
332 /* Get list of boot kernels */
333 if (isset($this->config->data['TABS'])){
334 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
336 if (!check_command($command)){
337 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
338 get_class($this));
339 } else {
340 $fh= popen($command, "r");
341 while (!feof($fh)) {
342 $buffer= trim(fgets($fh, 256));
344 if(!empty($buffer)){
346 $name=$value = $buffer;
348 if(preg_match("/:/",$buffer)){
349 $name = preg_replace("/:.*$/","",$buffer);
350 $value= preg_replace("/^.*:/","",$buffer);
351 $this->gotoBootKernels[$name]= $name.":".$value;
352 }else{
353 $this->gotoBootKernels[$name]= $value;
354 }
355 }
357 }
358 pclose($fh);
359 }
360 }
362 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
363 $this->FAIdebianMirror = "inherited";
364 }
366 /* Turn to default, if we've nothing to inherit */
367 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
368 $this->gotoBootKernel= "default";
369 }
370 }
373 /* This class is called by the contrucktor ONLY.
374 * It return the available classes for each
375 * Server / Release combination ...
376 * (Release specifies which classes are available)
377 */
378 function getAvailableClassesForThisRelease($release)
379 {
380 /* There could be more than one server providing this release,
381 so use cached result if available
382 */
383 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
384 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
385 }
387 $test2 = array();
388 $bb = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
389 $ldap = $this->config->get_ldap_link();
390 $ldap->cd($this->config->current['BASE']);
392 /* Get classes fpr given release */
393 $p_classes = get_all_objects_for_given_base($bb,
394 "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
395 "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
396 "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
398 /* Create list of classes */
399 foreach($p_classes as $class){
400 $ldap->cat($class['dn'],array("cn"));
401 $attr = $ldap->fetch();
402 $test2[$attr['cn'][0]] = $attr['cn'][0];
403 }
404 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
405 return($test2);
406 }
409 /* Create array to display available classes/profiles in a selectbox
410 * This function only displays the available classes.
411 * If a class is available is defined by these facts :
412 * 1. Is this class available for the selected release ?
413 * - if it is available, check if the release is available for the selected server
414 * (done by $this->getFAIreleases())
415 * 2. Is this class currently not assigned to $this->FAIclass
416 */
417 function selectFriendlyClasses(){
418 $tmp=array();
420 if($this->FAIdebianMirror == "inherited") return($tmp);
422 /* check if the current release exists,
423 else select the first one ..
424 */
425 $tmp2 = $this->getFAIreleases();
426 if(!in_array($this->FAIrelease, $tmp2)){
427 $this->FAIrelease = key($tmp2);
428 }
430 /* Get all Packages for this server/release combination
431 */
432 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
433 $pkgs = array();
434 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
435 }else{
436 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
437 }
439 /* Check each and every single class name
440 */
441 foreach($pkgs as $pkg){
443 /* Class already assigned to the classes list ?
444 * If not ... go on
445 */
446 if(!in_array($pkg,$this->FAIclass)){
448 /* Create the displayed list entry value
449 HKLMOP [-Pl P V T-] or something like that
450 */
451 $str = "";
452 foreach($this->FAIclassInfo[$pkg] as $entry){
453 if(isset($entry['kzl'])){
454 $str .= $entry['kzl']." ";
455 }
456 }
458 /* Append class if everyting was fine
459 */
460 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
461 }
462 }
463 /* Just sort and return new classes list ...
464 ( possibly we should cache the result ... )
465 */
466 natcasesort ($tmp);
467 return($tmp);
468 }
470 function check()
471 {
472 $messages = array();
474 /* Call common method to give check the hook */
475 $messages= plugin::check();
477 /* If there are packages selected, but no mirror show error */
478 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
479 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
480 }
482 return($messages);
483 }
485 function execute()
486 {
488 /* Call parent execute */
489 plugin::execute();
491 /* Do we need to flip is_account state? */
492 if(isset($_POST['modify_state'])){
493 if($this->is_account && $this->acl_is_removeable()){
494 $this->is_account= FALSE;
495 }elseif(!$this->is_account && $this->acl_is_createable()){
496 $this->is_account= TRUE;
497 }
498 }
500 /* Do we represent a valid terminal? */
501 if (!$this->is_account && $this->parent == NULL){
502 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
503 _("This 'dn' has no terminal features.")."</b>";
504 return ($display);
505 }
507 /* Add module */
508 if (isset ($_POST['add_module'])){
509 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
510 $this->add_list ($this->gotoModules, $_POST['module']);
511 }
512 }
514 /* Delete module */
515 if (isset ($_POST['delete_module'])){
516 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
517 $this->del_list ($this->gotoModules, $_POST['modules_list']);
518 }
519 }
521 /* FAI class management */
522 if($this->fai_activated){
523 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
524 $found = 0 ;
526 /* If this new class/profile will attach a second partition table
527 * to our list of classes, abort and show a message.
528 */
529 foreach($this->FAIclass as $name){
530 if(isset($this->FAIclassInfo[$name])){
531 foreach($this->FAIclassInfo[$name] as $atr){
532 if(isset($atr['obj'])){
533 if($atr['obj'] == "FAIpartitionTable"){
534 $found ++ ;
535 }
536 }
537 }
538 }
539 }
541 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
542 print_red(_("There is already a profile in your selection that contain partition table configurations."));
543 }else{
544 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
545 }
546 }
548 $sort = false;
550 /* Move one used class class one position up or down */
551 if($this->acl_is_writeable("FAIclass")){
552 foreach($_POST as $name => $val){
554 $sort_type = false;
555 if((preg_match("/sort_up/",$name))&&(!$sort)){
556 $sort_type = "sort_up_";
557 }
558 if((preg_match("/sort_down/",$name))&&(!$sort)){
559 $sort_type = "sort_down_";
560 }
562 if(($sort_type)&&(!$sort)){
563 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
564 $sort = true;
566 $last = -1;
567 $change_down = -1;
569 /* Create array with numeric index */
570 $tmp = array();
571 foreach($this->FAIclass as $class){
572 $tmp [] = $class;
573 }
575 /* Walk trough array */
576 foreach($tmp as $key => $faiName){
577 if($faiName == $value){
578 if($sort_type == "sort_up_"){
579 if($last != -1){
580 $change_down= $last;
581 }
582 }else{
583 if(isset($tmp[$key+1])){
584 $change_down = $key;
585 }
586 }
587 }
588 $last = $key;
589 }
591 $tmp2 = array();
592 $skip = false;
594 foreach($tmp as $ky => $vl){
596 if($ky == $change_down){
597 $skip = $vl;
598 }else{
599 $tmp2[$vl] = $vl;
600 }
601 if(($skip != false)&&($ky != $change_down)){
602 $tmp2[$skip] = $skip;
603 $skip =false;
604 }
605 }
606 $this->FAIclass = $tmp2;
607 }
609 if(preg_match("/fai_remove/i",$name)){
610 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
611 unset($this->FAIclass[$value]);
612 }
613 }
614 }
616 /* Delete selected class from our list */
617 if($this->acl_is_writeable("FAIclass")){
618 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
619 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
620 unset($this->FAIclass[$_POST['FAIclassSel']]);
621 }
622 }
623 }
624 }// END fai handling
626 /* Show main page */
627 $smarty= get_smarty();
629 /* Assign ACLs to smarty */
630 $tmp = $this->plInfo();
631 foreach($tmp['plProvidedAcls'] as $name => $translation){
632 $smarty->assign($name."ACL",$this->getacl($name));
633 }
635 $smarty->assign("SelectBoxLdapServer","");
637 /* In this section server shares will be defined
638 * A user can select one of the given shares and a mount point
639 * and attach this combination to his setup.
640 */
641 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
642 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
644 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
645 * This entry will be, a combination of mountPoint and sharedefinitions
646 */
647 if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
648 /* We assign a share to this user, if we don't know where to mount the share */
649 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
650 print_red(_("You must specify a valid mount point."));
651 }else{
652 if(count($this->gotoAvailableShares)){
653 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
654 $s_mount = $_POST['gotoShareMountPoint'];
655 /* Preparing the new assignment */
656 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
657 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
658 }
659 }
660 }
662 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
663 * If there is no defined share selected, we will abort the deletion without any message
664 */
665 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
666 unset($this->gotoShares[$_POST['gotoShare']]);
667 }
669 $smarty->assign("gotoShares",$this->printOutAssignedShares());
670 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
671 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
672 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
674 /* Arrays */
675 $tmp = $this->goLdapServerList;
677 /* Create divSelectBox for ldap server selection
678 */
679 $SelectBoxLdapServer = new divSelectBox("LdapServer");
680 $SelectBoxLdapServer->SetHeight(130);
682 /* Set first entry as selected, if $this->gotoLdapServer is empty
683 * or given entry is no longer available ...
684 */
685 $found = false;
686 foreach($tmp as $server){
687 if($this->gotoLdapServer==$server){
688 $found = true;
689 }
690 }
692 /* Add Entries
693 */
694 foreach($tmp as $key => $server){
695 $use ="";
696 if(($this->gotoLdapServer == $server) || ($found == false)) {
697 $found = true;
698 $use = " checked ";
699 };
701 $display = $server;
703 $SelectBoxLdapServer->AddEntry(
704 array(
705 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
706 "attach"=>"style='border-left:0px;'"),
707 array("string"=>$display)
708 ));
709 }
711 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
713 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
714 $smarty->assign("$val", $this->$val);
715 }
717 /* Values */
718 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
719 $smarty->assign($val, $this->$val);
720 }
722 $smarty->assign("fai_activated",$this->fai_activated);
724 /* Create FAI output */
725 if($this->fai_activated){
726 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
727 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
728 $smarty->assign("FAIreleases",$this->getFAIreleases());
729 $smarty->assign("FAIrelease",$this->FAIrelease);
730 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
731 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
732 $smarty->assign("FAIclassKeys",$this->FAIclass);
734 $inheritedRelease = array();
735 if(!empty($this->InheritedFAIrelease)){
736 $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
737 }
738 $smarty->assign("InheritedFAIrelease",$inheritedRelease);
740 $div = new divSelectBox("WSFAIscriptClasses");
741 $div -> SetHeight("110");
742 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
743 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
744 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
745 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
747 $i = 1;
749 if($this->FAIdebianMirror == "inherited"){
750 $tmp = $this->InheritedFAIclass;
751 }else{
752 $tmp = $this->FAIclass;
753 }
755 foreach($tmp as $class){
757 $marker = "";
758 if(in_array_ics($class,$this->unresolved_classes)){
759 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
760 }
762 if($this->FAIdebianMirror == "inherited"){
763 $str = "";
764 }else{
765 if($i==1){
766 $str = $str_empty.$str_down.$str_remove;
767 }elseif($i == count($this->FAIclass)){
768 $str = $str_up.$str_empty.$str_remove;
769 }else{
770 $str = $str_up.$str_down.$str_remove;
771 }
772 }
773 $i ++ ;
775 $div->AddEntry(array(
776 array("string"=>$class.$marker),
777 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
778 ));
779 }
781 $smarty->assign("FAIScriptlist",$div->DrawList());
782 }// END FAI output generation
784 /* Radio button group */
785 if (preg_match("/G/", $this->bootmode)) {
786 $smarty->assign("graphicalbootup", "checked");
787 } else {
788 $smarty->assign("graphicalbootup", "");
789 }
790 if (preg_match("/T/", $this->bootmode)) {
791 $smarty->assign("textbootup", "checked");
792 } else {
793 $smarty->assign("textbootup", "");
794 }
795 if (preg_match("/D/", $this->bootmode)) {
796 $smarty->assign("debugbootup", "checked");
797 } else {
798 $smarty->assign("debugbootup", "");
799 }
801 /* Show main page */
802 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
803 }
805 function remove_from_parent()
806 {
807 $this->handle_post_events("remove");
808 }
810 function generateDNSyn($release)
811 {
812 $str = "";
813 $tmp = split("\/",$release);
814 $tmp = array_reverse($tmp);
816 $base = "ou=fai,ou=configs,ou=systems,";
817 foreach($tmp as $departmentname){
819 $str .= ",ou=".$departmentname;
820 }
821 $str = preg_replace("/^,/","",($str.",".$base));
823 return($str);
824 }
826 function getFAIdebianMirrors()
827 {
828 $ret = array();
829 $ret['inherited']="["._("inherited")."]";
830 $ret['auto']=_("automatic");
831 $secs = array();
833 /* Walk through all available servers
834 and check if they support the currently selected classes
835 if not, dont't add them to our list
836 */
837 foreach($this->FAIServRepConfig as $mirror => $rest){
839 $use = false;
841 if(count($this->FAIclass) == 0){
842 $use = true;
843 }else{
844 $tmp = $this->getFAIreleases();
845 foreach($tmp as $release){
846 if(isset($rest['RELEASE'][$release])){
847 $use =true;
848 }
849 }
850 }
852 /* If current server, doesn't support this class
853 remove it from list
854 */
855 if($use){
856 $ret[$mirror] = $mirror;
857 }
858 }
859 return($ret);
860 }
862 function getFAIreleases()
863 {
864 $ret = array();
866 if($this->FAIdebianMirror == "inherited") return(array());
868 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
869 $this->FAIdebianMirror = "auto";
870 }
872 $errorClasses = array();
874 if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
875 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
876 $use = true;
878 if(!count($this->FAIclass) == 0){
879 foreach($this->FAIclass as $class){
880 if(!in_array($class, $sections['PACKAGES'])){
881 $use = false;
882 $errorClasses[$class] = $class;
883 }else{
884 if(isset($errorClasses[$class])){
885 unset($errorClasses[$class]);
886 }
887 }
888 }
889 }
890 if($use){
891 $ret[$release]=$release;
892 }
893 }
894 }
895 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
897 $eClasses = " ";
898 foreach($errorClasses as $class){
899 $eClasses .= $class." ";
900 }
902 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));
903 $this->FAIdebianMirror = "auto";
904 return($this->getFAIreleases());
905 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
907 $eClasses = " ";
908 foreach($errorClasses as $class){
909 $eClasses .= $class." ";
910 }
912 $eClasses = preg_replace("/ */","",$eClasses);
914 if(!empty($eClasses)) {
916 $this->unresolved_classes = $errorClasses;
917 $this->FAIdebianMirror = "auto";
918 print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. Server was reset to 'auto'."),$eClasses));
919 }
920 }
921 return($ret);
922 }
924 /* Save data to object */
925 function save_object()
926 {
927 plugin::save_object();
929 /* Save group radio buttons */
930 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
931 $this->bootmode= $_POST["bootmode"];
932 }
934 /* Save kernel parameters */
935 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
936 $this->customParameters= $_POST["customParameters"];
937 }
939 }
942 /* Save to LDAP */
943 function save()
944 {
946 /* Depending on the baseobject (Ogroup / WS) we
947 * use another set of objectClasses
948 * In case of WS itself, we use "array("GOhard", "FAIobject");"
949 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
950 */
951 if(isset($this->parent->by_object['ogroup'])){
952 $this->objectclasses = array("gotoWorkstationTemplate");
953 }elseif(isset($this->parent->by_object['workgeneric'])){
954 $this->objectclasses = array("GOhard");
955 }elseif(isset($this->parent->by_object['servgeneric'])){
956 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
957 }else{
958 print "Object Type Configuration : unknown";
959 exit();
960 }
962 /* Append FAI class */
963 if($this->fai_activated){
964 $this->objectclasses[] = "FAIobject";
965 }
967 /* Find proper terminal path for tftp configuration
968 FIXME: This is suboptimal when the default has changed to
969 another location! */
970 if (($this->gotoTerminalPath == "default")){
971 $ldap= $this->config->get_ldap_link();
973 /* Strip relevant part from dn, keep trailing ',' */
974 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
975 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
977 /* Walk from top to base and try to load default values for
978 'gotoTerminalPath'. Abort when an entry is found. */
979 while (TRUE){
980 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
982 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
983 $this->config->current['BASE'], array('gotoTerminalPath'));
984 $attrs= $ldap->fetch();
985 if (isset($attrs['gotoTerminalPath'])){
986 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
987 break;
988 }
990 /* Nothing left? */
991 if ($tmp == ""){
992 break;
993 }
994 }
995 }
997 /* Add semi automatic values */
998 // FIXME: LDAP Server may not be set here...
999 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1001 switch ($this->bootmode){
1002 case "D":
1003 $this->gotoKernelParameters.= " debug";
1004 break;
1005 case "G":
1006 $this->gotoKernelParameters.= " splash=silent";
1007 break;
1008 }
1009 if ($this->customParameters != ""){
1010 $this->gotoKernelParameters.= " o ".$this->customParameters;
1011 }
1013 plugin::save();
1015 unset( $this->attrs['FAIrelease'] );
1017 $str = "";
1019 /* Skip FAI attribute handling if not necessary */
1020 if($this->fai_activated){
1021 if($this->FAIdebianMirror == "inherited"){
1022 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1023 }else{
1024 foreach($this->FAIclass as $class){
1025 $str .= $class." ";
1026 }
1027 $str .= ":" . $this->FAIrelease;
1028 $this->attrs['FAIclass']= "";
1029 $this->attrs['FAIclass']= trim($str);
1031 if(empty($this->attrs['FAIclass'])){
1032 $this->attrs['FAIclass'] = array();
1033 }
1034 }
1035 }
1037 /* Add missing arrays */
1038 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1039 if (isset ($this->$val) && count ($this->$val) != 0){
1041 $this->attrs["$val"]= array_unique($this->$val);
1042 }
1043 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1044 }
1046 /* Strip out 'default' values */
1047 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1048 $this->attrs['gotoLdapServer']= array();
1049 }
1051 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1052 $this->attrs['gotoBootKernel']= array();
1053 }
1055 /* if mirror == none stop saving this attribute */
1056 if($this->FAIdebianMirror == "none"){
1057 $this->FAIdebianMirror = "";
1058 }
1060 /* Get FAIstate from object, the generic tab could have changed it during execute */
1061 $ldap= $this->config->get_ldap_link();
1062 $ldap->cd($this->dn);
1065 /* Skip FAI attribute handling if not necessary */
1066 if($this->fai_activated){
1067 $ldap->cat($this->dn,array("FAIstate"));
1068 $checkFAIstate = $ldap->fetch();
1070 /* Remove FAI objects if no FAI class is selected */
1071 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1072 $this->attrs['FAIclass'] = array();
1073 $this->attrs['FAIdebianMirror'] = array();
1074 }
1075 }
1078 /* prepare share settings */
1079 $tmp = array();
1080 foreach($this->gotoShares as $name => $settings){
1081 $tmp2= split("\|",$name);
1082 $name = $tmp2[0];
1083 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1084 }
1085 $this->attrs['gotoShare']=$tmp;
1087 $this->cleanup();
1088 $ldap->modify ($this->attrs);
1090 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1091 $this->handle_post_events("modify");
1092 }
1094 /* Add value to array, check if unique */
1095 function add_list (&$array, $value)
1096 {
1097 if ($value != ""){
1098 $array[]= $value;
1099 sort($array);
1100 array_unique ($array);
1101 }
1102 }
1105 /* Delete value to array, check if unique */
1106 function del_list (&$array, $list)
1107 {
1108 $tmp= array();
1109 foreach ($array as $mod){
1110 if (!in_array($mod, $list)){
1111 $tmp[]= $mod;
1112 }
1113 }
1114 $array= $tmp;
1115 }
1117 /* Generate ListBox frindly output for the defined shares
1118 * Possibly Add or remove an attribute here,
1119 */
1120 function printOutAssignedShares()
1121 {
1122 $a_return = array();
1123 if(is_array($this->gotoShares)){
1124 foreach($this->gotoShares as $share){
1125 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1126 }
1127 }
1128 return($a_return);
1129 }
1132 function GetHookElements()
1133 {
1134 $ret = array();
1135 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1136 if(!empty($cmd)){
1137 $res = shell_exec($cmd);
1138 $res2 = trim($res);
1139 if((!$res)){
1140 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1141 }elseif(empty($res2)){
1142 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1143 }else{
1144 $tmp = split("\n",$res);
1145 foreach($tmp as $line){
1146 if(empty($line)) continue;
1147 $ret[]= $line;
1148 }
1149 }
1150 }
1151 return($ret);
1152 }
1155 /* Return plugin informations for acl handling */
1156 function plInfo()
1157 {
1158 return (array(
1159 "plShortName" => _("Startup"),
1160 "plDescription" => _("System startup"),
1161 "plSelfModify" => FALSE,
1162 "plDepends" => array(),
1163 "plPriority" => 9,
1164 "plSection" => array("administration"),
1165 "plCategory" => array("workstation","server","ogroups"),
1167 "plProvidedAcls"=> array(
1168 "gotoLdapServer" => _("Ldap server"),
1169 "gotoBootKernel" => _("Boot kernel"),
1170 "gotoKernelParameters" => _("Kernel parameter"),
1172 "gotoModules" => _("Kernel modules"),
1173 "gotoShare" => _("Shares"),
1175 "FAIclass" => _("FAI classes"),
1176 "FAIdebianMirror" => _("Debian mirror"),
1177 "FAIrelease" => _("Debian release"),
1179 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1180 ));
1181 }
1182 }
1184 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1185 ?>