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