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){
934 $use = false;
935 if(count($this->FAIclass) == 0){
936 $use = true;
937 }else{
938 $tmp = $this->getFAIreleases();
939 foreach($tmp as $release => $data){
940 if(isset($rest['RELEASE'][$release])){
941 $use = $data['USE'];
942 }
943 }
944 }
946 /* If current server, doesn't support this class
947 remove it from list
948 */
949 $ret[$mirror]['NAME'] = $mirror;
950 $ret[$mirror]['USE'] = $use;
951 }
952 return($ret);
953 }
955 function getFAIreleases()
956 {
957 $ret = array();
959 if($this->FAIdebianMirror == "inherited") return(array());
961 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
962 $this->FAIdebianMirror = "auto";
963 }
965 $errorClasses = array();
967 foreach($this->FAIServRepConfig as $mirror => $rest){
968 if(isset($this->FAIServRepConfig[$mirror]['RELEASE'])){
969 foreach($this->FAIServRepConfig[$mirror]['RELEASE'] as $release => $sections){
970 $use = true;
972 if(!count($this->FAIclass) == 0){
973 foreach($this->FAIclass as $class){
974 if(!in_array($class, $sections['PACKAGES'])){
975 $use = false;
976 $errorClasses[$class] = $class;
977 }else{
978 if(isset($errorClasses[$class])){
979 unset($errorClasses[$class]);
980 }
981 }
982 }
983 }
985 if($mirror != $this->FAIdebianMirror){
986 $use = false;
987 }else{
988 $use = true;
989 }
990 $ret[$release]['NAME']=$release;
991 $ret[$release]['USE']=$use;
992 }
993 }
994 }
996 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
997 $eClasses = " ";
998 foreach($errorClasses as $class){
999 $eClasses .= $class." ";
1000 }
1002 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));
1003 $this->FAIdebianMirror = "auto";
1004 return($this->getFAIreleases());
1005 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
1007 $eClasses = " ";
1008 foreach($errorClasses as $class){
1009 $eClasses .= $class." ";
1010 }
1012 $eClasses = preg_replace("/ */","",$eClasses);
1014 if(!empty($eClasses)) {
1016 $this->unresolved_classes = $errorClasses;
1017 $this->FAIdebianMirror = "auto";
1018 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));
1019 }
1020 }
1021 return($ret);
1022 }
1024 /* Save data to object */
1025 function save_object()
1026 {
1027 plugin::save_object();
1029 if(isset($_POST['WorkstationStarttabPosted'])){
1030 if(isset($_POST['gotoLdap_inherit'])){
1031 $this->gotoLdap_inherit = TRUE;
1032 }else{
1033 $this->gotoLdap_inherit = FALSE;
1034 }
1036 /* Save group radio buttons */
1037 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
1038 $this->bootmode= $_POST["bootmode"];
1039 }
1041 /* Save kernel parameters */
1042 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
1043 $this->customParameters= $_POST["customParameters"];
1044 }
1045 }
1046 }
1049 /* Save to LDAP */
1050 function save()
1051 {
1053 /* Depending on the baseobject (Ogroup / WS) we
1054 * use another set of objectClasses
1055 * In case of WS itself, we use "array("GOhard", "FAIobject");"
1056 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
1057 */
1058 if(isset($this->parent->by_object['ogroup'])){
1059 $this->objectclasses = array("gotoWorkstationTemplate");
1060 }elseif(isset($this->parent->by_object['workgeneric'])){
1061 $this->objectclasses = array("GOhard");
1062 }elseif(isset($this->parent->by_object['servgeneric'])){
1063 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
1064 }else{
1065 print "Object Type Configuration : unknown";
1066 exit();
1067 }
1069 /* Append FAI class */
1070 if($this->fai_activated){
1071 $this->objectclasses[] = "FAIobject";
1072 }
1074 /* Find proper terminal path for tftp configuration
1075 FIXME: This is suboptimal when the default has changed to
1076 another location! */
1077 if (($this->gotoTerminalPath == "default")){
1078 $ldap= $this->config->get_ldap_link();
1080 /* Strip relevant part from dn, keep trailing ',' */
1081 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
1082 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
1084 /* Walk from top to base and try to load default values for
1085 'gotoTerminalPath'. Abort when an entry is found. */
1086 while (TRUE){
1087 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
1089 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
1090 $this->config->current['BASE'], array('gotoTerminalPath'));
1091 $attrs= $ldap->fetch();
1092 if (isset($attrs['gotoTerminalPath'])){
1093 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
1094 break;
1095 }
1097 /* Nothing left? */
1098 if ($tmp == ""){
1099 break;
1100 }
1101 }
1102 }
1104 /* Add semi automatic values */
1105 // FIXME: LDAP Server may not be set here...
1106 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1108 switch ($this->bootmode){
1109 case "D":
1110 $this->gotoKernelParameters.= " debug";
1111 break;
1112 case "G":
1113 $this->gotoKernelParameters.= " splash=silent";
1114 break;
1115 }
1116 if ($this->customParameters != ""){
1117 $this->gotoKernelParameters.= " o ".$this->customParameters;
1118 }
1120 plugin::save();
1122 unset( $this->attrs['FAIrelease'] );
1124 $str = "";
1126 /* Skip FAI attribute handling if not necessary */
1127 if($this->fai_activated){
1128 if($this->FAIdebianMirror == "inherited"){
1129 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1130 }else{
1131 foreach($this->FAIclass as $class){
1132 $str .= $class." ";
1133 }
1134 $str .= ":" . $this->FAIrelease;
1135 $this->attrs['FAIclass']= "";
1136 $this->attrs['FAIclass']= trim($str);
1138 if(empty($this->attrs['FAIclass'])){
1139 $this->attrs['FAIclass'] = array();
1140 }
1141 }
1142 }
1144 /* Add missing arrays */
1145 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1146 if (isset ($this->$val) && count ($this->$val) != 0){
1148 $this->attrs["$val"]= array_unique($this->$val);
1149 }
1150 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1151 }
1153 /* Prepare list of ldap servers */
1154 $this->attrs['gotoLdapServer'] = array();
1155 if(!$this->gotoLdap_inherit){
1156 $i = 0;
1157 foreach($this->gotoLdapServers as $server){
1158 $i ++;
1159 $this->attrs['gotoLdapServer'][] = $i.":".$server;
1160 }
1161 }
1163 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1164 $this->attrs['gotoBootKernel']= array();
1165 }
1167 /* if mirror == none stop saving this attribute */
1168 if($this->FAIdebianMirror == "none"){
1169 $this->FAIdebianMirror = "";
1170 }
1172 /* Get FAIstate from object, the generic tab could have changed it during execute */
1173 $ldap= $this->config->get_ldap_link();
1174 $ldap->cd($this->dn);
1177 /* Skip FAI attribute handling if not necessary */
1178 if($this->fai_activated){
1179 $ldap->cat($this->dn,array("FAIstate"));
1180 $checkFAIstate = $ldap->fetch();
1182 /* Remove FAI objects if no FAI class is selected */
1183 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1184 $this->attrs['FAIclass'] = array();
1185 $this->attrs['FAIdebianMirror'] = array();
1186 }
1187 }
1190 /* prepare share settings */
1191 $tmp = array();
1192 foreach($this->gotoShares as $name => $settings){
1193 $tmp2= split("\|",$name);
1194 $name = $tmp2[0];
1195 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1196 }
1197 $this->attrs['gotoShare']=$tmp;
1199 $this->cleanup();
1200 $ldap->modify ($this->attrs);
1201 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1203 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1204 $this->handle_post_events("modify");
1205 }
1207 /* Add value to array, check if unique */
1208 function add_list (&$array, $value)
1209 {
1210 if ($value != ""){
1211 $array[]= $value;
1212 sort($array);
1213 array_unique ($array);
1214 }
1215 }
1218 /* Delete value to array, check if unique */
1219 function del_list (&$array, $list)
1220 {
1221 $tmp= array();
1222 foreach ($array as $mod){
1223 if (!in_array($mod, $list)){
1224 $tmp[]= $mod;
1225 }
1226 }
1227 $array= $tmp;
1228 }
1230 /* Generate ListBox frindly output for the defined shares
1231 * Possibly Add or remove an attribute here,
1232 */
1233 function printOutAssignedShares()
1234 {
1235 $a_return = array();
1236 if(is_array($this->gotoShares)){
1237 foreach($this->gotoShares as $share){
1238 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1239 }
1240 }
1241 return($a_return);
1242 }
1245 function GetHookElements()
1246 {
1247 $ret = array();
1248 $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1249 if(!empty($cmd)){
1250 $res = shell_exec($cmd);
1251 $res2 = trim($res);
1252 if((!$res)){
1253 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1254 }elseif(empty($res2)){
1255 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1256 }else{
1257 $tmp = split("\n",$res);
1258 foreach($tmp as $line){
1259 if(empty($line)) continue;
1260 $ret[]= $line;
1261 }
1262 }
1263 }
1264 return($ret);
1265 }
1268 function PrepareForCopyPaste($source)
1269 {
1270 plugin::PrepareForCopyPaste($source);
1272 $source_o = new workstartup ($this->config, $source['dn']);
1274 foreach(array("gotoModules", "gotoAutoFs", "gotoFilesystem","gotoKernelParameters","gotoShares","customParameters") as $attr){
1275 $this->$attr = $source_o->$attr;
1276 }
1277 }
1280 function array_switch_item($ar,$from,$to)
1281 {
1282 if(!is_array($ar)){
1283 return(false);
1284 }
1285 if(!isset($ar[$from])){
1286 return(false);
1287 }
1288 if(!isset($ar[$to])){
1289 return(false);
1290 }
1292 $tmp = $ar[$from];
1293 $ar[$from] = $ar[$to];
1294 $ar[$to] = $tmp;
1295 return($ar);
1296 }
1299 /* Return plugin informations for acl handling */
1300 function plInfo()
1301 {
1302 return (array(
1303 "plShortName" => _("Startup"),
1304 "plDescription" => _("System startup"),
1305 "plSelfModify" => FALSE,
1306 "plDepends" => array(),
1307 "plPriority" => 9,
1308 "plSection" => array("administration"),
1309 "plCategory" => array("workstation","server","ogroups"),
1311 "plProvidedAcls"=> array(
1312 "gotoLdapServer" => _("Ldap server"),
1313 "gotoBootKernel" => _("Boot kernel"),
1314 "gotoKernelParameters" => _("Kernel parameter"),
1316 "gotoModules" => _("Kernel modules"),
1317 "gotoShare" => _("Shares"),
1319 "FAIclass" => _("FAI classes"),
1320 "FAIdebianMirror" => _("Debian mirror"),
1321 "FAIrelease" => _("Debian release"),
1323 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1324 ));
1325 }
1326 }
1328 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1329 ?>