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 }
371 @log::log("view","workstation/".get_class($this),$this->dn);
372 }
375 /* This class is called by the contrucktor ONLY.
376 * It return the available classes for each
377 * Server / Release combination ...
378 * (Release specifies which classes are available)
379 */
380 function getAvailableClassesForThisRelease($release)
381 {
382 /* There could be more than one server providing this release,
383 so use cached result if available
384 */
385 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
386 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
387 }
389 $test2 = array();
390 $bb = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
391 $ldap = $this->config->get_ldap_link();
392 $ldap->cd($this->config->current['BASE']);
394 /* Get classes fpr given release */
395 $p_classes = get_all_objects_for_given_base($bb,
396 "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
397 "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
398 "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
400 /* Create list of classes */
401 foreach($p_classes as $class){
402 $ldap->cat($class['dn'],array("cn"));
403 $attr = $ldap->fetch();
404 $test2[$attr['cn'][0]] = $attr['cn'][0];
405 }
406 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
407 return($test2);
408 }
411 /* Create array to display available classes/profiles in a selectbox
412 * This function only displays the available classes.
413 * If a class is available is defined by these facts :
414 * 1. Is this class available for the selected release ?
415 * - if it is available, check if the release is available for the selected server
416 * (done by $this->getFAIreleases())
417 * 2. Is this class currently not assigned to $this->FAIclass
418 */
419 function selectFriendlyClasses(){
420 $tmp=array();
422 if($this->FAIdebianMirror == "inherited") return($tmp);
424 /* check if the current release exists,
425 else select the first one ..
426 */
427 $tmp2 = $this->getFAIreleases();
428 if(!in_array($this->FAIrelease, $tmp2)){
429 $this->FAIrelease = key($tmp2);
430 }
432 /* Get all Packages for this server/release combination
433 */
434 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
435 $pkgs = array();
436 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
437 }else{
438 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
439 }
441 /* Check each and every single class name
442 */
443 foreach($pkgs as $pkg){
445 /* Class already assigned to the classes list ?
446 * If not ... go on
447 */
448 if(!in_array($pkg,$this->FAIclass)){
450 /* Create the displayed list entry value
451 HKLMOP [-Pl P V T-] or something like that
452 */
453 $str = "";
454 foreach($this->FAIclassInfo[$pkg] as $entry){
455 if(isset($entry['kzl'])){
456 $str .= $entry['kzl']." ";
457 }
458 }
460 /* Append class if everyting was fine
461 */
462 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
463 }
464 }
465 /* Just sort and return new classes list ...
466 ( possibly we should cache the result ... )
467 */
468 natcasesort ($tmp);
469 return($tmp);
470 }
472 function check()
473 {
474 $messages = array();
476 /* Call common method to give check the hook */
477 $messages= plugin::check();
479 /* If there are packages selected, but no mirror show error */
480 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
481 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
482 }
484 return($messages);
485 }
487 function execute()
488 {
490 /* Call parent execute */
491 plugin::execute();
493 /* Do we need to flip is_account state? */
494 if(isset($_POST['modify_state'])){
495 if($this->is_account && $this->acl_is_removeable()){
496 $this->is_account= FALSE;
497 }elseif(!$this->is_account && $this->acl_is_createable()){
498 $this->is_account= TRUE;
499 }
500 }
502 /* Do we represent a valid terminal? */
503 if (!$this->is_account && $this->parent == NULL){
504 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
505 _("This 'dn' has no terminal features.")."</b>";
506 return ($display);
507 }
509 /* Add module */
510 if (isset ($_POST['add_module'])){
511 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
512 $this->add_list ($this->gotoModules, $_POST['module']);
513 }
514 }
516 /* Delete module */
517 if (isset ($_POST['delete_module'])){
518 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
519 $this->del_list ($this->gotoModules, $_POST['modules_list']);
520 }
521 }
523 /* FAI class management */
524 if($this->fai_activated){
525 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
526 $found = 0 ;
528 /* If this new class/profile will attach a second partition table
529 * to our list of classes, abort and show a message.
530 */
531 foreach($this->FAIclass as $name){
532 if(isset($this->FAIclassInfo[$name])){
533 foreach($this->FAIclassInfo[$name] as $atr){
534 if(isset($atr['obj'])){
535 if($atr['obj'] == "FAIpartitionTable"){
536 $found ++ ;
537 }
538 }
539 }
540 }
541 }
543 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
544 print_red(_("There is already a profile in your selection that contain partition table configurations."));
545 }else{
546 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
547 }
548 }
550 $sort = false;
552 /* Move one used class class one position up or down */
553 if($this->acl_is_writeable("FAIclass")){
554 foreach($_POST as $name => $val){
556 $sort_type = false;
557 if((preg_match("/sort_up/",$name))&&(!$sort)){
558 $sort_type = "sort_up_";
559 }
560 if((preg_match("/sort_down/",$name))&&(!$sort)){
561 $sort_type = "sort_down_";
562 }
564 if(($sort_type)&&(!$sort)){
565 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
566 $sort = true;
568 $last = -1;
569 $change_down = -1;
571 /* Create array with numeric index */
572 $tmp = array();
573 foreach($this->FAIclass as $class){
574 $tmp [] = $class;
575 }
577 /* Walk trough array */
578 foreach($tmp as $key => $faiName){
579 if($faiName == $value){
580 if($sort_type == "sort_up_"){
581 if($last != -1){
582 $change_down= $last;
583 }
584 }else{
585 if(isset($tmp[$key+1])){
586 $change_down = $key;
587 }
588 }
589 }
590 $last = $key;
591 }
593 $tmp2 = array();
594 $skip = false;
596 foreach($tmp as $ky => $vl){
598 if($ky == $change_down){
599 $skip = $vl;
600 }else{
601 $tmp2[$vl] = $vl;
602 }
603 if(($skip != false)&&($ky != $change_down)){
604 $tmp2[$skip] = $skip;
605 $skip =false;
606 }
607 }
608 $this->FAIclass = $tmp2;
609 }
611 if(preg_match("/fai_remove/i",$name)){
612 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
613 unset($this->FAIclass[$value]);
614 }
615 }
616 }
618 /* Delete selected class from our list */
619 if($this->acl_is_writeable("FAIclass")){
620 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
621 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
622 unset($this->FAIclass[$_POST['FAIclassSel']]);
623 }
624 }
625 }
626 }// END fai handling
628 /* Show main page */
629 $smarty= get_smarty();
631 /* Assign ACLs to smarty */
632 $tmp = $this->plInfo();
633 foreach($tmp['plProvidedAcls'] as $name => $translation){
634 $smarty->assign($name."ACL",$this->getacl($name));
635 }
637 $smarty->assign("SelectBoxLdapServer","");
639 /* In this section server shares will be defined
640 * A user can select one of the given shares and a mount point
641 * and attach this combination to his setup.
642 */
643 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
644 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
646 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
647 * This entry will be, a combination of mountPoint and sharedefinitions
648 */
649 if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
650 /* We assign a share to this user, if we don't know where to mount the share */
651 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
652 print_red(_("You must specify a valid mount point."));
653 }else{
654 if(count($this->gotoAvailableShares)){
655 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
656 $s_mount = $_POST['gotoShareMountPoint'];
657 /* Preparing the new assignment */
658 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
659 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
660 }
661 }
662 }
664 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
665 * If there is no defined share selected, we will abort the deletion without any message
666 */
667 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
668 unset($this->gotoShares[$_POST['gotoShare']]);
669 }
671 $smarty->assign("gotoShares",$this->printOutAssignedShares());
672 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
673 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
674 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
676 /* Arrays */
677 $tmp = $this->goLdapServerList;
679 /* Create divSelectBox for ldap server selection
680 */
681 $SelectBoxLdapServer = new divSelectBox("LdapServer");
682 $SelectBoxLdapServer->SetHeight(130);
684 /* Set first entry as selected, if $this->gotoLdapServer is empty
685 * or given entry is no longer available ...
686 */
687 $found = false;
688 foreach($tmp as $server){
689 if($this->gotoLdapServer==$server){
690 $found = true;
691 }
692 }
694 /* Add Entries
695 */
696 foreach($tmp as $key => $server){
697 $use ="";
698 if(($this->gotoLdapServer == $server) || ($found == false)) {
699 $found = true;
700 $use = " checked ";
701 };
703 $display = $server;
705 $SelectBoxLdapServer->AddEntry(
706 array(
707 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
708 "attach"=>"style='border-left:0px;'"),
709 array("string"=>$display)
710 ));
711 }
713 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
715 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
716 $smarty->assign("$val", $this->$val);
717 }
719 /* Values */
720 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
721 $smarty->assign($val, $this->$val);
722 }
724 $smarty->assign("fai_activated",$this->fai_activated);
726 /* Create FAI output */
727 if($this->fai_activated){
728 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
729 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
730 $smarty->assign("FAIreleases",$this->getFAIreleases());
731 $smarty->assign("FAIrelease",$this->FAIrelease);
732 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
733 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
734 $smarty->assign("FAIclassKeys",$this->FAIclass);
736 $inheritedRelease = array();
737 if(!empty($this->InheritedFAIrelease)){
738 $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
739 }
740 $smarty->assign("InheritedFAIrelease",$inheritedRelease);
742 $div = new divSelectBox("WSFAIscriptClasses");
743 $div -> SetHeight("110");
744 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
745 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
746 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
747 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
749 $i = 1;
751 if($this->FAIdebianMirror == "inherited"){
752 $tmp = $this->InheritedFAIclass;
753 }else{
754 $tmp = $this->FAIclass;
755 }
757 foreach($tmp as $class){
759 $marker = "";
760 if(in_array_ics($class,$this->unresolved_classes)){
761 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
762 }
764 if($this->FAIdebianMirror == "inherited"){
765 $str = "";
766 }else{
767 if($i==1){
768 $str = $str_empty.$str_down.$str_remove;
769 }elseif($i == count($this->FAIclass)){
770 $str = $str_up.$str_empty.$str_remove;
771 }else{
772 $str = $str_up.$str_down.$str_remove;
773 }
774 }
775 $i ++ ;
777 $div->AddEntry(array(
778 array("string"=>$class.$marker),
779 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
780 ));
781 }
783 $smarty->assign("FAIScriptlist",$div->DrawList());
784 }// END FAI output generation
786 /* Radio button group */
787 if (preg_match("/G/", $this->bootmode)) {
788 $smarty->assign("graphicalbootup", "checked");
789 } else {
790 $smarty->assign("graphicalbootup", "");
791 }
792 if (preg_match("/T/", $this->bootmode)) {
793 $smarty->assign("textbootup", "checked");
794 } else {
795 $smarty->assign("textbootup", "");
796 }
797 if (preg_match("/D/", $this->bootmode)) {
798 $smarty->assign("debugbootup", "checked");
799 } else {
800 $smarty->assign("debugbootup", "");
801 }
803 /* Show main page */
804 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
805 }
807 function remove_from_parent()
808 {
809 $this->handle_post_events("remove");
810 @log::log("remove","workstation/".get_class($this),$this->dn);
811 }
813 function generateDNSyn($release)
814 {
815 $str = "";
816 $tmp = split("\/",$release);
817 $tmp = array_reverse($tmp);
819 $base = "ou=fai,ou=configs,ou=systems,";
820 foreach($tmp as $departmentname){
822 $str .= ",ou=".$departmentname;
823 }
824 $str = preg_replace("/^,/","",($str.",".$base));
826 return($str);
827 }
829 function getFAIdebianMirrors()
830 {
831 $ret = array();
832 $ret['inherited']="["._("inherited")."]";
833 $ret['auto']=_("automatic");
834 $secs = array();
836 /* Walk through all available servers
837 and check if they support the currently selected classes
838 if not, dont't add them to our list
839 */
840 foreach($this->FAIServRepConfig as $mirror => $rest){
842 $use = false;
844 if(count($this->FAIclass) == 0){
845 $use = true;
846 }else{
847 $tmp = $this->getFAIreleases();
848 foreach($tmp as $release){
849 if(isset($rest['RELEASE'][$release])){
850 $use =true;
851 }
852 }
853 }
855 /* If current server, doesn't support this class
856 remove it from list
857 */
858 if($use){
859 $ret[$mirror] = $mirror;
860 }
861 }
862 return($ret);
863 }
865 function getFAIreleases()
866 {
867 $ret = array();
869 if($this->FAIdebianMirror == "inherited") return(array());
871 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
872 $this->FAIdebianMirror = "auto";
873 }
875 $errorClasses = array();
877 if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
878 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
879 $use = true;
881 if(!count($this->FAIclass) == 0){
882 foreach($this->FAIclass as $class){
883 if(!in_array($class, $sections['PACKAGES'])){
884 $use = false;
885 $errorClasses[$class] = $class;
886 }else{
887 if(isset($errorClasses[$class])){
888 unset($errorClasses[$class]);
889 }
890 }
891 }
892 }
893 if($use){
894 $ret[$release]=$release;
895 }
896 }
897 }
898 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
900 $eClasses = " ";
901 foreach($errorClasses as $class){
902 $eClasses .= $class." ";
903 }
905 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));
906 $this->FAIdebianMirror = "auto";
907 return($this->getFAIreleases());
908 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
910 $eClasses = " ";
911 foreach($errorClasses as $class){
912 $eClasses .= $class." ";
913 }
915 $eClasses = preg_replace("/ */","",$eClasses);
917 if(!empty($eClasses)) {
919 $this->unresolved_classes = $errorClasses;
920 $this->FAIdebianMirror = "auto";
921 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));
922 }
923 }
924 return($ret);
925 }
927 /* Save data to object */
928 function save_object()
929 {
930 plugin::save_object();
932 /* Save group radio buttons */
933 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
934 $this->bootmode= $_POST["bootmode"];
935 }
937 /* Save kernel parameters */
938 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
939 $this->customParameters= $_POST["customParameters"];
940 }
942 }
945 /* Save to LDAP */
946 function save()
947 {
949 /* Depending on the baseobject (Ogroup / WS) we
950 * use another set of objectClasses
951 * In case of WS itself, we use "array("GOhard", "FAIobject");"
952 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
953 */
954 if(isset($this->parent->by_object['ogroup'])){
955 $this->objectclasses = array("gotoWorkstationTemplate");
956 }elseif(isset($this->parent->by_object['workgeneric'])){
957 $this->objectclasses = array("GOhard");
958 }elseif(isset($this->parent->by_object['servgeneric'])){
959 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
960 }else{
961 print "Object Type Configuration : unknown";
962 exit();
963 }
965 /* Append FAI class */
966 if($this->fai_activated){
967 $this->objectclasses[] = "FAIobject";
968 }
970 /* Find proper terminal path for tftp configuration
971 FIXME: This is suboptimal when the default has changed to
972 another location! */
973 if (($this->gotoTerminalPath == "default")){
974 $ldap= $this->config->get_ldap_link();
976 /* Strip relevant part from dn, keep trailing ',' */
977 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
978 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
980 /* Walk from top to base and try to load default values for
981 'gotoTerminalPath'. Abort when an entry is found. */
982 while (TRUE){
983 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
985 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
986 $this->config->current['BASE'], array('gotoTerminalPath'));
987 $attrs= $ldap->fetch();
988 if (isset($attrs['gotoTerminalPath'])){
989 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
990 break;
991 }
993 /* Nothing left? */
994 if ($tmp == ""){
995 break;
996 }
997 }
998 }
1000 /* Add semi automatic values */
1001 // FIXME: LDAP Server may not be set here...
1002 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1004 switch ($this->bootmode){
1005 case "D":
1006 $this->gotoKernelParameters.= " debug";
1007 break;
1008 case "G":
1009 $this->gotoKernelParameters.= " splash=silent";
1010 break;
1011 }
1012 if ($this->customParameters != ""){
1013 $this->gotoKernelParameters.= " o ".$this->customParameters;
1014 }
1016 plugin::save();
1018 unset( $this->attrs['FAIrelease'] );
1020 $str = "";
1022 /* Skip FAI attribute handling if not necessary */
1023 if($this->fai_activated){
1024 if($this->FAIdebianMirror == "inherited"){
1025 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1026 }else{
1027 foreach($this->FAIclass as $class){
1028 $str .= $class." ";
1029 }
1030 $str .= ":" . $this->FAIrelease;
1031 $this->attrs['FAIclass']= "";
1032 $this->attrs['FAIclass']= trim($str);
1034 if(empty($this->attrs['FAIclass'])){
1035 $this->attrs['FAIclass'] = array();
1036 }
1037 }
1038 }
1040 /* Add missing arrays */
1041 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1042 if (isset ($this->$val) && count ($this->$val) != 0){
1044 $this->attrs["$val"]= array_unique($this->$val);
1045 }
1046 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1047 }
1049 /* Strip out 'default' values */
1050 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1051 $this->attrs['gotoLdapServer']= array();
1052 }
1054 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1055 $this->attrs['gotoBootKernel']= array();
1056 }
1058 /* if mirror == none stop saving this attribute */
1059 if($this->FAIdebianMirror == "none"){
1060 $this->FAIdebianMirror = "";
1061 }
1063 /* Get FAIstate from object, the generic tab could have changed it during execute */
1064 $ldap= $this->config->get_ldap_link();
1065 $ldap->cd($this->dn);
1068 /* Skip FAI attribute handling if not necessary */
1069 if($this->fai_activated){
1070 $ldap->cat($this->dn,array("FAIstate"));
1071 $checkFAIstate = $ldap->fetch();
1073 /* Remove FAI objects if no FAI class is selected */
1074 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1075 $this->attrs['FAIclass'] = array();
1076 $this->attrs['FAIdebianMirror'] = array();
1077 }
1078 }
1081 /* prepare share settings */
1082 $tmp = array();
1083 foreach($this->gotoShares as $name => $settings){
1084 $tmp2= split("\|",$name);
1085 $name = $tmp2[0];
1086 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1087 }
1088 $this->attrs['gotoShare']=$tmp;
1090 $this->cleanup();
1091 $ldap->modify ($this->attrs);
1092 @log::log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1094 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1095 $this->handle_post_events("modify");
1096 }
1098 /* Add value to array, check if unique */
1099 function add_list (&$array, $value)
1100 {
1101 if ($value != ""){
1102 $array[]= $value;
1103 sort($array);
1104 array_unique ($array);
1105 }
1106 }
1109 /* Delete value to array, check if unique */
1110 function del_list (&$array, $list)
1111 {
1112 $tmp= array();
1113 foreach ($array as $mod){
1114 if (!in_array($mod, $list)){
1115 $tmp[]= $mod;
1116 }
1117 }
1118 $array= $tmp;
1119 }
1121 /* Generate ListBox frindly output for the defined shares
1122 * Possibly Add or remove an attribute here,
1123 */
1124 function printOutAssignedShares()
1125 {
1126 $a_return = array();
1127 if(is_array($this->gotoShares)){
1128 foreach($this->gotoShares as $share){
1129 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1130 }
1131 }
1132 return($a_return);
1133 }
1136 function GetHookElements()
1137 {
1138 $ret = array();
1139 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1140 if(!empty($cmd)){
1141 $res = shell_exec($cmd);
1142 $res2 = trim($res);
1143 if((!$res)){
1144 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1145 }elseif(empty($res2)){
1146 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1147 }else{
1148 $tmp = split("\n",$res);
1149 foreach($tmp as $line){
1150 if(empty($line)) continue;
1151 $ret[]= $line;
1152 }
1153 }
1154 }
1155 return($ret);
1156 }
1159 /* Return plugin informations for acl handling */
1160 function plInfo()
1161 {
1162 return (array(
1163 "plShortName" => _("Startup"),
1164 "plDescription" => _("System startup"),
1165 "plSelfModify" => FALSE,
1166 "plDepends" => array(),
1167 "plPriority" => 9,
1168 "plSection" => array("administration"),
1169 "plCategory" => array("workstation","server","ogroups"),
1171 "plProvidedAcls"=> array(
1172 "gotoLdapServer" => _("Ldap server"),
1173 "gotoBootKernel" => _("Boot kernel"),
1174 "gotoKernelParameters" => _("Kernel parameter"),
1176 "gotoModules" => _("Kernel modules"),
1177 "gotoShare" => _("Shares"),
1179 "FAIclass" => _("FAI classes"),
1180 "FAIdebianMirror" => _("Debian mirror"),
1181 "FAIrelease" => _("Debian release"),
1183 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1184 ));
1185 }
1186 }
1188 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1189 ?>