1fcae8be32a59edb37ccba7f969068dbbd69cf18
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";
13 var $gotoKernelParameters = "";
14 var $gotoLdapServer = "default";
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";
45 /* FAI class selection */
46 var $InheritedFAIclass = array();
47 var $InheritedFAIrelease = "";
48 var $InheritedFAIdebianMirror = "auto";
50 /* Contains all possible server/release/class settings */
51 var $FAIServRepConfig = array();
53 function workstartup ($config, $dn= NULL)
54 {
55 plugin::plugin ($config, $dn);
57 /* Creating a list of valid Mirrors
58 * none will not be saved to ldap.
59 */
60 $ldap = $this->config->get_ldap_link();
61 $ldap->cd($this->config->current['BASE']);
63 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
64 $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
65 }
67 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
68 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
70 /* Search all FAI objects */
71 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
72 /* Sort all entries, and attach elementtype.
73 * To be able to show the types in the listbox.
74 */
75 while($attr = $ldap->fetch()){
76 $cn = $attr['cn'][0];
78 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
80 if(in_array('FAIpackageList',$attr['objectClass'])){
81 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
82 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
83 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
84 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
85 }
86 if(in_array('FAItemplate',$attr['objectClass'])){
87 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
88 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
89 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
90 }
91 if(in_array('FAIvariable',$attr['objectClass'])){
92 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
93 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
94 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
95 }
96 if(in_array('FAIscript',$attr['objectClass'])){
97 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
98 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
99 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
100 }
101 if(in_array('FAIhook',$attr['objectClass'])){
102 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
103 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
104 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
105 }
106 if(in_array('FAIpartitionTable',$attr['objectClass'])){
107 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
108 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
109 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
110 }
111 if(in_array('FAIprofile',$attr['objectClass'])){
112 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
113 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
114 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
115 }
116 }
117 if(is_array($this->FAIclasses)){
118 natcasesort($this->FAIclasses);
119 }
121 if(isset($tmp2)){
122 $this->FAIclassInfo = $tmp2;
123 } else {
124 $this->FAIclassInfo = array();
125 }
127 /* Build up an array like this one :
128 [$url]['SERVER'] = 'srv1-002';
129 [$url]['RELEASE']['siga/rc9.0.2']
130 ['SECTIONS'][0] "main";
131 ['SECTIONS'][1] "non-free";
132 [$url]['RELEASE']['siga/rc9.0.2']
133 ['PACKAGES'][0] "pkg1";
134 ['PACKAGES'][1] "postfix";
135 */
137 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
138 $test = array();
139 while($attr = $ldap->fetch()){
140 if(isset($attr['FAIrepository'])){
142 unset($attr['FAIrepository']['count']);
144 foreach($attr['FAIrepository'] as $rep){
145 $tmp = split("\|",$rep);
147 if(count($tmp)==4){
148 $sections = split(",",$tmp[3]);
149 $release = $tmp[2];
150 $server = $tmp[1];
151 $url = $tmp[0];
153 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
155 /* Result will be cached
156 */
157 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
158 $test[$url]['SERVER'] = $server;
160 /* auto gets all releases/classes
161 */
162 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
163 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
164 }
165 }
166 }
167 }
169 /* Add possible elements from hook */
170 $lines= $this->GetHookElements();
171 foreach ($lines as $hline){
172 $entries= split(";", $hline);
173 if (isset($entries[1]) && !isset($test[$entries[1]])){
174 $test[$entries[1]]['RELEASE']= array();
176 /* Split releases */
177 if (isset($entries[2])){
178 $releases= split(",", $entries[2]);
180 foreach ($releases as $release){
181 $rname= preg_replace('/:.*$/', '', $release);
182 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
183 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
184 $test[$entries[1]]['RELEASE'][$rname]= array();
185 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
186 foreach ($classes as $class){
187 if ($class != ""){
188 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
189 }
190 }
191 }
192 }
193 }
194 }
196 $this->FAIServRepConfig= $test;
198 /* Get arrays */
199 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
200 if (isset($this->attrs["$val"]["count"])){
201 for ($i= 0; $i<$this->attrs["count"]; $i++){
202 if (isset($this->attrs["$val"][$i])){
203 array_push($this->$val, $this->attrs["$val"][$i]);
204 }
205 }
206 }
207 sort ($this->$val);
208 $this->$val= array_unique($this->$val);
209 }
211 /* Parse Kernel Parameters to decide what boot mode is enabled */
212 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
213 $this->bootmode= "G";
214 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
215 $this->bootmode= "D";
216 } elseif ($this->gotoKernelParameters == "") {
217 $this->bootmode= "G";
218 } else {
219 $this->bootmode= "T";
220 }
221 if (preg_match("/ o /", $this->gotoKernelParameters)){
222 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
223 } else {
224 $this->customParameters= "";
225 }
227 /* Prepare Shares */
228 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
229 unset($this->attrs['gotoShare']['count']);
230 foreach($this->attrs['gotoShare'] as $share){
231 $tmp = $tmp2 = array();
232 $tmp = split("\|",$share);
233 $tmp2['server'] =$tmp[0];
234 $tmp2['name'] =$tmp[1];
235 $tmp2['mountPoint'] =$tmp[2];
236 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
237 }
238 }
240 $this->gotoShareSelections= $config->getShareList(true);
241 $this->gotoAvailableShares= $config->getShareList(false);
242 $tmp2 = array();
244 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
245 $tmp = array();
246 $tmp = split(" ",$this->FAIclass);
247 $tmp2 =array();
249 foreach($tmp as $class){
250 if( ":" == $class[0] ) {
251 $this->FAIrelease = substr( $class, 1 );
252 }
253 else
254 $tmp2[$class] = $class;
255 }
256 $this->FAIclass = $tmp2;
257 }
259 if(!is_array($this->FAIclass)){
260 $this->FAIclass =array();
261 }
263 $this->orig_dn= $this->dn;
265 /* Handle inheritance value "default" */
266 $this->gotoBootKernels= array("%default%" => '['._("inherited").']');
269 /* Load hardware list */
270 $ldap= $this->config->get_ldap_link();
271 $ldap->cd($this->config->current['BASE']);
272 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
273 if ($ldap->count() == 1){
274 $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
275 $attrs= $ldap->fetch();
277 foreach ($map as $name){
278 if (!isset($attrs[$name][0])){
279 continue;
280 }
282 switch ($name){
283 case 'gotoLdapServer':
284 $this->goLdapServerList= array_merge(array('default' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
285 break;
287 case 'gotoBootKernel':
288 $this->gotoBootKernels['%default%']= _("inherited").' ['.$attrs[$name][0].']' ;
289 break;
291 case 'FAIclass':
292 $str = split(":",$attrs[$name][0]);
293 $this->InheritedFAIclass = split("\ ",trim($str[0]));
294 $this->InheritedFAIrelease = trim($str[1]);
295 break;
297 case 'FAIdebianMirror':
298 $this->InheritedFAIdebianMirror = $attrs[$name][0];
299 break;
300 }
301 }
302 }
304 /* Get list of boot kernels */
305 if (isset($this->config->data['TABS'])){
306 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
308 if (!check_command($command)){
309 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
310 get_class($this));
311 } else {
313 $fh= popen($command, "r");
314 while (!feof($fh)) {
315 $buffer= trim(fgets($fh, 256));
316 if ($buffer != ""){
317 $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
318 }
319 }
320 pclose($fh);
321 }
322 }
324 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
325 $this->FAIdebianMirror = "inherited";
326 }
327 }
330 /* This class is called by the contrucktor ONLY.
331 * It return the available classes for each
332 * Server / Release combination ...
333 * (Release specifies which classes are available)
334 */
335 function getAvailableClassesForThisRelease($release)
336 {
337 /* There could be more than one server providing this release,
338 so use cached result if available
339 */
340 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
341 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
342 }
344 /* Create cache with all classes
345 */
346 if((!isset($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
347 (!is_array($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
348 (count($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES']) ==0 )){
350 /* Get ldap connection */
351 $ldap = $this->config->get_ldap_link();
352 $ldap->cd($this->config->current['BASE']);
354 /* Get possible classes ...
355 This would be faste with some kind of caching ...
356 */
357 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn"),true);
358 /* Sort all entries, and attach elementtype.
359 * To be able to show the types in the listbox.
360 */
361 while($attr = $ldap->fetch()){
362 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
363 }
364 }
366 /* Walk through cache and get out what we need.
367 *
368 * Function od : "$this->generateDNSyn($release)"
369 * It returns an array like this one :
370 * array("ou=packges,ou=rc0.9.2,ou=siga,",
371 * "ou=scripts.. "
372 * ...);
373 * This helps us to select the correct classes for each release.
374 * It prevents errors like: 'siga' is selected as release, but all classes
375 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
376 */
377 $tmp2 = $this->generateDNSyn($release) ;
378 $test2 = array();
379 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
380 foreach($tmp2 as $dns){
381 if(preg_match("/".$dns."/",$attr['dn'])){
382 $test2[$attr['cn'][0]] = $attr['cn'][0];
383 }
384 }
385 }
386 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
387 return($test2);
388 }
391 /* Create array to display available classes/profiles in a selectbox
392 * This function only displays the available classes.
393 * If a class is available is defined by these facts :
394 * 1. Is this class available for the selected release ?
395 * - if it is available, check if the release is available for the selected server
396 * (done by $this->getFAIreleases())
397 * 2. Is this class currently not assigned to $this->FAIclass
398 */
399 function selectFriendlyClasses(){
400 $tmp=array();
402 if($this->FAIdebianMirror == "inherited") return($tmp);
404 /* check if the current release exists,
405 else select the first one ..
406 */
407 $tmp2 = $this->getFAIreleases();
408 if(!in_array($this->FAIrelease, $tmp2)){
409 $this->FAIrelease = key($tmp2);
410 }
412 /* Get all Packages for this server/release combination
413 */
414 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
415 $pkgs = array();
416 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
417 }else{
418 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
419 }
421 /* Check each and every single class name
422 */
423 foreach($pkgs as $pkg){
425 /* Class already assigned to the classes list ?
426 * If not ... go on
427 */
428 if(!in_array($pkg,$this->FAIclass)){
430 /* Create the displayed list entry value
431 HKLMOP [-Pl P V T-] or something like that
432 */
433 $str = "";
434 foreach($this->FAIclassInfo[$pkg] as $entry){
435 if(isset($entry['kzl'])){
436 $str .= $entry['kzl']." ";
437 }
438 }
440 /* Append class if everyting was fine
441 */
442 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
443 }
444 }
445 /* Just sort and return new classes list ...
446 ( possibly we should cache the result ... )
447 */
448 natcasesort ($tmp);
449 return($tmp);
450 }
452 function check()
453 {
454 $messages = array();
456 /* Call common method to give check the hook */
457 $messages= plugin::check();
459 /* If there are packages selected, but no mirror show error */
460 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
461 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
462 }
464 return($messages);
465 }
467 function execute()
468 {
470 /* Call parent execute */
471 plugin::execute();
473 /* Do we need to flip is_account state? */
474 if (isset($_POST['modify_state'])){
475 $this->is_account= !$this->is_account;
476 }
478 /* Do we represent a valid terminal? */
479 if (!$this->is_account && $this->parent == NULL){
480 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
481 _("This 'dn' has no terminal features.")."</b>";
482 return ($display);
483 }
485 /* Add module */
486 if (isset ($_POST['add_module'])){
487 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
488 $this->add_list ($this->gotoModules, $_POST['module']);
489 }
490 }
492 /* Delete module */
493 if (isset ($_POST['delete_module'])){
494 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
495 $this->del_list ($this->gotoModules, $_POST['modules_list']);
496 }
497 }
499 /* FAI class management */
500 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
501 $found = 0 ;
503 /* If this new class/profile will attach a second partition table
504 * to our list of classes, abort and show a message.
505 */
506 foreach($this->FAIclass as $name){
507 if(isset($this->FAIclassInfo[$name])){
508 foreach($this->FAIclassInfo[$name] as $atr){
509 if(isset($atr['obj'])){
510 if($atr['obj'] == "FAIpartitionTable"){
511 $found ++ ;
512 }
513 }
514 }
515 }
516 }
518 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
519 print_red(_("There is already a profile in your selection that contain partition table configurations."));
520 }else{
521 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
522 }
523 }
525 $sort = false;
526 foreach($_POST as $name => $val){
528 $sort_type = false;
529 if((preg_match("/sort_up/",$name))&&(!$sort)){
530 $sort_type = "sort_up_";
531 }
532 if((preg_match("/sort_down/",$name))&&(!$sort)){
533 $sort_type = "sort_down_";
534 }
536 if(($sort_type)&&(!$sort)){
537 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
538 $sort = true;
540 $last = -1;
541 $change_down = -1;
543 /* Create array with numeric index */
544 $tmp = array();
545 foreach($this->FAIclass as $class){
546 $tmp [] = $class;
547 }
549 /* Walk trough array */
550 foreach($tmp as $key => $faiName){
551 if($faiName == $value){
552 if($sort_type == "sort_up_"){
553 if($last != -1){
554 $change_down= $last;
555 }
556 }else{
557 if(isset($tmp[$key+1])){
558 $change_down = $key;
559 }
560 }
561 }
562 $last = $key;
563 }
565 $tmp2 = array();
566 $skip = false;
568 foreach($tmp as $ky => $vl){
570 if($ky == $change_down){
571 $skip = $vl;
572 }else{
573 $tmp2[$vl] = $vl;
574 }
575 if(($skip != false)&&($ky != $change_down)){
576 $tmp2[$skip] = $skip;
577 $skip =false;
578 }
579 }
580 $this->FAIclass = $tmp2;
581 }
583 if(preg_match("/fai_remove/i",$name)){
584 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
585 unset($this->FAIclass[$value]);
586 }
587 }
589 /* Show main page */
590 $smarty= get_smarty();
591 $smarty->assign("SelectBoxLdapServer","");
593 /* In this section server shares will be defined
594 * A user can select one of the given shares and a mount point
595 * and attach this combination to his setup.
596 */
597 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
598 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
600 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
601 * This entry will be, a combination of mountPoint and sharedefinitions
602 */
603 if(isset($_POST['gotoShareAdd'])){
604 /* We assign a share to this user, if we don't know where to mount the share */
605 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
606 print_red(_("You must specify a valid mount point."));
607 }else{
608 if(count($this->gotoAvailableShares)){
609 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
610 $s_mount = $_POST['gotoShareMountPoint'];
611 /* Preparing the new assignment */
612 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
613 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
614 }
615 }
616 }
618 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
619 * If there is no defined share selected, we will abort the deletion without any message
620 */
621 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
622 unset($this->gotoShares[$_POST['gotoShare']]);
623 }
625 $smarty->assign("gotoShares",$this->printOutAssignedShares());
626 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
627 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
628 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
630 /* Arrays */
631 $tmp = $this->goLdapServerList;
633 /* Create divSelectBox for ldap server selection
634 */
635 $SelectBoxLdapServer = new divSelectBox("LdapServer");
636 $SelectBoxLdapServer->SetHeight(130);
638 /* Set first entry as selected, if $this->gotoLdapServer is empty
639 * or given entry is no longer available ...
640 */
641 $found = false;
642 foreach($tmp as $server){
643 if($this->gotoLdapServer==$server){
644 $found = true;
645 }
646 }
648 /* Add Entries
649 */
650 foreach($tmp as $key => $server){
651 $use ="";
652 if(($this->gotoLdapServer == $server) || ($found == false)) {
653 $found = true;
654 $use = " checked ";
655 };
657 $display = $server;
659 $SelectBoxLdapServer->AddEntry(
660 array(
661 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
662 "attach"=>"style='border-left:0px;'"),
663 array("string"=>$display)
664 ));
665 }
667 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
669 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
670 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
671 $smarty->assign("$val", $this->$val);
672 }
674 /* Values */
675 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
676 $smarty->assign($val, $this->$val);
677 $smarty->assign($val."ACL", chkacl($this->acl, $val));
678 }
680 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
681 $smarty->assign("FAIreleases",$this->getFAIreleases());
682 $smarty->assign("FAIrelease",$this->FAIrelease);
683 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
684 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
685 $smarty->assign("FAIclassKeys",$this->FAIclass);
686 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
688 $div = new divSelectBox("WSFAIscriptClasses");
689 $div -> SetHeight("110");
690 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
691 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
692 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
693 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
695 $i = 1;
697 if($this->FAIdebianMirror == "inherited"){
698 $tmp = $this->InheritedFAIclass;
699 }else{
700 $tmp = $this->FAIclass;
701 }
703 foreach($tmp as $class){
705 if($this->FAIdebianMirror == "inherited"){
706 $str = "";
707 }else{
708 if($i==1){
709 $str = $str_empty.$str_down.$str_remove;
710 }elseif($i == count($this->FAIclass)){
711 $str = $str_up.$str_empty.$str_remove;
712 }else{
713 $str = $str_up.$str_down.$str_remove;
714 }
715 }
716 $i ++ ;
718 $div->AddEntry(array(
719 array("string"=>$class),
720 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
721 ));
722 }
724 $smarty->assign("FAIScriptlist",$div->DrawList());
726 /* Radio button group */
727 if (preg_match("/G/", $this->bootmode)) {
728 $smarty->assign("graphicalbootup", "checked");
729 } else {
730 $smarty->assign("graphicalbootup", "");
731 }
732 if (preg_match("/T/", $this->bootmode)) {
733 $smarty->assign("textbootup", "checked");
734 } else {
735 $smarty->assign("textbootup", "");
736 }
737 if (preg_match("/D/", $this->bootmode)) {
738 $smarty->assign("debugbootup", "checked");
739 } else {
740 $smarty->assign("debugbootup", "");
741 }
743 /* ACL's */
744 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
745 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
746 }
748 /* Show main page */
749 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
750 }
752 function remove_from_parent()
753 {
754 $this->handle_post_events("remove");
755 }
757 function generateDNSyn($release)
758 {
759 $str = "";
760 $tmp = split("\/",$release);
761 $tmp = array_reverse($tmp);
763 $base = ",ou=fai,";
765 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
767 foreach($tmp as $departmentname){
769 $str .= ",ou=".$departmentname;
770 }
771 $ret = array();
772 foreach($arr as $ar){
773 $ret[] = ",ou=".$ar.$str.$base;
774 }
775 return($ret);
776 }
778 function getFAIdebianMirrors()
779 {
780 $ret = array();
781 $ret['inherited']="["._("inherited")."]";
782 $ret['auto']=_("automatic");
783 $secs = array();
785 /* Walk through all available servers
786 and check if they support the currently selected classes
787 if not, dont't add them to our list
788 */
789 foreach($this->FAIServRepConfig as $mirror => $rest){
791 $use = false;
793 if(count($this->FAIclass) == 0){
794 $use = true;
795 }else{
796 $tmp = $this->getFAIreleases();
797 foreach($tmp as $release){
798 if(isset($rest['RELEASE'][$release])){
799 $use =true;
800 }
801 }
802 }
804 /* If current server, doesn't support this class
805 remove it from list
806 */
807 if($use){
808 $ret[$mirror] = $mirror;
809 }
810 }
811 return($ret);
812 }
814 function getFAIreleases()
815 {
816 $ret = array();
818 if($this->FAIdebianMirror == "inherited") return(array());
820 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
821 $this->FAIdebianMirror = "auto";
822 }
824 $errorClasses = "";
826 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
827 $use = true;
829 if(!count($this->FAIclass) == 0){
830 foreach($this->FAIclass as $class){
831 if(!in_array($class, $sections['PACKAGES'])){
832 $use = false;
833 $errorClasses[$class] = $class;
834 }else{
835 if(isset($errorClasses[$class])){
836 unset($errorClasses[$class]);
837 }
838 }
839 }
840 }
841 if($use){
842 $ret[$release]=$release;
843 }
844 }
845 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
847 $eClasses = " ";
848 foreach($errorClasses as $class){
849 $eClasses .= $class." ";
850 }
852 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));
853 $this->FAIdebianMirror = "auto";
854 return($this->getFAIreleases());
855 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
857 $eClasses = " ";
858 foreach($errorClasses as $class){
859 $eClasses .= $class." ";
860 }
862 $this->FAIclass= array();
863 print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. !All classes have been removed from this account, press cancel if you don't want this to be saved."),$eClasses));
864 }
865 return($ret);
866 }
868 /* Save data to object */
869 function save_object()
870 {
871 plugin::save_object();
873 /* Save group radio buttons */
874 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
875 $this->bootmode= $_POST["bootmode"];
876 }
878 /* Save kernel parameters */
879 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
880 $this->customParameters= $_POST["customParameters"];
881 }
883 }
886 /* Save to LDAP */
887 function save()
888 {
890 /* Depending on the baseobject (Ogroup / WS) we
891 * use another set of objectClasses
892 * In case of WS itself, we use "array("GOhard", "FAIobject");"
893 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
894 */
895 if(isset($this->parent->by_object['ogroup'])){
896 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
897 }elseif(isset($this->parent->by_object['workgeneric'])){
898 $this->objectclasses = array("GOhard", "FAIobject");
899 }elseif(isset($this->parent->by_object['servgeneric'])){
900 $this->objectclasses = array("GOhard", "FAIobject");
901 }else{
902 print "Object Type Configuration : unknown";
903 exit();
904 }
906 /* Find proper terminal path for tftp configuration
907 FIXME: This is suboptimal when the default has changed to
908 another location! */
909 if (($this->gotoTerminalPath == "default")){
910 $ldap= $this->config->get_ldap_link();
912 /* Strip relevant part from dn, keep trailing ',' */
913 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
914 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
916 /* Walk from top to base and try to load default values for
917 'gotoTerminalPath'. Abort when an entry is found. */
918 while (TRUE){
919 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
921 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
922 $this->config->current['BASE'], array('gotoTerminalPath'));
923 $attrs= $ldap->fetch();
924 if (isset($attrs['gotoTerminalPath'])){
925 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
926 break;
927 }
929 /* Nothing left? */
930 if ($tmp == ""){
931 break;
932 }
933 }
934 }
936 /* Add semi automatic values */
937 // FIXME: LDAP Server may not be set here...
938 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
940 switch ($this->bootmode){
941 case "D":
942 $this->gotoKernelParameters.= " debug";
943 break;
944 case "G":
945 $this->gotoKernelParameters.= " splash=silent";
946 break;
947 }
948 if ($this->customParameters != ""){
949 $this->gotoKernelParameters.= " o ".$this->customParameters;
950 }
952 plugin::save();
954 unset( $this->attrs['FAIrelease'] );
956 $str = "";
958 if($this->FAIdebianMirror == "inherited"){
960 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
962 }else{
964 foreach($this->FAIclass as $class){
965 $str .= $class." ";
966 }
967 $str .= ":" . $this->FAIrelease;
968 $this->attrs['FAIclass']= "";
969 $this->attrs['FAIclass']= trim($str);
971 if(empty($this->attrs['FAIclass'])){
972 $this->attrs['FAIclass'] = array();
973 }
974 }
976 /* Add missing arrays */
977 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
978 if (isset ($this->$val) && count ($this->$val) != 0){
980 $this->attrs["$val"]= array_unique($this->$val);
981 }
982 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
983 }
985 /* Strip out 'default' values */
986 if ($this->attrs['gotoLdapServer'] == "default"){
987 $this->attrs['gotoLdapServer']= array();
988 }
990 if (($this->attrs['gotoBootKernel'] == "default") || ($this->attrs['gotoBootKernel'] == "%default%")){
991 $this->attrs['gotoBootKernel']= array();
992 }
994 /* if mirror == none stop saving this attribute */
995 if($this->FAIdebianMirror == "none"){
996 $this->FAIdebianMirror = "";
997 }
999 /* Get FAIstate from object, the generic tab could have changed it during execute */
1000 $ldap= $this->config->get_ldap_link();
1001 $ldap->cd($this->dn);
1002 $ldap->cat($this->dn,array("FAIstate"));
1003 $checkFAIstate = $ldap->fetch();
1005 /* Remove FAI objects if no FAI class is selected */
1006 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1007 $tmp = array();
1008 foreach($this->attrs['objectClass'] as $class){
1009 if($class != "FAIobject"){
1010 $tmp[] = $class;
1011 }
1012 }
1013 $this->attrs['objectClass'] = $tmp;
1014 $this->attrs['FAIclass'] = array();
1015 $this->attrs['FAIdebianMirror'] = array();
1016 }
1018 /* prepare share settings */
1019 $tmp = array();
1020 foreach($this->gotoShares as $name => $settings){
1021 $tmp2= split("\|",$name);
1022 $name = $tmp2[0];
1023 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1024 }
1025 $this->attrs['gotoShare']=$tmp;
1027 $this->cleanup();
1028 $ldap->modify ($this->attrs);
1030 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1031 $this->handle_post_events("modify");
1032 }
1034 /* Add value to array, check if unique */
1035 function add_list (&$array, $value)
1036 {
1037 if ($value != ""){
1038 $array[]= $value;
1039 sort($array);
1040 array_unique ($array);
1041 }
1042 }
1045 /* Delete value to array, check if unique */
1046 function del_list (&$array, $list)
1047 {
1048 $tmp= array();
1049 foreach ($array as $mod){
1050 if (!in_array($mod, $list)){
1051 $tmp[]= $mod;
1052 }
1053 }
1054 $array= $tmp;
1055 }
1057 /* Generate ListBox frindly output for the defined shares
1058 * Possibly Add or remove an attribute here,
1059 */
1060 function printOutAssignedShares()
1061 {
1062 $a_return = array();
1063 if(is_array($this->gotoShares)){
1064 foreach($this->gotoShares as $share){
1065 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1066 }
1067 }
1068 return($a_return);
1069 }
1072 function GetHookElements()
1073 {
1074 $ret = array();
1075 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1076 if(!empty($cmd)){
1077 $res = shell_exec($cmd);
1078 $res2 = trim($res);
1079 if((!$res)){
1080 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1081 }elseif(empty($res2)){
1082 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1083 }else{
1084 $tmp = split("\n",$res);
1085 foreach($tmp as $line){
1086 if(empty($line)) continue;
1087 $ret[]= $line;
1088 }
1089 }
1090 }
1091 return($ret);
1092 }
1094 }
1096 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1097 ?>