cf53ff2725840c274ab474c3c85a782d58ffbfd4
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 $this->FAIclassInfo = $tmp2;
124 /* Build up an array like this one :
125 [$url]['SERVER'] = 'srv1-002';
126 [$url]['RELEASE']['siga/rc9.0.2']
127 ['SECTIONS'][0] "main";
128 ['SECTIONS'][1] "non-free";
129 [$url]['RELEASE']['siga/rc9.0.2']
130 ['PACKAGES'][0] "pkg1";
131 ['PACKAGES'][1] "postfix";
132 */
134 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
135 $test = array();
136 while($attr = $ldap->fetch()){
137 if(isset($attr['FAIrepository'])){
139 unset($attr['FAIrepository']['count']);
141 foreach($attr['FAIrepository'] as $rep){
142 $tmp = split("\|",$rep);
144 if(count($tmp)==4){
145 $sections = split(",",$tmp[3]);
146 $release = $tmp[2];
147 $server = $tmp[1];
148 $url = $tmp[0];
150 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
152 /* Result will be cached
153 */
154 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
155 $test[$url]['SERVER'] = $server;
157 /* auto gets all releases/classes
158 */
159 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
160 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
161 }
162 }
163 }
164 }
166 /* Add possible elements from hook */
167 $lines= $this->GetHookElements();
168 foreach ($lines as $hline){
169 $entries= split(";", $hline);
170 if (isset($entries[1]) && !isset($test[$entries[1]])){
171 $test[$entries[1]]['RELEASE']= array();
173 /* Split releases */
174 if (isset($entries[2])){
175 $releases= split(",", $entries[2]);
177 foreach ($releases as $release){
178 $rname= preg_replace('/:.*$/', '', $release);
179 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
180 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
181 $test[$entries[1]]['RELEASE'][$rname]= array();
182 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
183 foreach ($classes as $class){
184 if ($class != ""){
185 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
186 }
187 }
188 }
189 }
190 }
191 }
193 $this->FAIServRepConfig= $test;
195 /* Get arrays */
196 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
197 if (isset($this->attrs["$val"]["count"])){
198 for ($i= 0; $i<$this->attrs["count"]; $i++){
199 if (isset($this->attrs["$val"][$i])){
200 array_push($this->$val, $this->attrs["$val"][$i]);
201 }
202 }
203 }
204 sort ($this->$val);
205 $this->$val= array_unique($this->$val);
206 }
208 /* Parse Kernel Parameters to decide what boot mode is enabled */
209 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
210 $this->bootmode= "G";
211 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
212 $this->bootmode= "D";
213 } elseif ($this->gotoKernelParameters == "") {
214 $this->bootmode= "G";
215 } else {
216 $this->bootmode= "T";
217 }
218 if (preg_match("/ o /", $this->gotoKernelParameters)){
219 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
220 } else {
221 $this->customParameters= "";
222 }
224 /* Prepare Shares */
225 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
226 unset($this->attrs['gotoShare']['count']);
227 foreach($this->attrs['gotoShare'] as $share){
228 $tmp = $tmp2 = array();
229 $tmp = split("\|",$share);
230 $tmp2['server'] =$tmp[0];
231 $tmp2['name'] =$tmp[1];
232 $tmp2['mountPoint'] =$tmp[2];
233 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
234 }
235 }
237 $this->gotoShareSelections= $config->getShareList(true);
238 $this->gotoAvailableShares= $config->getShareList(false);
239 $tmp2 = array();
241 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
242 $tmp = array();
243 $tmp = split(" ",$this->FAIclass);
244 $tmp2 =array();
246 foreach($tmp as $class){
247 if( ":" == $class[0] ) {
248 $this->FAIrelease = substr( $class, 1 );
249 }
250 else
251 $tmp2[$class] = $class;
252 }
253 $this->FAIclass = $tmp2;
254 }
256 if(!is_array($this->FAIclass)){
257 $this->FAIclass =array();
258 }
260 $this->orig_dn= $this->dn;
262 /* Handle inheritance value "default" */
263 $this->gotoBootKernels= array("%default%" => '['._("inherited").']');
266 /* Load hardware list */
267 $ldap= $this->config->get_ldap_link();
268 $ldap->cd($this->config->current['BASE']);
269 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
270 if ($ldap->count() == 1){
271 $map= array("gotoLdapServer","gotoBootKernel","FAIclass","FAIdebianMirror");
272 $attrs= $ldap->fetch();
274 foreach ($map as $name){
275 if (!isset($attrs[$name][0])){
276 continue;
277 }
279 switch ($name){
280 case 'gotoLdapServer':
281 $this->goLdapServerList= array_merge(array('default' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
282 break;
284 case 'gotoBootKernel':
285 $this->gotoBootKernels['%default%']= _("inherited").' ['.$attrs[$name][0].']' ;
286 break;
288 case 'FAIclass':
289 $str = split(":",$attrs[$name][0]);
290 $this->InheritedFAIclass = split("\ ",trim($str[0]));
291 $this->InheritedFAIrelease = trim($str[1]);
292 break;
294 case 'FAIdebianMirror':
295 $this->InheritedFAIdebianMirror = $attrs[$name][0];
296 break;
297 }
298 }
299 }
301 /* Get list of boot kernels */
302 if (isset($this->config->data['TABS'])){
303 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
305 if (!check_command($command)){
306 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
307 get_class($this));
308 } else {
310 $fh= popen($command, "r");
311 while (!feof($fh)) {
312 $buffer= trim(fgets($fh, 256));
313 if ($buffer != ""){
314 $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
315 }
316 }
317 pclose($fh);
318 }
319 }
321 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
322 $this->FAIdebianMirror = "inherited";
323 }
324 }
327 /* This class is called by the contrucktor ONLY.
328 * It return the available classes for each
329 * Server / Release combination ...
330 * (Release specifies which classes are available)
331 */
332 function getAvailableClassesForThisRelease($release)
333 {
334 /* There could be more than one server providing this release,
335 so use cached result if available
336 */
337 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
338 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
339 }
341 /* Create cache with all classes
342 */
343 if((!isset($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
344 (!is_array($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
345 (count($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES']) ==0 )){
347 /* Get ldap connection */
348 $ldap = $this->config->get_ldap_link();
349 $ldap->cd($this->config->current['BASE']);
351 /* Get possible classes ...
352 This would be faste with some kind of caching ...
353 */
354 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn"),true);
355 /* Sort all entries, and attach elementtype.
356 * To be able to show the types in the listbox.
357 */
358 while($attr = $ldap->fetch()){
359 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
360 }
361 }
363 /* Walk through cache and get out what we need.
364 *
365 * Function od : "$this->generateDNSyn($release)"
366 * It returns an array like this one :
367 * array("ou=packges,ou=rc0.9.2,ou=siga,",
368 * "ou=scripts.. "
369 * ...);
370 * This helps us to select the correct classes for each release.
371 * It prevents errors like: 'siga' is selected as release, but all classes
372 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
373 */
374 $tmp2 = $this->generateDNSyn($release) ;
375 $test2 = array();
376 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
377 foreach($tmp2 as $dns){
378 if(preg_match("/".$dns."/",$attr['dn'])){
379 $test2[$attr['cn'][0]] = $attr['cn'][0];
380 }
381 }
382 }
383 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
384 return($test2);
385 }
388 /* Create array to display available classes/profiles in a selectbox
389 * This function only displays the available classes.
390 * If a class is available is defined by these facts :
391 * 1. Is this class available for the selected release ?
392 * - if it is available, check if the release is available for the selected server
393 * (done by $this->getFAIreleases())
394 * 2. Is this class currently not assigned to $this->FAIclass
395 */
396 function selectFriendlyClasses(){
397 $tmp=array();
399 if($this->FAIdebianMirror == "inherited") return($tmp);
401 /* check if the current release exists,
402 else select the first one ..
403 */
404 $tmp2 = $this->getFAIreleases();
405 if(!in_array($this->FAIrelease, $tmp2)){
406 $this->FAIrelease = key($tmp2);
407 }
409 /* Get all Packages for this server/release combination
410 */
411 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
412 $pkgs = array();
413 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
414 }else{
415 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
416 }
418 /* Check each and every single class name
419 */
420 foreach($pkgs as $pkg){
422 /* Class already assigned to the classes list ?
423 * If not ... go on
424 */
425 if(!in_array($pkg,$this->FAIclass)){
427 /* Create the displayed list entry value
428 HKLMOP [-Pl P V T-] or something like that
429 */
430 $str = "";
431 foreach($this->FAIclassInfo[$pkg] as $entry){
432 if(isset($entry['kzl'])){
433 $str .= $entry['kzl']." ";
434 }
435 }
437 /* Append class if everyting was fine
438 */
439 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
440 }
441 }
442 /* Just sort and return new classes list ...
443 ( possibly we should cache the result ... )
444 */
445 natcasesort ($tmp);
446 return($tmp);
447 }
449 function check()
450 {
451 $messages = array();
453 /* Call common method to give check the hook */
454 $messages= plugin::check();
456 /* If there are packages selected, but no mirror show error */
457 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
458 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
459 }
461 return($messages);
462 }
464 function execute()
465 {
467 /* Call parent execute */
468 plugin::execute();
470 /* Do we need to flip is_account state? */
471 if (isset($_POST['modify_state'])){
472 $this->is_account= !$this->is_account;
473 }
475 /* Do we represent a valid terminal? */
476 if (!$this->is_account && $this->parent == NULL){
477 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
478 _("This 'dn' has no terminal features.")."</b>";
479 return ($display);
480 }
482 /* Add module */
483 if (isset ($_POST['add_module'])){
484 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
485 $this->add_list ($this->gotoModules, $_POST['module']);
486 }
487 }
489 /* Delete module */
490 if (isset ($_POST['delete_module'])){
491 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
492 $this->del_list ($this->gotoModules, $_POST['modules_list']);
493 }
494 }
496 /* FAI class management */
497 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
498 $found = 0 ;
500 /* If this new class/profile will attach a second partition table
501 * to our list of classes, abort and show a message.
502 */
503 foreach($this->FAIclass as $name){
504 if(isset($this->FAIclassInfo[$name])){
505 foreach($this->FAIclassInfo[$name] as $atr){
506 if(isset($atr['obj'])){
507 if($atr['obj'] == "FAIpartitionTable"){
508 $found ++ ;
509 }
510 }
511 }
512 }
513 }
515 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
516 print_red(_("There is already a profile in your selection that contain partition table configurations."));
517 }else{
518 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
519 }
520 }
522 $sort = false;
523 foreach($_POST as $name => $val){
525 $sort_type = false;
526 if((preg_match("/sort_up/",$name))&&(!$sort)){
527 $sort_type = "sort_up_";
528 }
529 if((preg_match("/sort_down/",$name))&&(!$sort)){
530 $sort_type = "sort_down_";
531 }
533 if(($sort_type)&&(!$sort)){
534 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
535 $sort = true;
537 $last = -1;
538 $change_down = -1;
540 /* Create array with numeric index */
541 $tmp = array();
542 foreach($this->FAIclass as $class){
543 $tmp [] = $class;
544 }
546 /* Walk trough array */
547 foreach($tmp as $key => $faiName){
548 if($faiName == $value){
549 if($sort_type == "sort_up_"){
550 if($last != -1){
551 $change_down= $last;
552 }
553 }else{
554 if(isset($tmp[$key+1])){
555 $change_down = $key;
556 }
557 }
558 }
559 $last = $key;
560 }
562 $tmp2 = array();
563 $skip = false;
565 foreach($tmp as $ky => $vl){
567 if($ky == $change_down){
568 $skip = $vl;
569 }else{
570 $tmp2[$vl] = $vl;
571 }
572 if(($skip != false)&&($ky != $change_down)){
573 $tmp2[$skip] = $skip;
574 $skip =false;
575 }
576 }
577 $this->FAIclass = $tmp2;
578 }
580 if(preg_match("/fai_remove/i",$name)){
581 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
582 unset($this->FAIclass[$value]);
583 }
584 }
586 /* Delete selected class from our list */
587 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
588 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
589 unset($this->FAIclass[$_POST['FAIclassSel']]);
590 }
591 }
593 /* Show main page */
594 $smarty= get_smarty();
595 $smarty->assign("SelectBoxLdapServer","");
597 /* In this section server shares will be defined
598 * A user can select one of the given shares and a mount point
599 * and attach this combination to his setup.
600 */
601 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
602 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
604 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
605 * This entry will be, a combination of mountPoint and sharedefinitions
606 */
607 if(isset($_POST['gotoShareAdd'])){
608 /* We assign a share to this user, if we don't know where to mount the share */
609 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
610 print_red(_("You must specify a valid mount point."));
611 }else{
612 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
613 $s_mount = $_POST['gotoShareMountPoint'];
614 /* Preparing the new assignment */
615 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
616 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
617 }
618 }
620 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
621 * If there is no defined share selected, we will abort the deletion without any message
622 */
623 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
624 unset($this->gotoShares[$_POST['gotoShare']]);
625 }
627 $smarty->assign("gotoShares",$this->printOutAssignedShares());
628 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
629 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
631 /* Arrays */
632 $tmp = $this->goLdapServerList;
634 /* Create divSelectBox for ldap server selection
635 */
636 $SelectBoxLdapServer = new divSelectBox("LdapServer");
637 $SelectBoxLdapServer->SetHeight(130);
639 /* Set first entry as selected, if $this->gotoLdapServer is empty
640 * or given entry is no longer available ...
641 */
642 $found = false;
643 foreach($tmp as $server){
644 if($this->gotoLdapServer==$server){
645 $found = true;
646 }
647 }
649 /* Add Entries
650 */
651 foreach($tmp as $key => $server){
652 $use ="";
653 if(($this->gotoLdapServer == $server) || ($found == false)) {
654 $found = true;
655 $use = " checked ";
656 };
658 $display = $server;
660 $SelectBoxLdapServer->AddEntry(
661 array(
662 array("string"=>$display),
663 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
664 "attach"=>"style='border-right:0px;'")
665 ));
666 }
668 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
670 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
671 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
672 $smarty->assign("$val", $this->$val);
673 }
675 /* Values */
676 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
677 $smarty->assign($val, $this->$val);
678 $smarty->assign($val."ACL", chkacl($this->acl, $val));
679 }
681 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
682 $smarty->assign("FAIreleases",$this->getFAIreleases());
683 $smarty->assign("FAIrelease",$this->FAIrelease);
684 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
685 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
686 $smarty->assign("FAIclassKeys",$this->FAIclass);
687 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
689 $div = new divSelectBox("WSFAIscriptClasses");
690 $div -> SetHeight("110");
691 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
692 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
693 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
694 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
696 $i = 1;
698 if($this->FAIdebianMirror == "inherited"){
699 $tmp = $this->InheritedFAIclass;
700 }else{
701 $tmp = $this->FAIclass;
702 }
704 foreach($tmp as $class){
706 if($this->FAIdebianMirror == "inherited"){
707 $str = "";
708 }else{
709 if($i==1){
710 $str = $str_empty.$str_down.$str_remove;
711 }elseif($i == count($this->FAIclass)){
712 $str = $str_up.$str_empty.$str_remove;
713 }else{
714 $str = $str_up.$str_down.$str_remove;
715 }
716 }
717 $i ++ ;
719 $div->AddEntry(array(
720 array("string"=>$class),
721 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
722 ));
723 }
725 $smarty->assign("FAIScriptlist",$div->DrawList());
727 /* Radio button group */
728 if (preg_match("/G/", $this->bootmode)) {
729 $smarty->assign("graphicalbootup", "checked");
730 } else {
731 $smarty->assign("graphicalbootup", "");
732 }
733 if (preg_match("/T/", $this->bootmode)) {
734 $smarty->assign("textbootup", "checked");
735 } else {
736 $smarty->assign("textbootup", "");
737 }
738 if (preg_match("/D/", $this->bootmode)) {
739 $smarty->assign("debugbootup", "checked");
740 } else {
741 $smarty->assign("debugbootup", "");
742 }
744 /* ACL's */
745 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
746 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
747 }
749 /* Show main page */
750 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
751 }
753 function remove_from_parent()
754 {
755 $this->handle_post_events("remove");
756 }
758 function generateDNSyn($release)
759 {
760 $str = "";
761 $tmp = split("\/",$release);
762 $tmp = array_reverse($tmp);
764 $base = ",ou=fai,";
766 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
768 foreach($tmp as $departmentname){
770 $str .= ",ou=".$departmentname;
771 }
772 $ret = array();
773 foreach($arr as $ar){
774 $ret[] = ",ou=".$ar.$str.$base;
775 }
776 return($ret);
777 }
779 function getFAIdebianMirrors()
780 {
781 $ret = array();
782 $ret['inherited']="["._("inherited")."]";
783 $ret['auto']=_("automatic");
784 $secs = array();
786 /* Walk through all available servers
787 and check if they support the currently selected classes
788 if not, dont't add them to our list
789 */
790 foreach($this->FAIServRepConfig as $mirror => $rest){
792 $use = false;
794 if(count($this->FAIclass) == 0){
795 $use = true;
796 }else{
797 $tmp = $this->getFAIreleases();
798 foreach($tmp as $release){
799 if(isset($rest['RELEASE'][$release])){
800 $use =true;
801 }
802 }
803 }
805 /* If current server, doesn't support this class
806 remove it from list
807 */
808 if($use){
809 $ret[$mirror] = $mirror;
810 }
811 }
812 return($ret);
813 }
815 function getFAIreleases()
816 {
817 $ret = array();
819 if($this->FAIdebianMirror == "inherited") return(array());
821 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
822 $this->FAIdebianMirror = "auto";
823 }
825 $errorClasses = "";
827 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
828 $use = true;
830 if(!count($this->FAIclass) == 0){
831 foreach($this->FAIclass as $class){
832 if(!in_array($class, $sections['PACKAGES'])){
833 $use = false;
834 $errorClasses[$class] = $class;
835 }else{
836 if(isset($errorClasses[$class])){
837 unset($errorClasses[$class]);
838 }
839 }
840 }
841 }
842 if($use){
843 $ret[$release]=$release;
844 }
845 }
846 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
848 $eClasses = " ";
849 foreach($errorClasses as $class){
850 $eClasses .= $class." ";
851 }
853 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));
854 $this->FAIdebianMirror = "auto";
855 return($this->getFAIreleases());
856 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
858 $eClasses = " ";
859 foreach($errorClasses as $class){
860 $eClasses .= $class." ";
861 }
863 $this->FAIclass= array();
864 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));
865 }
866 return($ret);
867 }
869 /* Save data to object */
870 function save_object()
871 {
872 plugin::save_object();
874 /* Save group radio buttons */
875 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
876 $this->bootmode= $_POST["bootmode"];
877 }
879 /* Save kernel parameters */
880 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
881 $this->customParameters= $_POST["customParameters"];
882 }
884 }
887 /* Save to LDAP */
888 function save()
889 {
891 /* Depending on the baseobject (Ogroup / WS) we
892 * use another set of objectClasses
893 * In case of WS itself, we use "array("GOhard", "FAIobject");"
894 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
895 */
896 if(isset($this->parent->by_object['ogroup'])){
897 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
898 }elseif(isset($this->parent->by_object['workgeneric'])){
899 $this->objectclasses = array("GOhard", "FAIobject");
900 }elseif(isset($this->parent->by_object['servgeneric'])){
901 $this->objectclasses = array("GOhard", "FAIobject");
902 }else{
903 print "Object Type Configuration : unknown";
904 exit();
905 }
907 /* Find proper terminal path for tftp configuration
908 FIXME: This is suboptimal when the default has changed to
909 another location! */
910 if (($this->gotoTerminalPath == "default")){
911 $ldap= $this->config->get_ldap_link();
913 /* Strip relevant part from dn, keep trailing ',' */
914 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
915 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
917 /* Walk from top to base and try to load default values for
918 'gotoTerminalPath'. Abort when an entry is found. */
919 while (TRUE){
920 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
922 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
923 $this->config->current['BASE'], array('gotoTerminalPath'));
924 $attrs= $ldap->fetch();
925 if (isset($attrs['gotoTerminalPath'])){
926 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
927 break;
928 }
930 /* Nothing left? */
931 if ($tmp == ""){
932 break;
933 }
934 }
935 }
937 /* Add semi automatic values */
938 // FIXME: LDAP Server may not be set here...
939 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
941 switch ($this->bootmode){
942 case "D":
943 $this->gotoKernelParameters.= " debug";
944 break;
945 case "G":
946 $this->gotoKernelParameters.= " splash=silent";
947 break;
948 }
949 if ($this->customParameters != ""){
950 $this->gotoKernelParameters.= " o ".$this->customParameters;
951 }
953 plugin::save();
955 unset( $this->attrs['FAIrelease'] );
957 $str = "";
959 if($this->FAIdebianMirror == "inherited"){
961 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
963 }else{
965 foreach($this->FAIclass as $class){
966 $str .= $class." ";
967 }
968 $str .= ":" . $this->FAIrelease;
969 $this->attrs['FAIclass']= "";
970 $this->attrs['FAIclass']= trim($str);
972 if(empty($this->attrs['FAIclass'])){
973 $this->attrs['FAIclass'] = array();
974 }
975 }
977 /* Add missing arrays */
978 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
979 if (isset ($this->$val) && count ($this->$val) != 0){
981 $this->attrs["$val"]= array_unique($this->$val);
982 }
983 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
984 }
986 /* Strip out 'default' values */
987 if ($this->attrs['gotoLdapServer'] == "default"){
988 $this->attrs['gotoLdapServer']= array();
989 }
991 if (($this->attrs['gotoBootKernel'] == "default") || ($this->attrs['gotoBootKernel'] == "%default%")){
992 $this->attrs['gotoBootKernel']= array();
993 }
995 /* if mirror == none stop saving this attribute */
996 if($this->FAIdebianMirror == "none"){
997 $this->FAIdebianMirror = "";
998 }
1000 /* Remove FAI objects if no FAI class is selected */
1001 if(count($this->FAIclass)==0){
1002 $tmp = array();
1003 foreach($this->attrs['objectClass'] as $class){
1004 if($class != "FAIobject"){
1005 $tmp[] = $class;
1006 }
1007 }
1008 $this->attrs['objectClass'] = $tmp;
1009 $this->attrs['FAIclass'] = array();
1010 $this->attrs['FAIdebianMirror'] = array();
1011 }
1013 /* prepare share settings */
1014 $tmp = array();
1015 foreach($this->gotoShares as $name => $settings){
1016 $tmp2= split("\|",$name);
1017 $name = $tmp2[0];
1018 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1019 }
1020 $this->attrs['gotoShare']=$tmp;
1022 $ldap= $this->config->get_ldap_link();
1023 $ldap->cd($this->dn);
1024 $this->cleanup();
1025 $ldap->modify ($this->attrs);
1027 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1028 $this->handle_post_events("modify");
1029 }
1031 /* Add value to array, check if unique */
1032 function add_list (&$array, $value)
1033 {
1034 if ($value != ""){
1035 $array[]= $value;
1036 sort($array);
1037 array_unique ($array);
1038 }
1039 }
1042 /* Delete value to array, check if unique */
1043 function del_list (&$array, $list)
1044 {
1045 $tmp= array();
1046 foreach ($array as $mod){
1047 if (!in_array($mod, $list)){
1048 $tmp[]= $mod;
1049 }
1050 }
1051 $array= $tmp;
1052 }
1054 /* Generate ListBox frindly output for the defined shares
1055 * Possibly Add or remove an attribute here,
1056 */
1057 function printOutAssignedShares()
1058 {
1059 $a_return = array();
1060 if(is_array($this->gotoShares)){
1061 foreach($this->gotoShares as $share){
1062 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1063 }
1064 }
1065 return($a_return);
1066 }
1069 function GetHookElements()
1070 {
1071 $ret = array();
1072 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1073 if(!empty($cmd)){
1074 $res = shell_exec($cmd);
1075 $res2 = trim($res);
1076 if((!$res)){
1077 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1078 }elseif(empty($res2)){
1079 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1080 }else{
1081 $tmp = split("\n",$res);
1082 foreach($tmp as $line){
1083 if(empty($line)) continue;
1084 $ret[]= $line;
1085 }
1086 }
1087 }
1088 return($ret);
1089 }
1091 }
1093 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1094 ?>