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 {
268 $tmp2[$class] = $class;
269 }
270 }
271 $this->FAIclass = $tmp2;
272 }
274 if(!is_array($this->FAIclass)){
275 $this->FAIclass =array();
276 }
277 }// END of FAI initialization stuff
280 /* Get arrays */
281 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
282 if (isset($this->attrs["$val"]["count"])){
283 for ($i= 0; $i<$this->attrs["count"]; $i++){
284 if (isset($this->attrs["$val"][$i])){
285 array_push($this->$val, $this->attrs["$val"][$i]);
286 }
287 }
288 }
289 sort ($this->$val);
290 $this->$val= array_unique($this->$val);
291 }
293 /* Parse Kernel Parameters to decide what boot mode is enabled */
294 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
295 $this->bootmode= "G";
296 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
297 $this->bootmode= "D";
298 } elseif ($this->gotoKernelParameters == "") {
299 $this->bootmode= "G";
300 } else {
301 $this->bootmode= "T";
302 }
303 if (preg_match("/ o /", $this->gotoKernelParameters)){
304 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
305 } else {
306 $this->customParameters= "";
307 }
309 /* Prepare Shares */
310 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
311 unset($this->attrs['gotoShare']['count']);
312 foreach($this->attrs['gotoShare'] as $share){
313 $tmp = $tmp2 = array();
314 $tmp = split("\|",$share);
315 $tmp2['server'] =$tmp[0];
316 $tmp2['name'] =$tmp[1];
317 $tmp2['mountPoint'] =$tmp[2];
318 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
319 }
320 }
322 $this->gotoShareSelections= $config->getShareList(true);
323 $this->gotoAvailableShares= $config->getShareList(false);
324 $tmp2 = array();
327 $this->orig_dn= $this->dn;
329 /* Handle inheritance value "default" */
330 if ($this->member_of_ogroup){
331 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
332 }
334 /* Load hardware list */
335 if ($this->member_of_ogroup){
337 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
338 $this->FAIdebianMirror = "inherited";
339 }
341 if($this->fai_activated){
342 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
343 }else{
344 $map= array("gotoBootKernel");
345 }
347 $ldap = $this->config->get_ldap_link();
348 $ldap->cat($this->o_group_dn);
349 $attrs= $ldap->fetch();
351 foreach ($map as $name){
352 if (!isset($attrs[$name][0])){
353 continue;
354 }
356 switch ($name){
357 case 'gotoBootKernel':
358 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
359 break;
361 case 'FAIclass':
362 $str = split(":",$attrs[$name][0]);
363 $this->InheritedFAIclass = split("\ ",trim($str[0]));
364 $this->InheritedFAIrelease = trim($str[1]);
365 break;
367 case 'FAIdebianMirror':
368 $this->InheritedFAIdebianMirror = $attrs[$name][0];
369 break;
370 }
371 }
372 }
374 /* Get list of boot kernels */
375 if (isset($this->config->data['TABS'])){
376 $command= $this->config->search(get_class($this), "KERNELS",array('tabs'));
378 if (!check_command($command)){
379 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
380 get_class($this));
381 } else {
382 $fh= popen($command, "r");
383 while (!feof($fh)) {
384 $buffer= trim(fgets($fh, 256));
386 if(!empty($buffer)){
388 $name=$value = $buffer;
390 if(preg_match("/:/",$buffer)){
391 $name = preg_replace("/:.*$/","",$buffer);
392 $value= preg_replace("/^.*:/","",$buffer);
393 $this->gotoBootKernels[$name]= $name.":".$value;
394 }else{
395 $this->gotoBootKernels[$name]= $value;
396 }
397 }
399 }
400 pclose($fh);
401 }
402 }
404 /* Turn to default, if we've nothing to inherit */
405 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
406 $this->gotoBootKernel= "default";
407 }
408 }
411 /* This class is called by the contrucktor ONLY.
412 * It return the available classes for each
413 * Server / Release combination ...
414 * (Release specifies which classes are available)
415 */
416 function getAvailableClassesForThisRelease($release)
417 {
418 /* There could be more than one server providing this release,
419 so use cached result if available
420 */
421 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
422 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
423 }
425 $test2 = array();
426 # $bb = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
427 $bb = $this->generateDNSyn($release).$this->config->current['BASE'];
429 $ldap = $this->config->get_ldap_link();
430 $ldap->cd($this->config->current['BASE']);
432 /* Get classes fpr given release */
433 $p_classes = get_all_objects_for_given_base($bb,
434 "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
435 "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
436 "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
438 /* Create list of classes */
439 foreach($p_classes as $class){
440 $ldap->cat($class['dn'],array("cn"));
441 $attr = $ldap->fetch();
442 $test2[$attr['cn'][0]] = $attr['cn'][0];
443 }
444 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
445 return($test2);
446 }
449 /* Create array to display available classes/profiles in a selectbox
450 * This function only displays the available classes.
451 * If a class is available is defined by these facts :
452 * 1. Is this class available for the selected release ?
453 * - if it is available, check if the release is available for the selected server
454 * (done by $this->getFAIreleases())
455 * 2. Is this class currently not assigned to $this->FAIclass
456 */
457 function selectFriendlyClasses(){
458 $tmp=array();
460 if($this->FAIdebianMirror == "inherited") return($tmp);
462 /* check if the current release exists,
463 else select the first one ..
464 */
465 $tmp2 = $this->getFAIreleases();
466 if(!isset($tmp2[$this->FAIrelease]) || !$tmp2[$this->FAIrelease]['USE']){
467 foreach($tmp2 as $key => $data){
468 if($data['USE']){
469 $this->FAIrelease = $key;
470 }
471 }
472 }
473 if(!in_array($this->FAIrelease, $tmp2)){
474 # $this->FAIrelease = key($tmp2);
475 }
477 /* Get all Packages for this server/release combination
478 */
479 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
480 $pkgs = array();
481 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
482 }else{
483 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
484 }
486 /* Check each and every single class name
487 */
488 foreach($pkgs as $pkg){
490 /* Class already assigned to the classes list ?
491 * If not ... go on
492 */
493 if(!in_array($pkg,$this->FAIclass)){
495 /* Create the displayed list entry value
496 HKLMOP [-Pl P V T-] or something like that
497 */
498 $str = "";
499 foreach($this->FAIclassInfo[$pkg] as $entry){
500 if(isset($entry['kzl'])){
501 $str .= $entry['kzl']." ";
502 }
503 }
505 /* Append class if everyting was fine
506 */
507 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
508 }
509 }
510 /* Just sort and return new classes list ...
511 ( possibly we should cache the result ... )
512 */
513 natcasesort ($tmp);
514 return($tmp);
515 }
517 function check()
518 {
519 $messages = array();
521 /* Call common method to give check the hook */
522 $messages= plugin::check();
524 /* If there are packages selected, but no mirror show error */
525 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
526 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
527 }
529 return($messages);
530 }
532 function execute()
533 {
534 /* Call parent execute */
535 plugin::execute();
537 if($this->is_account && !$this->view_logged){
538 $this->view_logged = TRUE;
539 new log("view","workstation/".get_class($this),$this->dn);
540 }
542 /* Do we need to flip is_account state? */
543 if(isset($_POST['modify_state'])){
544 if($this->is_account && $this->acl_is_removeable()){
545 $this->is_account= FALSE;
546 }elseif(!$this->is_account && $this->acl_is_createable()){
547 $this->is_account= TRUE;
548 }
549 }
551 /* Do we represent a valid terminal? */
552 if (!$this->is_account && $this->parent === NULL){
553 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
554 _("This 'dn' has no terminal features.")."</b>";
555 return ($display);
556 }
558 /* Add module */
559 if (isset ($_POST['add_module'])){
560 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
561 $this->add_list ($this->gotoModules, $_POST['module']);
562 }
563 }
565 /* Delete module */
566 if (isset ($_POST['delete_module'])){
567 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
568 $this->del_list ($this->gotoModules, $_POST['modules_list']);
569 }
570 }
572 /* FAI class management */
573 if($this->fai_activated){
574 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
575 $found = 0 ;
577 /* If this new class/profile will attach a second partition table
578 * to our list of classes, abort and show a message.
579 */
580 foreach($this->FAIclass as $name){
581 if(isset($this->FAIclassInfo[$name])){
582 foreach($this->FAIclassInfo[$name] as $atr){
583 if(isset($atr['obj'])){
584 if($atr['obj'] == "FAIpartitionTable"){
585 $found ++ ;
586 }
587 }
588 }
589 }
590 }
592 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
593 print_red(_("There is already a profile in your selection that contain partition table configurations."));
594 }else{
595 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
596 }
597 }
599 $sort = false;
601 /* Move one used class class one position up or down */
602 if($this->acl_is_writeable("FAIclass")){
603 foreach($_POST as $name => $val){
605 $sort_type = false;
606 if((preg_match("/sort_up/",$name))&&(!$sort)){
607 $sort_type = "sort_up_";
608 }
609 if((preg_match("/sort_down/",$name))&&(!$sort)){
610 $sort_type = "sort_down_";
611 }
613 if(($sort_type)&&(!$sort)){
614 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
615 $sort = true;
617 $last = -1;
618 $change_down = -1;
620 /* Create array with numeric index */
621 $tmp = array();
622 foreach($this->FAIclass as $class){
623 $tmp [] = $class;
624 }
626 /* Walk trough array */
627 foreach($tmp as $key => $faiName){
628 if($faiName == $value){
629 if($sort_type == "sort_up_"){
630 if($last != -1){
631 $change_down= $last;
632 }
633 }else{
634 if(isset($tmp[$key+1])){
635 $change_down = $key;
636 }
637 }
638 }
639 $last = $key;
640 }
642 $tmp2 = array();
643 $skip = false;
645 foreach($tmp as $ky => $vl){
647 if($ky == $change_down){
648 $skip = $vl;
649 }else{
650 $tmp2[$vl] = $vl;
651 }
652 if(($skip != false)&&($ky != $change_down)){
653 $tmp2[$skip] = $skip;
654 $skip =false;
655 }
656 }
657 $this->FAIclass = $tmp2;
658 }
660 if(preg_match("/fai_remove/i",$name)){
661 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
662 unset($this->FAIclass[$value]);
663 }
664 }
665 }
667 /* Delete selected class from our list */
668 if($this->acl_is_writeable("FAIclass")){
669 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
670 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
671 unset($this->FAIclass[$_POST['FAIclassSel']]);
672 }
673 }
674 }
675 }// END fai handling
677 /* Show main page */
678 $smarty= get_smarty();
680 /* Assign ACLs to smarty */
681 $tmp = $this->plInfo();
682 foreach($tmp['plProvidedAcls'] as $name => $translation){
683 $smarty->assign($name."ACL",$this->getacl($name));
684 }
686 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
688 /* In this section server shares will be defined
689 * A user can select one of the given shares and a mount point
690 * and attach this combination to his setup.
691 */
692 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
693 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
695 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
696 * This entry will be, a combination of mountPoint and sharedefinitions
697 */
698 if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
699 /* We assign a share to this user, if we don't know where to mount the share */
700 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
701 print_red(_("You must specify a valid mount point."));
702 }else{
703 if(count($this->gotoAvailableShares)){
704 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
705 $s_mount = $_POST['gotoShareMountPoint'];
706 /* Preparing the new assignment */
707 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
708 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
709 }
710 }
711 }
713 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
714 * If there is no defined share selected, we will abort the deletion without any message
715 */
716 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
717 unset($this->gotoShares[$_POST['gotoShare']]);
718 }
720 $smarty->assign("gotoShares",$this->printOutAssignedShares());
721 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
722 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
723 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
725 /* Create divSelectBox for ldap server selection
726 */
727 $SelectBoxLdapServer = new divSelectBox("LdapServer");
728 $SelectBoxLdapServer->SetHeight(130);
730 /* Add new ldap server to the list */
731 if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){
732 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
733 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
734 if(!in_array($to_add,$this->gotoLdapServers)){
735 $this->gotoLdapServers[] = $to_add;
736 }
737 }
738 }
740 /* Move ldap servers up and down */
741 if(!$this->gotoLdap_inherit){
742 foreach($_POST as $name => $value){
743 if(preg_match("/sort_ldap_up_/",$name)){
744 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
745 $from = $id;
746 $to = $id -1;
747 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
748 if($tmp){
749 $this->gotoLdapServers = $tmp;
750 }
751 break;
752 }
753 if(preg_match("/sort_ldap_down_/",$name)){
754 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
755 $from = $id;
756 $to = $id +1;
757 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
758 if($tmp){
759 $this->gotoLdapServers = $tmp;
760 }
761 break;
762 }
763 if(preg_match("/gotoLdapRemove_/",$name)){
764 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
765 $value = $this->gotoLdapServers[$id];
766 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
767 break;
768 }
769 }
770 }
772 /* Add Entries
773 */
774 foreach($this->gotoLdapServers as $key => $server){
775 if(!in_array($server,$this->gotoLdapServerList)){
776 $server = $server." <font style='color:red'>(missing)</font>";
777 }
779 $SelectBoxLdapServer->AddEntry(
780 array(array("string" => $server),
781 array("string" =>
782 "<input class='center' type='image' src='images/sort_up.png' name='sort_ldap_up_".$key."'> ".
783 "<input class='center' type='image' src='images/sort_down.png' name='sort_ldap_down_".$key."'> ".
784 "<input class='center' type='image' src='images/edittrash.png' name='gotoLdapRemove_".$key."'>",
785 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
786 }
788 if($this->gotoLdap_inherit){
789 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
790 }else{
791 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
792 }
794 $list = array();
795 foreach($this->gotoLdapServerList as $key => $entry){
796 if(!in_array($entry,$this->gotoLdapServers)){
797 $list[$key] = $entry;
798 }
799 }
800 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
801 $smarty->assign("gotoLdapServerList", $list);
802 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
803 $smarty->assign("JS", $_SESSION['js']);
805 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
806 $smarty->assign("$val", $this->$val);
807 }
809 /* Values */
810 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
811 $smarty->assign($val, $this->$val);
812 }
814 $smarty->assign("fai_activated",$this->fai_activated);
816 /* Create FAI output */
817 if($this->fai_activated){
818 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
819 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
820 $smarty->assign("FAIreleases",$this->getFAIreleases());
821 $smarty->assign("FAIrelease",$this->FAIrelease);
822 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
823 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
824 $smarty->assign("FAIclassKeys",$this->FAIclass);
826 $inheritedRelease = array();
827 if(!empty($this->InheritedFAIrelease)){
828 $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
829 }
830 $smarty->assign("InheritedFAIrelease",$inheritedRelease);
832 $div = new divSelectBox("WSFAIscriptClasses");
833 $div -> SetHeight("110");
834 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
835 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
836 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
837 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
839 $i = 1;
841 if($this->FAIdebianMirror == "inherited"){
842 $tmp = $this->InheritedFAIclass;
843 }else{
844 $tmp = $this->FAIclass;
845 }
847 foreach($tmp as $class){
849 $marker = "";
850 if(in_array_ics($class,$this->unresolved_classes)){
851 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
852 }
854 if($this->FAIdebianMirror == "inherited"){
855 $str = "";
856 }else{
857 if($i==1){
858 $str = $str_empty.$str_down.$str_remove;
859 }elseif($i == count($this->FAIclass)){
860 $str = $str_up.$str_empty.$str_remove;
861 }else{
862 $str = $str_up.$str_down.$str_remove;
863 }
864 }
865 $i ++ ;
867 $desc = "";
868 foreach($this->FAIclassInfo[$class] as $types ){
869 if(isset($types['desc'][0])){
870 $desc.= $types['desc'][0]." ";
871 }
872 }
873 if(!empty($desc)){
874 $desc = " [".trim($desc)."]";
875 }
877 $div->AddEntry(array(
878 array("string"=>$class.$desc.$marker),
879 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
880 ));
881 }
882 $smarty->assign("FAIScriptlist",$div->DrawList());
883 }// END FAI output generation
885 /* Radio button group */
886 if (preg_match("/G/", $this->bootmode)) {
887 $smarty->assign("graphicalbootup", "checked");
888 } else {
889 $smarty->assign("graphicalbootup", "");
890 }
891 if (preg_match("/T/", $this->bootmode)) {
892 $smarty->assign("textbootup", "checked");
893 } else {
894 $smarty->assign("textbootup", "");
895 }
896 if (preg_match("/D/", $this->bootmode)) {
897 $smarty->assign("debugbootup", "checked");
898 } else {
899 $smarty->assign("debugbootup", "");
900 }
902 /* Show main page */
903 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
904 }
906 function remove_from_parent()
907 {
908 $this->handle_post_events("remove");
909 new log("remove","workstation/".get_class($this),$this->dn);
910 }
912 function generateDNSyn($release)
913 {
914 $str = "";
915 $tmp = split("\/",$release);
916 $tmp = array_reverse($tmp);
918 $base = "ou=fai,ou=configs,ou=systems,";
919 foreach($tmp as $departmentname){
921 $str .= ",ou=".$departmentname;
922 }
923 $str = preg_replace("/^,/","",($str.",".$base));
925 return($str);
926 }
928 function getFAIdebianMirrors()
929 {
930 $ret = array();
932 /* Only add inherit option, if we are part in an object group
933 */
934 if($this->member_of_ogroup) {
935 $ret['inherited']['NAME']="["._("inherited")."]";
936 $ret['inherited']['USE'] = TRUE;
937 }
939 $ret['auto']['NAME']=_("automatic");
940 $ret['auto']['USE'] = TRUE;
941 $secs = array();
943 /* Walk through all available servers
944 and check if they support the currently selected classes
945 if not, dont't add them to our list
946 */
947 foreach($this->FAIServRepConfig as $mirror => $rest){
949 /* Automatically selection is available everytime */
950 if($mirror == "auto"){
951 continue;
952 }
954 $use = false;
955 if(count($this->FAIclass) == 0){
956 $use = true;
957 }else{
958 $tmp = $this->getFAIreleases();
959 foreach($tmp as $release => $data){
960 if(isset($rest['RELEASE'][$release]) && $release == $this->FAIrelease){
961 $use = $data['USE'];
962 }
963 }
964 }
966 /* If current server, doesn't support this class
967 remove it from list
968 */
969 $ret[$mirror]['NAME'] = $mirror;
970 $ret[$mirror]['USE'] = $use;
971 }
972 return($ret);
973 }
975 function getFAIreleases()
976 {
977 $ret = array();
979 if($this->FAIdebianMirror == "inherited") {
980 return(array());
981 }
983 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
984 $this->FAIdebianMirror = "auto";
985 }
987 $errorClasses = array();
988 if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
989 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
990 $use = true;
992 if(!count($this->FAIclass) == 0){
993 foreach($this->FAIclass as $class){
994 if(!in_array($class, $sections['PACKAGES'])){
995 $use = false;
996 $errorClasses[$class] = $class;
997 }else{
998 if(isset($errorClasses[$class])){
999 unset($errorClasses[$class]);
1000 }
1001 }
1002 }
1003 }
1004 $ret[$release]['NAME']=$release;
1005 $ret[$release]['USE']=$use;
1006 }
1007 }
1009 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
1010 $eClasses = " ";
1011 foreach($errorClasses as $class){
1012 $eClasses .= $class." ";
1013 }
1015 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));
1016 $this->FAIdebianMirror = "auto";
1017 return($this->getFAIreleases());
1018 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
1020 $eClasses = " ";
1021 foreach($errorClasses as $class){
1022 $eClasses .= $class." ";
1023 }
1025 $eClasses = preg_replace("/ */","",$eClasses);
1027 if(!empty($eClasses)) {
1029 $this->unresolved_classes = $errorClasses;
1030 $this->FAIdebianMirror = "auto";
1031 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));
1032 }
1033 }
1034 return($ret);
1035 }
1037 /* Save data to object */
1038 function save_object()
1039 {
1040 plugin::save_object();
1042 if(isset($_POST['WorkstationStarttabPosted'])){
1043 if(isset($_POST['gotoLdap_inherit'])){
1044 $this->gotoLdap_inherit = TRUE;
1045 }else{
1046 $this->gotoLdap_inherit = FALSE;
1047 }
1049 /* Save group radio buttons */
1050 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
1051 $this->bootmode= $_POST["bootmode"];
1052 }
1054 /* Save kernel parameters */
1055 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
1056 $this->customParameters= $_POST["customParameters"];
1057 }
1058 }
1059 }
1062 /* Save to LDAP */
1063 function save()
1064 {
1066 /* Depending on the baseobject (Ogroup / WS) we
1067 * use another set of objectClasses
1068 * In case of WS itself, we use "array("GOhard", "FAIobject");"
1069 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
1070 */
1071 if(isset($this->parent->by_object['ogroup'])){
1072 $this->objectclasses = array("gotoWorkstationTemplate");
1073 }elseif(isset($this->parent->by_object['workgeneric'])){
1074 $this->objectclasses = array("GOhard");
1075 }elseif(isset($this->parent->by_object['servgeneric'])){
1076 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
1077 }else{
1078 print "Object Type Configuration : unknown";
1079 exit();
1080 }
1082 /* Append FAI class */
1083 if($this->fai_activated){
1084 $this->objectclasses[] = "FAIobject";
1085 }
1087 /* Find proper terminal path for tftp configuration
1088 FIXME: This is suboptimal when the default has changed to
1089 another location! */
1090 if (($this->gotoTerminalPath == "default")){
1091 $ldap= $this->config->get_ldap_link();
1093 /* Strip relevant part from dn, keep trailing ',' */
1094 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
1095 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
1097 /* Walk from top to base and try to load default values for
1098 'gotoTerminalPath'. Abort when an entry is found. */
1099 while (TRUE){
1100 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
1102 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
1103 $this->config->current['BASE'], array('gotoTerminalPath'));
1104 $attrs= $ldap->fetch();
1105 if (isset($attrs['gotoTerminalPath'])){
1106 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
1107 break;
1108 }
1110 /* Nothing left? */
1111 if ($tmp == ""){
1112 break;
1113 }
1114 }
1115 }
1117 /* Add semi automatic values */
1118 // FIXME: LDAP Server may not be set here...
1119 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1121 switch ($this->bootmode){
1122 case "D":
1123 $this->gotoKernelParameters.= " debug";
1124 break;
1125 case "G":
1126 $this->gotoKernelParameters.= " splash=silent";
1127 break;
1128 }
1129 if ($this->customParameters != ""){
1130 $this->gotoKernelParameters.= " o ".$this->customParameters;
1131 }
1133 plugin::save();
1135 unset( $this->attrs['FAIrelease'] );
1137 $str = "";
1139 /* Skip FAI attribute handling if not necessary */
1140 if($this->fai_activated){
1141 if($this->FAIdebianMirror == "inherited"){
1142 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1143 }else{
1144 foreach($this->FAIclass as $class){
1145 $str .= $class." ";
1146 }
1147 $str .= ":" . $this->FAIrelease;
1148 $this->attrs['FAIclass']= "";
1149 $this->attrs['FAIclass']= trim($str);
1151 if(empty($this->attrs['FAIclass'])){
1152 $this->attrs['FAIclass'] = array();
1153 }
1154 }
1155 }
1157 /* Add missing arrays */
1158 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1159 if (isset ($this->$val) && count ($this->$val) != 0){
1161 $this->attrs["$val"]= array_unique($this->$val);
1162 }
1163 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1164 }
1166 /* Prepare list of ldap servers */
1167 $this->attrs['gotoLdapServer'] = array();
1168 if(!$this->gotoLdap_inherit){
1169 $i = 0;
1170 foreach($this->gotoLdapServers as $server){
1171 $i ++;
1172 $this->attrs['gotoLdapServer'][] = $i.":".$server;
1173 }
1174 }
1176 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1177 $this->attrs['gotoBootKernel']= array();
1178 }
1180 /* if mirror == none stop saving this attribute */
1181 if($this->FAIdebianMirror == "none"){
1182 $this->FAIdebianMirror = "";
1183 }
1185 /* Get FAIstate from object, the generic tab could have changed it during execute */
1186 $ldap= $this->config->get_ldap_link();
1187 $ldap->cd($this->dn);
1190 /* Skip FAI attribute handling if not necessary */
1191 if($this->fai_activated){
1192 $ldap->cat($this->dn,array("FAIstate"));
1193 $checkFAIstate = $ldap->fetch();
1195 /* Remove FAI objects if no FAI class is selected */
1196 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1197 $this->attrs['FAIclass'] = array();
1198 $this->attrs['FAIdebianMirror'] = array();
1199 }
1200 }
1203 /* prepare share settings */
1204 $tmp = array();
1205 foreach($this->gotoShares as $name => $settings){
1206 $tmp2= split("\|",$name);
1207 $name = $tmp2[0];
1208 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1209 }
1210 $this->attrs['gotoShare']=$tmp;
1212 $this->cleanup();
1213 $ldap->modify ($this->attrs);
1214 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1216 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1217 $this->handle_post_events("modify");
1218 }
1220 /* Add value to array, check if unique */
1221 function add_list (&$array, $value)
1222 {
1223 if ($value != ""){
1224 $array[]= $value;
1225 sort($array);
1226 array_unique ($array);
1227 }
1228 }
1231 /* Delete value to array, check if unique */
1232 function del_list (&$array, $list)
1233 {
1234 $tmp= array();
1235 foreach ($array as $mod){
1236 if (!in_array($mod, $list)){
1237 $tmp[]= $mod;
1238 }
1239 }
1240 $array= $tmp;
1241 }
1243 /* Generate ListBox frindly output for the defined shares
1244 * Possibly Add or remove an attribute here,
1245 */
1246 function printOutAssignedShares()
1247 {
1248 $a_return = array();
1249 if(is_array($this->gotoShares)){
1250 foreach($this->gotoShares as $share){
1251 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1252 }
1253 }
1254 return($a_return);
1255 }
1258 function GetHookElements()
1259 {
1260 $ret = array();
1261 $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1262 if(!empty($cmd)){
1263 $res = shell_exec($cmd);
1264 $res2 = trim($res);
1265 if((!$res)){
1266 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1267 }elseif(empty($res2)){
1268 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1269 }else{
1270 $tmp = split("\n",$res);
1271 foreach($tmp as $line){
1272 if(empty($line)) continue;
1273 $ret[]= $line;
1274 }
1275 }
1276 }
1277 return($ret);
1278 }
1281 function PrepareForCopyPaste($source)
1282 {
1283 plugin::PrepareForCopyPaste($source);
1285 $source_o = new workstartup ($this->config, $source['dn']);
1287 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem","gotoKernelParameters","gotoShares","customParameters") as $attr){
1288 $this->$attr = $source_o->$attr;
1289 }
1290 }
1293 function array_switch_item($ar,$from,$to)
1294 {
1295 if(!is_array($ar)){
1296 return(false);
1297 }
1298 if(!isset($ar[$from])){
1299 return(false);
1300 }
1301 if(!isset($ar[$to])){
1302 return(false);
1303 }
1305 $tmp = $ar[$from];
1306 $ar[$from] = $ar[$to];
1307 $ar[$to] = $tmp;
1308 return($ar);
1309 }
1312 /* Return plugin informations for acl handling */
1313 static function plInfo()
1314 {
1315 return (array(
1316 "plShortName" => _("Startup"),
1317 "plDescription" => _("System startup"),
1318 "plSelfModify" => FALSE,
1319 "plDepends" => array(),
1320 "plPriority" => 9,
1321 "plSection" => array("administration"),
1322 "plCategory" => array("workstation","server","ogroups"),
1324 "plProvidedAcls"=> array(
1325 "gotoLdapServer" => _("Ldap server"),
1326 "gotoBootKernel" => _("Boot kernel"),
1327 "gotoKernelParameters" => _("Kernel parameter"),
1329 "gotoModules" => _("Kernel modules"),
1330 "gotoShare" => _("Shares"),
1332 "FAIclass" => _("FAI classes"),
1333 "FAIdebianMirror" => _("Debian mirror"),
1334 "FAIrelease" => _("Debian release"),
1336 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1337 ));
1338 }
1339 }
1341 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1342 ?>