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(!in_array($this->FAIrelease, $tmp2)){
454 $this->FAIrelease = key($tmp2);
455 }
457 /* Get all Packages for this server/release combination
458 */
459 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
460 $pkgs = array();
461 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
462 }else{
463 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
464 }
466 /* Check each and every single class name
467 */
468 foreach($pkgs as $pkg){
470 /* Class already assigned to the classes list ?
471 * If not ... go on
472 */
473 if(!in_array($pkg,$this->FAIclass)){
475 /* Create the displayed list entry value
476 HKLMOP [-Pl P V T-] or something like that
477 */
478 $str = "";
479 foreach($this->FAIclassInfo[$pkg] as $entry){
480 if(isset($entry['kzl'])){
481 $str .= $entry['kzl']." ";
482 }
483 }
485 /* Append class if everyting was fine
486 */
487 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
488 }
489 }
490 /* Just sort and return new classes list ...
491 ( possibly we should cache the result ... )
492 */
493 natcasesort ($tmp);
494 return($tmp);
495 }
497 function check()
498 {
499 $messages = array();
501 /* Call common method to give check the hook */
502 $messages= plugin::check();
504 /* If there are packages selected, but no mirror show error */
505 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
506 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
507 }
509 return($messages);
510 }
512 function execute()
513 {
515 /* Call parent execute */
516 plugin::execute();
518 if($this->is_account && !$this->view_logged){
519 $this->view_logged = TRUE;
520 new log("view","workstation/".get_class($this),$this->dn);
521 }
523 /* Do we need to flip is_account state? */
524 if(isset($_POST['modify_state'])){
525 if($this->is_account && $this->acl_is_removeable()){
526 $this->is_account= FALSE;
527 }elseif(!$this->is_account && $this->acl_is_createable()){
528 $this->is_account= TRUE;
529 }
530 }
532 /* Do we represent a valid terminal? */
533 if (!$this->is_account && $this->parent === NULL){
534 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
535 _("This 'dn' has no terminal features.")."</b>";
536 return ($display);
537 }
539 /* Add module */
540 if (isset ($_POST['add_module'])){
541 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
542 $this->add_list ($this->gotoModules, $_POST['module']);
543 }
544 }
546 /* Delete module */
547 if (isset ($_POST['delete_module'])){
548 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
549 $this->del_list ($this->gotoModules, $_POST['modules_list']);
550 }
551 }
553 /* FAI class management */
554 if($this->fai_activated){
555 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
556 $found = 0 ;
558 /* If this new class/profile will attach a second partition table
559 * to our list of classes, abort and show a message.
560 */
561 foreach($this->FAIclass as $name){
562 if(isset($this->FAIclassInfo[$name])){
563 foreach($this->FAIclassInfo[$name] as $atr){
564 if(isset($atr['obj'])){
565 if($atr['obj'] == "FAIpartitionTable"){
566 $found ++ ;
567 }
568 }
569 }
570 }
571 }
573 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
574 print_red(_("There is already a profile in your selection that contain partition table configurations."));
575 }else{
576 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
577 }
578 }
580 $sort = false;
582 /* Move one used class class one position up or down */
583 if($this->acl_is_writeable("FAIclass")){
584 foreach($_POST as $name => $val){
586 $sort_type = false;
587 if((preg_match("/sort_up/",$name))&&(!$sort)){
588 $sort_type = "sort_up_";
589 }
590 if((preg_match("/sort_down/",$name))&&(!$sort)){
591 $sort_type = "sort_down_";
592 }
594 if(($sort_type)&&(!$sort)){
595 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
596 $sort = true;
598 $last = -1;
599 $change_down = -1;
601 /* Create array with numeric index */
602 $tmp = array();
603 foreach($this->FAIclass as $class){
604 $tmp [] = $class;
605 }
607 /* Walk trough array */
608 foreach($tmp as $key => $faiName){
609 if($faiName == $value){
610 if($sort_type == "sort_up_"){
611 if($last != -1){
612 $change_down= $last;
613 }
614 }else{
615 if(isset($tmp[$key+1])){
616 $change_down = $key;
617 }
618 }
619 }
620 $last = $key;
621 }
623 $tmp2 = array();
624 $skip = false;
626 foreach($tmp as $ky => $vl){
628 if($ky == $change_down){
629 $skip = $vl;
630 }else{
631 $tmp2[$vl] = $vl;
632 }
633 if(($skip != false)&&($ky != $change_down)){
634 $tmp2[$skip] = $skip;
635 $skip =false;
636 }
637 }
638 $this->FAIclass = $tmp2;
639 }
641 if(preg_match("/fai_remove/i",$name)){
642 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
643 unset($this->FAIclass[$value]);
644 }
645 }
646 }
648 /* Delete selected class from our list */
649 if($this->acl_is_writeable("FAIclass")){
650 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
651 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
652 unset($this->FAIclass[$_POST['FAIclassSel']]);
653 }
654 }
655 }
656 }// END fai handling
658 /* Show main page */
659 $smarty= get_smarty();
661 /* Assign ACLs to smarty */
662 $tmp = $this->plInfo();
663 foreach($tmp['plProvidedAcls'] as $name => $translation){
664 $smarty->assign($name."ACL",$this->getacl($name));
665 }
667 /* In this section server shares will be defined
668 * A user can select one of the given shares and a mount point
669 * and attach this combination to his setup.
670 */
671 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
672 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
674 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
675 * This entry will be, a combination of mountPoint and sharedefinitions
676 */
677 if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
678 /* We assign a share to this user, if we don't know where to mount the share */
679 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
680 print_red(_("You must specify a valid mount point."));
681 }else{
682 if(count($this->gotoAvailableShares)){
683 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
684 $s_mount = $_POST['gotoShareMountPoint'];
685 /* Preparing the new assignment */
686 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
687 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
688 }
689 }
690 }
692 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
693 * If there is no defined share selected, we will abort the deletion without any message
694 */
695 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
696 unset($this->gotoShares[$_POST['gotoShare']]);
697 }
699 $smarty->assign("gotoShares",$this->printOutAssignedShares());
700 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
701 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
702 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
704 /* Create divSelectBox for ldap server selection
705 */
706 $SelectBoxLdapServer = new divSelectBox("LdapServer");
707 $SelectBoxLdapServer->SetHeight(130);
709 /* Add new ldap server to the list */
710 if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){
711 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
712 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
713 if(!in_array($to_add,$this->gotoLdapServers)){
714 $this->gotoLdapServers[] = $to_add;
715 }
716 }
717 }
719 /* Move ldap servers up and down */
720 if(!$this->gotoLdap_inherit){
721 foreach($_POST as $name => $value){
722 if(preg_match("/sort_ldap_up_/",$name)){
723 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
724 $from = $id;
725 $to = $id -1;
726 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
727 if($tmp){
728 $this->gotoLdapServers = $tmp;
729 }
730 break;
731 }
732 if(preg_match("/sort_ldap_down_/",$name)){
733 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
734 $from = $id;
735 $to = $id +1;
736 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
737 if($tmp){
738 $this->gotoLdapServers = $tmp;
739 }
740 break;
741 }
742 if(preg_match("/gotoLdapRemove_/",$name)){
743 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
744 $value = $this->gotoLdapServers[$id];
745 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
746 break;
747 }
748 }
749 }
751 /* Add Entries
752 */
753 foreach($this->gotoLdapServers as $key => $server){
754 if(!in_array($server,$this->gotoLdapServerList)){
755 $server = $server." <font style='color:red'>(missing)</font>";
756 }
758 $SelectBoxLdapServer->AddEntry(
759 array(array("string" => $server),
760 array("string" =>
761 "<input class='center' type='image' src='images/sort_up.png' name='sort_ldap_up_".$key."'> ".
762 "<input class='center' type='image' src='images/sort_down.png' name='sort_ldap_down_".$key."'> ".
763 "<input class='center' type='image' src='images/edittrash.png' name='gotoLdapRemove_".$key."'>",
764 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
765 }
767 if($this->gotoLdap_inherit){
768 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
769 }else{
770 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
771 }
773 $list = array();
774 foreach($this->gotoLdapServerList as $key => $entry){
775 if(!in_array($entry,$this->gotoLdapServers)){
776 $list[$key] = $entry;
777 }
778 }
779 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
780 $smarty->assign("gotoLdapServerList", $list);
781 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
782 $smarty->assign("JS", $_SESSION['js']);
784 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
785 $smarty->assign("$val", $this->$val);
786 }
788 /* Values */
789 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
790 $smarty->assign($val, $this->$val);
791 }
793 $smarty->assign("fai_activated",$this->fai_activated);
795 /* Create FAI output */
796 if($this->fai_activated){
797 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
798 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
799 $smarty->assign("FAIreleases",$this->getFAIreleases());
800 $smarty->assign("FAIrelease",$this->FAIrelease);
801 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
802 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
803 $smarty->assign("FAIclassKeys",$this->FAIclass);
805 $inheritedRelease = array();
806 if(!empty($this->InheritedFAIrelease)){
807 $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
808 }
809 $smarty->assign("InheritedFAIrelease",$inheritedRelease);
811 $div = new divSelectBox("WSFAIscriptClasses");
812 $div -> SetHeight("110");
813 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
814 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
815 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
816 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
818 $i = 1;
820 if($this->FAIdebianMirror == "inherited"){
821 $tmp = $this->InheritedFAIclass;
822 }else{
823 $tmp = $this->FAIclass;
824 }
826 foreach($tmp as $class){
828 $marker = "";
829 if(in_array_ics($class,$this->unresolved_classes)){
830 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
831 }
833 if($this->FAIdebianMirror == "inherited"){
834 $str = "";
835 }else{
836 if($i==1){
837 $str = $str_empty.$str_down.$str_remove;
838 }elseif($i == count($this->FAIclass)){
839 $str = $str_up.$str_empty.$str_remove;
840 }else{
841 $str = $str_up.$str_down.$str_remove;
842 }
843 }
844 $i ++ ;
846 $desc = "";
847 foreach($this->FAIclassInfo[$class] as $types ){
848 if(isset($types['desc'][0])){
849 $desc.= $types['desc'][0]." ";
850 }
851 }
852 if(!empty($desc)){
853 $desc = " [".trim($desc)."]";
854 }
856 $div->AddEntry(array(
857 array("string"=>$class.$desc.$marker),
858 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
859 ));
860 }
861 $smarty->assign("FAIScriptlist",$div->DrawList());
862 }// END FAI output generation
864 /* Radio button group */
865 if (preg_match("/G/", $this->bootmode)) {
866 $smarty->assign("graphicalbootup", "checked");
867 } else {
868 $smarty->assign("graphicalbootup", "");
869 }
870 if (preg_match("/T/", $this->bootmode)) {
871 $smarty->assign("textbootup", "checked");
872 } else {
873 $smarty->assign("textbootup", "");
874 }
875 if (preg_match("/D/", $this->bootmode)) {
876 $smarty->assign("debugbootup", "checked");
877 } else {
878 $smarty->assign("debugbootup", "");
879 }
881 /* Show main page */
882 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
883 }
885 function remove_from_parent()
886 {
887 $this->handle_post_events("remove");
888 new log("remove","workstation/".get_class($this),$this->dn);
889 }
891 function generateDNSyn($release)
892 {
893 $str = "";
894 $tmp = split("\/",$release);
895 $tmp = array_reverse($tmp);
897 $base = "ou=fai,ou=configs,ou=systems,";
898 foreach($tmp as $departmentname){
900 $str .= ",ou=".$departmentname;
901 }
902 $str = preg_replace("/^,/","",($str.",".$base));
904 return($str);
905 }
907 function getFAIdebianMirrors()
908 {
909 $ret = array();
911 /* Only add inherit option, if we are part in an object group
912 */
913 if($this->member_of_ogroup) {
914 $ret['inherited']="["._("inherited")."]";
915 }
917 $ret['auto']=_("automatic");
918 $secs = array();
920 /* Walk through all available servers
921 and check if they support the currently selected classes
922 if not, dont't add them to our list
923 */
924 foreach($this->FAIServRepConfig as $mirror => $rest){
926 $use = false;
928 if(count($this->FAIclass) == 0){
929 $use = true;
930 }else{
931 $tmp = $this->getFAIreleases();
932 foreach($tmp as $release){
933 if(isset($rest['RELEASE'][$release])){
934 $use =true;
935 }
936 }
937 }
939 /* If current server, doesn't support this class
940 remove it from list
941 */
942 if($use){
943 $ret[$mirror] = $mirror;
944 }
945 }
946 return($ret);
947 }
949 function getFAIreleases()
950 {
951 $ret = array();
953 if($this->FAIdebianMirror == "inherited") return(array());
955 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
956 $this->FAIdebianMirror = "auto";
957 }
959 $errorClasses = array();
961 if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
962 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
963 $use = true;
965 if(!count($this->FAIclass) == 0){
966 foreach($this->FAIclass as $class){
967 if(!in_array($class, $sections['PACKAGES'])){
968 $use = false;
969 $errorClasses[$class] = $class;
970 }else{
971 if(isset($errorClasses[$class])){
972 unset($errorClasses[$class]);
973 }
974 }
975 }
976 }
977 if($use){
978 $ret[$release]=$release;
979 }
980 }
981 }
982 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
984 $eClasses = " ";
985 foreach($errorClasses as $class){
986 $eClasses .= $class." ";
987 }
989 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));
990 $this->FAIdebianMirror = "auto";
991 return($this->getFAIreleases());
992 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
994 $eClasses = " ";
995 foreach($errorClasses as $class){
996 $eClasses .= $class." ";
997 }
999 $eClasses = preg_replace("/ */","",$eClasses);
1001 if(!empty($eClasses)) {
1003 $this->unresolved_classes = $errorClasses;
1004 $this->FAIdebianMirror = "auto";
1005 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));
1006 }
1007 }
1008 return($ret);
1009 }
1011 /* Save data to object */
1012 function save_object()
1013 {
1014 plugin::save_object();
1016 if(isset($_POST['WorkstationStarttabPosted'])){
1017 if(isset($_POST['gotoLdap_inherit'])){
1018 $this->gotoLdap_inherit = TRUE;
1019 }else{
1020 $this->gotoLdap_inherit = FALSE;
1021 }
1023 /* Save group radio buttons */
1024 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
1025 $this->bootmode= $_POST["bootmode"];
1026 }
1028 /* Save kernel parameters */
1029 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
1030 $this->customParameters= $_POST["customParameters"];
1031 }
1032 }
1033 }
1036 /* Save to LDAP */
1037 function save()
1038 {
1040 /* Depending on the baseobject (Ogroup / WS) we
1041 * use another set of objectClasses
1042 * In case of WS itself, we use "array("GOhard", "FAIobject");"
1043 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
1044 */
1045 if(isset($this->parent->by_object['ogroup'])){
1046 $this->objectclasses = array("gotoWorkstationTemplate");
1047 }elseif(isset($this->parent->by_object['workgeneric'])){
1048 $this->objectclasses = array("GOhard");
1049 }elseif(isset($this->parent->by_object['servgeneric'])){
1050 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
1051 }else{
1052 print "Object Type Configuration : unknown";
1053 exit();
1054 }
1056 /* Append FAI class */
1057 if($this->fai_activated){
1058 $this->objectclasses[] = "FAIobject";
1059 }
1061 /* Find proper terminal path for tftp configuration
1062 FIXME: This is suboptimal when the default has changed to
1063 another location! */
1064 if (($this->gotoTerminalPath == "default")){
1065 $ldap= $this->config->get_ldap_link();
1067 /* Strip relevant part from dn, keep trailing ',' */
1068 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
1069 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
1071 /* Walk from top to base and try to load default values for
1072 'gotoTerminalPath'. Abort when an entry is found. */
1073 while (TRUE){
1074 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
1076 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
1077 $this->config->current['BASE'], array('gotoTerminalPath'));
1078 $attrs= $ldap->fetch();
1079 if (isset($attrs['gotoTerminalPath'])){
1080 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
1081 break;
1082 }
1084 /* Nothing left? */
1085 if ($tmp == ""){
1086 break;
1087 }
1088 }
1089 }
1091 /* Add semi automatic values */
1092 // FIXME: LDAP Server may not be set here...
1093 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1095 switch ($this->bootmode){
1096 case "D":
1097 $this->gotoKernelParameters.= " debug";
1098 break;
1099 case "G":
1100 $this->gotoKernelParameters.= " splash=silent";
1101 break;
1102 }
1103 if ($this->customParameters != ""){
1104 $this->gotoKernelParameters.= " o ".$this->customParameters;
1105 }
1107 plugin::save();
1109 unset( $this->attrs['FAIrelease'] );
1111 $str = "";
1113 /* Skip FAI attribute handling if not necessary */
1114 if($this->fai_activated){
1115 if($this->FAIdebianMirror == "inherited"){
1116 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1117 }else{
1118 foreach($this->FAIclass as $class){
1119 $str .= $class." ";
1120 }
1121 $str .= ":" . $this->FAIrelease;
1122 $this->attrs['FAIclass']= "";
1123 $this->attrs['FAIclass']= trim($str);
1125 if(empty($this->attrs['FAIclass'])){
1126 $this->attrs['FAIclass'] = array();
1127 }
1128 }
1129 }
1131 /* Add missing arrays */
1132 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1133 if (isset ($this->$val) && count ($this->$val) != 0){
1135 $this->attrs["$val"]= array_unique($this->$val);
1136 }
1137 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1138 }
1140 /* Prepare list of ldap servers */
1141 $this->attrs['gotoLdapServer'] = array();
1142 if(!$this->gotoLdap_inherit){
1143 $i = 0;
1144 foreach($this->gotoLdapServers as $server){
1145 $i ++;
1146 $this->attrs['gotoLdapServer'][] = $i.":".$server;
1147 }
1148 }
1150 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1151 $this->attrs['gotoBootKernel']= array();
1152 }
1154 /* if mirror == none stop saving this attribute */
1155 if($this->FAIdebianMirror == "none"){
1156 $this->FAIdebianMirror = "";
1157 }
1159 /* Get FAIstate from object, the generic tab could have changed it during execute */
1160 $ldap= $this->config->get_ldap_link();
1161 $ldap->cd($this->dn);
1164 /* Skip FAI attribute handling if not necessary */
1165 if($this->fai_activated){
1166 $ldap->cat($this->dn,array("FAIstate"));
1167 $checkFAIstate = $ldap->fetch();
1169 /* Remove FAI objects if no FAI class is selected */
1170 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1171 $this->attrs['FAIclass'] = array();
1172 $this->attrs['FAIdebianMirror'] = array();
1173 }
1174 }
1177 /* prepare share settings */
1178 $tmp = array();
1179 foreach($this->gotoShares as $name => $settings){
1180 $tmp2= split("\|",$name);
1181 $name = $tmp2[0];
1182 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1183 }
1184 $this->attrs['gotoShare']=$tmp;
1186 $this->cleanup();
1187 $ldap->modify ($this->attrs);
1188 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1190 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1191 $this->handle_post_events("modify");
1192 }
1194 /* Add value to array, check if unique */
1195 function add_list (&$array, $value)
1196 {
1197 if ($value != ""){
1198 $array[]= $value;
1199 sort($array);
1200 array_unique ($array);
1201 }
1202 }
1205 /* Delete value to array, check if unique */
1206 function del_list (&$array, $list)
1207 {
1208 $tmp= array();
1209 foreach ($array as $mod){
1210 if (!in_array($mod, $list)){
1211 $tmp[]= $mod;
1212 }
1213 }
1214 $array= $tmp;
1215 }
1217 /* Generate ListBox frindly output for the defined shares
1218 * Possibly Add or remove an attribute here,
1219 */
1220 function printOutAssignedShares()
1221 {
1222 $a_return = array();
1223 if(is_array($this->gotoShares)){
1224 foreach($this->gotoShares as $share){
1225 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1226 }
1227 }
1228 return($a_return);
1229 }
1232 function GetHookElements()
1233 {
1234 $ret = array();
1235 $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1236 if(!empty($cmd)){
1237 $res = shell_exec($cmd);
1238 $res2 = trim($res);
1239 if((!$res)){
1240 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1241 }elseif(empty($res2)){
1242 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1243 }else{
1244 $tmp = split("\n",$res);
1245 foreach($tmp as $line){
1246 if(empty($line)) continue;
1247 $ret[]= $line;
1248 }
1249 }
1250 }
1251 return($ret);
1252 }
1255 function PrepareForCopyPaste($source)
1256 {
1257 plugin::PrepareForCopyPaste($source);
1259 $source_o = new workstartup ($this->config, $source['dn']);
1261 foreach(array("gotoModules", "gotoAutoFs", "gotoFilesystem","gotoKernelParameters","gotoShares","customParameters") as $attr){
1262 $this->$attr = $source_o->$attr;
1263 }
1264 }
1267 function array_switch_item($ar,$from,$to)
1268 {
1269 if(!is_array($ar)){
1270 return(false);
1271 }
1272 if(!isset($ar[$from])){
1273 return(false);
1274 }
1275 if(!isset($ar[$to])){
1276 return(false);
1277 }
1279 $tmp = $ar[$from];
1280 $ar[$from] = $ar[$to];
1281 $ar[$to] = $tmp;
1282 return($ar);
1283 }
1286 /* Return plugin informations for acl handling */
1287 function plInfo()
1288 {
1289 return (array(
1290 "plShortName" => _("Startup"),
1291 "plDescription" => _("System startup"),
1292 "plSelfModify" => FALSE,
1293 "plDepends" => array(),
1294 "plPriority" => 9,
1295 "plSection" => array("administration"),
1296 "plCategory" => array("workstation","server","ogroups"),
1298 "plProvidedAcls"=> array(
1299 "gotoLdapServer" => _("Ldap server"),
1300 "gotoBootKernel" => _("Boot kernel"),
1301 "gotoKernelParameters" => _("Kernel parameter"),
1303 "gotoModules" => _("Kernel modules"),
1304 "gotoShare" => _("Shares"),
1306 "FAIclass" => _("FAI classes"),
1307 "FAIdebianMirror" => _("Debian mirror"),
1308 "FAIrelease" => _("Debian release"),
1310 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1311 ));
1312 }
1313 }
1315 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1316 ?>