ef0244274ed5e61fb09bec445d83698d12d15889
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 $ui = get_userinfo();
71 $res = get_list( "(|(objectClass=FAIpackageList)".
72 "(objectClass=FAItemplate)".
73 "(objectClass=FAIvariable)".
74 "(objectClass=FAIscript)".
75 "(objectClass=FAIhook)".
76 "(objectClass=FAIprofile)".
77 "(objectClass=FAIpartitionTable))",
78 $ui->subtreeACL,$this->config->current['BASE'],
79 array("cn","objectClass","FAIdebianSection"));
81 foreach($res as $attr){
82 $cn = $attr['cn'][0];
84 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
86 if(in_array('FAIpackageList',$attr['objectClass'])){
87 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
88 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
89 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
90 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
91 }
92 if(in_array('FAItemplate',$attr['objectClass'])){
93 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
94 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
95 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
96 }
97 if(in_array('FAIvariable',$attr['objectClass'])){
98 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
99 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
100 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
101 }
102 if(in_array('FAIscript',$attr['objectClass'])){
103 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
104 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
105 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
106 }
107 if(in_array('FAIhook',$attr['objectClass'])){
108 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
109 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
110 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
111 }
112 if(in_array('FAIpartitionTable',$attr['objectClass'])){
113 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
114 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
115 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
116 }
117 if(in_array('FAIprofile',$attr['objectClass'])){
118 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
119 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
120 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
121 }
122 }
123 if(is_array($this->FAIclasses)){
124 natcasesort($this->FAIclasses);
125 }
127 if(isset($tmp2)){
128 $this->FAIclassInfo = $tmp2;
129 } else {
130 $this->FAIclassInfo = array();
131 }
133 /* Build up an array like this one :
134 [$url]['SERVER'] = 'srv1-002';
135 [$url]['RELEASE']['siga/rc9.0.2']
136 ['SECTIONS'][0] "main";
137 ['SECTIONS'][1] "non-free";
138 [$url]['RELEASE']['siga/rc9.0.2']
139 ['PACKAGES'][0] "pkg1";
140 ['PACKAGES'][1] "postfix";
141 */
143 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
144 $test = array();
145 while($attr = $ldap->fetch()){
146 if(isset($attr['FAIrepository'])){
148 unset($attr['FAIrepository']['count']);
150 foreach($attr['FAIrepository'] as $rep){
151 $tmp = split("\|",$rep);
153 if(count($tmp)==4){
154 $sections = split(",",$tmp[3]);
155 $release = $tmp[2];
156 $server = $tmp[1];
157 $url = $tmp[0];
159 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
161 /* Result will be cached
162 */
163 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
164 $test[$url]['SERVER'] = $server;
166 /* auto gets all releases/classes
167 */
168 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
169 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
170 }
171 }
172 }
173 }
175 /* Add possible elements from hook */
176 $lines= $this->GetHookElements();
177 foreach ($lines as $hline){
178 $entries= split(";", $hline);
179 if (isset($entries[1]) && !isset($test[$entries[1]])){
180 $test[$entries[1]]['RELEASE']= array();
182 /* Split releases */
183 if (isset($entries[2])){
184 $releases= split(",", $entries[2]);
186 foreach ($releases as $release){
187 $rname= preg_replace('/:.*$/', '', $release);
188 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
189 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
190 $test[$entries[1]]['RELEASE'][$rname]= array();
191 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
192 foreach ($classes as $class){
193 if ($class != ""){
194 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
195 }
196 }
197 }
198 }
199 }
200 }
202 $this->FAIServRepConfig= $test;
204 /* Get arrays */
205 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
206 if (isset($this->attrs["$val"]["count"])){
207 for ($i= 0; $i<$this->attrs["count"]; $i++){
208 if (isset($this->attrs["$val"][$i])){
209 array_push($this->$val, $this->attrs["$val"][$i]);
210 }
211 }
212 }
213 sort ($this->$val);
214 $this->$val= array_unique($this->$val);
215 }
217 /* Parse Kernel Parameters to decide what boot mode is enabled */
218 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
219 $this->bootmode= "G";
220 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
221 $this->bootmode= "D";
222 } elseif ($this->gotoKernelParameters == "") {
223 $this->bootmode= "G";
224 } else {
225 $this->bootmode= "T";
226 }
227 if (preg_match("/ o /", $this->gotoKernelParameters)){
228 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
229 } else {
230 $this->customParameters= "";
231 }
233 /* Prepare Shares */
234 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
235 unset($this->attrs['gotoShare']['count']);
236 foreach($this->attrs['gotoShare'] as $share){
237 $tmp = $tmp2 = array();
238 $tmp = split("\|",$share);
239 $tmp2['server'] =$tmp[0];
240 $tmp2['name'] =$tmp[1];
241 $tmp2['mountPoint'] =$tmp[2];
242 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
243 }
244 }
246 $this->gotoShareSelections= $config->getShareList(true);
247 $this->gotoAvailableShares= $config->getShareList(false);
248 $tmp2 = array();
250 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
251 $tmp = array();
252 $tmp = split(" ",$this->FAIclass);
253 $tmp2 =array();
255 foreach($tmp as $class){
256 if( ":" == $class[0] ) {
257 $this->FAIrelease = substr( $class, 1 );
258 }
259 else
260 $tmp2[$class] = $class;
261 }
262 $this->FAIclass = $tmp2;
263 }
265 if(!is_array($this->FAIclass)){
266 $this->FAIclass =array();
267 }
269 $this->orig_dn= $this->dn;
271 /* Handle inheritance value "default" */
272 $this->gotoBootKernels= array("%default%" => '['._("inherited").']');
275 /* Load hardware list */
276 $ldap= $this->config->get_ldap_link();
277 $ldap->cd($this->config->current['BASE']);
278 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
279 if ($ldap->count() == 1){
280 $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
281 $attrs= $ldap->fetch();
283 foreach ($map as $name){
284 if (!isset($attrs[$name][0])){
285 continue;
286 }
288 switch ($name){
289 case 'gotoLdapServer':
290 $this->goLdapServerList= array_merge(array('default' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
291 break;
293 case 'gotoBootKernel':
294 $this->gotoBootKernels['%default%']= _("inherited").' ['.$attrs[$name][0].']' ;
295 break;
297 case 'FAIclass':
298 $str = split(":",$attrs[$name][0]);
299 $this->InheritedFAIclass = split("\ ",trim($str[0]));
300 $this->InheritedFAIrelease = trim($str[1]);
301 break;
303 case 'FAIdebianMirror':
304 $this->InheritedFAIdebianMirror = $attrs[$name][0];
305 break;
306 }
307 }
308 }
310 /* Get list of boot kernels */
311 if (isset($this->config->data['TABS'])){
312 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
314 if (!check_command($command)){
315 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
316 get_class($this));
317 } else {
319 $fh= popen($command, "r");
320 while (!feof($fh)) {
321 $buffer= trim(fgets($fh, 256));
322 if ($buffer != ""){
323 $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
324 }
325 }
326 pclose($fh);
327 }
328 }
330 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
331 $this->FAIdebianMirror = "inherited";
332 }
333 }
336 /* This class is called by the contrucktor ONLY.
337 * It return the available classes for each
338 * Server / Release combination ...
339 * (Release specifies which classes are available)
340 */
341 function getAvailableClassesForThisRelease($release)
342 {
343 /* There could be more than one server providing this release,
344 so use cached result if available
345 */
346 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
347 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
348 }
350 /* Walk through cache and get out what we need.
351 *
352 * Function od : "$this->generateDNSyn($release)"
353 * It returns an array like this one :
354 * array("ou=packges,ou=rc0.9.2,ou=siga,",
355 * "ou=scripts.. "
356 * ...);
357 * This helps us to select the correct classes for each release.
358 * It prevents errors like: 'siga' is selected as release, but all classes
359 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
360 */
361 $tmp2 = $this->generateDNSyn($release) ;
362 $test2 = array();
363 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
364 foreach($tmp2 as $dns){
365 if(preg_match("/".$dns."/",$attr['dn'])){
366 $test2[$attr['cn'][0]] = $attr['cn'][0];
367 }
368 }
369 }
370 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
371 return($test2);
372 }
375 /* Create array to display available classes/profiles in a selectbox
376 * This function only displays the available classes.
377 * If a class is available is defined by these facts :
378 * 1. Is this class available for the selected release ?
379 * - if it is available, check if the release is available for the selected server
380 * (done by $this->getFAIreleases())
381 * 2. Is this class currently not assigned to $this->FAIclass
382 */
383 function selectFriendlyClasses(){
384 $tmp=array();
386 if($this->FAIdebianMirror == "inherited") return($tmp);
388 /* check if the current release exists,
389 else select the first one ..
390 */
391 $tmp2 = $this->getFAIreleases();
392 if(!in_array($this->FAIrelease, $tmp2)){
393 $this->FAIrelease = key($tmp2);
394 }
396 /* Get all Packages for this server/release combination
397 */
398 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
399 $pkgs = array();
400 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
401 }else{
402 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
403 }
405 /* Check each and every single class name
406 */
407 foreach($pkgs as $pkg){
409 /* Class already assigned to the classes list ?
410 * If not ... go on
411 */
412 if(!in_array($pkg,$this->FAIclass)){
414 /* Create the displayed list entry value
415 HKLMOP [-Pl P V T-] or something like that
416 */
417 $str = "";
418 foreach($this->FAIclassInfo[$pkg] as $entry){
419 if(isset($entry['kzl'])){
420 $str .= $entry['kzl']." ";
421 }
422 }
424 /* Append class if everyting was fine
425 */
426 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
427 }
428 }
429 /* Just sort and return new classes list ...
430 ( possibly we should cache the result ... )
431 */
432 natcasesort ($tmp);
433 return($tmp);
434 }
436 function check()
437 {
438 $messages = array();
440 /* Call common method to give check the hook */
441 $messages= plugin::check();
443 /* If there are packages selected, but no mirror show error */
444 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
445 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
446 }
448 return($messages);
449 }
451 function execute()
452 {
454 /* Call parent execute */
455 plugin::execute();
457 /* Do we need to flip is_account state? */
458 if (isset($_POST['modify_state'])){
459 $this->is_account= !$this->is_account;
460 }
462 /* Do we represent a valid terminal? */
463 if (!$this->is_account && $this->parent == NULL){
464 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
465 _("This 'dn' has no terminal features.")."</b>";
466 return ($display);
467 }
469 /* Add module */
470 if (isset ($_POST['add_module'])){
471 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
472 $this->add_list ($this->gotoModules, $_POST['module']);
473 }
474 }
476 /* Delete module */
477 if (isset ($_POST['delete_module'])){
478 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
479 $this->del_list ($this->gotoModules, $_POST['modules_list']);
480 }
481 }
483 /* FAI class management */
484 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
485 $found = 0 ;
487 /* If this new class/profile will attach a second partition table
488 * to our list of classes, abort and show a message.
489 */
490 foreach($this->FAIclass as $name){
491 if(isset($this->FAIclassInfo[$name])){
492 foreach($this->FAIclassInfo[$name] as $atr){
493 if(isset($atr['obj'])){
494 if($atr['obj'] == "FAIpartitionTable"){
495 $found ++ ;
496 }
497 }
498 }
499 }
500 }
502 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
503 print_red(_("There is already a profile in your selection that contain partition table configurations."));
504 }else{
505 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
506 }
507 }
509 $sort = false;
510 foreach($_POST as $name => $val){
512 $sort_type = false;
513 if((preg_match("/sort_up/",$name))&&(!$sort)){
514 $sort_type = "sort_up_";
515 }
516 if((preg_match("/sort_down/",$name))&&(!$sort)){
517 $sort_type = "sort_down_";
518 }
520 if(($sort_type)&&(!$sort)){
521 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
522 $sort = true;
524 $last = -1;
525 $change_down = -1;
527 /* Create array with numeric index */
528 $tmp = array();
529 foreach($this->FAIclass as $class){
530 $tmp [] = $class;
531 }
533 /* Walk trough array */
534 foreach($tmp as $key => $faiName){
535 if($faiName == $value){
536 if($sort_type == "sort_up_"){
537 if($last != -1){
538 $change_down= $last;
539 }
540 }else{
541 if(isset($tmp[$key+1])){
542 $change_down = $key;
543 }
544 }
545 }
546 $last = $key;
547 }
549 $tmp2 = array();
550 $skip = false;
552 foreach($tmp as $ky => $vl){
554 if($ky == $change_down){
555 $skip = $vl;
556 }else{
557 $tmp2[$vl] = $vl;
558 }
559 if(($skip != false)&&($ky != $change_down)){
560 $tmp2[$skip] = $skip;
561 $skip =false;
562 }
563 }
564 $this->FAIclass = $tmp2;
565 }
567 if(preg_match("/fai_remove/i",$name)){
568 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
569 unset($this->FAIclass[$value]);
570 }
571 }
573 /* Show main page */
574 $smarty= get_smarty();
575 $smarty->assign("SelectBoxLdapServer","");
577 /* In this section server shares will be defined
578 * A user can select one of the given shares and a mount point
579 * and attach this combination to his setup.
580 */
581 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
582 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
584 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
585 * This entry will be, a combination of mountPoint and sharedefinitions
586 */
587 if(isset($_POST['gotoShareAdd'])){
588 /* We assign a share to this user, if we don't know where to mount the share */
589 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
590 print_red(_("You must specify a valid mount point."));
591 }else{
592 if(count($this->gotoAvailableShares)){
593 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
594 $s_mount = $_POST['gotoShareMountPoint'];
595 /* Preparing the new assignment */
596 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
597 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
598 }
599 }
600 }
602 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
603 * If there is no defined share selected, we will abort the deletion without any message
604 */
605 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
606 unset($this->gotoShares[$_POST['gotoShare']]);
607 }
609 $smarty->assign("gotoShares",$this->printOutAssignedShares());
610 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
611 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
612 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
614 /* Arrays */
615 $tmp = $this->goLdapServerList;
617 /* Create divSelectBox for ldap server selection
618 */
619 $SelectBoxLdapServer = new divSelectBox("LdapServer");
620 $SelectBoxLdapServer->SetHeight(130);
622 /* Set first entry as selected, if $this->gotoLdapServer is empty
623 * or given entry is no longer available ...
624 */
625 $found = false;
626 foreach($tmp as $server){
627 if($this->gotoLdapServer==$server){
628 $found = true;
629 }
630 }
632 /* Add Entries
633 */
634 foreach($tmp as $key => $server){
635 $use ="";
636 if(($this->gotoLdapServer == $server) || ($found == false)) {
637 $found = true;
638 $use = " checked ";
639 };
641 $display = $server;
643 $SelectBoxLdapServer->AddEntry(
644 array(
645 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
646 "attach"=>"style='border-left:0px;'"),
647 array("string"=>$display)
648 ));
649 }
651 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
653 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
654 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
655 $smarty->assign("$val", $this->$val);
656 }
658 /* Values */
659 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
660 $smarty->assign($val, $this->$val);
661 $smarty->assign($val."ACL", chkacl($this->acl, $val));
662 }
664 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
665 $smarty->assign("FAIreleases",$this->getFAIreleases());
666 $smarty->assign("FAIrelease",$this->FAIrelease);
667 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
668 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
669 $smarty->assign("FAIclassKeys",$this->FAIclass);
670 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
672 $div = new divSelectBox("WSFAIscriptClasses");
673 $div -> SetHeight("110");
674 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
675 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
676 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
677 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
679 $i = 1;
681 if($this->FAIdebianMirror == "inherited"){
682 $tmp = $this->InheritedFAIclass;
683 }else{
684 $tmp = $this->FAIclass;
685 }
687 foreach($tmp as $class){
689 if($this->FAIdebianMirror == "inherited"){
690 $str = "";
691 }else{
692 if($i==1){
693 $str = $str_empty.$str_down.$str_remove;
694 }elseif($i == count($this->FAIclass)){
695 $str = $str_up.$str_empty.$str_remove;
696 }else{
697 $str = $str_up.$str_down.$str_remove;
698 }
699 }
700 $i ++ ;
702 $div->AddEntry(array(
703 array("string"=>$class),
704 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
705 ));
706 }
708 $smarty->assign("FAIScriptlist",$div->DrawList());
710 /* Radio button group */
711 if (preg_match("/G/", $this->bootmode)) {
712 $smarty->assign("graphicalbootup", "checked");
713 } else {
714 $smarty->assign("graphicalbootup", "");
715 }
716 if (preg_match("/T/", $this->bootmode)) {
717 $smarty->assign("textbootup", "checked");
718 } else {
719 $smarty->assign("textbootup", "");
720 }
721 if (preg_match("/D/", $this->bootmode)) {
722 $smarty->assign("debugbootup", "checked");
723 } else {
724 $smarty->assign("debugbootup", "");
725 }
727 /* ACL's */
728 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
729 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
730 }
732 /* Show main page */
733 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
734 }
736 function remove_from_parent()
737 {
738 $this->handle_post_events("remove");
739 }
741 function generateDNSyn($release)
742 {
743 $str = "";
744 $tmp = split("\/",$release);
745 $tmp = array_reverse($tmp);
747 $base = ",ou=fai,";
749 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
751 foreach($tmp as $departmentname){
753 $str .= ",ou=".$departmentname;
754 }
755 $ret = array();
756 foreach($arr as $ar){
757 $ret[] = ",ou=".$ar.$str.$base;
758 }
759 return($ret);
760 }
762 function getFAIdebianMirrors()
763 {
764 $ret = array();
765 $ret['inherited']="["._("inherited")."]";
766 $ret['auto']=_("automatic");
767 $secs = array();
769 /* Walk through all available servers
770 and check if they support the currently selected classes
771 if not, dont't add them to our list
772 */
773 foreach($this->FAIServRepConfig as $mirror => $rest){
775 $use = false;
777 if(count($this->FAIclass) == 0){
778 $use = true;
779 }else{
780 $tmp = $this->getFAIreleases();
781 foreach($tmp as $release){
782 if(isset($rest['RELEASE'][$release])){
783 $use =true;
784 }
785 }
786 }
788 /* If current server, doesn't support this class
789 remove it from list
790 */
791 if($use){
792 $ret[$mirror] = $mirror;
793 }
794 }
795 return($ret);
796 }
798 function getFAIreleases()
799 {
800 $ret = array();
802 if($this->FAIdebianMirror == "inherited") return(array());
804 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
805 $this->FAIdebianMirror = "auto";
806 }
808 $errorClasses = "";
810 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
811 $use = true;
813 if(!count($this->FAIclass) == 0){
814 foreach($this->FAIclass as $class){
815 if(!in_array($class, $sections['PACKAGES'])){
816 $use = false;
817 $errorClasses[$class] = $class;
818 }else{
819 if(isset($errorClasses[$class])){
820 unset($errorClasses[$class]);
821 }
822 }
823 }
824 }
825 if($use){
826 $ret[$release]=$release;
827 }
828 }
829 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
831 $eClasses = " ";
832 foreach($errorClasses as $class){
833 $eClasses .= $class." ";
834 }
836 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));
837 $this->FAIdebianMirror = "auto";
838 return($this->getFAIreleases());
839 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
841 $eClasses = " ";
842 foreach($errorClasses as $class){
843 $eClasses .= $class." ";
844 }
846 $this->FAIclass= array();
847 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));
848 }
849 return($ret);
850 }
852 /* Save data to object */
853 function save_object()
854 {
855 plugin::save_object();
857 /* Save group radio buttons */
858 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
859 $this->bootmode= $_POST["bootmode"];
860 }
862 /* Save kernel parameters */
863 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
864 $this->customParameters= $_POST["customParameters"];
865 }
867 }
870 /* Save to LDAP */
871 function save()
872 {
874 /* Depending on the baseobject (Ogroup / WS) we
875 * use another set of objectClasses
876 * In case of WS itself, we use "array("GOhard", "FAIobject");"
877 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
878 */
879 if(isset($this->parent->by_object['ogroup'])){
880 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
881 }elseif(isset($this->parent->by_object['workgeneric'])){
882 $this->objectclasses = array("GOhard", "FAIobject");
883 }elseif(isset($this->parent->by_object['servgeneric'])){
884 $this->objectclasses = array("GOhard", "FAIobject");
885 }else{
886 print "Object Type Configuration : unknown";
887 exit();
888 }
890 /* Find proper terminal path for tftp configuration
891 FIXME: This is suboptimal when the default has changed to
892 another location! */
893 if (($this->gotoTerminalPath == "default")){
894 $ldap= $this->config->get_ldap_link();
896 /* Strip relevant part from dn, keep trailing ',' */
897 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
898 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
900 /* Walk from top to base and try to load default values for
901 'gotoTerminalPath'. Abort when an entry is found. */
902 while (TRUE){
903 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
905 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
906 $this->config->current['BASE'], array('gotoTerminalPath'));
907 $attrs= $ldap->fetch();
908 if (isset($attrs['gotoTerminalPath'])){
909 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
910 break;
911 }
913 /* Nothing left? */
914 if ($tmp == ""){
915 break;
916 }
917 }
918 }
920 /* Add semi automatic values */
921 // FIXME: LDAP Server may not be set here...
922 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
924 switch ($this->bootmode){
925 case "D":
926 $this->gotoKernelParameters.= " debug";
927 break;
928 case "G":
929 $this->gotoKernelParameters.= " splash=silent";
930 break;
931 }
932 if ($this->customParameters != ""){
933 $this->gotoKernelParameters.= " o ".$this->customParameters;
934 }
936 plugin::save();
938 unset( $this->attrs['FAIrelease'] );
940 $str = "";
942 if($this->FAIdebianMirror == "inherited"){
944 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
946 }else{
948 foreach($this->FAIclass as $class){
949 $str .= $class." ";
950 }
951 $str .= ":" . $this->FAIrelease;
952 $this->attrs['FAIclass']= "";
953 $this->attrs['FAIclass']= trim($str);
955 if(empty($this->attrs['FAIclass'])){
956 $this->attrs['FAIclass'] = array();
957 }
958 }
960 /* Add missing arrays */
961 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
962 if (isset ($this->$val) && count ($this->$val) != 0){
964 $this->attrs["$val"]= array_unique($this->$val);
965 }
966 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
967 }
969 /* Strip out 'default' values */
970 if ($this->attrs['gotoLdapServer'] == "default"){
971 $this->attrs['gotoLdapServer']= array();
972 }
974 if (($this->attrs['gotoBootKernel'] == "default") || ($this->attrs['gotoBootKernel'] == "%default%")){
975 $this->attrs['gotoBootKernel']= array();
976 }
978 /* if mirror == none stop saving this attribute */
979 if($this->FAIdebianMirror == "none"){
980 $this->FAIdebianMirror = "";
981 }
983 /* Get FAIstate from object, the generic tab could have changed it during execute */
984 $ldap= $this->config->get_ldap_link();
985 $ldap->cd($this->dn);
986 $ldap->cat($this->dn,array("FAIstate"));
987 $checkFAIstate = $ldap->fetch();
989 /* Remove FAI objects if no FAI class is selected */
990 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
991 $tmp = array();
992 foreach($this->attrs['objectClass'] as $class){
993 if($class != "FAIobject"){
994 $tmp[] = $class;
995 }
996 }
997 $this->attrs['objectClass'] = $tmp;
998 $this->attrs['FAIclass'] = array();
999 $this->attrs['FAIdebianMirror'] = array();
1000 }
1002 /* prepare share settings */
1003 $tmp = array();
1004 foreach($this->gotoShares as $name => $settings){
1005 $tmp2= split("\|",$name);
1006 $name = $tmp2[0];
1007 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1008 }
1009 $this->attrs['gotoShare']=$tmp;
1011 $this->cleanup();
1012 $ldap->modify ($this->attrs);
1014 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1015 $this->handle_post_events("modify");
1016 }
1018 /* Add value to array, check if unique */
1019 function add_list (&$array, $value)
1020 {
1021 if ($value != ""){
1022 $array[]= $value;
1023 sort($array);
1024 array_unique ($array);
1025 }
1026 }
1029 /* Delete value to array, check if unique */
1030 function del_list (&$array, $list)
1031 {
1032 $tmp= array();
1033 foreach ($array as $mod){
1034 if (!in_array($mod, $list)){
1035 $tmp[]= $mod;
1036 }
1037 }
1038 $array= $tmp;
1039 }
1041 /* Generate ListBox frindly output for the defined shares
1042 * Possibly Add or remove an attribute here,
1043 */
1044 function printOutAssignedShares()
1045 {
1046 $a_return = array();
1047 if(is_array($this->gotoShares)){
1048 foreach($this->gotoShares as $share){
1049 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1050 }
1051 }
1052 return($a_return);
1053 }
1056 function GetHookElements()
1057 {
1058 $ret = array();
1059 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1060 if(!empty($cmd)){
1061 $res = shell_exec($cmd);
1062 $res2 = trim($res);
1063 if((!$res)){
1064 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1065 }elseif(empty($res2)){
1066 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1067 }else{
1068 $tmp = split("\n",$res);
1069 foreach($tmp as $line){
1070 if(empty($line)) continue;
1071 $ret[]= $line;
1072 }
1073 }
1074 }
1075 return($ret);
1076 }
1078 }
1080 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1081 ?>