6df7411c75390f6a503a06bb57e438d86d806400
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-inherited";
13 var $gotoKernelParameters = "";
14 var $gotoLdapServer = "default-inherited";
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" => '['._("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' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
285 break;
287 case 'gotoBootKernel':
288 $this->gotoBootKernels['default-inherited']= _("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 {
312 $fh= popen($command, "r");
313 while (!feof($fh)) {
314 $buffer= trim(fgets($fh, 256));
316 if(!empty($buffer)){
318 $name=$value = $buffer;
320 if(preg_match("/:/",$buffer)){
321 $name = preg_replace("/:.*$/","",$buffer);
322 $value= preg_replace("/^.*:/","",$buffer);
323 $this->gotoBootKernels[$name]= $name.":".$value;
324 }else{
325 $this->gotoBootKernels[$name]= $value;
326 }
327 }
329 }
330 pclose($fh);
331 }
332 }
334 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
335 $this->FAIdebianMirror = "inherited";
336 }
337 }
340 /* This class is called by the contrucktor ONLY.
341 * It return the available classes for each
342 * Server / Release combination ...
343 * (Release specifies which classes are available)
344 */
345 function getAvailableClassesForThisRelease($release)
346 {
347 /* There could be more than one server providing this release,
348 so use cached result if available
349 */
350 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
351 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
352 }
354 $test2 = array();
355 $bb = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
356 $ldap = $this->config->get_ldap_link();
357 $ldap->cd($this->config->current['BASE']);
359 /* Get classes fpr given release */
360 $p_classes = get_all_objects_for_given_base($bb,
361 "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
362 "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
363 "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
365 /* Create list of classes */
366 foreach($p_classes as $class){
367 $ldap->cat($class['dn'],array("cn"));
368 $attr = $ldap->fetch();
369 $test2[$attr['cn'][0]] = $attr['cn'][0];
370 }
371 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
372 return($test2);
373 }
376 /* Create array to display available classes/profiles in a selectbox
377 * This function only displays the available classes.
378 * If a class is available is defined by these facts :
379 * 1. Is this class available for the selected release ?
380 * - if it is available, check if the release is available for the selected server
381 * (done by $this->getFAIreleases())
382 * 2. Is this class currently not assigned to $this->FAIclass
383 */
384 function selectFriendlyClasses(){
385 $tmp=array();
387 if($this->FAIdebianMirror == "inherited") return($tmp);
389 /* check if the current release exists,
390 else select the first one ..
391 */
392 $tmp2 = $this->getFAIreleases();
393 if(!in_array($this->FAIrelease, $tmp2)){
394 $this->FAIrelease = key($tmp2);
395 }
397 /* Get all Packages for this server/release combination
398 */
399 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
400 $pkgs = array();
401 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
402 }else{
403 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
404 }
406 /* Check each and every single class name
407 */
408 foreach($pkgs as $pkg){
410 /* Class already assigned to the classes list ?
411 * If not ... go on
412 */
413 if(!in_array($pkg,$this->FAIclass)){
415 /* Create the displayed list entry value
416 HKLMOP [-Pl P V T-] or something like that
417 */
418 $str = "";
419 foreach($this->FAIclassInfo[$pkg] as $entry){
420 if(isset($entry['kzl'])){
421 $str .= $entry['kzl']." ";
422 }
423 }
425 /* Append class if everyting was fine
426 */
427 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
428 }
429 }
430 /* Just sort and return new classes list ...
431 ( possibly we should cache the result ... )
432 */
433 natcasesort ($tmp);
434 return($tmp);
435 }
437 function check()
438 {
439 $messages = array();
441 /* Call common method to give check the hook */
442 $messages= plugin::check();
444 /* If there are packages selected, but no mirror show error */
445 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
446 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
447 }
449 return($messages);
450 }
452 function execute()
453 {
455 /* Call parent execute */
456 plugin::execute();
458 /* Do we need to flip is_account state? */
459 if (isset($_POST['modify_state'])){
460 $this->is_account= !$this->is_account;
461 }
463 /* Do we represent a valid terminal? */
464 if (!$this->is_account && $this->parent == NULL){
465 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
466 _("This 'dn' has no terminal features.")."</b>";
467 return ($display);
468 }
470 /* Add module */
471 if (isset ($_POST['add_module'])){
472 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
473 $this->add_list ($this->gotoModules, $_POST['module']);
474 }
475 }
477 /* Delete module */
478 if (isset ($_POST['delete_module'])){
479 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
480 $this->del_list ($this->gotoModules, $_POST['modules_list']);
481 }
482 }
484 /* FAI class management */
485 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
486 $found = 0 ;
488 /* If this new class/profile will attach a second partition table
489 * to our list of classes, abort and show a message.
490 */
491 foreach($this->FAIclass as $name){
492 if(isset($this->FAIclassInfo[$name])){
493 foreach($this->FAIclassInfo[$name] as $atr){
494 if(isset($atr['obj'])){
495 if($atr['obj'] == "FAIpartitionTable"){
496 $found ++ ;
497 }
498 }
499 }
500 }
501 }
503 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
504 print_red(_("There is already a profile in your selection that contain partition table configurations."));
505 }else{
506 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
507 }
508 }
510 $sort = false;
511 foreach($_POST as $name => $val){
513 $sort_type = false;
514 if((preg_match("/sort_up/",$name))&&(!$sort)){
515 $sort_type = "sort_up_";
516 }
517 if((preg_match("/sort_down/",$name))&&(!$sort)){
518 $sort_type = "sort_down_";
519 }
521 if(($sort_type)&&(!$sort)){
522 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
523 $sort = true;
525 $last = -1;
526 $change_down = -1;
528 /* Create array with numeric index */
529 $tmp = array();
530 foreach($this->FAIclass as $class){
531 $tmp [] = $class;
532 }
534 /* Walk trough array */
535 foreach($tmp as $key => $faiName){
536 if($faiName == $value){
537 if($sort_type == "sort_up_"){
538 if($last != -1){
539 $change_down= $last;
540 }
541 }else{
542 if(isset($tmp[$key+1])){
543 $change_down = $key;
544 }
545 }
546 }
547 $last = $key;
548 }
550 $tmp2 = array();
551 $skip = false;
553 foreach($tmp as $ky => $vl){
555 if($ky == $change_down){
556 $skip = $vl;
557 }else{
558 $tmp2[$vl] = $vl;
559 }
560 if(($skip != false)&&($ky != $change_down)){
561 $tmp2[$skip] = $skip;
562 $skip =false;
563 }
564 }
565 $this->FAIclass = $tmp2;
566 }
568 if(preg_match("/fai_remove/i",$name)){
569 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
570 unset($this->FAIclass[$value]);
571 }
572 }
574 /* Delete selected class from our list */
575 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
576 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
577 unset($this->FAIclass[$_POST['FAIclassSel']]);
578 }
579 }
581 /* Show main page */
582 $smarty= get_smarty();
583 $smarty->assign("SelectBoxLdapServer","");
585 /* In this section server shares will be defined
586 * A user can select one of the given shares and a mount point
587 * and attach this combination to his setup.
588 */
589 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
590 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
592 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
593 * This entry will be, a combination of mountPoint and sharedefinitions
594 */
595 if(isset($_POST['gotoShareAdd'])){
596 /* We assign a share to this user, if we don't know where to mount the share */
597 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
598 print_red(_("You must specify a valid mount point."));
599 }else{
600 if(count($this->gotoAvailableShares)){
601 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
602 $s_mount = $_POST['gotoShareMountPoint'];
603 /* Preparing the new assignment */
604 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
605 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
606 }
607 }
608 }
610 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
611 * If there is no defined share selected, we will abort the deletion without any message
612 */
613 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
614 unset($this->gotoShares[$_POST['gotoShare']]);
615 }
617 $smarty->assign("gotoShares",$this->printOutAssignedShares());
618 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
619 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
620 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
622 /* Arrays */
623 $tmp = $this->goLdapServerList;
625 /* Create divSelectBox for ldap server selection
626 */
627 $SelectBoxLdapServer = new divSelectBox("LdapServer");
628 $SelectBoxLdapServer->SetHeight(130);
630 /* Set first entry as selected, if $this->gotoLdapServer is empty
631 * or given entry is no longer available ...
632 */
633 $found = false;
634 foreach($tmp as $server){
635 if($this->gotoLdapServer==$server){
636 $found = true;
637 }
638 }
640 /* Add Entries
641 */
642 foreach($tmp as $key => $server){
643 $use ="";
644 if(($this->gotoLdapServer == $server) || ($found == false)) {
645 $found = true;
646 $use = " checked ";
647 };
649 $display = $server;
651 $SelectBoxLdapServer->AddEntry(
652 array(
653 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
654 "attach"=>"style='border-left:0px;'"),
655 array("string"=>$display)
656 ));
657 }
659 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
661 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
662 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
663 $smarty->assign("$val", $this->$val);
664 }
666 /* Values */
667 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
668 $smarty->assign($val, $this->$val);
669 $smarty->assign($val."ACL", chkacl($this->acl, $val));
670 }
672 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
673 $smarty->assign("FAIreleases",$this->getFAIreleases());
674 $smarty->assign("FAIrelease",$this->FAIrelease);
675 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
676 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
677 $smarty->assign("FAIclassKeys",$this->FAIclass);
678 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
680 $div = new divSelectBox("WSFAIscriptClasses");
681 $div -> SetHeight("110");
682 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
683 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
684 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
685 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
687 $i = 1;
689 if($this->FAIdebianMirror == "inherited"){
690 $tmp = $this->InheritedFAIclass;
691 }else{
692 $tmp = $this->FAIclass;
693 }
695 foreach($tmp as $class){
697 if($this->FAIdebianMirror == "inherited"){
698 $str = "";
699 }else{
700 if($i==1){
701 $str = $str_empty.$str_down.$str_remove;
702 }elseif($i == count($this->FAIclass)){
703 $str = $str_up.$str_empty.$str_remove;
704 }else{
705 $str = $str_up.$str_down.$str_remove;
706 }
707 }
708 $i ++ ;
710 $div->AddEntry(array(
711 array("string"=>$class),
712 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
713 ));
714 }
716 $smarty->assign("FAIScriptlist",$div->DrawList());
718 /* Radio button group */
719 if (preg_match("/G/", $this->bootmode)) {
720 $smarty->assign("graphicalbootup", "checked");
721 } else {
722 $smarty->assign("graphicalbootup", "");
723 }
724 if (preg_match("/T/", $this->bootmode)) {
725 $smarty->assign("textbootup", "checked");
726 } else {
727 $smarty->assign("textbootup", "");
728 }
729 if (preg_match("/D/", $this->bootmode)) {
730 $smarty->assign("debugbootup", "checked");
731 } else {
732 $smarty->assign("debugbootup", "");
733 }
735 /* ACL's */
736 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
737 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
738 }
740 /* Show main page */
741 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
742 }
744 function remove_from_parent()
745 {
746 $this->handle_post_events("remove");
747 }
749 function generateDNSyn($release)
750 {
751 $str = "";
752 $tmp = split("\/",$release);
753 $tmp = array_reverse($tmp);
755 $base = "ou=fai,ou=configs,ou=systems,";
756 foreach($tmp as $departmentname){
758 $str .= ",ou=".$departmentname;
759 }
760 $str = preg_replace("/^,/","",($str.",".$base));
762 return($str);
763 }
765 function getFAIdebianMirrors()
766 {
767 $ret = array();
768 $ret['inherited']="["._("inherited")."]";
769 $ret['auto']=_("automatic");
770 $secs = array();
772 /* Walk through all available servers
773 and check if they support the currently selected classes
774 if not, dont't add them to our list
775 */
776 foreach($this->FAIServRepConfig as $mirror => $rest){
778 $use = false;
780 if(count($this->FAIclass) == 0){
781 $use = true;
782 }else{
783 $tmp = $this->getFAIreleases();
784 foreach($tmp as $release){
785 if(isset($rest['RELEASE'][$release])){
786 $use =true;
787 }
788 }
789 }
791 /* If current server, doesn't support this class
792 remove it from list
793 */
794 if($use){
795 $ret[$mirror] = $mirror;
796 }
797 }
798 return($ret);
799 }
801 function getFAIreleases()
802 {
803 $ret = array();
805 if($this->FAIdebianMirror == "inherited") return(array());
807 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
808 $this->FAIdebianMirror = "auto";
809 }
811 $errorClasses = array();
813 if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
814 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
815 $use = true;
817 if(!count($this->FAIclass) == 0){
818 foreach($this->FAIclass as $class){
819 if(!in_array($class, $sections['PACKAGES'])){
820 $use = false;
821 $errorClasses[$class] = $class;
822 }else{
823 if(isset($errorClasses[$class])){
824 unset($errorClasses[$class]);
825 }
826 }
827 }
828 }
829 if($use){
830 $ret[$release]=$release;
831 }
832 }
833 }
834 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
836 $eClasses = " ";
837 foreach($errorClasses as $class){
838 $eClasses .= $class." ";
839 }
841 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));
842 $this->FAIdebianMirror = "auto";
843 return($this->getFAIreleases());
844 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
846 $eClasses = " ";
847 foreach($errorClasses as $class){
848 $eClasses .= $class." ";
849 }
851 $eClasses = preg_replace("/ */","",$eClasses);
853 if(!empty($eClasses)) {
854 $this->FAIclass= array();
855 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));
856 }
857 }
858 return($ret);
859 }
861 /* Save data to object */
862 function save_object()
863 {
864 plugin::save_object();
866 /* Save group radio buttons */
867 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
868 $this->bootmode= $_POST["bootmode"];
869 }
871 /* Save kernel parameters */
872 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
873 $this->customParameters= $_POST["customParameters"];
874 }
876 }
879 /* Save to LDAP */
880 function save()
881 {
883 /* Depending on the baseobject (Ogroup / WS) we
884 * use another set of objectClasses
885 * In case of WS itself, we use "array("GOhard", "FAIobject");"
886 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
887 */
888 if(isset($this->parent->by_object['ogroup'])){
889 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
890 }elseif(isset($this->parent->by_object['workgeneric'])){
891 $this->objectclasses = array("GOhard", "FAIobject");
892 }elseif(isset($this->parent->by_object['servgeneric'])){
893 $this->objectclasses = array("GOhard", "FAIobject","gotoWorkstationTemplate");
894 }else{
895 print "Object Type Configuration : unknown";
896 exit();
897 }
899 /* Find proper terminal path for tftp configuration
900 FIXME: This is suboptimal when the default has changed to
901 another location! */
902 if (($this->gotoTerminalPath == "default")){
903 $ldap= $this->config->get_ldap_link();
905 /* Strip relevant part from dn, keep trailing ',' */
906 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
907 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
909 /* Walk from top to base and try to load default values for
910 'gotoTerminalPath'. Abort when an entry is found. */
911 while (TRUE){
912 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
914 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
915 $this->config->current['BASE'], array('gotoTerminalPath'));
916 $attrs= $ldap->fetch();
917 if (isset($attrs['gotoTerminalPath'])){
918 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
919 break;
920 }
922 /* Nothing left? */
923 if ($tmp == ""){
924 break;
925 }
926 }
927 }
929 /* Add semi automatic values */
930 // FIXME: LDAP Server may not be set here...
931 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
933 switch ($this->bootmode){
934 case "D":
935 $this->gotoKernelParameters.= " debug";
936 break;
937 case "G":
938 $this->gotoKernelParameters.= " splash=silent";
939 break;
940 }
941 if ($this->customParameters != ""){
942 $this->gotoKernelParameters.= " o ".$this->customParameters;
943 }
945 plugin::save();
947 unset( $this->attrs['FAIrelease'] );
949 $str = "";
951 if($this->FAIdebianMirror == "inherited"){
953 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
955 }else{
957 foreach($this->FAIclass as $class){
958 $str .= $class." ";
959 }
960 $str .= ":" . $this->FAIrelease;
961 $this->attrs['FAIclass']= "";
962 $this->attrs['FAIclass']= trim($str);
964 if(empty($this->attrs['FAIclass'])){
965 $this->attrs['FAIclass'] = array();
966 }
967 }
969 /* Add missing arrays */
970 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
971 if (isset ($this->$val) && count ($this->$val) != 0){
973 $this->attrs["$val"]= array_unique($this->$val);
974 }
975 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
976 }
978 /* Strip out 'default' values */
979 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
980 $this->attrs['gotoLdapServer']= array();
981 }
983 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
984 $this->attrs['gotoBootKernel']= array();
985 }
987 /* if mirror == none stop saving this attribute */
988 if($this->FAIdebianMirror == "none"){
989 $this->FAIdebianMirror = "";
990 }
992 /* Get FAIstate from object, the generic tab could have changed it during execute */
993 $ldap= $this->config->get_ldap_link();
994 $ldap->cd($this->dn);
995 $ldap->cat($this->dn,array("FAIstate"));
996 $checkFAIstate = $ldap->fetch();
998 /* Remove FAI objects if no FAI class is selected */
999 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1000 $tmp = array();
1001 foreach($this->attrs['objectClass'] as $class){
1002 if($class != "FAIobject"){
1003 $tmp[] = $class;
1004 }
1005 }
1006 $this->attrs['objectClass'] = $tmp;
1007 $this->attrs['FAIclass'] = array();
1008 $this->attrs['FAIdebianMirror'] = array();
1009 }
1011 /* prepare share settings */
1012 $tmp = array();
1013 foreach($this->gotoShares as $name => $settings){
1014 $tmp2= split("\|",$name);
1015 $name = $tmp2[0];
1016 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1017 }
1018 $this->attrs['gotoShare']=$tmp;
1020 $this->cleanup();
1021 $ldap->modify ($this->attrs);
1023 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1024 $this->handle_post_events("modify");
1025 }
1027 /* Add value to array, check if unique */
1028 function add_list (&$array, $value)
1029 {
1030 if ($value != ""){
1031 $array[]= $value;
1032 sort($array);
1033 array_unique ($array);
1034 }
1035 }
1038 /* Delete value to array, check if unique */
1039 function del_list (&$array, $list)
1040 {
1041 $tmp= array();
1042 foreach ($array as $mod){
1043 if (!in_array($mod, $list)){
1044 $tmp[]= $mod;
1045 }
1046 }
1047 $array= $tmp;
1048 }
1050 /* Generate ListBox frindly output for the defined shares
1051 * Possibly Add or remove an attribute here,
1052 */
1053 function printOutAssignedShares()
1054 {
1055 $a_return = array();
1056 if(is_array($this->gotoShares)){
1057 foreach($this->gotoShares as $share){
1058 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1059 }
1060 }
1061 return($a_return);
1062 }
1065 function GetHookElements()
1066 {
1067 $ret = array();
1068 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1069 if(!empty($cmd)){
1070 $res = shell_exec($cmd);
1071 $res2 = trim($res);
1072 if((!$res)){
1073 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1074 }elseif(empty($res2)){
1075 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1076 }else{
1077 $tmp = split("\n",$res);
1078 foreach($tmp as $line){
1079 if(empty($line)) continue;
1080 $ret[]= $line;
1081 }
1082 }
1083 }
1084 return($ret);
1085 }
1088 /* Return plugin informations for acl handling */
1089 function plInfo()
1090 {
1091 return (array(
1092 "plShortName" => _("Startup"),
1093 "plDescription" => _("System startup"),
1094 "plSelfModify" => FALSE,
1095 "plDepends" => array(),
1096 "plPriority" => 0,
1097 "plSection" => array("administration"),
1098 "plCategory" => array("workstation","server","ogroups"),
1100 "plProvidedAcls"=> array(
1101 "gotoLdapServer" => _("Ldap server"),
1102 "gotoBootKernel" => _("Boot kernel"),
1103 "gotoKernelParameters" => _("Kernel parameter"),
1104 "FAIclass" => _("FAI classes"),
1105 "FAIstatus" => _("FAI status flag"),
1106 "gotoShare" => _("Shares"),
1107 "FAIdebianMirror" => _("Debian mirror"),
1108 "FAIrelease" => _("Debian release"))
1109 ));
1110 }
1111 }
1113 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1114 ?>