2b8f96f67ab9ce5cfc7c5db3abffb661fc1b3471
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 = "";
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 $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();
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","gotoBootKernel");
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' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
291 break;
293 case 'gotoBootKernel':
294 $this->gotoBootKernels['default-inherited']= _("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 $first = false;
320 $fh= popen($command, "r");
321 while (!feof($fh)) {
322 $buffer= trim(fgets($fh, 256));
324 if(!empty($buffer)){
326 $name=$value = $buffer;
327 if(preg_match("/:/",$buffer)){
328 $name = preg_replace("/:.*$/","",$buffer);
329 $value= preg_replace("/^.*:/","",$buffer);
330 $this->gotoBootKernels[$name]= $name.":".$value;
331 }else{
332 $this->gotoBootKernels[$name]= $value;
333 }
334 if($this->gotoBootKernel =="" ){
335 $this->gotoBootKernel = $name;
336 }
338 }
339 }
340 pclose($fh);
341 }
342 }
344 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
345 $this->FAIdebianMirror = "inherited";
346 }
347 }
350 /* This class is called by the contrucktor ONLY.
351 * It return the available classes for each
352 * Server / Release combination ...
353 * (Release specifies which classes are available)
354 */
355 function getAvailableClassesForThisRelease($release)
356 {
357 /* There could be more than one server providing this release,
358 so use cached result if available
359 */
360 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
361 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
362 }
364 /* Walk through cache and get out what we need.
365 *
366 * Function od : "$this->generateDNSyn($release)"
367 * It returns an array like this one :
368 * array("ou=packges,ou=rc0.9.2,ou=siga,",
369 * "ou=scripts.. "
370 * ...);
371 * This helps us to select the correct classes for each release.
372 * It prevents errors like: 'siga' is selected as release, but all classes
373 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
374 */
375 $tmp2 = $this->generateDNSyn($release) ;
376 $test2 = array();
377 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
378 foreach($tmp2 as $dns){
379 if(preg_match("/".$dns."/",$attr['dn'])){
380 $test2[$attr['cn'][0]] = $attr['cn'][0];
381 }
382 }
383 }
384 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
385 return($test2);
386 }
389 /* Create array to display available classes/profiles in a selectbox
390 * This function only displays the available classes.
391 * If a class is available is defined by these facts :
392 * 1. Is this class available for the selected release ?
393 * - if it is available, check if the release is available for the selected server
394 * (done by $this->getFAIreleases())
395 * 2. Is this class currently not assigned to $this->FAIclass
396 */
397 function selectFriendlyClasses(){
398 $tmp=array();
400 if($this->FAIdebianMirror == "inherited") return($tmp);
402 /* check if the current release exists,
403 else select the first one ..
404 */
405 $tmp2 = $this->getFAIreleases();
406 if(!in_array($this->FAIrelease, $tmp2)){
407 $this->FAIrelease = key($tmp2);
408 }
410 /* Get all Packages for this server/release combination
411 */
412 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
413 $pkgs = array();
414 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
415 }else{
416 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
417 }
419 /* Check each and every single class name
420 */
421 foreach($pkgs as $pkg){
423 /* Class already assigned to the classes list ?
424 * If not ... go on
425 */
426 if(!in_array($pkg,$this->FAIclass)){
428 /* Create the displayed list entry value
429 HKLMOP [-Pl P V T-] or something like that
430 */
431 $str = "";
432 foreach($this->FAIclassInfo[$pkg] as $entry){
433 if(isset($entry['kzl'])){
434 $str .= $entry['kzl']." ";
435 }
436 }
438 /* Append class if everyting was fine
439 */
440 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
441 }
442 }
443 /* Just sort and return new classes list ...
444 ( possibly we should cache the result ... )
445 */
446 natcasesort ($tmp);
447 return($tmp);
448 }
450 function check()
451 {
452 $messages = array();
454 /* Call common method to give check the hook */
455 $messages= plugin::check();
457 /* If there are packages selected, but no mirror show error */
458 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
459 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
460 }
462 return($messages);
463 }
465 function execute()
466 {
468 /* Call parent execute */
469 plugin::execute();
471 /* Do we need to flip is_account state? */
472 if (isset($_POST['modify_state'])){
473 $this->is_account= !$this->is_account;
474 }
476 /* Do we represent a valid terminal? */
477 if (!$this->is_account && $this->parent == NULL){
478 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
479 _("This 'dn' has no terminal features.")."</b>";
480 return ($display);
481 }
483 /* Add module */
484 if (isset ($_POST['add_module'])){
485 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
486 $this->add_list ($this->gotoModules, $_POST['module']);
487 }
488 }
490 /* Delete module */
491 if (isset ($_POST['delete_module'])){
492 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
493 $this->del_list ($this->gotoModules, $_POST['modules_list']);
494 }
495 }
497 /* FAI class management */
498 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
499 $found = 0 ;
501 /* If this new class/profile will attach a second partition table
502 * to our list of classes, abort and show a message.
503 */
504 foreach($this->FAIclass as $name){
505 if(isset($this->FAIclassInfo[$name])){
506 foreach($this->FAIclassInfo[$name] as $atr){
507 if(isset($atr['obj'])){
508 if($atr['obj'] == "FAIpartitionTable"){
509 $found ++ ;
510 }
511 }
512 }
513 }
514 }
516 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
517 print_red(_("There is already a profile in your selection that contain partition table configurations."));
518 }else{
519 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
520 }
521 }
523 $sort = false;
524 foreach($_POST as $name => $val){
526 $sort_type = false;
527 if((preg_match("/sort_up/",$name))&&(!$sort)){
528 $sort_type = "sort_up_";
529 }
530 if((preg_match("/sort_down/",$name))&&(!$sort)){
531 $sort_type = "sort_down_";
532 }
534 if(($sort_type)&&(!$sort)){
535 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
536 $sort = true;
538 $last = -1;
539 $change_down = -1;
541 /* Create array with numeric index */
542 $tmp = array();
543 foreach($this->FAIclass as $class){
544 $tmp [] = $class;
545 }
547 /* Walk trough array */
548 foreach($tmp as $key => $faiName){
549 if($faiName == $value){
550 if($sort_type == "sort_up_"){
551 if($last != -1){
552 $change_down= $last;
553 }
554 }else{
555 if(isset($tmp[$key+1])){
556 $change_down = $key;
557 }
558 }
559 }
560 $last = $key;
561 }
563 $tmp2 = array();
564 $skip = false;
566 foreach($tmp as $ky => $vl){
568 if($ky == $change_down){
569 $skip = $vl;
570 }else{
571 $tmp2[$vl] = $vl;
572 }
573 if(($skip != false)&&($ky != $change_down)){
574 $tmp2[$skip] = $skip;
575 $skip =false;
576 }
577 }
578 $this->FAIclass = $tmp2;
579 }
581 if(preg_match("/fai_remove/i",$name)){
582 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
583 unset($this->FAIclass[$value]);
584 }
585 }
587 /* Show main page */
588 $smarty= get_smarty();
589 $smarty->assign("SelectBoxLdapServer","");
591 /* In this section server shares will be defined
592 * A user can select one of the given shares and a mount point
593 * and attach this combination to his setup.
594 */
595 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
596 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
598 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
599 * This entry will be, a combination of mountPoint and sharedefinitions
600 */
601 if(isset($_POST['gotoShareAdd'])){
602 /* We assign a share to this user, if we don't know where to mount the share */
603 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
604 print_red(_("You must specify a valid mount point."));
605 }else{
606 if(count($this->gotoAvailableShares)){
607 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
608 $s_mount = $_POST['gotoShareMountPoint'];
609 /* Preparing the new assignment */
610 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
611 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
612 }
613 }
614 }
616 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
617 * If there is no defined share selected, we will abort the deletion without any message
618 */
619 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
620 unset($this->gotoShares[$_POST['gotoShare']]);
621 }
623 $smarty->assign("gotoShares",$this->printOutAssignedShares());
624 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
625 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
626 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
628 /* Arrays */
629 $tmp = $this->goLdapServerList;
631 /* Create divSelectBox for ldap server selection
632 */
633 $SelectBoxLdapServer = new divSelectBox("LdapServer");
634 $SelectBoxLdapServer->SetHeight(130);
636 /* Set first entry as selected, if $this->gotoLdapServer is empty
637 * or given entry is no longer available ...
638 */
639 $found = false;
640 foreach($tmp as $server){
641 if($this->gotoLdapServer==$server){
642 $found = true;
643 }
644 }
646 /* Add Entries
647 */
648 foreach($tmp as $key => $server){
649 $use ="";
650 if(($this->gotoLdapServer == $server) || ($found == false)) {
651 $found = true;
652 $use = " checked ";
653 };
655 $display = $server;
657 $SelectBoxLdapServer->AddEntry(
658 array(
659 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
660 "attach"=>"style='border-left:0px;'"),
661 array("string"=>$display)
662 ));
663 }
665 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
667 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
668 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
669 $smarty->assign("$val", $this->$val);
670 }
672 /* Values */
673 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
674 $smarty->assign($val, $this->$val);
675 $smarty->assign($val."ACL", chkacl($this->acl, $val));
676 }
678 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
679 $smarty->assign("FAIreleases",$this->getFAIreleases());
680 $smarty->assign("FAIrelease",$this->FAIrelease);
681 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
682 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
683 $smarty->assign("FAIclassKeys",$this->FAIclass);
684 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
686 $div = new divSelectBox("WSFAIscriptClasses");
687 $div -> SetHeight("110");
688 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
689 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
690 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
691 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
693 $i = 1;
695 if($this->FAIdebianMirror == "inherited"){
696 $tmp = $this->InheritedFAIclass;
697 }else{
698 $tmp = $this->FAIclass;
699 }
701 foreach($tmp as $class){
703 if($this->FAIdebianMirror == "inherited"){
704 $str = "";
705 }else{
706 if($i==1){
707 $str = $str_empty.$str_down.$str_remove;
708 }elseif($i == count($this->FAIclass)){
709 $str = $str_up.$str_empty.$str_remove;
710 }else{
711 $str = $str_up.$str_down.$str_remove;
712 }
713 }
714 $i ++ ;
716 $div->AddEntry(array(
717 array("string"=>$class),
718 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
719 ));
720 }
722 $smarty->assign("FAIScriptlist",$div->DrawList());
724 /* Radio button group */
725 if (preg_match("/G/", $this->bootmode)) {
726 $smarty->assign("graphicalbootup", "checked");
727 } else {
728 $smarty->assign("graphicalbootup", "");
729 }
730 if (preg_match("/T/", $this->bootmode)) {
731 $smarty->assign("textbootup", "checked");
732 } else {
733 $smarty->assign("textbootup", "");
734 }
735 if (preg_match("/D/", $this->bootmode)) {
736 $smarty->assign("debugbootup", "checked");
737 } else {
738 $smarty->assign("debugbootup", "");
739 }
741 /* ACL's */
742 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
743 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
744 }
746 /* Show main page */
747 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
748 }
750 function remove_from_parent()
751 {
752 $this->handle_post_events("remove");
753 }
755 function generateDNSyn($release)
756 {
757 $str = "";
758 $tmp = split("\/",$release);
759 $tmp = array_reverse($tmp);
761 $base = ",ou=fai,";
763 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
765 foreach($tmp as $departmentname){
767 $str .= ",ou=".$departmentname;
768 }
769 $ret = array();
770 foreach($arr as $ar){
771 $ret[] = ",ou=".$ar.$str.$base;
772 }
773 return($ret);
774 }
776 function getFAIdebianMirrors()
777 {
778 $ret = array();
779 $ret['inherited']="["._("inherited")."]";
780 $ret['auto']=_("automatic");
781 $secs = array();
783 /* Walk through all available servers
784 and check if they support the currently selected classes
785 if not, dont't add them to our list
786 */
787 foreach($this->FAIServRepConfig as $mirror => $rest){
789 $use = false;
791 if(count($this->FAIclass) == 0){
792 $use = true;
793 }else{
794 $tmp = $this->getFAIreleases();
795 foreach($tmp as $release){
796 if(isset($rest['RELEASE'][$release])){
797 $use =true;
798 }
799 }
800 }
802 /* If current server, doesn't support this class
803 remove it from list
804 */
805 if($use){
806 $ret[$mirror] = $mirror;
807 }
808 }
809 return($ret);
810 }
812 function getFAIreleases()
813 {
814 $ret = array();
816 if($this->FAIdebianMirror == "inherited") return(array());
818 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
819 $this->FAIdebianMirror = "auto";
820 }
822 $errorClasses = array();
823 if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
824 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
825 $use = true;
827 if(!count($this->FAIclass) == 0){
828 foreach($this->FAIclass as $class){
829 if(!in_array($class, $sections['PACKAGES'])){
830 $use = false;
831 $errorClasses[$class] = $class;
832 }else{
833 if(isset($errorClasses[$class])){
834 unset($errorClasses[$class]);
835 }
836 }
837 }
838 }
839 if($use){
840 $ret[$release]=$release;
841 }
842 }
843 }
844 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
846 $eClasses = " ";
847 foreach($errorClasses as $class){
848 $eClasses .= $class." ";
849 }
851 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));
852 $this->FAIdebianMirror = "auto";
853 return($this->getFAIreleases());
854 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
856 $eClasses = " ";
857 foreach($errorClasses as $class){
858 $eClasses .= $class." ";
859 }
861 $this->FAIclass= array();
862 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));
863 }
864 return($ret);
865 }
867 /* Save data to object */
868 function save_object()
869 {
870 plugin::save_object();
872 /* Save group radio buttons */
873 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
874 $this->bootmode= $_POST["bootmode"];
875 }
877 /* Save kernel parameters */
878 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
879 $this->customParameters= $_POST["customParameters"];
880 }
882 }
885 /* Save to LDAP */
886 function save()
887 {
889 /* Depending on the baseobject (Ogroup / WS) we
890 * use another set of objectClasses
891 * In case of WS itself, we use "array("GOhard", "FAIobject");"
892 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
893 */
894 if(isset($this->parent->by_object['ogroup'])){
895 $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
896 }elseif(isset($this->parent->by_object['workgeneric'])){
897 $this->objectclasses = array("GOhard", "FAIobject");
898 }elseif(isset($this->parent->by_object['servgeneric'])){
899 $this->objectclasses = array("GOhard", "FAIobject");
900 }else{
901 print "Object Type Configuration : unknown";
902 exit();
903 }
905 /* Find proper terminal path for tftp configuration
906 FIXME: This is suboptimal when the default has changed to
907 another location! */
908 if (($this->gotoTerminalPath == "default")){
909 $ldap= $this->config->get_ldap_link();
911 /* Strip relevant part from dn, keep trailing ',' */
912 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
913 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
915 /* Walk from top to base and try to load default values for
916 'gotoTerminalPath'. Abort when an entry is found. */
917 while (TRUE){
918 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
920 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
921 $this->config->current['BASE'], array('gotoTerminalPath'));
922 $attrs= $ldap->fetch();
923 if (isset($attrs['gotoTerminalPath'])){
924 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
925 break;
926 }
928 /* Nothing left? */
929 if ($tmp == ""){
930 break;
931 }
932 }
933 }
935 /* Add semi automatic values */
936 // FIXME: LDAP Server may not be set here...
937 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
939 switch ($this->bootmode){
940 case "D":
941 $this->gotoKernelParameters.= " debug";
942 break;
943 case "G":
944 $this->gotoKernelParameters.= " splash=silent";
945 break;
946 }
947 if ($this->customParameters != ""){
948 $this->gotoKernelParameters.= " o ".$this->customParameters;
949 }
951 plugin::save();
953 unset( $this->attrs['FAIrelease'] );
955 $str = "";
957 if($this->FAIdebianMirror == "inherited"){
959 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
961 }else{
963 foreach($this->FAIclass as $class){
964 $str .= $class." ";
965 }
966 $str .= ":" . $this->FAIrelease;
967 $this->attrs['FAIclass']= "";
968 $this->attrs['FAIclass']= trim($str);
970 if(empty($this->attrs['FAIclass'])){
971 $this->attrs['FAIclass'] = array();
972 }
973 }
975 /* Add missing arrays */
976 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
977 if (isset ($this->$val) && count ($this->$val) != 0){
979 $this->attrs["$val"]= array_unique($this->$val);
980 }
981 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
982 }
984 /* Strip out 'default' values */
985 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
986 $this->attrs['gotoLdapServer']= array();
987 }
989 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
990 $this->attrs['gotoBootKernel']= array();
991 }
993 /* if mirror == none stop saving this attribute */
994 if($this->FAIdebianMirror == "none"){
995 $this->FAIdebianMirror = "";
996 }
998 /* Get FAIstate from object, the generic tab could have changed it during execute */
999 $ldap= $this->config->get_ldap_link();
1000 $ldap->cd($this->dn);
1001 $ldap->cat($this->dn,array("FAIstate"));
1002 $checkFAIstate = $ldap->fetch();
1004 /* Remove FAI objects if no FAI class is selected */
1005 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1006 $tmp = array();
1007 foreach($this->attrs['objectClass'] as $class){
1008 if($class != "FAIobject"){
1009 $tmp[] = $class;
1010 }
1011 }
1012 $this->attrs['objectClass'] = $tmp;
1013 $this->attrs['FAIclass'] = array();
1014 $this->attrs['FAIdebianMirror'] = array();
1015 }
1017 /* prepare share settings */
1018 $tmp = array();
1019 foreach($this->gotoShares as $name => $settings){
1020 $tmp2= split("\|",$name);
1021 $name = $tmp2[0];
1022 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1023 }
1024 $this->attrs['gotoShare']=$tmp;
1026 $this->cleanup();
1027 $ldap->modify ($this->attrs);
1029 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1030 $this->handle_post_events("modify");
1031 }
1033 /* Add value to array, check if unique */
1034 function add_list (&$array, $value)
1035 {
1036 if ($value != ""){
1037 $array[]= $value;
1038 sort($array);
1039 array_unique ($array);
1040 }
1041 }
1044 /* Delete value to array, check if unique */
1045 function del_list (&$array, $list)
1046 {
1047 $tmp= array();
1048 foreach ($array as $mod){
1049 if (!in_array($mod, $list)){
1050 $tmp[]= $mod;
1051 }
1052 }
1053 $array= $tmp;
1054 }
1056 /* Generate ListBox frindly output for the defined shares
1057 * Possibly Add or remove an attribute here,
1058 */
1059 function printOutAssignedShares()
1060 {
1061 $a_return = array();
1062 if(is_array($this->gotoShares)){
1063 foreach($this->gotoShares as $share){
1064 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1065 }
1066 }
1067 return($a_return);
1068 }
1071 function GetHookElements()
1072 {
1073 $ret = array();
1074 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1075 if(!empty($cmd)){
1076 $res = shell_exec($cmd);
1077 $res2 = trim($res);
1078 if((!$res)){
1079 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1080 }elseif(empty($res2)){
1081 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1082 }else{
1083 $tmp = split("\n",$res);
1084 foreach($tmp as $line){
1085 if(empty($line)) continue;
1086 $ret[]= $line;
1087 }
1088 }
1089 }
1090 return($ret);
1091 }
1093 }
1095 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1096 ?>