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 /* Ldap server list */
10 var $gotoLdapServers = array();
11 var $gotoLdapServerList = array();
12 var $gotoLdap_inherit = FALSE;
14 /* Generic terminal attributes */
15 var $bootmode = "G";
16 var $gotoBootKernel = "default-inherited";
17 var $gotoKernelParameters = "";
18 var $gotoLdapServer = "default-inherited";
19 var $gotoModules = array();
20 var $gotoAutoFs = array();
21 var $gotoFilesystem = array();
22 var $gotoTerminalPath = "";
23 var $FAIstatus = "";
24 var $gotoBootKernels = array();
26 /* attribute list for save action */
27 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
28 var $objectclasses = array("GOhard", "FAIobject");
30 /* Share */
31 var $gotoShares = array();// Currently Share Option
32 var $gotoShare = ""; // currently selected Share Option
33 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
34 var $gotoAvailableShares= array();// Available Shares for this account
36 /* Helper */
37 var $customParameters = "";
38 var $orig_dn = "";
39 var $ignore_account = TRUE;
41 /* FAI class selection */
42 var $FAIclass = array();
43 var $FAIclasses = array();
44 var $FAIclassInfo = array();
45 var $FAIrelease = "";
46 var $FAIdebianMirror = "auto";
48 var $unresolved_classes = array();
49 var $view_logged = FALSE;
51 /* FAI class selection */
52 var $InheritedFAIclass = array();
53 var $InheritedFAIrelease = "";
54 var $InheritedFAIdebianMirror = "auto";
56 /* Contains all possible server/release/class settings */
57 var $FAIServRepConfig = array();
59 var $CopyPasteVars = array("gotoModules","gotoShares");
61 var $fai_activated = FALSE;
62 var $o_group_dn ="";
63 var $member_of_ogroup = FALSE;
65 function workstartup (&$config, $dn= NULL, $parent= NULL)
66 {
67 /* Check if FAI is active */
68 $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
69 if(!empty($tmp)){
70 $this->fai_activated = TRUE;
71 }else{
72 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
73 $this->objectclasses = array("GOhard");
74 }
76 plugin::plugin ($config, $dn, $parent);
78 if(!isset($this->parent->by_object['ogroup'])){
79 $ldap = $this->config->get_ldap_link();
80 $ldap->cd ($this->config->current['BASE']);
81 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))",array("cn","dn"));
82 if($ldap->count()){
83 $this->member_of_ogroup = TRUE;
84 $attrs = $ldap->fetch();
85 $this->o_group_dn = $attrs['dn'];
86 }
87 }
89 /* Creating a list of valid Mirrors
90 * none will not be saved to ldap.
91 */
92 $ldap = $this->config->get_ldap_link();
93 $ldap->cd($this->config->current['BASE']);
95 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
96 $this->gotoLdapServerList[]= $server;
97 }
99 if(isset($this->attrs['gotoLdapServer'])){
100 unset($this->attrs['gotoLdapServer']['count']);
101 sort($this->attrs['gotoLdapServer']);
102 foreach($this->attrs['gotoLdapServer'] as $value){
103 $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
104 }
105 }
106 if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
107 $this->gotoLdap_inherit = TRUE;
108 }
110 /* FAI Initialization
111 Skip this if FAI is not activated
112 */
113 if($this->fai_activated) {
115 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
116 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
118 /* Search all FAI objects */
119 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection",'description'));
120 /* Sort all entries, and attach elementtype.
121 * To be able to show the types in the listbox.
122 */
123 while($attr = $ldap->fetch()){
124 $cn = $attr['cn'][0];
126 if(!isset($attr['description'])){
127 $attr['description'][0] ="";
128 }
130 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
132 if(in_array('FAIpackageList',$attr['objectClass'])){
133 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
134 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
135 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
136 $tmp2[$cn]['FAIpackageList']['desc'] = $attr['description'];
137 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
138 }
139 if(in_array('FAItemplate',$attr['objectClass'])){
140 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
141 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
142 $tmp2[$cn]['FAItemplate']['desc'] = $attr['description'];
143 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
144 }
145 if(in_array('FAIvariable',$attr['objectClass'])){
146 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
147 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
148 $tmp2[$cn]['FAIvariable']['desc'] = $attr['description'];
149 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
150 }
151 if(in_array('FAIscript',$attr['objectClass'])){
152 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
153 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
154 $tmp2[$cn]['FAIscript']['desc'] = $attr['description'];
155 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
156 }
157 if(in_array('FAIhook',$attr['objectClass'])){
158 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
159 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
160 $tmp2[$cn]['FAIhook']['desc'] = $attr['description'];
161 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
162 }
163 if(in_array('FAIpartitionTable',$attr['objectClass'])){
164 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
165 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
166 $tmp2[$cn]['FAIpartitionTable']['desc'] = $attr['description'];
167 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
168 }
169 if(in_array('FAIprofile',$attr['objectClass'])){
170 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
171 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
172 $tmp2[$cn]['FAIprofile']['desc'] = $attr['description'];
173 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
174 }
175 }
176 if(is_array($this->FAIclasses)){
177 natcasesort($this->FAIclasses);
178 }
180 if(isset($tmp2)){
181 $this->FAIclassInfo = $tmp2;
182 } else {
183 $this->FAIclassInfo = array();
184 }
186 /* Build up an array like this one :
187 [$url]['SERVER'] = 'srv1-002';
188 [$url]['RELEASE']['siga/rc9.0.2']
189 ['SECTIONS'][0] "main";
190 ['SECTIONS'][1] "non-free";
191 [$url]['RELEASE']['siga/rc9.0.2']
192 ['PACKAGES'][0] "pkg1";
193 ['PACKAGES'][1] "postfix";
194 */
196 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
197 $test = array();
198 while($attr = $ldap->fetch()){
199 if(isset($attr['FAIrepository'])){
201 unset($attr['FAIrepository']['count']);
203 foreach($attr['FAIrepository'] as $rep){
204 $tmp = split("\|",$rep);
206 if(count($tmp)==4){
207 $sections = split(",",$tmp[3]);
208 $release = $tmp[2];
209 $server = $tmp[1];
210 $url = $tmp[0];
212 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
214 /* Result will be cached
215 */
216 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
217 $test[$url]['SERVER'] = $server;
219 /* auto gets all releases/classes
220 */
221 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
222 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
223 }
224 }
225 }
226 }
228 /* Add possible elements from hook */
229 $lines= $this->GetHookElements();
230 foreach ($lines as $hline){
231 $entries= split(";", $hline);
232 if (isset($entries[1]) && !isset($test[$entries[1]])){
233 $test[$entries[1]]['RELEASE']= array();
235 /* Split releases */
236 if (isset($entries[2])){
237 $releases= split(",", $entries[2]);
239 foreach ($releases as $release){
240 $rname= preg_replace('/:.*$/', '', $release);
241 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
242 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
243 $test[$entries[1]]['RELEASE'][$rname]= array();
244 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
245 foreach ($classes as $class){
246 if ($class != ""){
247 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
248 }
249 }
250 }
251 }
252 }
253 }
255 $this->FAIServRepConfig= $test;
257 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
258 $tmp = array();
259 $tmp = split(" ",$this->FAIclass);
260 $tmp2 =array();
262 foreach($tmp as $class){
263 if( ":" == $class[0] ) {
264 $this->FAIrelease = substr( $class, 1 );
265 }
266 else
267 $tmp2[$class] = $class;
268 }
269 $this->FAIclass = $tmp2;
270 }
272 if(!is_array($this->FAIclass)){
273 $this->FAIclass =array();
274 }
275 }// END of FAI initialization stuff
278 /* Get arrays */
279 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
280 if (isset($this->attrs["$val"]["count"])){
281 for ($i= 0; $i<$this->attrs["count"]; $i++){
282 if (isset($this->attrs["$val"][$i])){
283 array_push($this->$val, $this->attrs["$val"][$i]);
284 }
285 }
286 }
287 sort ($this->$val);
288 $this->$val= array_unique($this->$val);
289 }
291 /* Parse Kernel Parameters to decide what boot mode is enabled */
292 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
293 $this->bootmode= "G";
294 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
295 $this->bootmode= "D";
296 } elseif ($this->gotoKernelParameters == "") {
297 $this->bootmode= "G";
298 } else {
299 $this->bootmode= "T";
300 }
301 if (preg_match("/ o /", $this->gotoKernelParameters)){
302 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
303 } else {
304 $this->customParameters= "";
305 }
307 /* Prepare Shares */
308 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
309 unset($this->attrs['gotoShare']['count']);
310 foreach($this->attrs['gotoShare'] as $share){
311 $tmp = $tmp2 = array();
312 $tmp = split("\|",$share);
313 $tmp2['server'] =$tmp[0];
314 $tmp2['name'] =$tmp[1];
315 $tmp2['mountPoint'] =$tmp[2];
316 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
317 }
318 }
320 $this->gotoShareSelections= $config->getShareList(true);
321 $this->gotoAvailableShares= $config->getShareList(false);
322 $tmp2 = array();
325 $this->orig_dn= $this->dn;
327 /* Handle inheritance value "default" */
328 if ($this->member_of_ogroup){
329 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
330 }
332 /* Load hardware list */
333 if ($this->member_of_ogroup){
335 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
336 $this->FAIdebianMirror = "inherited";
337 }
339 if($this->fai_activated){
340 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
341 }else{
342 $map= array("gotoBootKernel");
343 }
345 $ldap = $this->config->get_ldap_link();
346 $ldap->cat($this->o_group_dn);
347 $attrs= $ldap->fetch();
349 foreach ($map as $name){
350 if (!isset($attrs[$name][0])){
351 continue;
352 }
354 switch ($name){
355 case 'gotoBootKernel':
356 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
357 break;
359 case 'FAIclass':
360 $str = split(":",$attrs[$name][0]);
361 $this->InheritedFAIclass = split("\ ",trim($str[0]));
362 $this->InheritedFAIrelease = trim($str[1]);
363 break;
365 case 'FAIdebianMirror':
366 $this->InheritedFAIdebianMirror = $attrs[$name][0];
367 break;
368 }
369 }
370 }
372 /* Get list of boot kernels */
373 if (isset($this->config->data['TABS'])){
374 $command= $this->config->search(get_class($this), "KERNELS",array('tabs'));
376 if (!check_command($command)){
377 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
378 get_class($this));
379 } else {
380 $fh= popen($command, "r");
381 while (!feof($fh)) {
382 $buffer= trim(fgets($fh, 256));
384 if(!empty($buffer)){
386 $name=$value = $buffer;
388 if(preg_match("/:/",$buffer)){
389 $name = preg_replace("/:.*$/","",$buffer);
390 $value= preg_replace("/^.*:/","",$buffer);
391 $this->gotoBootKernels[$name]= $name.":".$value;
392 }else{
393 $this->gotoBootKernels[$name]= $value;
394 }
395 }
397 }
398 pclose($fh);
399 }
400 }
402 /* Turn to default, if we've nothing to inherit */
403 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
404 $this->gotoBootKernel= "default";
405 }
406 }
409 /* This class is called by the contrucktor ONLY.
410 * It return the available classes for each
411 * Server / Release combination ...
412 * (Release specifies which classes are available)
413 */
414 function getAvailableClassesForThisRelease($release)
415 {
416 /* There could be more than one server providing this release,
417 so use cached result if available
418 */
419 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
420 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
421 }
423 $test2 = array();
424 # $bb = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
425 $bb = $this->generateDNSyn($release).$this->config->current['BASE'];
427 $ldap = $this->config->get_ldap_link();
428 $ldap->cd($this->config->current['BASE']);
430 /* Get classes fpr given release */
431 $p_classes = get_all_objects_for_given_base($bb,
432 "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
433 "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
434 "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
436 /* Create list of classes */
437 foreach($p_classes as $class){
438 $ldap->cat($class['dn'],array("cn"));
439 $attr = $ldap->fetch();
440 $test2[$attr['cn'][0]] = $attr['cn'][0];
441 }
442 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
443 return($test2);
444 }
447 /* Create array to display available classes/profiles in a selectbox
448 * This function only displays the available classes.
449 * If a class is available is defined by these facts :
450 * 1. Is this class available for the selected release ?
451 * - if it is available, check if the release is available for the selected server
452 * (done by $this->getFAIreleases())
453 * 2. Is this class currently not assigned to $this->FAIclass
454 */
455 function selectFriendlyClasses(){
456 $tmp=array();
458 if($this->FAIdebianMirror == "inherited") return($tmp);
460 /* check if the current release exists,
461 else select the first one ..
462 */
463 $tmp2 = $this->getFAIreleases();
464 if(!isset($tmp2[$this->FAIrelease]) || !$tmp2[$this->FAIrelease]['USE']){
465 foreach($tmp2 as $key => $data){
466 if($data['USE']){
467 $this->FAIrelease = $key;
468 }
469 }
470 }
471 if(!in_array($this->FAIrelease, $tmp2)){
472 # $this->FAIrelease = key($tmp2);
473 }
475 /* Get all Packages for this server/release combination
476 */
477 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
478 $pkgs = array();
479 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
480 }else{
481 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
482 }
484 /* Check each and every single class name
485 */
486 foreach($pkgs as $pkg){
488 /* Class already assigned to the classes list ?
489 * If not ... go on
490 */
491 if(!in_array($pkg,$this->FAIclass)){
493 /* Create the displayed list entry value
494 HKLMOP [-Pl P V T-] or something like that
495 */
496 $str = "";
497 foreach($this->FAIclassInfo[$pkg] as $entry){
498 if(isset($entry['kzl'])){
499 $str .= $entry['kzl']." ";
500 }
501 }
503 /* Append class if everyting was fine
504 */
505 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
506 }
507 }
508 /* Just sort and return new classes list ...
509 ( possibly we should cache the result ... )
510 */
511 natcasesort ($tmp);
512 return($tmp);
513 }
515 function check()
516 {
517 $messages = array();
519 /* Call common method to give check the hook */
520 $messages= plugin::check();
522 /* If there are packages selected, but no mirror show error */
523 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
524 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
525 }
527 return($messages);
528 }
530 function execute()
531 {
532 /* Call parent execute */
533 plugin::execute();
535 if($this->is_account && !$this->view_logged){
536 $this->view_logged = TRUE;
537 new log("view","workstation/".get_class($this),$this->dn);
538 }
540 /* Do we need to flip is_account state? */
541 if(isset($_POST['modify_state'])){
542 if($this->is_account && $this->acl_is_removeable()){
543 $this->is_account= FALSE;
544 }elseif(!$this->is_account && $this->acl_is_createable()){
545 $this->is_account= TRUE;
546 }
547 }
549 /* Do we represent a valid terminal? */
550 if (!$this->is_account && $this->parent === NULL){
551 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
552 _("This 'dn' has no terminal features.")."</b>";
553 return ($display);
554 }
556 /* Add module */
557 if (isset ($_POST['add_module'])){
558 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
559 $this->add_list ($this->gotoModules, $_POST['module']);
560 }
561 }
563 /* Delete module */
564 if (isset ($_POST['delete_module'])){
565 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
566 $this->del_list ($this->gotoModules, $_POST['modules_list']);
567 }
568 }
570 /* FAI class management */
571 if($this->fai_activated){
572 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
573 $found = 0 ;
575 /* If this new class/profile will attach a second partition table
576 * to our list of classes, abort and show a message.
577 */
578 foreach($this->FAIclass as $name){
579 if(isset($this->FAIclassInfo[$name])){
580 foreach($this->FAIclassInfo[$name] as $atr){
581 if(isset($atr['obj'])){
582 if($atr['obj'] == "FAIpartitionTable"){
583 $found ++ ;
584 }
585 }
586 }
587 }
588 }
590 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
591 print_red(_("There is already a profile in your selection that contain partition table configurations."));
592 }else{
593 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
594 }
595 }
597 $sort = false;
599 /* Move one used class class one position up or down */
600 if($this->acl_is_writeable("FAIclass")){
601 foreach($_POST as $name => $val){
603 $sort_type = false;
604 if((preg_match("/sort_up/",$name))&&(!$sort)){
605 $sort_type = "sort_up_";
606 }
607 if((preg_match("/sort_down/",$name))&&(!$sort)){
608 $sort_type = "sort_down_";
609 }
611 if(($sort_type)&&(!$sort)){
612 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
613 $sort = true;
615 $last = -1;
616 $change_down = -1;
618 /* Create array with numeric index */
619 $tmp = array();
620 foreach($this->FAIclass as $class){
621 $tmp [] = $class;
622 }
624 /* Walk trough array */
625 foreach($tmp as $key => $faiName){
626 if($faiName == $value){
627 if($sort_type == "sort_up_"){
628 if($last != -1){
629 $change_down= $last;
630 }
631 }else{
632 if(isset($tmp[$key+1])){
633 $change_down = $key;
634 }
635 }
636 }
637 $last = $key;
638 }
640 $tmp2 = array();
641 $skip = false;
643 foreach($tmp as $ky => $vl){
645 if($ky == $change_down){
646 $skip = $vl;
647 }else{
648 $tmp2[$vl] = $vl;
649 }
650 if(($skip != false)&&($ky != $change_down)){
651 $tmp2[$skip] = $skip;
652 $skip =false;
653 }
654 }
655 $this->FAIclass = $tmp2;
656 }
658 if(preg_match("/fai_remove/i",$name)){
659 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
660 unset($this->FAIclass[$value]);
661 }
662 }
663 }
665 /* Delete selected class from our list */
666 if($this->acl_is_writeable("FAIclass")){
667 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
668 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
669 unset($this->FAIclass[$_POST['FAIclassSel']]);
670 }
671 }
672 }
673 }// END fai handling
675 /* Show main page */
676 $smarty= get_smarty();
678 /* Assign ACLs to smarty */
679 $tmp = $this->plInfo();
680 foreach($tmp['plProvidedAcls'] as $name => $translation){
681 $smarty->assign($name."ACL",$this->getacl($name));
682 }
684 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
686 /* In this section server shares will be defined
687 * A user can select one of the given shares and a mount point
688 * and attach this combination to his setup.
689 */
690 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
691 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
693 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
694 * This entry will be, a combination of mountPoint and sharedefinitions
695 */
696 if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
697 /* We assign a share to this user, if we don't know where to mount the share */
698 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
699 print_red(_("You must specify a valid mount point."));
700 }else{
701 if(count($this->gotoAvailableShares)){
702 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
703 $s_mount = $_POST['gotoShareMountPoint'];
704 /* Preparing the new assignment */
705 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
706 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
707 }
708 }
709 }
711 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
712 * If there is no defined share selected, we will abort the deletion without any message
713 */
714 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
715 unset($this->gotoShares[$_POST['gotoShare']]);
716 }
718 $smarty->assign("gotoShares",$this->printOutAssignedShares());
719 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
720 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
721 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
723 /* Create divSelectBox for ldap server selection
724 */
725 $SelectBoxLdapServer = new divSelectBox("LdapServer");
726 $SelectBoxLdapServer->SetHeight(130);
728 /* Add new ldap server to the list */
729 if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){
730 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
731 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
732 if(!in_array($to_add,$this->gotoLdapServers)){
733 $this->gotoLdapServers[] = $to_add;
734 }
735 }
736 }
738 /* Move ldap servers up and down */
739 if(!$this->gotoLdap_inherit){
740 foreach($_POST as $name => $value){
741 if(preg_match("/sort_ldap_up_/",$name)){
742 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
743 $from = $id;
744 $to = $id -1;
745 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
746 if($tmp){
747 $this->gotoLdapServers = $tmp;
748 }
749 break;
750 }
751 if(preg_match("/sort_ldap_down_/",$name)){
752 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
753 $from = $id;
754 $to = $id +1;
755 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
756 if($tmp){
757 $this->gotoLdapServers = $tmp;
758 }
759 break;
760 }
761 if(preg_match("/gotoLdapRemove_/",$name)){
762 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
763 $value = $this->gotoLdapServers[$id];
764 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
765 break;
766 }
767 }
768 }
770 /* Add Entries
771 */
772 foreach($this->gotoLdapServers as $key => $server){
773 if(!in_array($server,$this->gotoLdapServerList)){
774 $server = $server." <font style='color:red'>(missing)</font>";
775 }
777 $SelectBoxLdapServer->AddEntry(
778 array(array("string" => $server),
779 array("string" =>
780 "<input class='center' type='image' src='images/sort_up.png' name='sort_ldap_up_".$key."'> ".
781 "<input class='center' type='image' src='images/sort_down.png' name='sort_ldap_down_".$key."'> ".
782 "<input class='center' type='image' src='images/edittrash.png' name='gotoLdapRemove_".$key."'>",
783 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
784 }
786 if($this->gotoLdap_inherit){
787 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
788 }else{
789 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
790 }
792 $list = array();
793 foreach($this->gotoLdapServerList as $key => $entry){
794 if(!in_array($entry,$this->gotoLdapServers)){
795 $list[$key] = $entry;
796 }
797 }
798 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
799 $smarty->assign("gotoLdapServerList", $list);
800 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
801 $smarty->assign("JS", $_SESSION['js']);
803 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
804 $smarty->assign("$val", $this->$val);
805 }
807 /* Values */
808 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
809 $smarty->assign($val, $this->$val);
810 }
812 $smarty->assign("fai_activated",$this->fai_activated);
814 /* Create FAI output */
815 if($this->fai_activated){
816 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
817 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
818 $smarty->assign("FAIreleases",$this->getFAIreleases());
819 $smarty->assign("FAIrelease",$this->FAIrelease);
820 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
821 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
822 $smarty->assign("FAIclassKeys",$this->FAIclass);
824 $inheritedRelease = array();
825 if(!empty($this->InheritedFAIrelease)){
826 $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
827 }
828 $smarty->assign("InheritedFAIrelease",$inheritedRelease);
830 $div = new divSelectBox("WSFAIscriptClasses");
831 $div -> SetHeight("110");
832 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
833 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
834 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
835 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
837 $i = 1;
839 if($this->FAIdebianMirror == "inherited"){
840 $tmp = $this->InheritedFAIclass;
841 }else{
842 $tmp = $this->FAIclass;
843 }
845 foreach($tmp as $class){
847 $marker = "";
848 if(in_array_ics($class,$this->unresolved_classes)){
849 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
850 }
852 if($this->FAIdebianMirror == "inherited"){
853 $str = "";
854 }else{
855 if($i==1){
856 $str = $str_empty.$str_down.$str_remove;
857 }elseif($i == count($this->FAIclass)){
858 $str = $str_up.$str_empty.$str_remove;
859 }else{
860 $str = $str_up.$str_down.$str_remove;
861 }
862 }
863 $i ++ ;
865 $desc = "";
866 foreach($this->FAIclassInfo[$class] as $types ){
867 if(isset($types['desc'][0])){
868 $desc.= $types['desc'][0]." ";
869 }
870 }
871 if(!empty($desc)){
872 $desc = " [".trim($desc)."]";
873 }
875 $div->AddEntry(array(
876 array("string"=>$class.$desc.$marker),
877 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
878 ));
879 }
880 $smarty->assign("FAIScriptlist",$div->DrawList());
881 }// END FAI output generation
883 /* Radio button group */
884 if (preg_match("/G/", $this->bootmode)) {
885 $smarty->assign("graphicalbootup", "checked");
886 } else {
887 $smarty->assign("graphicalbootup", "");
888 }
889 if (preg_match("/T/", $this->bootmode)) {
890 $smarty->assign("textbootup", "checked");
891 } else {
892 $smarty->assign("textbootup", "");
893 }
894 if (preg_match("/D/", $this->bootmode)) {
895 $smarty->assign("debugbootup", "checked");
896 } else {
897 $smarty->assign("debugbootup", "");
898 }
900 /* Show main page */
901 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
902 }
904 function remove_from_parent()
905 {
906 $this->handle_post_events("remove");
907 new log("remove","workstation/".get_class($this),$this->dn);
908 }
910 function generateDNSyn($release)
911 {
912 $str = "";
913 $tmp = split("\/",$release);
914 $tmp = array_reverse($tmp);
916 $base = "ou=fai,ou=configs,ou=systems,";
917 foreach($tmp as $departmentname){
919 $str .= ",ou=".$departmentname;
920 }
921 $str = preg_replace("/^,/","",($str.",".$base));
923 return($str);
924 }
926 function getFAIdebianMirrors()
927 {
928 $ret = array();
930 /* Only add inherit option, if we are part in an object group
931 */
932 if($this->member_of_ogroup) {
933 $ret['inherited']['NAME']="["._("inherited")."]";
934 $ret['inherited']['USE'] = TRUE;
935 }
937 $ret['auto']['NAME']=_("automatic");
938 $ret['auto']['USE'] = TRUE;
939 $secs = array();
941 /* Walk through all available servers
942 and check if they support the currently selected classes
943 if not, dont't add them to our list
944 */
945 foreach($this->FAIServRepConfig as $mirror => $rest){
947 /* Automatically selection is available everytime */
948 if($mirror == "auto"){
949 continue;
950 }
952 $use = false;
953 if(count($this->FAIclass) == 0){
954 $use = true;
955 }else{
956 $tmp = $this->getFAIreleases();
957 foreach($tmp as $release => $data){
958 if(isset($rest['RELEASE'][$release]) && $release == $this->FAIrelease){
959 $use = $data['USE'];
960 }
961 }
962 }
964 /* If current server, doesn't support this class
965 remove it from list
966 */
967 $ret[$mirror]['NAME'] = $mirror;
968 $ret[$mirror]['USE'] = $use;
969 }
970 return($ret);
971 }
973 function getFAIreleases()
974 {
975 $ret = array();
977 if($this->FAIdebianMirror == "inherited") {
978 return(array());
979 }
981 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
982 $this->FAIdebianMirror = "auto";
983 }
985 $errorClasses = array();
986 if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
987 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
988 $use = true;
990 if(!count($this->FAIclass) == 0){
991 foreach($this->FAIclass as $class){
992 if(!in_array($class, $sections['PACKAGES'])){
993 $use = false;
994 $errorClasses[$class] = $class;
995 }else{
996 if(isset($errorClasses[$class])){
997 unset($errorClasses[$class]);
998 }
999 }
1000 }
1001 }
1002 $ret[$release]['NAME']=$release;
1003 $ret[$release]['USE']=$use;
1004 }
1005 }
1007 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
1008 $eClasses = " ";
1009 foreach($errorClasses as $class){
1010 $eClasses .= $class." ";
1011 }
1013 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));
1014 $this->FAIdebianMirror = "auto";
1015 return($this->getFAIreleases());
1016 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
1018 $eClasses = " ";
1019 foreach($errorClasses as $class){
1020 $eClasses .= $class." ";
1021 }
1023 $eClasses = preg_replace("/ */","",$eClasses);
1025 if(!empty($eClasses)) {
1027 $this->unresolved_classes = $errorClasses;
1028 $this->FAIdebianMirror = "auto";
1029 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));
1030 }
1031 }
1032 return($ret);
1033 }
1035 /* Save data to object */
1036 function save_object()
1037 {
1038 plugin::save_object();
1040 if(isset($_POST['WorkstationStarttabPosted'])){
1041 if(isset($_POST['gotoLdap_inherit'])){
1042 $this->gotoLdap_inherit = TRUE;
1043 }else{
1044 $this->gotoLdap_inherit = FALSE;
1045 }
1047 /* Save group radio buttons */
1048 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
1049 $this->bootmode= $_POST["bootmode"];
1050 }
1052 /* Save kernel parameters */
1053 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
1054 $this->customParameters= $_POST["customParameters"];
1055 }
1056 }
1057 }
1060 /* Save to LDAP */
1061 function save()
1062 {
1064 /* Depending on the baseobject (Ogroup / WS) we
1065 * use another set of objectClasses
1066 * In case of WS itself, we use "array("GOhard", "FAIobject");"
1067 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
1068 */
1069 if(isset($this->parent->by_object['ogroup'])){
1070 $this->objectclasses = array("gotoWorkstationTemplate");
1071 }elseif(isset($this->parent->by_object['workgeneric'])){
1072 $this->objectclasses = array("GOhard");
1073 }elseif(isset($this->parent->by_object['servgeneric'])){
1074 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
1075 }else{
1076 print "Object Type Configuration : unknown";
1077 exit();
1078 }
1080 /* Append FAI class */
1081 if($this->fai_activated){
1082 $this->objectclasses[] = "FAIobject";
1083 }
1085 /* Find proper terminal path for tftp configuration
1086 FIXME: This is suboptimal when the default has changed to
1087 another location! */
1088 if (($this->gotoTerminalPath == "default")){
1089 $ldap= $this->config->get_ldap_link();
1091 /* Strip relevant part from dn, keep trailing ',' */
1092 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
1093 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
1095 /* Walk from top to base and try to load default values for
1096 'gotoTerminalPath'. Abort when an entry is found. */
1097 while (TRUE){
1098 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
1100 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
1101 $this->config->current['BASE'], array('gotoTerminalPath'));
1102 $attrs= $ldap->fetch();
1103 if (isset($attrs['gotoTerminalPath'])){
1104 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
1105 break;
1106 }
1108 /* Nothing left? */
1109 if ($tmp == ""){
1110 break;
1111 }
1112 }
1113 }
1115 /* Add semi automatic values */
1116 // FIXME: LDAP Server may not be set here...
1117 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1119 switch ($this->bootmode){
1120 case "D":
1121 $this->gotoKernelParameters.= " debug";
1122 break;
1123 case "G":
1124 $this->gotoKernelParameters.= " splash=silent";
1125 break;
1126 }
1127 if ($this->customParameters != ""){
1128 $this->gotoKernelParameters.= " o ".$this->customParameters;
1129 }
1131 plugin::save();
1133 unset( $this->attrs['FAIrelease'] );
1135 $str = "";
1137 /* Skip FAI attribute handling if not necessary */
1138 if($this->fai_activated){
1139 if($this->FAIdebianMirror == "inherited"){
1140 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1141 }else{
1142 foreach($this->FAIclass as $class){
1143 $str .= $class." ";
1144 }
1145 $str .= ":" . $this->FAIrelease;
1146 $this->attrs['FAIclass']= "";
1147 $this->attrs['FAIclass']= trim($str);
1149 if(empty($this->attrs['FAIclass'])){
1150 $this->attrs['FAIclass'] = array();
1151 }
1152 }
1153 }
1155 /* Add missing arrays */
1156 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1157 if (isset ($this->$val) && count ($this->$val) != 0){
1159 $this->attrs["$val"]= array_unique($this->$val);
1160 }
1161 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1162 }
1164 /* Prepare list of ldap servers */
1165 $this->attrs['gotoLdapServer'] = array();
1166 if(!$this->gotoLdap_inherit){
1167 $i = 0;
1168 foreach($this->gotoLdapServers as $server){
1169 $i ++;
1170 $this->attrs['gotoLdapServer'][] = $i.":".$server;
1171 }
1172 }
1174 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1175 $this->attrs['gotoBootKernel']= array();
1176 }
1178 /* if mirror == none stop saving this attribute */
1179 if($this->FAIdebianMirror == "none"){
1180 $this->FAIdebianMirror = "";
1181 }
1183 /* Get FAIstate from object, the generic tab could have changed it during execute */
1184 $ldap= $this->config->get_ldap_link();
1185 $ldap->cd($this->dn);
1188 /* Skip FAI attribute handling if not necessary */
1189 if($this->fai_activated){
1190 $ldap->cat($this->dn,array("FAIstate"));
1191 $checkFAIstate = $ldap->fetch();
1193 /* Remove FAI objects if no FAI class is selected */
1194 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1195 $this->attrs['FAIclass'] = array();
1196 $this->attrs['FAIdebianMirror'] = array();
1197 }
1198 }
1201 /* prepare share settings */
1202 $tmp = array();
1203 foreach($this->gotoShares as $name => $settings){
1204 $tmp2= split("\|",$name);
1205 $name = $tmp2[0];
1206 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1207 }
1208 $this->attrs['gotoShare']=$tmp;
1210 $this->cleanup();
1211 $ldap->modify ($this->attrs);
1212 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1214 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1215 $this->handle_post_events("modify");
1216 }
1218 /* Add value to array, check if unique */
1219 function add_list (&$array, $value)
1220 {
1221 if ($value != ""){
1222 $array[]= $value;
1223 sort($array);
1224 array_unique ($array);
1225 }
1226 }
1229 /* Delete value to array, check if unique */
1230 function del_list (&$array, $list)
1231 {
1232 $tmp= array();
1233 foreach ($array as $mod){
1234 if (!in_array($mod, $list)){
1235 $tmp[]= $mod;
1236 }
1237 }
1238 $array= $tmp;
1239 }
1241 /* Generate ListBox frindly output for the defined shares
1242 * Possibly Add or remove an attribute here,
1243 */
1244 function printOutAssignedShares()
1245 {
1246 $a_return = array();
1247 if(is_array($this->gotoShares)){
1248 foreach($this->gotoShares as $share){
1249 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1250 }
1251 }
1252 return($a_return);
1253 }
1256 function GetHookElements()
1257 {
1258 $ret = array();
1259 $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1260 if(!empty($cmd)){
1261 $res = shell_exec($cmd);
1262 $res2 = trim($res);
1263 if((!$res)){
1264 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1265 }elseif(empty($res2)){
1266 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1267 }else{
1268 $tmp = split("\n",$res);
1269 foreach($tmp as $line){
1270 if(empty($line)) continue;
1271 $ret[]= $line;
1272 }
1273 }
1274 }
1275 return($ret);
1276 }
1279 function PrepareForCopyPaste($source)
1280 {
1281 plugin::PrepareForCopyPaste($source);
1283 $source_o = new workstartup ($this->config, $source['dn']);
1285 foreach(array("gotoModules", "gotoAutoFs", "gotoFilesystem","gotoKernelParameters","gotoShares","customParameters") as $attr){
1286 $this->$attr = $source_o->$attr;
1287 }
1288 }
1291 function array_switch_item($ar,$from,$to)
1292 {
1293 if(!is_array($ar)){
1294 return(false);
1295 }
1296 if(!isset($ar[$from])){
1297 return(false);
1298 }
1299 if(!isset($ar[$to])){
1300 return(false);
1301 }
1303 $tmp = $ar[$from];
1304 $ar[$from] = $ar[$to];
1305 $ar[$to] = $tmp;
1306 return($ar);
1307 }
1310 /* Return plugin informations for acl handling */
1311 function plInfo()
1312 {
1313 return (array(
1314 "plShortName" => _("Startup"),
1315 "plDescription" => _("System startup"),
1316 "plSelfModify" => FALSE,
1317 "plDepends" => array(),
1318 "plPriority" => 9,
1319 "plSection" => array("administration"),
1320 "plCategory" => array("workstation","server","ogroups"),
1322 "plProvidedAcls"=> array(
1323 "gotoLdapServer" => _("Ldap server"),
1324 "gotoBootKernel" => _("Boot kernel"),
1325 "gotoKernelParameters" => _("Kernel parameter"),
1327 "gotoModules" => _("Kernel modules"),
1328 "gotoShare" => _("Shares"),
1330 "FAIclass" => _("FAI classes"),
1331 "FAIdebianMirror" => _("Debian mirror"),
1332 "FAIrelease" => _("Debian release"),
1334 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1335 ));
1336 }
1337 }
1339 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1340 ?>