812a48982592ef4df973562f09cbee2308fc918d
1 <?php
3 class workstartup extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage terminal startup options";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* Generic terminal attributes */
11 var $bootmode = "G";
12 var $goLdapServerList = array();
13 var $gotoBootKernel = "default-inherited";
14 var $gotoKernelParameters = "";
15 var $gotoLdapServer = "default-inherited";
16 var $gotoModules = array();
17 var $gotoAutoFs = array();
18 var $gotoFilesystem = array();
19 var $gotoTerminalPath = "";
20 var $FAIstatus = "";
21 var $gotoBootKernels = array();
23 /* attribute list for save action */
24 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
25 var $objectclasses = array("GOhard", "FAIobject");
27 /* Share */
28 var $gotoShares = array();// Currently Share Option
29 var $gotoShare = ""; // currently selected Share Option
30 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
31 var $gotoAvailableShares= array();// Available Shares for this account
33 /* Helper */
34 var $customParameters = "";
35 var $orig_dn = "";
36 var $ignore_account = TRUE;
38 /* FAI class selection */
39 var $FAIclass = array();
40 var $FAIclasses = array();
41 var $FAIclassInfo = array();
42 var $FAIrelease = "";
43 var $FAIdebianMirror = "auto";
46 /* FAI class selection */
47 var $InheritedFAIclass = array();
48 var $InheritedFAIrelease = "";
49 var $InheritedFAIdebianMirror = "auto";
51 /* Contains all possible server/release/class settings */
52 var $FAIServRepConfig = array();
54 function workstartup ($config, $dn= NULL, $parent= NULL)
55 {
56 plugin::plugin ($config, $dn, $parent);
58 /* Creating a list of valid Mirrors
59 * none will not be saved to ldap.
60 */
61 $ldap = $this->config->get_ldap_link();
62 $ldap->cd($this->config->current['BASE']);
64 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
65 $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
66 }
68 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
69 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
71 $ui = get_userinfo();
72 $res = get_list( "(|(objectClass=FAIpackageList)".
73 "(objectClass=FAItemplate)".
74 "(objectClass=FAIvariable)".
75 "(objectClass=FAIscript)".
76 "(objectClass=FAIhook)".
77 "(objectClass=FAIprofile)".
78 "(objectClass=FAIpartitionTable))",
79 $ui->subtreeACL,$this->config->current['BASE'],
80 array("cn","objectClass","FAIdebianSection"));
82 foreach($res as $attr){
83 $cn = $attr['cn'][0];
85 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
87 if(in_array('FAIpackageList',$attr['objectClass'])){
88 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
89 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
90 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
91 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
92 }
93 if(in_array('FAItemplate',$attr['objectClass'])){
94 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
95 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
96 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
97 }
98 if(in_array('FAIvariable',$attr['objectClass'])){
99 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
100 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
101 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
102 }
103 if(in_array('FAIscript',$attr['objectClass'])){
104 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
105 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
106 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
107 }
108 if(in_array('FAIhook',$attr['objectClass'])){
109 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
110 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
111 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
112 }
113 if(in_array('FAIpartitionTable',$attr['objectClass'])){
114 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
115 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
116 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
117 }
118 if(in_array('FAIprofile',$attr['objectClass'])){
119 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
120 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
121 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
122 }
123 }
124 if(is_array($this->FAIclasses)){
125 natcasesort($this->FAIclasses);
126 }
128 if(isset($tmp2)){
129 $this->FAIclassInfo = $tmp2;
130 } else {
131 $this->FAIclassInfo = array();
132 }
134 /* Build up an array like this one :
135 [$url]['SERVER'] = 'srv1-002';
136 [$url]['RELEASE']['siga/rc9.0.2']
137 ['SECTIONS'][0] "main";
138 ['SECTIONS'][1] "non-free";
139 [$url]['RELEASE']['siga/rc9.0.2']
140 ['PACKAGES'][0] "pkg1";
141 ['PACKAGES'][1] "postfix";
142 */
144 $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
145 $test = array();
146 while($attr = $ldap->fetch()){
147 if(isset($attr['FAIrepository'])){
149 unset($attr['FAIrepository']['count']);
151 foreach($attr['FAIrepository'] as $rep){
152 $tmp = split("\|",$rep);
154 if(count($tmp)==4){
155 $sections = split(",",$tmp[3]);
156 $release = $tmp[2];
157 $server = $tmp[1];
158 $url = $tmp[0];
160 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
162 /* Result will be cached
163 */
164 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
165 $test[$url]['SERVER'] = $server;
167 /* auto gets all releases/classes
168 */
169 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
170 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
171 }
172 }
173 }
174 }
176 /* Add possible elements from hook */
177 $lines= $this->GetHookElements();
178 foreach ($lines as $hline){
179 $entries= split(";", $hline);
180 if (isset($entries[1]) && !isset($test[$entries[1]])){
181 $test[$entries[1]]['RELEASE']= array();
183 /* Split releases */
184 if (isset($entries[2])){
185 $releases= split(",", $entries[2]);
187 foreach ($releases as $release){
188 $rname= preg_replace('/:.*$/', '', $release);
189 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
190 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
191 $test[$entries[1]]['RELEASE'][$rname]= array();
192 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
193 foreach ($classes as $class){
194 if ($class != ""){
195 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
196 }
197 }
198 }
199 }
200 }
201 }
203 $this->FAIServRepConfig= $test;
205 /* Get arrays */
206 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
207 if (isset($this->attrs["$val"]["count"])){
208 for ($i= 0; $i<$this->attrs["count"]; $i++){
209 if (isset($this->attrs["$val"][$i])){
210 array_push($this->$val, $this->attrs["$val"][$i]);
211 }
212 }
213 }
214 sort ($this->$val);
215 $this->$val= array_unique($this->$val);
216 }
218 /* Parse Kernel Parameters to decide what boot mode is enabled */
219 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
220 $this->bootmode= "G";
221 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
222 $this->bootmode= "D";
223 } elseif ($this->gotoKernelParameters == "") {
224 $this->bootmode= "G";
225 } else {
226 $this->bootmode= "T";
227 }
228 if (preg_match("/ o /", $this->gotoKernelParameters)){
229 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
230 } else {
231 $this->customParameters= "";
232 }
234 /* Prepare Shares */
235 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
236 unset($this->attrs['gotoShare']['count']);
237 foreach($this->attrs['gotoShare'] as $share){
238 $tmp = $tmp2 = array();
239 $tmp = split("\|",$share);
240 $tmp2['server'] =$tmp[0];
241 $tmp2['name'] =$tmp[1];
242 $tmp2['mountPoint'] =$tmp[2];
243 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
244 }
245 }
247 $this->gotoShareSelections= $config->getShareList(true);
248 $this->gotoAvailableShares= $config->getShareList(false);
249 $tmp2 = array();
251 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
252 $tmp = array();
253 $tmp = split(" ",$this->FAIclass);
254 $tmp2 =array();
256 foreach($tmp as $class){
257 if( ":" == $class[0] ) {
258 $this->FAIrelease = substr( $class, 1 );
259 }
260 else
261 $tmp2[$class] = $class;
262 }
263 $this->FAIclass = $tmp2;
264 }
266 if(!is_array($this->FAIclass)){
267 $this->FAIclass =array();
268 }
270 $this->orig_dn= $this->dn;
272 /* Handle inheritance value "default" */
273 $this->gotoBootKernels= array();
276 /* Load hardware list */
277 $ldap= $this->config->get_ldap_link();
278 $ldap->cd($this->config->current['BASE']);
279 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
280 if ($ldap->count() == 1){
281 $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
282 $attrs= $ldap->fetch();
284 foreach ($map as $name){
285 if (!isset($attrs[$name][0])){
286 continue;
287 }
289 switch ($name){
290 case 'gotoLdapServer':
291 $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
292 break;
294 case 'gotoBootKernel':
295 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
296 break;
298 case 'FAIclass':
299 $str = split(":",$attrs[$name][0]);
300 $this->InheritedFAIclass = split("\ ",trim($str[0]));
301 $this->InheritedFAIrelease = trim($str[1]);
302 break;
304 case 'FAIdebianMirror':
305 $this->InheritedFAIdebianMirror = $attrs[$name][0];
306 break;
307 }
308 }
309 }
311 /* Get list of boot kernels */
312 if (isset($this->config->data['TABS'])){
313 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
315 if (!check_command($command)){
316 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
317 get_class($this));
318 } else {
320 $first = false;
321 $fh= popen($command, "r");
322 while (!feof($fh)) {
323 $buffer= trim(fgets($fh, 256));
325 if(!empty($buffer)){
327 $name=$value = $buffer;
328 if(preg_match("/:/",$buffer)){
329 $name = preg_replace("/:.*$/","",$buffer);
330 $value= preg_replace("/^.*:/","",$buffer);
331 $this->gotoBootKernels[$name]= $name.":".$value;
332 }else{
333 $this->gotoBootKernels[$name]= $value;
334 }
335 if($this->gotoBootKernel =="" ){
336 $this->gotoBootKernel = $name;
337 }
339 }
340 }
341 pclose($fh);
342 }
343 }
345 /* Turn to default, if we've nothing to inherit */
346 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
347 $this->gotoBootKernel= "default";
348 }
350 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
351 $this->FAIdebianMirror = "inherited";
352 }
353 }
356 /* This class is called by the contrucktor ONLY.
357 * It return the available classes for each
358 * Server / Release combination ...
359 * (Release specifies which classes are available)
360 */
361 function getAvailableClassesForThisRelease($release)
362 {
363 /* There could be more than one server providing this release,
364 so use cached result if available
365 */
366 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
367 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
368 }
370 /* Walk through cache and get out what we need.
371 *
372 * Function od : "$this->generateDNSyn($release)"
373 * It returns an array like this one :
374 * array("ou=packges,ou=rc0.9.2,ou=siga,",
375 * "ou=scripts.. "
376 * ...);
377 * This helps us to select the correct classes for each release.
378 * It prevents errors like: 'siga' is selected as release, but all classes
379 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
380 */
381 $tmp2 = $this->generateDNSyn($release) ;
382 $test2 = array();
383 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
384 foreach($tmp2 as $dns){
385 if(preg_match("/".$dns."/",$attr['dn'])){
386 $test2[$attr['cn'][0]] = $attr['cn'][0];
387 }
388 }
389 }
390 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
391 return($test2);
392 }
395 /* Create array to display available classes/profiles in a selectbox
396 * This function only displays the available classes.
397 * If a class is available is defined by these facts :
398 * 1. Is this class available for the selected release ?
399 * - if it is available, check if the release is available for the selected server
400 * (done by $this->getFAIreleases())
401 * 2. Is this class currently not assigned to $this->FAIclass
402 */
403 function selectFriendlyClasses(){
404 $tmp=array();
406 if($this->FAIdebianMirror == "inherited") return($tmp);
408 /* check if the current release exists,
409 else select the first one ..
410 */
411 $tmp2 = $this->getFAIreleases();
412 if(!in_array($this->FAIrelease, $tmp2)){
413 $this->FAIrelease = key($tmp2);
414 }
416 /* Get all Packages for this server/release combination
417 */
418 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
419 $pkgs = array();
420 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
421 }else{
422 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
423 }
425 /* Check each and every single class name
426 */
427 foreach($pkgs as $pkg){
429 /* Class already assigned to the classes list ?
430 * If not ... go on
431 */
432 if(!in_array($pkg,$this->FAIclass)){
434 /* Create the displayed list entry value
435 HKLMOP [-Pl P V T-] or something like that
436 */
437 $str = "";
438 foreach($this->FAIclassInfo[$pkg] as $entry){
439 if(isset($entry['kzl'])){
440 $str .= $entry['kzl']." ";
441 }
442 }
444 /* Append class if everyting was fine
445 */
446 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
447 }
448 }
449 /* Just sort and return new classes list ...
450 ( possibly we should cache the result ... )
451 */
452 natcasesort ($tmp);
453 return($tmp);
454 }
456 function check()
457 {
458 $messages = array();
460 /* Call common method to give check the hook */
461 $messages= plugin::check();
463 /* If there are packages selected, but no mirror show error */
464 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
465 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
466 }
468 return($messages);
469 }
471 function execute()
472 {
474 /* Call parent execute */
475 plugin::execute();
477 /* Do we need to flip is_account state? */
478 if (isset($_POST['modify_state'])){
479 $this->is_account= !$this->is_account;
480 }
482 /* Do we represent a valid terminal? */
483 if (!$this->is_account && $this->parent == NULL){
484 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
485 _("This 'dn' has no terminal features.")."</b>";
486 return ($display);
487 }
489 /* Add module */
490 if (isset ($_POST['add_module'])){
491 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
492 $this->add_list ($this->gotoModules, $_POST['module']);
493 }
494 }
496 /* Delete module */
497 if (isset ($_POST['delete_module'])){
498 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
499 $this->del_list ($this->gotoModules, $_POST['modules_list']);
500 }
501 }
503 /* FAI class management */
504 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
505 $found = 0 ;
507 /* If this new class/profile will attach a second partition table
508 * to our list of classes, abort and show a message.
509 */
510 foreach($this->FAIclass as $name){
511 if(isset($this->FAIclassInfo[$name])){
512 foreach($this->FAIclassInfo[$name] as $atr){
513 if(isset($atr['obj'])){
514 if($atr['obj'] == "FAIpartitionTable"){
515 $found ++ ;
516 }
517 }
518 }
519 }
520 }
522 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
523 print_red(_("There is already a profile in your selection that contain partition table configurations."));
524 }else{
525 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
526 }
527 }
529 $sort = false;
530 foreach($_POST as $name => $val){
532 $sort_type = false;
533 if((preg_match("/sort_up/",$name))&&(!$sort)){
534 $sort_type = "sort_up_";
535 }
536 if((preg_match("/sort_down/",$name))&&(!$sort)){
537 $sort_type = "sort_down_";
538 }
540 if(($sort_type)&&(!$sort)){
541 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
542 $sort = true;
544 $last = -1;
545 $change_down = -1;
547 /* Create array with numeric index */
548 $tmp = array();
549 foreach($this->FAIclass as $class){
550 $tmp [] = $class;
551 }
553 /* Walk trough array */
554 foreach($tmp as $key => $faiName){
555 if($faiName == $value){
556 if($sort_type == "sort_up_"){
557 if($last != -1){
558 $change_down= $last;
559 }
560 }else{
561 if(isset($tmp[$key+1])){
562 $change_down = $key;
563 }
564 }
565 }
566 $last = $key;
567 }
569 $tmp2 = array();
570 $skip = false;
572 foreach($tmp as $ky => $vl){
574 if($ky == $change_down){
575 $skip = $vl;
576 }else{
577 $tmp2[$vl] = $vl;
578 }
579 if(($skip != false)&&($ky != $change_down)){
580 $tmp2[$skip] = $skip;
581 $skip =false;
582 }
583 }
584 $this->FAIclass = $tmp2;
585 }
587 if(preg_match("/fai_remove/i",$name)){
588 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
589 unset($this->FAIclass[$value]);
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"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
666 "attach"=>"style='border-left:0px;'"),
667 array("string"=>$display)
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 = array();
829 if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
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 }
850 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
852 $eClasses = " ";
853 foreach($errorClasses as $class){
854 $eClasses .= $class." ";
855 }
857 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));
858 $this->FAIdebianMirror = "auto";
859 return($this->getFAIreleases());
860 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
862 $eClasses = " ";
863 foreach($errorClasses as $class){
864 $eClasses .= $class." ";
865 }
867 $this->FAIclass= array();
868 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));
869 }
870 return($ret);
871 }
873 /* Save data to object */
874 function save_object()
875 {
876 plugin::save_object();
878 /* Save group radio buttons */
879 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
880 $this->bootmode= $_POST["bootmode"];
881 }
883 /* Save kernel parameters */
884 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
885 $this->customParameters= $_POST["customParameters"];
886 }
888 }
891 /* Save to LDAP */
892 function save()
893 {
895 /* Depending on the baseobject (Ogroup / WS) we
896 * use another set of objectClasses
897 * In case of WS itself, we use "array("GOhard", "FAIobject");"
898 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
899 */
900 if(isset($this->parent->by_object['ogroup'])){
901 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
902 }elseif(isset($this->parent->by_object['workgeneric'])){
903 $this->objectclasses = array("GOhard", "FAIobject");
904 }elseif(isset($this->parent->by_object['servgeneric'])){
905 $this->objectclasses = array("GOhard", "FAIobject");
906 }else{
907 print "Object Type Configuration : unknown";
908 exit();
909 }
911 /* Find proper terminal path for tftp configuration
912 FIXME: This is suboptimal when the default has changed to
913 another location! */
914 if (($this->gotoTerminalPath == "default")){
915 $ldap= $this->config->get_ldap_link();
917 /* Strip relevant part from dn, keep trailing ',' */
918 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
919 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
921 /* Walk from top to base and try to load default values for
922 'gotoTerminalPath'. Abort when an entry is found. */
923 while (TRUE){
924 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
926 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
927 $this->config->current['BASE'], array('gotoTerminalPath'));
928 $attrs= $ldap->fetch();
929 if (isset($attrs['gotoTerminalPath'])){
930 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
931 break;
932 }
934 /* Nothing left? */
935 if ($tmp == ""){
936 break;
937 }
938 }
939 }
941 /* Add semi automatic values */
942 // FIXME: LDAP Server may not be set here...
943 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
945 switch ($this->bootmode){
946 case "D":
947 $this->gotoKernelParameters.= " debug";
948 break;
949 case "G":
950 $this->gotoKernelParameters.= " splash=silent";
951 break;
952 }
953 if ($this->customParameters != ""){
954 $this->gotoKernelParameters.= " o ".$this->customParameters;
955 }
957 plugin::save();
959 unset( $this->attrs['FAIrelease'] );
961 $str = "";
963 if($this->FAIdebianMirror == "inherited"){
965 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
967 }else{
969 foreach($this->FAIclass as $class){
970 $str .= $class." ";
971 }
972 $str .= ":" . $this->FAIrelease;
973 $this->attrs['FAIclass']= "";
974 $this->attrs['FAIclass']= trim($str);
976 if(empty($this->attrs['FAIclass'])){
977 $this->attrs['FAIclass'] = array();
978 }
979 }
981 /* Add missing arrays */
982 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
983 if (isset ($this->$val) && count ($this->$val) != 0){
985 $this->attrs["$val"]= array_unique($this->$val);
986 }
987 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
988 }
990 /* Strip out 'default' values */
991 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
992 $this->attrs['gotoLdapServer']= array();
993 }
995 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
996 $this->attrs['gotoBootKernel']= array();
997 }
999 /* if mirror == none stop saving this attribute */
1000 if($this->FAIdebianMirror == "none"){
1001 $this->FAIdebianMirror = "";
1002 }
1004 /* Get FAIstate from object, the generic tab could have changed it during execute */
1005 $ldap= $this->config->get_ldap_link();
1006 $ldap->cd($this->dn);
1007 $ldap->cat($this->dn,array("FAIstate"));
1008 $checkFAIstate = $ldap->fetch();
1010 /* Remove FAI objects if no FAI class is selected */
1011 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
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 $this->cleanup();
1026 $ldap->modify ($this->attrs);
1028 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1029 $this->handle_post_events("modify");
1030 }
1032 /* Add value to array, check if unique */
1033 function add_list (&$array, $value)
1034 {
1035 if ($value != ""){
1036 $array[]= $value;
1037 sort($array);
1038 array_unique ($array);
1039 }
1040 }
1043 /* Delete value to array, check if unique */
1044 function del_list (&$array, $list)
1045 {
1046 $tmp= array();
1047 foreach ($array as $mod){
1048 if (!in_array($mod, $list)){
1049 $tmp[]= $mod;
1050 }
1051 }
1052 $array= $tmp;
1053 }
1055 /* Generate ListBox frindly output for the defined shares
1056 * Possibly Add or remove an attribute here,
1057 */
1058 function printOutAssignedShares()
1059 {
1060 $a_return = array();
1061 if(is_array($this->gotoShares)){
1062 foreach($this->gotoShares as $share){
1063 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1064 }
1065 }
1066 return($a_return);
1067 }
1070 function GetHookElements()
1071 {
1072 $ret = array();
1073 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1074 if(!empty($cmd)){
1075 $res = shell_exec($cmd);
1076 $res2 = trim($res);
1077 if((!$res)){
1078 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1079 }elseif(empty($res2)){
1080 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1081 }else{
1082 $tmp = split("\n",$res);
1083 foreach($tmp as $line){
1084 if(empty($line)) continue;
1085 $ret[]= $line;
1086 }
1087 }
1088 }
1089 return($ret);
1090 }
1092 }
1094 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1095 ?>