3d4d1300dbe8a2c6d3fff8f8c13efbf8f4539f2d
1 <?php
3 class workstartup extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage terminal startup options";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* Generic terminal attributes */
11 var $bootmode = "G";
12 var $goLdapServerList = array();
13 var $gotoBootKernel = "default-inherited";
14 var $gotoKernelParameters = "";
15 var $gotoLdapServer = "default-inherited";
16 var $gotoModules = array();
17 var $gotoAutoFs = array();
18 var $gotoFilesystem = array();
19 var $gotoTerminalPath = "";
20 var $FAIstatus = "";
21 var $gotoBootKernels = array();
23 /* attribute list for save action */
24 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
25 var $objectclasses = array("GOhard", "FAIobject");
27 /* Share */
28 var $gotoShares = array();// Currently Share Option
29 var $gotoShare = ""; // currently selected Share Option
30 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
31 var $gotoAvailableShares= array();// Available Shares for this account
33 /* Helper */
34 var $customParameters = "";
35 var $orig_dn = "";
36 var $ignore_account = TRUE;
38 /* FAI class selection */
39 var $FAIclass = array();
40 var $FAIclasses = array();
41 var $FAIclassInfo = array();
42 var $FAIrelease = "";
43 var $FAIdebianMirror = "auto";
45 var $unresolved_classes = array();
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 function workstartup ($config, $dn= NULL, $parent= NULL)
56 {
57 plugin::plugin ($config, $dn, $parent);
59 /* Creating a list of valid Mirrors
60 * none will not be saved to ldap.
61 */
62 $ldap = $this->config->get_ldap_link();
63 $ldap->cd($this->config->current['BASE']);
65 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
66 $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
67 }
69 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
70 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
72 $ui = get_userinfo();
73 $res = get_list( "(|(objectClass=FAIpackageList)".
74 "(objectClass=FAItemplate)".
75 "(objectClass=FAIvariable)".
76 "(objectClass=FAIscript)".
77 "(objectClass=FAIhook)".
78 "(objectClass=FAIprofile)".
79 "(objectClass=FAIpartitionTable))",
80 $ui->subtreeACL,$this->config->current['BASE'],
81 array("cn","objectClass","FAIdebianSection"));
83 foreach($res as $attr){
84 $cn = $attr['cn'][0];
86 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
88 if(in_array('FAIpackageList',$attr['objectClass'])){
89 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
90 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
91 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
92 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
93 }
94 if(in_array('FAItemplate',$attr['objectClass'])){
95 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
96 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
97 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
98 }
99 if(in_array('FAIvariable',$attr['objectClass'])){
100 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
101 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
102 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
103 }
104 if(in_array('FAIscript',$attr['objectClass'])){
105 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
106 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
107 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
108 }
109 if(in_array('FAIhook',$attr['objectClass'])){
110 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
111 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
112 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
113 }
114 if(in_array('FAIpartitionTable',$attr['objectClass'])){
115 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
116 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
117 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
118 }
119 if(in_array('FAIprofile',$attr['objectClass'])){
120 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
121 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
122 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
123 }
124 }
125 if(is_array($this->FAIclasses)){
126 natcasesort($this->FAIclasses);
127 }
129 if(isset($tmp2)){
130 $this->FAIclassInfo = $tmp2;
131 } else {
132 $this->FAIclassInfo = array();
133 }
135 /* Build up an array like this one :
136 [$url]['SERVER'] = 'srv1-002';
137 [$url]['RELEASE']['siga/rc9.0.2']
138 ['SECTIONS'][0] "main";
139 ['SECTIONS'][1] "non-free";
140 [$url]['RELEASE']['siga/rc9.0.2']
141 ['PACKAGES'][0] "pkg1";
142 ['PACKAGES'][1] "postfix";
143 */
145 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
146 $test = array();
147 while($attr = $ldap->fetch()){
148 if(isset($attr['FAIrepository'])){
150 unset($attr['FAIrepository']['count']);
152 foreach($attr['FAIrepository'] as $rep){
153 $tmp = split("\|",$rep);
155 if(count($tmp)==4){
156 $sections = split(",",$tmp[3]);
157 $release = $tmp[2];
158 $server = $tmp[1];
159 $url = $tmp[0];
161 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
163 /* Result will be cached
164 */
165 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
166 $test[$url]['SERVER'] = $server;
168 /* auto gets all releases/classes
169 */
170 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
171 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
172 }
173 }
174 }
175 }
177 /* Add possible elements from hook */
178 $lines= $this->GetHookElements();
179 foreach ($lines as $hline){
180 $entries= split(";", $hline);
181 if (isset($entries[1]) && !isset($test[$entries[1]])){
182 $test[$entries[1]]['RELEASE']= array();
184 /* Split releases */
185 if (isset($entries[2])){
186 $releases= split(",", $entries[2]);
188 foreach ($releases as $release){
189 $rname= preg_replace('/:.*$/', '', $release);
190 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
191 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
192 $test[$entries[1]]['RELEASE'][$rname]= array();
193 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
194 foreach ($classes as $class){
195 if ($class != ""){
196 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
197 }
198 }
199 }
200 }
201 }
202 }
204 $this->FAIServRepConfig= $test;
206 /* Get arrays */
207 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
208 if (isset($this->attrs["$val"]["count"])){
209 for ($i= 0; $i<$this->attrs["count"]; $i++){
210 if (isset($this->attrs["$val"][$i])){
211 array_push($this->$val, $this->attrs["$val"][$i]);
212 }
213 }
214 }
215 sort ($this->$val);
216 $this->$val= array_unique($this->$val);
217 }
219 /* Parse Kernel Parameters to decide what boot mode is enabled */
220 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
221 $this->bootmode= "G";
222 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
223 $this->bootmode= "D";
224 } elseif ($this->gotoKernelParameters == "") {
225 $this->bootmode= "G";
226 } else {
227 $this->bootmode= "T";
228 }
229 if (preg_match("/ o /", $this->gotoKernelParameters)){
230 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
231 } else {
232 $this->customParameters= "";
233 }
235 /* Prepare Shares */
236 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
237 unset($this->attrs['gotoShare']['count']);
238 foreach($this->attrs['gotoShare'] as $share){
239 $tmp = $tmp2 = array();
240 $tmp = split("\|",$share);
241 $tmp2['server'] =$tmp[0];
242 $tmp2['name'] =$tmp[1];
243 $tmp2['mountPoint'] =$tmp[2];
244 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
245 }
246 }
248 $this->gotoShareSelections= $config->getShareList(true);
249 $this->gotoAvailableShares= $config->getShareList(false);
250 $tmp2 = array();
252 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
253 $tmp = array();
254 $tmp = split(" ",$this->FAIclass);
255 $tmp2 =array();
257 foreach($tmp as $class){
258 if( ":" == $class[0] ) {
259 $this->FAIrelease = substr( $class, 1 );
260 }
261 else
262 $tmp2[$class] = $class;
263 }
264 $this->FAIclass = $tmp2;
265 }
267 if(!is_array($this->FAIclass)){
268 $this->FAIclass =array();
269 }
271 $this->orig_dn= $this->dn;
273 /* Handle inheritance value "default" */
274 $this->gotoBootKernels= array();
277 /* Load hardware list */
278 $ldap= $this->config->get_ldap_link();
279 $ldap->cd($this->config->current['BASE']);
280 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
281 if ($ldap->count() == 1){
282 $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
283 $attrs= $ldap->fetch();
285 foreach ($map as $name){
286 if (!isset($attrs[$name][0])){
287 continue;
288 }
290 switch ($name){
291 case 'gotoLdapServer':
292 $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
293 break;
295 case 'gotoBootKernel':
296 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
297 break;
299 case 'FAIclass':
300 $str = split(":",$attrs[$name][0]);
301 $this->InheritedFAIclass = split("\ ",trim($str[0]));
302 $this->InheritedFAIrelease = trim($str[1]);
303 break;
305 case 'FAIdebianMirror':
306 $this->InheritedFAIdebianMirror = $attrs[$name][0];
307 break;
308 }
309 }
310 }
312 /* Get list of boot kernels */
313 if (isset($this->config->data['TABS'])){
314 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
316 if (!check_command($command)){
317 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
318 get_class($this));
319 } else {
321 $first = false;
322 $fh= popen($command, "r");
323 while (!feof($fh)) {
324 $buffer= trim(fgets($fh, 256));
326 if(!empty($buffer)){
328 $name=$value = $buffer;
329 if(preg_match("/:/",$buffer)){
330 $name = preg_replace("/:.*$/","",$buffer);
331 $value= preg_replace("/^.*:/","",$buffer);
332 $this->gotoBootKernels[$name]= $name.":".$value;
333 }else{
334 $this->gotoBootKernels[$name]= $value;
335 }
336 if($this->gotoBootKernel =="" ){
337 $this->gotoBootKernel = $name;
338 }
340 }
341 }
342 pclose($fh);
343 }
344 }
346 /* Turn to default, if we've nothing to inherit */
347 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
348 $this->gotoBootKernel= "default";
349 }
351 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
352 $this->FAIdebianMirror = "inherited";
353 }
354 }
357 /* This class is called by the contrucktor ONLY.
358 * It return the available classes for each
359 * Server / Release combination ...
360 * (Release specifies which classes are available)
361 */
362 function getAvailableClassesForThisRelease($release)
363 {
364 /* There could be more than one server providing this release,
365 so use cached result if available
366 */
367 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
368 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
369 }
371 /* Walk through cache and get out what we need.
372 *
373 * Function od : "$this->generateDNSyn($release)"
374 * It returns an array like this one :
375 * array("ou=packges,ou=rc0.9.2,ou=siga,",
376 * "ou=scripts.. "
377 * ...);
378 * This helps us to select the correct classes for each release.
379 * It prevents errors like: 'siga' is selected as release, but all classes
380 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
381 */
382 $tmp2 = $this->generateDNSyn($release) ;
383 $test2 = array();
384 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
385 foreach($tmp2 as $dns){
386 if(preg_match("/".$dns."/",$attr['dn'])){
387 $test2[$attr['cn'][0]] = $attr['cn'][0];
388 }
389 }
390 }
391 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
392 return($test2);
393 }
396 /* Create array to display available classes/profiles in a selectbox
397 * This function only displays the available classes.
398 * If a class is available is defined by these facts :
399 * 1. Is this class available for the selected release ?
400 * - if it is available, check if the release is available for the selected server
401 * (done by $this->getFAIreleases())
402 * 2. Is this class currently not assigned to $this->FAIclass
403 */
404 function selectFriendlyClasses(){
405 $tmp=array();
407 if($this->FAIdebianMirror == "inherited") return($tmp);
409 /* check if the current release exists,
410 else select the first one ..
411 */
412 $tmp2 = $this->getFAIreleases();
413 if(!in_array($this->FAIrelease, $tmp2)){
414 $this->FAIrelease = key($tmp2);
415 }
417 /* Get all Packages for this server/release combination
418 */
419 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
420 $pkgs = array();
421 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
422 }else{
423 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
424 }
426 /* Check each and every single class name
427 */
428 foreach($pkgs as $pkg){
430 /* Class already assigned to the classes list ?
431 * If not ... go on
432 */
433 if(!in_array($pkg,$this->FAIclass)){
435 /* Create the displayed list entry value
436 HKLMOP [-Pl P V T-] or something like that
437 */
438 $str = "";
439 foreach($this->FAIclassInfo[$pkg] as $entry){
440 if(isset($entry['kzl'])){
441 $str .= $entry['kzl']." ";
442 }
443 }
445 /* Append class if everyting was fine
446 */
447 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
448 }
449 }
450 /* Just sort and return new classes list ...
451 ( possibly we should cache the result ... )
452 */
453 natcasesort ($tmp);
454 return($tmp);
455 }
457 function check()
458 {
459 $messages = array();
461 /* Call common method to give check the hook */
462 $messages= plugin::check();
464 /* If there are packages selected, but no mirror show error */
465 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
466 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
467 }
469 return($messages);
470 }
472 function execute()
473 {
475 /* Call parent execute */
476 plugin::execute();
478 /* Do we need to flip is_account state? */
479 if (isset($_POST['modify_state'])){
480 $this->is_account= !$this->is_account;
481 }
483 /* Do we represent a valid terminal? */
484 if (!$this->is_account && $this->parent == NULL){
485 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
486 _("This 'dn' has no terminal features.")."</b>";
487 return ($display);
488 }
490 /* Add module */
491 if (isset ($_POST['add_module'])){
492 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
493 $this->add_list ($this->gotoModules, $_POST['module']);
494 }
495 }
497 /* Delete module */
498 if (isset ($_POST['delete_module'])){
499 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
500 $this->del_list ($this->gotoModules, $_POST['modules_list']);
501 }
502 }
504 /* FAI class management */
505 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
506 $found = 0 ;
508 /* If this new class/profile will attach a second partition table
509 * to our list of classes, abort and show a message.
510 */
511 foreach($this->FAIclass as $name){
512 if(isset($this->FAIclassInfo[$name])){
513 foreach($this->FAIclassInfo[$name] as $atr){
514 if(isset($atr['obj'])){
515 if($atr['obj'] == "FAIpartitionTable"){
516 $found ++ ;
517 }
518 }
519 }
520 }
521 }
523 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
524 print_red(_("There is already a profile in your selection that contain partition table configurations."));
525 }else{
526 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
527 }
528 }
530 $sort = false;
531 foreach($_POST as $name => $val){
533 $sort_type = false;
534 if((preg_match("/sort_up/",$name))&&(!$sort)){
535 $sort_type = "sort_up_";
536 }
537 if((preg_match("/sort_down/",$name))&&(!$sort)){
538 $sort_type = "sort_down_";
539 }
541 if(($sort_type)&&(!$sort)){
542 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
543 $sort = true;
545 $last = -1;
546 $change_down = -1;
548 /* Create array with numeric index */
549 $tmp = array();
550 foreach($this->FAIclass as $class){
551 $tmp [] = $class;
552 }
554 /* Walk trough array */
555 foreach($tmp as $key => $faiName){
556 if($faiName == $value){
557 if($sort_type == "sort_up_"){
558 if($last != -1){
559 $change_down= $last;
560 }
561 }else{
562 if(isset($tmp[$key+1])){
563 $change_down = $key;
564 }
565 }
566 }
567 $last = $key;
568 }
570 $tmp2 = array();
571 $skip = false;
573 foreach($tmp as $ky => $vl){
575 if($ky == $change_down){
576 $skip = $vl;
577 }else{
578 $tmp2[$vl] = $vl;
579 }
580 if(($skip != false)&&($ky != $change_down)){
581 $tmp2[$skip] = $skip;
582 $skip =false;
583 }
584 }
585 $this->FAIclass = $tmp2;
586 }
588 if(preg_match("/fai_remove/i",$name)){
589 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
590 unset($this->FAIclass[$value]);
591 }
592 }
594 /* Show main page */
595 $smarty= get_smarty();
596 $smarty->assign("SelectBoxLdapServer","");
598 /* In this section server shares will be defined
599 * A user can select one of the given shares and a mount point
600 * and attach this combination to his setup.
601 */
602 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
603 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
605 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
606 * This entry will be, a combination of mountPoint and sharedefinitions
607 */
608 if(isset($_POST['gotoShareAdd'])){
609 /* We assign a share to this user, if we don't know where to mount the share */
610 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
611 print_red(_("You must specify a valid mount point."));
612 }else{
613 if(count($this->gotoAvailableShares)){
614 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
615 $s_mount = $_POST['gotoShareMountPoint'];
616 /* Preparing the new assignment */
617 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
618 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
619 }
620 }
621 }
623 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
624 * If there is no defined share selected, we will abort the deletion without any message
625 */
626 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
627 unset($this->gotoShares[$_POST['gotoShare']]);
628 }
630 $smarty->assign("gotoShares",$this->printOutAssignedShares());
631 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
632 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
633 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
635 /* Arrays */
636 $tmp = $this->goLdapServerList;
638 /* Create divSelectBox for ldap server selection
639 */
640 $SelectBoxLdapServer = new divSelectBox("LdapServer");
641 $SelectBoxLdapServer->SetHeight(130);
643 /* Set first entry as selected, if $this->gotoLdapServer is empty
644 * or given entry is no longer available ...
645 */
646 $found = false;
647 foreach($tmp as $server){
648 if($this->gotoLdapServer==$server){
649 $found = true;
650 }
651 }
653 /* Add Entries
654 */
655 foreach($tmp as $key => $server){
656 $use ="";
657 if(($this->gotoLdapServer == $server) || ($found == false)) {
658 $found = true;
659 $use = " checked ";
660 };
662 $display = $server;
664 $SelectBoxLdapServer->AddEntry(
665 array(
666 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
667 "attach"=>"style='border-left:0px;'"),
668 array("string"=>$display)
669 ));
670 }
672 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
674 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
675 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
676 $smarty->assign("$val", $this->$val);
677 }
679 /* Values */
680 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
681 $smarty->assign($val, $this->$val);
682 $smarty->assign($val."ACL", chkacl($this->acl, $val));
683 }
685 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
686 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
687 $smarty->assign("FAIreleases",$this->getFAIreleases());
688 $smarty->assign("FAIrelease",$this->FAIrelease);
689 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
690 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
691 $smarty->assign("FAIclassKeys",$this->FAIclass);
692 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
694 $div = new divSelectBox("WSFAIscriptClasses");
695 $div -> SetHeight("110");
696 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
697 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
698 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
699 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
701 $i = 1;
703 if($this->FAIdebianMirror == "inherited"){
704 $tmp = $this->InheritedFAIclass;
705 }else{
706 $tmp = $this->FAIclass;
707 }
709 foreach($tmp as $class){
711 $marker = "";
712 if(in_array_ics($class,$this->unresolved_classes)){
713 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
714 }
716 if($this->FAIdebianMirror == "inherited"){
717 $str = "";
718 }else{
719 if($i==1){
720 $str = $str_empty.$str_down.$str_remove;
721 }elseif($i == count($this->FAIclass)){
722 $str = $str_up.$str_empty.$str_remove;
723 }else{
724 $str = $str_up.$str_down.$str_remove;
725 }
726 }
727 $i ++ ;
729 $div->AddEntry(array(
730 array("string"=>$class.$marker),
731 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
732 ));
733 }
735 $smarty->assign("FAIScriptlist",$div->DrawList());
737 /* Radio button group */
738 if (preg_match("/G/", $this->bootmode)) {
739 $smarty->assign("graphicalbootup", "checked");
740 } else {
741 $smarty->assign("graphicalbootup", "");
742 }
743 if (preg_match("/T/", $this->bootmode)) {
744 $smarty->assign("textbootup", "checked");
745 } else {
746 $smarty->assign("textbootup", "");
747 }
748 if (preg_match("/D/", $this->bootmode)) {
749 $smarty->assign("debugbootup", "checked");
750 } else {
751 $smarty->assign("debugbootup", "");
752 }
754 /* ACL's */
755 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
756 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
757 }
759 /* Show main page */
760 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
761 }
763 function remove_from_parent()
764 {
765 $this->handle_post_events("remove");
766 }
768 function generateDNSyn($release)
769 {
770 $str = "";
771 $tmp = split("\/",$release);
772 $tmp = array_reverse($tmp);
774 $base = ",ou=fai,";
776 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
778 foreach($tmp as $departmentname){
780 $str .= ",ou=".$departmentname;
781 }
782 $ret = array();
783 foreach($arr as $ar){
784 $ret[] = ",ou=".$ar.$str.$base;
785 }
786 return($ret);
787 }
789 function getFAIdebianMirrors()
790 {
791 $ret = array();
792 $ret['inherited']="["._("inherited")."]";
793 $ret['auto']=_("automatic");
794 $secs = array();
796 /* Walk through all available servers
797 and check if they support the currently selected classes
798 if not, dont't add them to our list
799 */
800 foreach($this->FAIServRepConfig as $mirror => $rest){
802 $use = false;
804 if(count($this->FAIclass) == 0){
805 $use = true;
806 }else{
807 $tmp = $this->getFAIreleases();
808 foreach($tmp as $release){
809 if(isset($rest['RELEASE'][$release])){
810 $use =true;
811 }
812 }
813 }
815 /* If current server, doesn't support this class
816 remove it from list
817 */
818 if($use){
819 $ret[$mirror] = $mirror;
820 }
821 }
822 return($ret);
823 }
825 function getFAIreleases()
826 {
827 $ret = array();
829 if($this->FAIdebianMirror == "inherited") return(array());
831 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
832 $this->FAIdebianMirror = "auto";
833 }
835 $errorClasses = array();
836 if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
837 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
838 $use = true;
840 if(!count($this->FAIclass) == 0){
841 foreach($this->FAIclass as $class){
842 if(!in_array($class, $sections['PACKAGES'])){
843 $use = false;
844 $errorClasses[$class] = $class;
845 }else{
846 if(isset($errorClasses[$class])){
847 unset($errorClasses[$class]);
848 }
849 }
850 }
851 }
852 if($use){
853 $ret[$release]=$release;
854 }
855 }
856 }
857 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
859 $eClasses = " ";
860 foreach($errorClasses as $class){
861 $eClasses .= $class." ";
862 }
864 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));
865 $this->FAIdebianMirror = "auto";
866 return($this->getFAIreleases());
867 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
869 $eClasses = " ";
870 foreach($errorClasses as $class){
871 $eClasses .= $class." ";
872 }
874 $this->unresolved_classes = $errorClasses;
875 $this->FAIdebianMirror = "auto";
876 //$this->FAIclass= array();
877 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));
878 }
879 return($ret);
880 }
882 /* Save data to object */
883 function save_object()
884 {
885 plugin::save_object();
887 /* Save group radio buttons */
888 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
889 $this->bootmode= $_POST["bootmode"];
890 }
892 /* Save kernel parameters */
893 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
894 $this->customParameters= $_POST["customParameters"];
895 }
897 }
900 /* Save to LDAP */
901 function save()
902 {
904 /* Depending on the baseobject (Ogroup / WS) we
905 * use another set of objectClasses
906 * In case of WS itself, we use "array("GOhard", "FAIobject");"
907 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
908 */
909 if(isset($this->parent->by_object['ogroup'])){
910 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
911 }elseif(isset($this->parent->by_object['workgeneric'])){
912 $this->objectclasses = array("GOhard", "FAIobject");
913 }elseif(isset($this->parent->by_object['servgeneric'])){
914 $this->objectclasses = array("GOhard", "FAIobject");
915 }else{
916 print "Object Type Configuration : unknown";
917 exit();
918 }
920 /* Find proper terminal path for tftp configuration
921 FIXME: This is suboptimal when the default has changed to
922 another location! */
923 if (($this->gotoTerminalPath == "default")){
924 $ldap= $this->config->get_ldap_link();
926 /* Strip relevant part from dn, keep trailing ',' */
927 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
928 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
930 /* Walk from top to base and try to load default values for
931 'gotoTerminalPath'. Abort when an entry is found. */
932 while (TRUE){
933 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
935 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
936 $this->config->current['BASE'], array('gotoTerminalPath'));
937 $attrs= $ldap->fetch();
938 if (isset($attrs['gotoTerminalPath'])){
939 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
940 break;
941 }
943 /* Nothing left? */
944 if ($tmp == ""){
945 break;
946 }
947 }
948 }
950 /* Add semi automatic values */
951 // FIXME: LDAP Server may not be set here...
952 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
954 switch ($this->bootmode){
955 case "D":
956 $this->gotoKernelParameters.= " debug";
957 break;
958 case "G":
959 $this->gotoKernelParameters.= " splash=silent";
960 break;
961 }
962 if ($this->customParameters != ""){
963 $this->gotoKernelParameters.= " o ".$this->customParameters;
964 }
966 plugin::save();
968 unset( $this->attrs['FAIrelease'] );
970 $str = "";
972 if($this->FAIdebianMirror == "inherited"){
974 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
976 }else{
978 foreach($this->FAIclass as $class){
979 $str .= $class." ";
980 }
981 $str .= ":" . $this->FAIrelease;
982 $this->attrs['FAIclass']= "";
983 $this->attrs['FAIclass']= trim($str);
985 if(empty($this->attrs['FAIclass'])){
986 $this->attrs['FAIclass'] = array();
987 }
988 }
990 /* Add missing arrays */
991 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
992 if (isset ($this->$val) && count ($this->$val) != 0){
994 $this->attrs["$val"]= array_unique($this->$val);
995 }
996 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
997 }
999 /* Strip out 'default' values */
1000 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1001 $this->attrs['gotoLdapServer']= array();
1002 }
1004 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1005 $this->attrs['gotoBootKernel']= array();
1006 }
1008 /* if mirror == none stop saving this attribute */
1009 if($this->FAIdebianMirror == "none"){
1010 $this->FAIdebianMirror = "";
1011 }
1013 /* Get FAIstate from object, the generic tab could have changed it during execute */
1014 $ldap= $this->config->get_ldap_link();
1015 $ldap->cd($this->dn);
1016 $ldap->cat($this->dn,array("FAIstate"));
1017 $checkFAIstate = $ldap->fetch();
1019 /* Remove FAI objects if no FAI class is selected */
1020 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1021 $this->attrs['FAIclass'] = array();
1022 $this->attrs['FAIdebianMirror'] = array();
1023 }
1025 /* prepare share settings */
1026 $tmp = array();
1027 foreach($this->gotoShares as $name => $settings){
1028 $tmp2= split("\|",$name);
1029 $name = $tmp2[0];
1030 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1031 }
1032 $this->attrs['gotoShare']=$tmp;
1034 $this->cleanup();
1035 $ldap->modify ($this->attrs);
1037 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1038 $this->handle_post_events("modify");
1039 }
1041 /* Add value to array, check if unique */
1042 function add_list (&$array, $value)
1043 {
1044 if ($value != ""){
1045 $array[]= $value;
1046 sort($array);
1047 array_unique ($array);
1048 }
1049 }
1052 /* Delete value to array, check if unique */
1053 function del_list (&$array, $list)
1054 {
1055 $tmp= array();
1056 foreach ($array as $mod){
1057 if (!in_array($mod, $list)){
1058 $tmp[]= $mod;
1059 }
1060 }
1061 $array= $tmp;
1062 }
1064 /* Generate ListBox frindly output for the defined shares
1065 * Possibly Add or remove an attribute here,
1066 */
1067 function printOutAssignedShares()
1068 {
1069 $a_return = array();
1070 if(is_array($this->gotoShares)){
1071 foreach($this->gotoShares as $share){
1072 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1073 }
1074 }
1075 return($a_return);
1076 }
1079 function GetHookElements()
1080 {
1081 $ret = array();
1082 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1083 if(!empty($cmd)){
1084 $res = shell_exec($cmd);
1085 $res2 = trim($res);
1086 if((!$res)){
1087 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1088 }elseif(empty($res2)){
1089 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1090 }else{
1091 $tmp = split("\n",$res);
1092 foreach($tmp as $line){
1093 if(empty($line)) continue;
1094 $ret[]= $line;
1095 }
1096 }
1097 }
1098 return($ret);
1099 }
1101 }
1103 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1104 ?>