5f1952d128732bf6e32faf61ed168ae786060c1e
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 if(count($this->gotoAvailableShares)){
613 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
614 $s_mount = $_POST['gotoShareMountPoint'];
615 /* Preparing the new assignment */
616 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
617 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
618 }
619 }
620 }
622 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
623 * If there is no defined share selected, we will abort the deletion without any message
624 */
625 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
626 unset($this->gotoShares[$_POST['gotoShare']]);
627 }
629 $smarty->assign("gotoShares",$this->printOutAssignedShares());
630 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
631 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
632 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
634 /* Arrays */
635 $tmp = $this->goLdapServerList;
637 /* Create divSelectBox for ldap server selection
638 */
639 $SelectBoxLdapServer = new divSelectBox("LdapServer");
640 $SelectBoxLdapServer->SetHeight(130);
642 /* Set first entry as selected, if $this->gotoLdapServer is empty
643 * or given entry is no longer available ...
644 */
645 $found = false;
646 foreach($tmp as $server){
647 if($this->gotoLdapServer==$server){
648 $found = true;
649 }
650 }
652 /* Add Entries
653 */
654 foreach($tmp as $key => $server){
655 $use ="";
656 if(($this->gotoLdapServer == $server) || ($found == false)) {
657 $found = true;
658 $use = " checked ";
659 };
661 $display = $server;
663 $SelectBoxLdapServer->AddEntry(
664 array(
665 array("string"=>$display),
666 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
667 "attach"=>"style='border-right:0px;'")
668 ));
669 }
671 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
673 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
674 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
675 $smarty->assign("$val", $this->$val);
676 }
678 /* Values */
679 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
680 $smarty->assign($val, $this->$val);
681 $smarty->assign($val."ACL", chkacl($this->acl, $val));
682 }
684 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
685 $smarty->assign("FAIreleases",$this->getFAIreleases());
686 $smarty->assign("FAIrelease",$this->FAIrelease);
687 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
688 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
689 $smarty->assign("FAIclassKeys",$this->FAIclass);
690 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
692 $div = new divSelectBox("WSFAIscriptClasses");
693 $div -> SetHeight("110");
694 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
695 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
696 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
697 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
699 $i = 1;
701 if($this->FAIdebianMirror == "inherited"){
702 $tmp = $this->InheritedFAIclass;
703 }else{
704 $tmp = $this->FAIclass;
705 }
707 foreach($tmp as $class){
709 if($this->FAIdebianMirror == "inherited"){
710 $str = "";
711 }else{
712 if($i==1){
713 $str = $str_empty.$str_down.$str_remove;
714 }elseif($i == count($this->FAIclass)){
715 $str = $str_up.$str_empty.$str_remove;
716 }else{
717 $str = $str_up.$str_down.$str_remove;
718 }
719 }
720 $i ++ ;
722 $div->AddEntry(array(
723 array("string"=>$class),
724 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
725 ));
726 }
728 $smarty->assign("FAIScriptlist",$div->DrawList());
730 /* Radio button group */
731 if (preg_match("/G/", $this->bootmode)) {
732 $smarty->assign("graphicalbootup", "checked");
733 } else {
734 $smarty->assign("graphicalbootup", "");
735 }
736 if (preg_match("/T/", $this->bootmode)) {
737 $smarty->assign("textbootup", "checked");
738 } else {
739 $smarty->assign("textbootup", "");
740 }
741 if (preg_match("/D/", $this->bootmode)) {
742 $smarty->assign("debugbootup", "checked");
743 } else {
744 $smarty->assign("debugbootup", "");
745 }
747 /* ACL's */
748 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
749 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
750 }
752 /* Show main page */
753 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
754 }
756 function remove_from_parent()
757 {
758 $this->handle_post_events("remove");
759 }
761 function generateDNSyn($release)
762 {
763 $str = "";
764 $tmp = split("\/",$release);
765 $tmp = array_reverse($tmp);
767 $base = ",ou=fai,";
769 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
771 foreach($tmp as $departmentname){
773 $str .= ",ou=".$departmentname;
774 }
775 $ret = array();
776 foreach($arr as $ar){
777 $ret[] = ",ou=".$ar.$str.$base;
778 }
779 return($ret);
780 }
782 function getFAIdebianMirrors()
783 {
784 $ret = array();
785 $ret['inherited']="["._("inherited")."]";
786 $ret['auto']=_("automatic");
787 $secs = array();
789 /* Walk through all available servers
790 and check if they support the currently selected classes
791 if not, dont't add them to our list
792 */
793 foreach($this->FAIServRepConfig as $mirror => $rest){
795 $use = false;
797 if(count($this->FAIclass) == 0){
798 $use = true;
799 }else{
800 $tmp = $this->getFAIreleases();
801 foreach($tmp as $release){
802 if(isset($rest['RELEASE'][$release])){
803 $use =true;
804 }
805 }
806 }
808 /* If current server, doesn't support this class
809 remove it from list
810 */
811 if($use){
812 $ret[$mirror] = $mirror;
813 }
814 }
815 return($ret);
816 }
818 function getFAIreleases()
819 {
820 $ret = array();
822 if($this->FAIdebianMirror == "inherited") return(array());
824 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
825 $this->FAIdebianMirror = "auto";
826 }
828 $errorClasses = "";
830 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
831 $use = true;
833 if(!count($this->FAIclass) == 0){
834 foreach($this->FAIclass as $class){
835 if(!in_array($class, $sections['PACKAGES'])){
836 $use = false;
837 $errorClasses[$class] = $class;
838 }else{
839 if(isset($errorClasses[$class])){
840 unset($errorClasses[$class]);
841 }
842 }
843 }
844 }
845 if($use){
846 $ret[$release]=$release;
847 }
848 }
849 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
851 $eClasses = " ";
852 foreach($errorClasses as $class){
853 $eClasses .= $class." ";
854 }
856 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));
857 $this->FAIdebianMirror = "auto";
858 return($this->getFAIreleases());
859 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
861 $eClasses = " ";
862 foreach($errorClasses as $class){
863 $eClasses .= $class." ";
864 }
866 $this->FAIclass= array();
867 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));
868 }
869 return($ret);
870 }
872 /* Save data to object */
873 function save_object()
874 {
875 plugin::save_object();
877 /* Save group radio buttons */
878 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
879 $this->bootmode= $_POST["bootmode"];
880 }
882 /* Save kernel parameters */
883 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
884 $this->customParameters= $_POST["customParameters"];
885 }
887 }
890 /* Save to LDAP */
891 function save()
892 {
894 /* Depending on the baseobject (Ogroup / WS) we
895 * use another set of objectClasses
896 * In case of WS itself, we use "array("GOhard", "FAIobject");"
897 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
898 */
899 if(isset($this->parent->by_object['ogroup'])){
900 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
901 }elseif(isset($this->parent->by_object['workgeneric'])){
902 $this->objectclasses = array("GOhard", "FAIobject");
903 }elseif(isset($this->parent->by_object['servgeneric'])){
904 $this->objectclasses = array("GOhard", "FAIobject");
905 }else{
906 print "Object Type Configuration : unknown";
907 exit();
908 }
910 /* Find proper terminal path for tftp configuration
911 FIXME: This is suboptimal when the default has changed to
912 another location! */
913 if (($this->gotoTerminalPath == "default")){
914 $ldap= $this->config->get_ldap_link();
916 /* Strip relevant part from dn, keep trailing ',' */
917 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
918 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
920 /* Walk from top to base and try to load default values for
921 'gotoTerminalPath'. Abort when an entry is found. */
922 while (TRUE){
923 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
925 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
926 $this->config->current['BASE'], array('gotoTerminalPath'));
927 $attrs= $ldap->fetch();
928 if (isset($attrs['gotoTerminalPath'])){
929 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
930 break;
931 }
933 /* Nothing left? */
934 if ($tmp == ""){
935 break;
936 }
937 }
938 }
940 /* Add semi automatic values */
941 // FIXME: LDAP Server may not be set here...
942 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
944 switch ($this->bootmode){
945 case "D":
946 $this->gotoKernelParameters.= " debug";
947 break;
948 case "G":
949 $this->gotoKernelParameters.= " splash=silent";
950 break;
951 }
952 if ($this->customParameters != ""){
953 $this->gotoKernelParameters.= " o ".$this->customParameters;
954 }
956 plugin::save();
958 unset( $this->attrs['FAIrelease'] );
960 $str = "";
962 if($this->FAIdebianMirror == "inherited"){
964 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
966 }else{
968 foreach($this->FAIclass as $class){
969 $str .= $class." ";
970 }
971 $str .= ":" . $this->FAIrelease;
972 $this->attrs['FAIclass']= "";
973 $this->attrs['FAIclass']= trim($str);
975 if(empty($this->attrs['FAIclass'])){
976 $this->attrs['FAIclass'] = array();
977 }
978 }
980 /* Add missing arrays */
981 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
982 if (isset ($this->$val) && count ($this->$val) != 0){
984 $this->attrs["$val"]= array_unique($this->$val);
985 }
986 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
987 }
989 /* Strip out 'default' values */
990 if ($this->attrs['gotoLdapServer'] == "default"){
991 $this->attrs['gotoLdapServer']= array();
992 }
994 if (($this->attrs['gotoBootKernel'] == "default") || ($this->attrs['gotoBootKernel'] == "%default%")){
995 $this->attrs['gotoBootKernel']= array();
996 }
998 /* if mirror == none stop saving this attribute */
999 if($this->FAIdebianMirror == "none"){
1000 $this->FAIdebianMirror = "";
1001 }
1003 /* Remove FAI objects if no FAI class is selected */
1004 if(count($this->FAIclass)==0){
1005 $tmp = array();
1006 foreach($this->attrs['objectClass'] as $class){
1007 if($class != "FAIobject"){
1008 $tmp[] = $class;
1009 }
1010 }
1011 $this->attrs['objectClass'] = $tmp;
1012 $this->attrs['FAIclass'] = array();
1013 $this->attrs['FAIdebianMirror'] = array();
1014 }
1016 /* prepare share settings */
1017 $tmp = array();
1018 foreach($this->gotoShares as $name => $settings){
1019 $tmp2= split("\|",$name);
1020 $name = $tmp2[0];
1021 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1022 }
1023 $this->attrs['gotoShare']=$tmp;
1025 $ldap= $this->config->get_ldap_link();
1026 $ldap->cd($this->dn);
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 ?>