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 /* Delete selected class from our list */
590 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
591 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
592 unset($this->FAIclass[$_POST['FAIclassSel']]);
593 }
594 }
596 /* Show main page */
597 $smarty= get_smarty();
598 $smarty->assign("SelectBoxLdapServer","");
600 /* In this section server shares will be defined
601 * A user can select one of the given shares and a mount point
602 * and attach this combination to his setup.
603 */
604 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
605 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
607 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
608 * This entry will be, a combination of mountPoint and sharedefinitions
609 */
610 if(isset($_POST['gotoShareAdd'])){
611 /* We assign a share to this user, if we don't know where to mount the share */
612 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
613 print_red(_("You must specify a valid mount point."));
614 }else{
615 if(count($this->gotoAvailableShares)){
616 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
617 $s_mount = $_POST['gotoShareMountPoint'];
618 /* Preparing the new assignment */
619 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
620 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
621 }
622 }
623 }
625 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
626 * If there is no defined share selected, we will abort the deletion without any message
627 */
628 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
629 unset($this->gotoShares[$_POST['gotoShare']]);
630 }
632 $smarty->assign("gotoShares",$this->printOutAssignedShares());
633 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
634 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
635 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
637 /* Arrays */
638 $tmp = $this->goLdapServerList;
640 /* Create divSelectBox for ldap server selection
641 */
642 $SelectBoxLdapServer = new divSelectBox("LdapServer");
643 $SelectBoxLdapServer->SetHeight(130);
645 /* Set first entry as selected, if $this->gotoLdapServer is empty
646 * or given entry is no longer available ...
647 */
648 $found = false;
649 foreach($tmp as $server){
650 if($this->gotoLdapServer==$server){
651 $found = true;
652 }
653 }
655 /* Add Entries
656 */
657 foreach($tmp as $key => $server){
658 $use ="";
659 if(($this->gotoLdapServer == $server) || ($found == false)) {
660 $found = true;
661 $use = " checked ";
662 };
664 $display = $server;
666 $SelectBoxLdapServer->AddEntry(
667 array(
668 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
669 "attach"=>"style='border-left:0px;'"),
670 array("string"=>$display)
671 ));
672 }
674 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
676 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
677 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
678 $smarty->assign("$val", $this->$val);
679 }
681 /* Values */
682 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
683 $smarty->assign($val, $this->$val);
684 $smarty->assign($val."ACL", chkacl($this->acl, $val));
685 }
687 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
688 $smarty->assign("FAIreleases",$this->getFAIreleases());
689 $smarty->assign("FAIrelease",$this->FAIrelease);
690 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
691 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
692 $smarty->assign("FAIclassKeys",$this->FAIclass);
693 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
695 $div = new divSelectBox("WSFAIscriptClasses");
696 $div -> SetHeight("110");
697 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
698 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
699 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
700 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
702 $i = 1;
704 if($this->FAIdebianMirror == "inherited"){
705 $tmp = $this->InheritedFAIclass;
706 }else{
707 $tmp = $this->FAIclass;
708 }
710 foreach($tmp as $class){
712 if($this->FAIdebianMirror == "inherited"){
713 $str = "";
714 }else{
715 if($i==1){
716 $str = $str_empty.$str_down.$str_remove;
717 }elseif($i == count($this->FAIclass)){
718 $str = $str_up.$str_empty.$str_remove;
719 }else{
720 $str = $str_up.$str_down.$str_remove;
721 }
722 }
723 $i ++ ;
725 $div->AddEntry(array(
726 array("string"=>$class),
727 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
728 ));
729 }
731 $smarty->assign("FAIScriptlist",$div->DrawList());
733 /* Radio button group */
734 if (preg_match("/G/", $this->bootmode)) {
735 $smarty->assign("graphicalbootup", "checked");
736 } else {
737 $smarty->assign("graphicalbootup", "");
738 }
739 if (preg_match("/T/", $this->bootmode)) {
740 $smarty->assign("textbootup", "checked");
741 } else {
742 $smarty->assign("textbootup", "");
743 }
744 if (preg_match("/D/", $this->bootmode)) {
745 $smarty->assign("debugbootup", "checked");
746 } else {
747 $smarty->assign("debugbootup", "");
748 }
750 /* ACL's */
751 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
752 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
753 }
755 /* Show main page */
756 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
757 }
759 function remove_from_parent()
760 {
761 $this->handle_post_events("remove");
762 }
764 function generateDNSyn($release)
765 {
766 $str = "";
767 $tmp = split("\/",$release);
768 $tmp = array_reverse($tmp);
770 $base = ",ou=fai,";
772 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
774 foreach($tmp as $departmentname){
776 $str .= ",ou=".$departmentname;
777 }
778 $ret = array();
779 foreach($arr as $ar){
780 $ret[] = ",ou=".$ar.$str.$base;
781 }
782 return($ret);
783 }
785 function getFAIdebianMirrors()
786 {
787 $ret = array();
788 $ret['inherited']="["._("inherited")."]";
789 $ret['auto']=_("automatic");
790 $secs = array();
792 /* Walk through all available servers
793 and check if they support the currently selected classes
794 if not, dont't add them to our list
795 */
796 foreach($this->FAIServRepConfig as $mirror => $rest){
798 $use = false;
800 if(count($this->FAIclass) == 0){
801 $use = true;
802 }else{
803 $tmp = $this->getFAIreleases();
804 foreach($tmp as $release){
805 if(isset($rest['RELEASE'][$release])){
806 $use =true;
807 }
808 }
809 }
811 /* If current server, doesn't support this class
812 remove it from list
813 */
814 if($use){
815 $ret[$mirror] = $mirror;
816 }
817 }
818 return($ret);
819 }
821 function getFAIreleases()
822 {
823 $ret = array();
825 if($this->FAIdebianMirror == "inherited") return(array());
827 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
828 $this->FAIdebianMirror = "auto";
829 }
831 $errorClasses = "";
833 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
834 $use = true;
836 if(!count($this->FAIclass) == 0){
837 foreach($this->FAIclass as $class){
838 if(!in_array($class, $sections['PACKAGES'])){
839 $use = false;
840 $errorClasses[$class] = $class;
841 }else{
842 if(isset($errorClasses[$class])){
843 unset($errorClasses[$class]);
844 }
845 }
846 }
847 }
848 if($use){
849 $ret[$release]=$release;
850 }
851 }
852 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
854 $eClasses = " ";
855 foreach($errorClasses as $class){
856 $eClasses .= $class." ";
857 }
859 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));
860 $this->FAIdebianMirror = "auto";
861 return($this->getFAIreleases());
862 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
864 $eClasses = " ";
865 foreach($errorClasses as $class){
866 $eClasses .= $class." ";
867 }
869 $this->FAIclass= array();
870 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));
871 }
872 return($ret);
873 }
875 /* Save data to object */
876 function save_object()
877 {
878 plugin::save_object();
880 /* Save group radio buttons */
881 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
882 $this->bootmode= $_POST["bootmode"];
883 }
885 /* Save kernel parameters */
886 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
887 $this->customParameters= $_POST["customParameters"];
888 }
890 }
893 /* Save to LDAP */
894 function save()
895 {
897 /* Depending on the baseobject (Ogroup / WS) we
898 * use another set of objectClasses
899 * In case of WS itself, we use "array("GOhard", "FAIobject");"
900 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
901 */
902 if(isset($this->parent->by_object['ogroup'])){
903 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
904 }elseif(isset($this->parent->by_object['workgeneric'])){
905 $this->objectclasses = array("GOhard", "FAIobject");
906 }elseif(isset($this->parent->by_object['servgeneric'])){
907 $this->objectclasses = array("GOhard", "FAIobject","gotoWorkstationTemplate");
908 }else{
909 print "Object Type Configuration : unknown";
910 exit();
911 }
913 /* Find proper terminal path for tftp configuration
914 FIXME: This is suboptimal when the default has changed to
915 another location! */
916 if (($this->gotoTerminalPath == "default")){
917 $ldap= $this->config->get_ldap_link();
919 /* Strip relevant part from dn, keep trailing ',' */
920 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
921 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
923 /* Walk from top to base and try to load default values for
924 'gotoTerminalPath'. Abort when an entry is found. */
925 while (TRUE){
926 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
928 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
929 $this->config->current['BASE'], array('gotoTerminalPath'));
930 $attrs= $ldap->fetch();
931 if (isset($attrs['gotoTerminalPath'])){
932 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
933 break;
934 }
936 /* Nothing left? */
937 if ($tmp == ""){
938 break;
939 }
940 }
941 }
943 /* Add semi automatic values */
944 // FIXME: LDAP Server may not be set here...
945 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
947 switch ($this->bootmode){
948 case "D":
949 $this->gotoKernelParameters.= " debug";
950 break;
951 case "G":
952 $this->gotoKernelParameters.= " splash=silent";
953 break;
954 }
955 if ($this->customParameters != ""){
956 $this->gotoKernelParameters.= " o ".$this->customParameters;
957 }
959 plugin::save();
961 unset( $this->attrs['FAIrelease'] );
963 $str = "";
965 if($this->FAIdebianMirror == "inherited"){
967 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
969 }else{
971 foreach($this->FAIclass as $class){
972 $str .= $class." ";
973 }
974 $str .= ":" . $this->FAIrelease;
975 $this->attrs['FAIclass']= "";
976 $this->attrs['FAIclass']= trim($str);
978 if(empty($this->attrs['FAIclass'])){
979 $this->attrs['FAIclass'] = array();
980 }
981 }
983 /* Add missing arrays */
984 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
985 if (isset ($this->$val) && count ($this->$val) != 0){
987 $this->attrs["$val"]= array_unique($this->$val);
988 }
989 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
990 }
992 /* Strip out 'default' values */
993 if ($this->attrs['gotoLdapServer'] == "default"){
994 $this->attrs['gotoLdapServer']= array();
995 }
997 if (($this->attrs['gotoBootKernel'] == "default") || ($this->attrs['gotoBootKernel'] == "%default%")){
998 $this->attrs['gotoBootKernel']= array();
999 }
1001 /* if mirror == none stop saving this attribute */
1002 if($this->FAIdebianMirror == "none"){
1003 $this->FAIdebianMirror = "";
1004 }
1006 /* Get FAIstate from object, the generic tab could have changed it during execute */
1007 $ldap= $this->config->get_ldap_link();
1008 $ldap->cd($this->dn);
1009 $ldap->cat($this->dn,array("FAIstate"));
1010 $checkFAIstate = $ldap->fetch();
1012 /* Remove FAI objects if no FAI class is selected */
1013 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1014 $tmp = array();
1015 foreach($this->attrs['objectClass'] as $class){
1016 if($class != "FAIobject"){
1017 $tmp[] = $class;
1018 }
1019 }
1020 $this->attrs['objectClass'] = $tmp;
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 ?>