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 /* Generic terminal attributes */
10 var $bootmode = "G";
11 var $goLdapServerList = array();
12 var $gotoBootKernel = "default-inherited";
13 var $gotoKernelParameters = "";
14 var $gotoLdapServer = "default-inherited";
15 var $gotoModules = array();
16 var $gotoAutoFs = array();
17 var $gotoFilesystem = array();
18 var $gotoTerminalPath = "";
19 var $FAIstatus = "";
20 var $gotoBootKernels = array();
22 /* attribute list for save action */
23 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
24 var $objectclasses = array("GOhard", "FAIobject");
26 /* Share */
27 var $gotoShares = array();// Currently Share Option
28 var $gotoShare = ""; // currently selected Share Option
29 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
30 var $gotoAvailableShares= array();// Available Shares for this account
32 /* Helper */
33 var $customParameters = "";
34 var $orig_dn = "";
35 var $ignore_account = TRUE;
37 /* FAI class selection */
38 var $FAIclass = array();
39 var $FAIclasses = array();
40 var $FAIclassInfo = array();
41 var $FAIrelease = "";
42 var $FAIdebianMirror = "auto";
44 var $unresolved_classes = array();
45 var $view_logged = FALSE;
47 /* FAI class selection */
48 var $InheritedFAIclass = array();
49 var $InheritedFAIrelease = "";
50 var $InheritedFAIdebianMirror = "auto";
52 /* Contains all possible server/release/class settings */
53 var $FAIServRepConfig = array();
55 var $CopyPasteVars = array("gotoModules","gotoShares");
57 var $fai_activated = FALSE;
59 var $member_of_ogroup = FALSE;
61 function workstartup ($config, $dn= NULL, $parent= NULL)
62 {
63 /* Check if FAI is active */
64 $tmp = search_config($config->data,"faiManagement","CLASS");
65 if(!empty($tmp)){
66 $this->fai_activated = TRUE;
67 }else{
68 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
69 $this->objectclasses = array("GOhard");
70 }
72 plugin::plugin ($config, $dn, $parent);
74 if(!isset($this->parent->by_object['ogroup'])){
75 $ldap = $this->config->get_ldap_link();
76 $ldap->cd ($this->config->current['BASE']);
77 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))",array("cn"));
78 $this->member_of_ogroup = $ldap->count() >= 1;
79 }
81 /* Creating a list of valid Mirrors
82 * none will not be saved to ldap.
83 */
84 $ldap = $this->config->get_ldap_link();
85 $ldap->cd($this->config->current['BASE']);
87 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
88 $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
89 }
92 /* FAI Initialization
93 Skip this if FAI is not activated
94 */
95 if($this->fai_activated) {
97 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
98 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
100 /* Search all FAI objects */
101 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
102 /* Sort all entries, and attach elementtype.
103 * To be able to show the types in the listbox.
104 */
105 while($attr = $ldap->fetch()){
106 $cn = $attr['cn'][0];
108 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
110 if(in_array('FAIpackageList',$attr['objectClass'])){
111 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
112 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
113 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
114 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
115 }
116 if(in_array('FAItemplate',$attr['objectClass'])){
117 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
118 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
119 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
120 }
121 if(in_array('FAIvariable',$attr['objectClass'])){
122 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
123 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
124 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
125 }
126 if(in_array('FAIscript',$attr['objectClass'])){
127 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
128 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
129 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
130 }
131 if(in_array('FAIhook',$attr['objectClass'])){
132 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
133 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
134 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
135 }
136 if(in_array('FAIpartitionTable',$attr['objectClass'])){
137 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
138 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
139 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
140 }
141 if(in_array('FAIprofile',$attr['objectClass'])){
142 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
143 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
144 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
145 }
146 }
147 if(is_array($this->FAIclasses)){
148 natcasesort($this->FAIclasses);
149 }
151 if(isset($tmp2)){
152 $this->FAIclassInfo = $tmp2;
153 } else {
154 $this->FAIclassInfo = array();
155 }
157 /* Build up an array like this one :
158 [$url]['SERVER'] = 'srv1-002';
159 [$url]['RELEASE']['siga/rc9.0.2']
160 ['SECTIONS'][0] "main";
161 ['SECTIONS'][1] "non-free";
162 [$url]['RELEASE']['siga/rc9.0.2']
163 ['PACKAGES'][0] "pkg1";
164 ['PACKAGES'][1] "postfix";
165 */
167 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
168 $test = array();
169 while($attr = $ldap->fetch()){
170 if(isset($attr['FAIrepository'])){
172 unset($attr['FAIrepository']['count']);
174 foreach($attr['FAIrepository'] as $rep){
175 $tmp = split("\|",$rep);
177 if(count($tmp)==4){
178 $sections = split(",",$tmp[3]);
179 $release = $tmp[2];
180 $server = $tmp[1];
181 $url = $tmp[0];
183 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
185 /* Result will be cached
186 */
187 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
188 $test[$url]['SERVER'] = $server;
190 /* auto gets all releases/classes
191 */
192 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
193 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
194 }
195 }
196 }
197 }
199 /* Add possible elements from hook */
200 $lines= $this->GetHookElements();
201 foreach ($lines as $hline){
202 $entries= split(";", $hline);
203 if (isset($entries[1]) && !isset($test[$entries[1]])){
204 $test[$entries[1]]['RELEASE']= array();
206 /* Split releases */
207 if (isset($entries[2])){
208 $releases= split(",", $entries[2]);
210 foreach ($releases as $release){
211 $rname= preg_replace('/:.*$/', '', $release);
212 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
213 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
214 $test[$entries[1]]['RELEASE'][$rname]= array();
215 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
216 foreach ($classes as $class){
217 if ($class != ""){
218 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
219 }
220 }
221 }
222 }
223 }
224 }
226 $this->FAIServRepConfig= $test;
228 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
229 $tmp = array();
230 $tmp = split(" ",$this->FAIclass);
231 $tmp2 =array();
233 foreach($tmp as $class){
234 if( ":" == $class[0] ) {
235 $this->FAIrelease = substr( $class, 1 );
236 }
237 else
238 $tmp2[$class] = $class;
239 }
240 $this->FAIclass = $tmp2;
241 }
243 if(!is_array($this->FAIclass)){
244 $this->FAIclass =array();
245 }
246 }// END of FAI initialization stuff
249 /* Get arrays */
250 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
251 if (isset($this->attrs["$val"]["count"])){
252 for ($i= 0; $i<$this->attrs["count"]; $i++){
253 if (isset($this->attrs["$val"][$i])){
254 array_push($this->$val, $this->attrs["$val"][$i]);
255 }
256 }
257 }
258 sort ($this->$val);
259 $this->$val= array_unique($this->$val);
260 }
262 /* Parse Kernel Parameters to decide what boot mode is enabled */
263 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
264 $this->bootmode= "G";
265 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
266 $this->bootmode= "D";
267 } elseif ($this->gotoKernelParameters == "") {
268 $this->bootmode= "G";
269 } else {
270 $this->bootmode= "T";
271 }
272 if (preg_match("/ o /", $this->gotoKernelParameters)){
273 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
274 } else {
275 $this->customParameters= "";
276 }
278 /* Prepare Shares */
279 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
280 unset($this->attrs['gotoShare']['count']);
281 foreach($this->attrs['gotoShare'] as $share){
282 $tmp = $tmp2 = array();
283 $tmp = split("\|",$share);
284 $tmp2['server'] =$tmp[0];
285 $tmp2['name'] =$tmp[1];
286 $tmp2['mountPoint'] =$tmp[2];
287 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
288 }
289 }
291 $this->gotoShareSelections= $config->getShareList(true);
292 $this->gotoAvailableShares= $config->getShareList(false);
293 $tmp2 = array();
296 $this->orig_dn= $this->dn;
298 /* Handle inheritance value "default" */
299 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
301 /* Load hardware list */
302 if ($this->member_of_ogroup){
304 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
305 $this->FAIdebianMirror = "inherited";
306 }
308 if($this->fai_activated){
309 $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
310 }else{
311 $map= array("gotoLdapServer");
312 }
313 $attrs= $ldap->fetch();
315 foreach ($map as $name){
316 if (!isset($attrs[$name][0])){
317 continue;
318 }
320 switch ($name){
321 case 'gotoLdapServer':
322 $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
323 break;
325 case 'gotoBootKernel':
326 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
327 break;
329 case 'FAIclass':
330 $str = split(":",$attrs[$name][0]);
331 $this->InheritedFAIclass = split("\ ",trim($str[0]));
332 $this->InheritedFAIrelease = trim($str[1]);
333 break;
335 case 'FAIdebianMirror':
336 $this->InheritedFAIdebianMirror = $attrs[$name][0];
337 break;
338 }
339 }
340 }
342 /* Get list of boot kernels */
343 if (isset($this->config->data['TABS'])){
344 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
346 if (!check_command($command)){
347 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
348 get_class($this));
349 } else {
350 $fh= popen($command, "r");
351 while (!feof($fh)) {
352 $buffer= trim(fgets($fh, 256));
354 if(!empty($buffer)){
356 $name=$value = $buffer;
358 if(preg_match("/:/",$buffer)){
359 $name = preg_replace("/:.*$/","",$buffer);
360 $value= preg_replace("/^.*:/","",$buffer);
361 $this->gotoBootKernels[$name]= $name.":".$value;
362 }else{
363 $this->gotoBootKernels[$name]= $value;
364 }
365 }
367 }
368 pclose($fh);
369 }
370 }
372 /* Turn to default, if we've nothing to inherit */
373 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
374 $this->gotoBootKernel= "default";
375 }
376 }
379 /* This class is called by the contrucktor ONLY.
380 * It return the available classes for each
381 * Server / Release combination ...
382 * (Release specifies which classes are available)
383 */
384 function getAvailableClassesForThisRelease($release)
385 {
386 /* There could be more than one server providing this release,
387 so use cached result if available
388 */
389 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
390 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
391 }
393 $test2 = array();
394 $bb = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
395 $ldap = $this->config->get_ldap_link();
396 $ldap->cd($this->config->current['BASE']);
398 /* Get classes fpr given release */
399 $p_classes = get_all_objects_for_given_base($bb,
400 "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
401 "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
402 "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
404 /* Create list of classes */
405 foreach($p_classes as $class){
406 $ldap->cat($class['dn'],array("cn"));
407 $attr = $ldap->fetch();
408 $test2[$attr['cn'][0]] = $attr['cn'][0];
409 }
410 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
411 return($test2);
412 }
415 /* Create array to display available classes/profiles in a selectbox
416 * This function only displays the available classes.
417 * If a class is available is defined by these facts :
418 * 1. Is this class available for the selected release ?
419 * - if it is available, check if the release is available for the selected server
420 * (done by $this->getFAIreleases())
421 * 2. Is this class currently not assigned to $this->FAIclass
422 */
423 function selectFriendlyClasses(){
424 $tmp=array();
426 if($this->FAIdebianMirror == "inherited") return($tmp);
428 /* check if the current release exists,
429 else select the first one ..
430 */
431 $tmp2 = $this->getFAIreleases();
432 if(!in_array($this->FAIrelease, $tmp2)){
433 $this->FAIrelease = key($tmp2);
434 }
436 /* Get all Packages for this server/release combination
437 */
438 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
439 $pkgs = array();
440 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
441 }else{
442 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
443 }
445 /* Check each and every single class name
446 */
447 foreach($pkgs as $pkg){
449 /* Class already assigned to the classes list ?
450 * If not ... go on
451 */
452 if(!in_array($pkg,$this->FAIclass)){
454 /* Create the displayed list entry value
455 HKLMOP [-Pl P V T-] or something like that
456 */
457 $str = "";
458 foreach($this->FAIclassInfo[$pkg] as $entry){
459 if(isset($entry['kzl'])){
460 $str .= $entry['kzl']." ";
461 }
462 }
464 /* Append class if everyting was fine
465 */
466 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
467 }
468 }
469 /* Just sort and return new classes list ...
470 ( possibly we should cache the result ... )
471 */
472 natcasesort ($tmp);
473 return($tmp);
474 }
476 function check()
477 {
478 $messages = array();
480 /* Call common method to give check the hook */
481 $messages= plugin::check();
483 /* If there are packages selected, but no mirror show error */
484 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
485 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
486 }
488 return($messages);
489 }
491 function execute()
492 {
494 /* Call parent execute */
495 plugin::execute();
497 if($this->is_account && !$this->view_logged){
498 $this->view_logged = TRUE;
499 new log("view","workstation/".get_class($this),$this->dn);
500 }
502 /* Do we need to flip is_account state? */
503 if(isset($_POST['modify_state'])){
504 if($this->is_account && $this->acl_is_removeable()){
505 $this->is_account= FALSE;
506 }elseif(!$this->is_account && $this->acl_is_createable()){
507 $this->is_account= TRUE;
508 }
509 }
511 /* Do we represent a valid terminal? */
512 if (!$this->is_account && $this->parent == NULL){
513 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
514 _("This 'dn' has no terminal features.")."</b>";
515 return ($display);
516 }
518 /* Add module */
519 if (isset ($_POST['add_module'])){
520 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
521 $this->add_list ($this->gotoModules, $_POST['module']);
522 }
523 }
525 /* Delete module */
526 if (isset ($_POST['delete_module'])){
527 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
528 $this->del_list ($this->gotoModules, $_POST['modules_list']);
529 }
530 }
532 /* FAI class management */
533 if($this->fai_activated){
534 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
535 $found = 0 ;
537 /* If this new class/profile will attach a second partition table
538 * to our list of classes, abort and show a message.
539 */
540 foreach($this->FAIclass as $name){
541 if(isset($this->FAIclassInfo[$name])){
542 foreach($this->FAIclassInfo[$name] as $atr){
543 if(isset($atr['obj'])){
544 if($atr['obj'] == "FAIpartitionTable"){
545 $found ++ ;
546 }
547 }
548 }
549 }
550 }
552 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
553 print_red(_("There is already a profile in your selection that contain partition table configurations."));
554 }else{
555 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
556 }
557 }
559 $sort = false;
561 /* Move one used class class one position up or down */
562 if($this->acl_is_writeable("FAIclass")){
563 foreach($_POST as $name => $val){
565 $sort_type = false;
566 if((preg_match("/sort_up/",$name))&&(!$sort)){
567 $sort_type = "sort_up_";
568 }
569 if((preg_match("/sort_down/",$name))&&(!$sort)){
570 $sort_type = "sort_down_";
571 }
573 if(($sort_type)&&(!$sort)){
574 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
575 $sort = true;
577 $last = -1;
578 $change_down = -1;
580 /* Create array with numeric index */
581 $tmp = array();
582 foreach($this->FAIclass as $class){
583 $tmp [] = $class;
584 }
586 /* Walk trough array */
587 foreach($tmp as $key => $faiName){
588 if($faiName == $value){
589 if($sort_type == "sort_up_"){
590 if($last != -1){
591 $change_down= $last;
592 }
593 }else{
594 if(isset($tmp[$key+1])){
595 $change_down = $key;
596 }
597 }
598 }
599 $last = $key;
600 }
602 $tmp2 = array();
603 $skip = false;
605 foreach($tmp as $ky => $vl){
607 if($ky == $change_down){
608 $skip = $vl;
609 }else{
610 $tmp2[$vl] = $vl;
611 }
612 if(($skip != false)&&($ky != $change_down)){
613 $tmp2[$skip] = $skip;
614 $skip =false;
615 }
616 }
617 $this->FAIclass = $tmp2;
618 }
620 if(preg_match("/fai_remove/i",$name)){
621 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
622 unset($this->FAIclass[$value]);
623 }
624 }
625 }
627 /* Delete selected class from our list */
628 if($this->acl_is_writeable("FAIclass")){
629 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
630 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
631 unset($this->FAIclass[$_POST['FAIclassSel']]);
632 }
633 }
634 }
635 }// END fai handling
637 /* Show main page */
638 $smarty= get_smarty();
640 /* Assign ACLs to smarty */
641 $tmp = $this->plInfo();
642 foreach($tmp['plProvidedAcls'] as $name => $translation){
643 $smarty->assign($name."ACL",$this->getacl($name));
644 }
646 $smarty->assign("SelectBoxLdapServer","");
648 /* In this section server shares will be defined
649 * A user can select one of the given shares and a mount point
650 * and attach this combination to his setup.
651 */
652 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
653 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
655 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
656 * This entry will be, a combination of mountPoint and sharedefinitions
657 */
658 if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
659 /* We assign a share to this user, if we don't know where to mount the share */
660 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
661 print_red(_("You must specify a valid mount point."));
662 }else{
663 if(count($this->gotoAvailableShares)){
664 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
665 $s_mount = $_POST['gotoShareMountPoint'];
666 /* Preparing the new assignment */
667 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
668 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
669 }
670 }
671 }
673 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
674 * If there is no defined share selected, we will abort the deletion without any message
675 */
676 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
677 unset($this->gotoShares[$_POST['gotoShare']]);
678 }
680 $smarty->assign("gotoShares",$this->printOutAssignedShares());
681 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
682 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
683 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
685 /* Arrays */
686 $tmp = $this->goLdapServerList;
688 /* Create divSelectBox for ldap server selection
689 */
690 $SelectBoxLdapServer = new divSelectBox("LdapServer");
691 $SelectBoxLdapServer->SetHeight(130);
693 /* Set first entry as selected, if $this->gotoLdapServer is empty
694 * or given entry is no longer available ...
695 */
696 $found = false;
697 foreach($tmp as $server){
698 if($this->gotoLdapServer==$server){
699 $found = true;
700 }
701 }
703 /* Add Entries
704 */
705 foreach($tmp as $key => $server){
706 $use ="";
707 if(($this->gotoLdapServer == $server) || ($found == false)) {
708 $found = true;
709 $use = " checked ";
710 };
712 $display = $server;
714 $SelectBoxLdapServer->AddEntry(
715 array(
716 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
717 "attach"=>"style='border-left:0px;'"),
718 array("string"=>$display)
719 ));
720 }
722 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
724 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
725 $smarty->assign("$val", $this->$val);
726 }
728 /* Values */
729 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
730 $smarty->assign($val, $this->$val);
731 }
733 $smarty->assign("fai_activated",$this->fai_activated);
735 /* Create FAI output */
736 if($this->fai_activated){
737 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
738 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
739 $smarty->assign("FAIreleases",$this->getFAIreleases());
740 $smarty->assign("FAIrelease",$this->FAIrelease);
741 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
742 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
743 $smarty->assign("FAIclassKeys",$this->FAIclass);
745 $inheritedRelease = array();
746 if(!empty($this->InheritedFAIrelease)){
747 $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
748 }
749 $smarty->assign("InheritedFAIrelease",$inheritedRelease);
751 $div = new divSelectBox("WSFAIscriptClasses");
752 $div -> SetHeight("110");
753 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
754 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
755 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
756 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
758 $i = 1;
760 if($this->FAIdebianMirror == "inherited"){
761 $tmp = $this->InheritedFAIclass;
762 }else{
763 $tmp = $this->FAIclass;
764 }
766 foreach($tmp as $class){
768 $marker = "";
769 if(in_array_ics($class,$this->unresolved_classes)){
770 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
771 }
773 if($this->FAIdebianMirror == "inherited"){
774 $str = "";
775 }else{
776 if($i==1){
777 $str = $str_empty.$str_down.$str_remove;
778 }elseif($i == count($this->FAIclass)){
779 $str = $str_up.$str_empty.$str_remove;
780 }else{
781 $str = $str_up.$str_down.$str_remove;
782 }
783 }
784 $i ++ ;
786 $div->AddEntry(array(
787 array("string"=>$class.$marker),
788 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
789 ));
790 }
792 $smarty->assign("FAIScriptlist",$div->DrawList());
793 }// END FAI output generation
795 /* Radio button group */
796 if (preg_match("/G/", $this->bootmode)) {
797 $smarty->assign("graphicalbootup", "checked");
798 } else {
799 $smarty->assign("graphicalbootup", "");
800 }
801 if (preg_match("/T/", $this->bootmode)) {
802 $smarty->assign("textbootup", "checked");
803 } else {
804 $smarty->assign("textbootup", "");
805 }
806 if (preg_match("/D/", $this->bootmode)) {
807 $smarty->assign("debugbootup", "checked");
808 } else {
809 $smarty->assign("debugbootup", "");
810 }
812 /* Show main page */
813 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
814 }
816 function remove_from_parent()
817 {
818 $this->handle_post_events("remove");
819 new log("remove","workstation/".get_class($this),$this->dn);
820 }
822 function generateDNSyn($release)
823 {
824 $str = "";
825 $tmp = split("\/",$release);
826 $tmp = array_reverse($tmp);
828 $base = "ou=fai,ou=configs,ou=systems,";
829 foreach($tmp as $departmentname){
831 $str .= ",ou=".$departmentname;
832 }
833 $str = preg_replace("/^,/","",($str.",".$base));
835 return($str);
836 }
838 function getFAIdebianMirrors()
839 {
840 $ret = array();
842 /* Only add inherit option, if we are part in an object group
843 */
844 if($this->member_of_ogroup) {
845 $ret['inherited']="["._("inherited")."]";
846 }
848 $ret['auto']=_("automatic");
849 $secs = array();
851 /* Walk through all available servers
852 and check if they support the currently selected classes
853 if not, dont't add them to our list
854 */
855 foreach($this->FAIServRepConfig as $mirror => $rest){
857 $use = false;
859 if(count($this->FAIclass) == 0){
860 $use = true;
861 }else{
862 $tmp = $this->getFAIreleases();
863 foreach($tmp as $release){
864 if(isset($rest['RELEASE'][$release])){
865 $use =true;
866 }
867 }
868 }
870 /* If current server, doesn't support this class
871 remove it from list
872 */
873 if($use){
874 $ret[$mirror] = $mirror;
875 }
876 }
877 return($ret);
878 }
880 function getFAIreleases()
881 {
882 $ret = array();
884 if($this->FAIdebianMirror == "inherited") return(array());
886 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
887 $this->FAIdebianMirror = "auto";
888 }
890 $errorClasses = array();
892 if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
893 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
894 $use = true;
896 if(!count($this->FAIclass) == 0){
897 foreach($this->FAIclass as $class){
898 if(!in_array($class, $sections['PACKAGES'])){
899 $use = false;
900 $errorClasses[$class] = $class;
901 }else{
902 if(isset($errorClasses[$class])){
903 unset($errorClasses[$class]);
904 }
905 }
906 }
907 }
908 if($use){
909 $ret[$release]=$release;
910 }
911 }
912 }
913 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
915 $eClasses = " ";
916 foreach($errorClasses as $class){
917 $eClasses .= $class." ";
918 }
920 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));
921 $this->FAIdebianMirror = "auto";
922 return($this->getFAIreleases());
923 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
925 $eClasses = " ";
926 foreach($errorClasses as $class){
927 $eClasses .= $class." ";
928 }
930 $eClasses = preg_replace("/ */","",$eClasses);
932 if(!empty($eClasses)) {
934 $this->unresolved_classes = $errorClasses;
935 $this->FAIdebianMirror = "auto";
936 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));
937 }
938 }
939 return($ret);
940 }
942 /* Save data to object */
943 function save_object()
944 {
945 plugin::save_object();
947 /* Save group radio buttons */
948 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
949 $this->bootmode= $_POST["bootmode"];
950 }
952 /* Save kernel parameters */
953 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
954 $this->customParameters= $_POST["customParameters"];
955 }
957 }
960 /* Save to LDAP */
961 function save()
962 {
964 /* Depending on the baseobject (Ogroup / WS) we
965 * use another set of objectClasses
966 * In case of WS itself, we use "array("GOhard", "FAIobject");"
967 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
968 */
969 if(isset($this->parent->by_object['ogroup'])){
970 $this->objectclasses = array("gotoWorkstationTemplate");
971 }elseif(isset($this->parent->by_object['workgeneric'])){
972 $this->objectclasses = array("GOhard");
973 }elseif(isset($this->parent->by_object['servgeneric'])){
974 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
975 }else{
976 print "Object Type Configuration : unknown";
977 exit();
978 }
980 /* Append FAI class */
981 if($this->fai_activated){
982 $this->objectclasses[] = "FAIobject";
983 }
985 /* Find proper terminal path for tftp configuration
986 FIXME: This is suboptimal when the default has changed to
987 another location! */
988 if (($this->gotoTerminalPath == "default")){
989 $ldap= $this->config->get_ldap_link();
991 /* Strip relevant part from dn, keep trailing ',' */
992 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
993 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
995 /* Walk from top to base and try to load default values for
996 'gotoTerminalPath'. Abort when an entry is found. */
997 while (TRUE){
998 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
1000 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
1001 $this->config->current['BASE'], array('gotoTerminalPath'));
1002 $attrs= $ldap->fetch();
1003 if (isset($attrs['gotoTerminalPath'])){
1004 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
1005 break;
1006 }
1008 /* Nothing left? */
1009 if ($tmp == ""){
1010 break;
1011 }
1012 }
1013 }
1015 /* Add semi automatic values */
1016 // FIXME: LDAP Server may not be set here...
1017 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1019 switch ($this->bootmode){
1020 case "D":
1021 $this->gotoKernelParameters.= " debug";
1022 break;
1023 case "G":
1024 $this->gotoKernelParameters.= " splash=silent";
1025 break;
1026 }
1027 if ($this->customParameters != ""){
1028 $this->gotoKernelParameters.= " o ".$this->customParameters;
1029 }
1031 plugin::save();
1033 unset( $this->attrs['FAIrelease'] );
1035 $str = "";
1037 /* Skip FAI attribute handling if not necessary */
1038 if($this->fai_activated){
1039 if($this->FAIdebianMirror == "inherited"){
1040 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1041 }else{
1042 foreach($this->FAIclass as $class){
1043 $str .= $class." ";
1044 }
1045 $str .= ":" . $this->FAIrelease;
1046 $this->attrs['FAIclass']= "";
1047 $this->attrs['FAIclass']= trim($str);
1049 if(empty($this->attrs['FAIclass'])){
1050 $this->attrs['FAIclass'] = array();
1051 }
1052 }
1053 }
1055 /* Add missing arrays */
1056 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1057 if (isset ($this->$val) && count ($this->$val) != 0){
1059 $this->attrs["$val"]= array_unique($this->$val);
1060 }
1061 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1062 }
1064 /* Strip out 'default' values */
1065 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1066 $this->attrs['gotoLdapServer']= array();
1067 }
1069 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1070 $this->attrs['gotoBootKernel']= array();
1071 }
1073 /* if mirror == none stop saving this attribute */
1074 if($this->FAIdebianMirror == "none"){
1075 $this->FAIdebianMirror = "";
1076 }
1078 /* Get FAIstate from object, the generic tab could have changed it during execute */
1079 $ldap= $this->config->get_ldap_link();
1080 $ldap->cd($this->dn);
1083 /* Skip FAI attribute handling if not necessary */
1084 if($this->fai_activated){
1085 $ldap->cat($this->dn,array("FAIstate"));
1086 $checkFAIstate = $ldap->fetch();
1088 /* Remove FAI objects if no FAI class is selected */
1089 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1090 $this->attrs['FAIclass'] = array();
1091 $this->attrs['FAIdebianMirror'] = array();
1092 }
1093 }
1096 /* prepare share settings */
1097 $tmp = array();
1098 foreach($this->gotoShares as $name => $settings){
1099 $tmp2= split("\|",$name);
1100 $name = $tmp2[0];
1101 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1102 }
1103 $this->attrs['gotoShare']=$tmp;
1105 $this->cleanup();
1106 $ldap->modify ($this->attrs);
1107 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1109 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1110 $this->handle_post_events("modify");
1111 }
1113 /* Add value to array, check if unique */
1114 function add_list (&$array, $value)
1115 {
1116 if ($value != ""){
1117 $array[]= $value;
1118 sort($array);
1119 array_unique ($array);
1120 }
1121 }
1124 /* Delete value to array, check if unique */
1125 function del_list (&$array, $list)
1126 {
1127 $tmp= array();
1128 foreach ($array as $mod){
1129 if (!in_array($mod, $list)){
1130 $tmp[]= $mod;
1131 }
1132 }
1133 $array= $tmp;
1134 }
1136 /* Generate ListBox frindly output for the defined shares
1137 * Possibly Add or remove an attribute here,
1138 */
1139 function printOutAssignedShares()
1140 {
1141 $a_return = array();
1142 if(is_array($this->gotoShares)){
1143 foreach($this->gotoShares as $share){
1144 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1145 }
1146 }
1147 return($a_return);
1148 }
1151 function GetHookElements()
1152 {
1153 $ret = array();
1154 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1155 if(!empty($cmd)){
1156 $res = shell_exec($cmd);
1157 $res2 = trim($res);
1158 if((!$res)){
1159 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1160 }elseif(empty($res2)){
1161 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1162 }else{
1163 $tmp = split("\n",$res);
1164 foreach($tmp as $line){
1165 if(empty($line)) continue;
1166 $ret[]= $line;
1167 }
1168 }
1169 }
1170 return($ret);
1171 }
1174 function PrepareForCopyPaste($source)
1175 {
1176 plugin::PrepareForCopyPaste($source);
1178 $source_o = new workstartup ($this->config, $source['dn']);
1180 foreach(array("gotoModules", "gotoAutoFs", "gotoFilesystem","gotoKernelParameters","gotoShares","customParameters") as $attr){
1181 $this->$attr = $source_o->$attr;
1182 }
1183 }
1186 /* Return plugin informations for acl handling */
1187 function plInfo()
1188 {
1189 return (array(
1190 "plShortName" => _("Startup"),
1191 "plDescription" => _("System startup"),
1192 "plSelfModify" => FALSE,
1193 "plDepends" => array(),
1194 "plPriority" => 9,
1195 "plSection" => array("administration"),
1196 "plCategory" => array("workstation","server","ogroups"),
1198 "plProvidedAcls"=> array(
1199 "gotoLdapServer" => _("Ldap server"),
1200 "gotoBootKernel" => _("Boot kernel"),
1201 "gotoKernelParameters" => _("Kernel parameter"),
1203 "gotoModules" => _("Kernel modules"),
1204 "gotoShare" => _("Shares"),
1206 "FAIclass" => _("FAI classes"),
1207 "FAIdebianMirror" => _("Debian mirror"),
1208 "FAIrelease" => _("Debian release"),
1210 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1211 ));
1212 }
1213 }
1215 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1216 ?>