1 <?php
3 class workstartup extends plugin
4 {
5 /* Generic terminal attributes */
6 var $bootmode = "G";
7 var $goLdapServerList = array();
8 var $gotoBootKernel = "default-inherited";
9 var $gotoKernelParameters = "";
10 var $gotoLdapServer = "default-inherited";
11 var $gotoModules = array();
12 var $gotoAutoFs = array();
13 var $gotoFilesystem = array();
14 var $gotoTerminalPath = "";
15 var $FAIstatus = "";
16 var $gotoBootKernels = array();
18 /* attribute list for save action */
19 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
20 var $objectclasses = array("GOhard", "FAIobject");
22 /* These vars are required to copy object groups !. */
23 var $CopyPasteVars = array("gotoModules","gotoShares","customParameters","FAIclass","FAIrelease","FAIdebianMirror");
25 /* Share */
26 var $gotoShares = array();// Currently Share Option
27 var $gotoShare = ""; // currently selected Share Option
28 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
29 var $gotoAvailableShares= array();// Available Shares for this account
31 /* Helper */
32 var $customParameters = "";
33 var $orig_dn = "";
34 var $ignore_account = TRUE;
36 /* FAI class selection */
37 var $FAIclass = array();
38 var $FAIclasses = array();
39 var $FAIclassInfo = array();
40 var $FAIrelease = "";
41 var $FAIdebianMirror = "auto";
43 var $unresolved_classes = array();
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 var $fai_activated = FALSE;
55 function workstartup ($config, $dn= NULL, $parent= NULL)
56 {
57 /* Cehck if FAI is activated, else do not save any FAI attributes */
58 $tmp = search_config($config->data,"faiManagement","CLASS");
59 if(!empty($tmp)){
60 $this->fai_activated = TRUE;
61 }else{
62 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
63 $this->objectclasses = array("GOhard");
64 }
66 plugin::plugin ($config, $dn, $parent);
68 /* Creating a list of valid Mirrors
69 * none will not be saved to ldap.
70 */
71 $ldap = $this->config->get_ldap_link();
72 $ldap->cd($this->config->current['BASE']);
74 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
75 $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
76 }
79 /* Perform some special FAI stuff, only if it is activated */
80 if($this->fai_activated){
82 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
83 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
85 $ui = get_userinfo();
86 $res = get_list( "(|(objectClass=FAIpackageList)".
87 "(objectClass=FAItemplate)".
88 "(objectClass=FAIvariable)".
89 "(objectClass=FAIscript)".
90 "(objectClass=FAIhook)".
91 "(objectClass=FAIprofile)".
92 "(objectClass=FAIpartitionTable))",
93 $ui->subtreeACL,$this->config->current['BASE'],
94 array("cn","objectClass","FAIdebianSection"));
96 foreach($res as $attr){
97 $cn = $attr['cn'][0];
99 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
101 if(in_array('FAIpackageList',$attr['objectClass'])){
102 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
103 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
104 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
105 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
106 }
107 if(in_array('FAItemplate',$attr['objectClass'])){
108 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
109 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
110 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
111 }
112 if(in_array('FAIvariable',$attr['objectClass'])){
113 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
114 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
115 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
116 }
117 if(in_array('FAIscript',$attr['objectClass'])){
118 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
119 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
120 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
121 }
122 if(in_array('FAIhook',$attr['objectClass'])){
123 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
124 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
125 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
126 }
127 if(in_array('FAIpartitionTable',$attr['objectClass'])){
128 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
129 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
130 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
131 }
132 if(in_array('FAIprofile',$attr['objectClass'])){
133 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
134 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
135 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
136 }
137 }
138 if(is_array($this->FAIclasses)){
139 natcasesort($this->FAIclasses);
140 }
142 if(isset($tmp2)){
143 $this->FAIclassInfo = $tmp2;
144 } else {
145 $this->FAIclassInfo = array();
146 }
148 /* Build up an array like this one :
149 [$url]['SERVER'] = 'srv1-002';
150 [$url]['RELEASE']['siga/rc9.0.2']
151 ['SECTIONS'][0] "main";
152 ['SECTIONS'][1] "non-free";
153 [$url]['RELEASE']['siga/rc9.0.2']
154 ['PACKAGES'][0] "pkg1";
155 ['PACKAGES'][1] "postfix";
156 */
157 $filter= "";
158 $ui= get_userinfo();
159 if (isset($config->current['STRICT_UNITS']) && preg_match('/TRUE/i', $config->current['STRICT_UNITS']) && $ui->gosaUnitTag != ""){ $filter= "(gosaUnitTag=".$ui->gosaUnitTag.")";
160 } $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer)$filter)",array("FAIrepository"));
161 $test = array();
162 while($attr = $ldap->fetch()){
163 if(isset($attr['FAIrepository'])){
165 unset($attr['FAIrepository']['count']);
167 foreach($attr['FAIrepository'] as $rep){
168 $tmp = split("\|",$rep);
170 if(count($tmp)==4){
171 $sections = split(",",$tmp[3]);
172 $release = $tmp[2];
173 $server = $tmp[1];
174 $url = $tmp[0];
176 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
178 /* Result will be cached
179 */
180 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
181 $test[$url]['SERVER'] = $server;
183 /* auto gets all releases/classes
184 */
185 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
186 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
187 }
188 }
189 }
190 }
192 /* Add possible elements from hook */
193 $lines= $this->GetHookElements();
194 foreach ($lines as $hline){
195 $entries= split(";", $hline);
196 if (isset($entries[1]) && !isset($test[$entries[1]])){
197 $test[$entries[1]]['RELEASE']= array();
199 /* Split releases */
200 if (isset($entries[2])){
201 $releases= split(",", $entries[2]);
203 foreach ($releases as $release){
204 $rname= preg_replace('/:.*$/', '', $release);
205 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
206 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
207 $test[$entries[1]]['RELEASE'][$rname]= array();
208 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
209 foreach ($classes as $class){
210 if ($class != ""){
211 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
212 }
213 }
214 }
215 }
216 }
217 }
219 $this->FAIServRepConfig= $test;
220 } // Do FAI stuff end
222 /* Get arrays */
223 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
224 if (isset($this->attrs["$val"]["count"])){
225 for ($i= 0; $i<$this->attrs["count"]; $i++){
226 if (isset($this->attrs["$val"][$i])){
227 array_push($this->$val, $this->attrs["$val"][$i]);
228 }
229 }
230 }
231 sort ($this->$val);
232 $this->$val= array_unique($this->$val);
233 $this->saved_attributes[$val]= $this->$val;
234 }
236 /* Parse Kernel Parameters to decide what boot mode is enabled */
237 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
238 $this->bootmode= "G";
239 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
240 $this->bootmode= "D";
241 } elseif ($this->gotoKernelParameters == "") {
242 $this->bootmode= "G";
243 } else {
244 $this->bootmode= "T";
245 }
246 if (preg_match("/ o /", $this->gotoKernelParameters)){
247 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
248 } else {
249 $this->customParameters= "";
250 }
252 /* Prepare Shares */
253 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
254 unset($this->attrs['gotoShare']['count']);
255 foreach($this->attrs['gotoShare'] as $share){
256 $tmp = $tmp2 = array();
257 $tmp = split("\|",$share);
258 $tmp2['server'] =$tmp[0];
259 $tmp2['name'] =$tmp[1];
260 $tmp2['mountPoint'] =$tmp[2];
261 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
262 }
263 }
265 $this->gotoShareSelections= $config->getShareList(true);
266 $this->gotoAvailableShares= $config->getShareList(false);
267 $tmp2 = array();
270 /* Again some special FAI stuff */
271 if($this->fai_activated){
272 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
273 $tmp = array();
274 $tmp = split(" ",$this->FAIclass);
275 $tmp2 =array();
277 foreach($tmp as $class){
278 if( ":" == $class[0] ) {
279 $this->FAIrelease = substr( $class, 1 );
280 }
281 else
282 $tmp2[$class] = $class;
283 }
284 $this->FAIclass = $tmp2;
285 }
287 if(!is_array($this->FAIclass)){
288 $this->FAIclass =array();
289 }
290 }
292 $this->orig_dn= $this->dn;
294 /* Handle inheritance value "default" */
295 $this->gotoBootKernels= array();
298 /* Load hardware list */
299 $ldap= $this->config->get_ldap_link();
300 $ldap->cd($this->config->current['BASE']);
301 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
302 if ($ldap->count() == 1){
305 if($this->fai_activated){
306 $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
307 }else{
308 $map= array("gotoLdapServer","gotoBootKernel");
309 }
311 $attrs= $ldap->fetch();
313 foreach ($map as $name){
314 if (!isset($attrs[$name][0])){
315 continue;
316 }
318 switch ($name){
319 case 'gotoLdapServer':
320 $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
321 break;
323 case 'gotoBootKernel':
324 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
325 break;
327 case 'FAIclass':
328 $str = split(":",$attrs[$name][0]);
329 $this->InheritedFAIclass = split("\ ",trim($str[0]));
330 $this->InheritedFAIrelease = trim($str[1]);
331 break;
333 case 'FAIdebianMirror':
334 $this->InheritedFAIdebianMirror = $attrs[$name][0];
335 break;
336 }
337 }
338 }
340 /* Get list of boot kernels */
341 if (isset($this->config->data['TABS'])){
342 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
344 if (!check_command($command)){
345 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
346 get_class($this));
347 } else {
349 $first = false;
350 $fh= popen($command, "r");
351 while (!feof($fh)) {
352 $buffer= trim(fgets($fh, 256));
354 if(!empty($buffer)){
356 $name=$value = $buffer;
357 if(preg_match("/:/",$buffer)){
358 $name = preg_replace("/:.*$/","",$buffer);
359 $value= preg_replace("/^.*:/","",$buffer);
360 $this->gotoBootKernels[$name]= $name.":".$value;
361 }else{
362 $this->gotoBootKernels[$name]= $value;
363 }
364 if($this->gotoBootKernel =="" ){
365 $this->gotoBootKernel = $name;
366 }
368 }
369 }
370 pclose($fh);
371 }
372 }
374 /* Turn to default, if we've nothing to inherit */
375 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
376 $this->gotoBootKernel= "default";
377 }
379 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
380 $this->FAIdebianMirror = "inherited";
381 }
382 }
385 /* This class is called by the contrucktor ONLY.
386 * It return the available classes for each
387 * Server / Release combination ...
388 * (Release specifies which classes are available)
389 */
390 function getAvailableClassesForThisRelease($release)
391 {
392 /* There could be more than one server providing this release,
393 so use cached result if available
394 */
395 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
396 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
397 }
399 /* Walk through cache and get out what we need.
400 *
401 * Function od : "$this->generateDNSyn($release)"
402 * It returns an array like this one :
403 * array("ou=packges,ou=rc0.9.2,ou=siga,",
404 * "ou=scripts.. "
405 * ...);
406 * This helps us to select the correct classes for each release.
407 * It prevents errors like: 'siga' is selected as release, but all classes
408 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
409 */
410 $tmp2 = $this->generateDNSyn($release) ;
411 $test2 = array();
412 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
413 foreach($tmp2 as $dns){
414 if(preg_match("/".$dns."/",$attr['dn'])){
415 $test2[$attr['cn'][0]] = $attr['cn'][0];
416 }
417 }
418 }
419 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
420 return($test2);
421 }
424 /* Create array to display available classes/profiles in a selectbox
425 * This function only displays the available classes.
426 * If a class is available is defined by these facts :
427 * 1. Is this class available for the selected release ?
428 * - if it is available, check if the release is available for the selected server
429 * (done by $this->getFAIreleases())
430 * 2. Is this class currently not assigned to $this->FAIclass
431 */
432 function selectFriendlyClasses(){
433 $tmp=array();
435 if($this->FAIdebianMirror == "inherited") return($tmp);
437 /* check if the current release exists,
438 else select the first one ..
439 */
440 $tmp2 = $this->getFAIreleases();
441 if(!in_array($this->FAIrelease, $tmp2)){
442 $this->FAIrelease = key($tmp2);
443 }
445 /* Get all Packages for this server/release combination
446 */
447 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
448 $pkgs = array();
449 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
450 }else{
451 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
452 }
454 /* Check each and every single class name
455 */
456 foreach($pkgs as $pkg){
458 /* Class already assigned to the classes list ?
459 * If not ... go on
460 */
461 if(!in_array($pkg,$this->FAIclass)){
463 /* Create the displayed list entry value
464 HKLMOP [-Pl P V T-] or something like that
465 */
466 $str = "";
467 foreach($this->FAIclassInfo[$pkg] as $entry){
468 if(isset($entry['kzl'])){
469 $str .= $entry['kzl']." ";
470 }
471 }
473 /* Append class if everyting was fine
474 */
475 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
476 }
477 }
478 /* Just sort and return new classes list ...
479 ( possibly we should cache the result ... )
480 */
481 natcasesort ($tmp);
482 return($tmp);
483 }
485 function check()
486 {
487 $messages = array();
489 /* Call common method to give check the hook */
490 $messages= plugin::check();
492 /* If there are packages selected, but no mirror show error */
493 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
494 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
495 }
497 return($messages);
498 }
500 function execute()
501 {
503 /* Call parent execute */
504 plugin::execute();
506 /* Do we need to flip is_account state? */
507 if (isset($_POST['modify_state'])){
508 $this->is_account= !$this->is_account;
509 }
511 /* Do we represent a valid terminal? */
512 if (!$this->is_account && $this->parent == NULL){
513 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
514 _("This 'dn' has no terminal features.")."</b>";
515 return ($display);
516 }
518 /* Add module */
519 if (isset ($_POST['add_module']) ){
520 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
521 $this->add_list ($this->gotoModules, $_POST['module']);
522 }
523 }
525 /* Delete module */
526 if (isset ($_POST['delete_module'])){
527 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
528 $this->del_list ($this->gotoModules, $_POST['modules_list']);
529 }
530 }
532 /* FAI class management */
533 if($this->fai_activated && chkacl($this->acl,"FAIclass") == ""){
535 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
536 $found = 0 ;
538 /* If this new class/profile will attach a second partition table
539 * to our list of classes, abort and show a message.
540 */
541 foreach($this->FAIclass as $name){
542 if(isset($this->FAIclassInfo[$name])){
543 foreach($this->FAIclassInfo[$name] as $atr){
544 if(isset($atr['obj'])){
545 if($atr['obj'] == "FAIpartitionTable"){
546 $found ++ ;
547 }
548 }
549 }
550 }
551 }
553 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
554 print_red(_("There is already a profile in your selection that contain partition table configurations."));
555 }else{
556 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
557 }
558 }
560 $sort = false;
561 foreach($_POST as $name => $val){
563 $sort_type = false;
564 if((preg_match("/sort_up/",$name))&&(!$sort)){
565 $sort_type = "sort_up_";
566 }
567 if((preg_match("/sort_down/",$name))&&(!$sort)){
568 $sort_type = "sort_down_";
569 }
571 if(($sort_type)&&(!$sort)){
572 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
573 $sort = true;
575 $last = -1;
576 $change_down = -1;
578 /* Create array with numeric index */
579 $tmp = array();
580 foreach($this->FAIclass as $class){
581 $tmp [] = $class;
582 }
584 /* Walk trough array */
585 foreach($tmp as $key => $faiName){
586 if($faiName == $value){
587 if($sort_type == "sort_up_"){
588 if($last != -1){
589 $change_down= $last;
590 }
591 }else{
592 if(isset($tmp[$key+1])){
593 $change_down = $key;
594 }
595 }
596 }
597 $last = $key;
598 }
600 $tmp2 = array();
601 $skip = false;
603 foreach($tmp as $ky => $vl){
605 if($ky == $change_down){
606 $skip = $vl;
607 }else{
608 $tmp2[$vl] = $vl;
609 }
610 if(($skip != false)&&($ky != $change_down)){
611 $tmp2[$skip] = $skip;
612 $skip =false;
613 }
614 }
615 $this->FAIclass = $tmp2;
616 }
618 if(preg_match("/fai_remove/i",$name)){
619 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
620 unset($this->FAIclass[$value]);
621 }
622 }
623 }
625 /* Show main page */
626 $smarty= get_smarty();
627 $smarty->assign("SelectBoxLdapServer","");
629 /* In this section server shares will be defined
630 * A user can select one of the given shares and a mount point
631 * and attach this combination to his setup.
632 */
633 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
634 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
636 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
637 * This entry will be, a combination of mountPoint and sharedefinitions
638 */
639 if(isset($_POST['gotoShareAdd']) && chkacl($this->acl,"gotoShare") ==""){
640 /* We assign a share to this user, if we don't know where to mount the share */
641 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
642 print_red(_("You must specify a valid mount point."));
643 }else{
644 if(count($this->gotoAvailableShares)){
645 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
646 $s_mount = $_POST['gotoShareMountPoint'];
647 /* Preparing the new assignment */
648 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
649 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
650 }
651 }
652 }
654 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
655 * If there is no defined share selected, we will abort the deletion without any message
656 */
657 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare'])) && chkacl($this->acl,"gotoShare") ==""){
658 unset($this->gotoShares[$_POST['gotoShare']]);
659 }
661 $smarty->assign("gotoShares",$this->printOutAssignedShares());
662 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
663 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
664 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
666 /* Arrays */
667 $tmp = $this->goLdapServerList;
669 /* Create divSelectBox for ldap server selection
670 */
671 $SelectBoxLdapServer = new divSelectBox("LdapServer");
672 $SelectBoxLdapServer->SetHeight(130);
674 /* Set first entry as selected, if $this->gotoLdapServer is empty
675 * or given entry is no longer available ...
676 */
677 $found = false;
678 foreach($tmp as $server){
679 if($this->gotoLdapServer==$server){
680 $found = true;
681 }
682 }
684 /* Add Entries
685 */
686 foreach($tmp as $key => $server){
687 $use ="";
688 if(($this->gotoLdapServer == $server) || ($found == false)) {
689 $found = true;
690 $use = " checked ";
691 };
693 $use .= chkacl($this->acl,"gotoLdapServer");
695 $display = $server;
697 $SelectBoxLdapServer->AddEntry(
698 array(
699 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
700 "attach"=>"style='border-left:0px;'"),
701 array("string"=>$display)
702 ));
703 }
705 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
707 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
708 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
709 $smarty->assign("$val", $this->$val);
710 }
712 /* Values */
713 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
714 $smarty->assign($val, $this->$val);
715 $smarty->assign($val."ACL", chkacl($this->acl, $val));
716 }
718 $smarty->assign("fai_activated",$this->fai_activated);
719 if($this->fai_activated){
720 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
721 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
722 $smarty->assign("FAIreleases",$this->getFAIreleases());
723 $smarty->assign("FAIrelease",$this->FAIrelease);
724 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
725 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
726 $smarty->assign("FAIclassKeys",$this->FAIclass);
727 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
729 $div = new divSelectBox("WSFAIscriptClasses");
730 $div -> SetHeight("110");
731 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
732 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
733 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
734 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
736 $i = 1;
738 if($this->FAIdebianMirror == "inherited"){
739 $tmp = $this->InheritedFAIclass;
740 }else{
741 $tmp = $this->FAIclass;
742 }
744 foreach($tmp as $class){
746 $marker = "";
747 if(in_array_ics($class,$this->unresolved_classes)){
748 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
749 }
751 if($this->FAIdebianMirror == "inherited"){
752 $str = "";
753 }else{
754 if($i==1){
755 $str = $str_empty.$str_down.$str_remove;
756 }elseif($i == count($this->FAIclass)){
757 $str = $str_up.$str_empty.$str_remove;
758 }else{
759 $str = $str_up.$str_down.$str_remove;
760 }
761 }
762 $i ++ ;
764 $div->AddEntry(array(
765 array("string"=>$class.$marker),
766 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
767 ));
768 }
770 $smarty->assign("FAIScriptlist",$div->DrawList());
771 }
773 /* Radio button group */
774 if (preg_match("/G/", $this->bootmode)) {
775 $smarty->assign("graphicalbootup", "checked");
776 } else {
777 $smarty->assign("graphicalbootup", "");
778 }
779 if (preg_match("/T/", $this->bootmode)) {
780 $smarty->assign("textbootup", "checked");
781 } else {
782 $smarty->assign("textbootup", "");
783 }
784 if (preg_match("/D/", $this->bootmode)) {
785 $smarty->assign("debugbootup", "checked");
786 } else {
787 $smarty->assign("debugbootup", "");
788 }
790 /* ACL's */
791 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
792 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
793 }
795 /* Show main page */
796 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
797 }
799 function remove_from_parent()
800 {
801 $this->handle_post_events("remove");
802 }
804 function generateDNSyn($release)
805 {
806 $str = "";
807 $tmp = split("\/",$release);
808 $tmp = array_reverse($tmp);
810 $base = ",ou=fai,";
812 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
814 foreach($tmp as $departmentname){
816 $str .= ",ou=".$departmentname;
817 }
818 $ret = array();
819 foreach($arr as $ar){
820 $ret[] = ",ou=".$ar.$str.$base;
821 }
822 return($ret);
823 }
825 function getFAIdebianMirrors()
826 {
827 $ret = array();
828 $ret['inherited']="["._("inherited")."]";
829 $ret['auto']=_("automatic");
830 $secs = array();
832 /* Walk through all available servers
833 and check if they support the currently selected classes
834 if not, dont't add them to our list
835 */
836 foreach($this->FAIServRepConfig as $mirror => $rest){
838 $use = false;
840 if(count($this->FAIclass) == 0){
841 $use = true;
842 }else{
843 $tmp = $this->getFAIreleases();
844 foreach($tmp as $release){
845 if(isset($rest['RELEASE'][$release])){
846 $use =true;
847 }
848 }
849 }
851 /* If current server, doesn't support this class
852 remove it from list
853 */
854 if($use){
855 $ret[$mirror] = $mirror;
856 }
857 }
858 return($ret);
859 }
861 function getFAIreleases()
862 {
863 $ret = array();
865 if($this->FAIdebianMirror == "inherited") return(array());
867 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
868 $this->FAIdebianMirror = "auto";
869 }
871 $errorClasses = array();
872 if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
873 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
874 $use = true;
876 if(!count($this->FAIclass) == 0){
877 foreach($this->FAIclass as $class){
878 if(!in_array($class, $sections['PACKAGES'])){
879 $use = false;
880 $errorClasses[$class] = $class;
881 }else{
882 if(isset($errorClasses[$class])){
883 unset($errorClasses[$class]);
884 }
885 }
886 }
887 }
888 if($use){
889 $ret[$release]=$release;
890 }
891 }
892 }
893 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
895 $eClasses = " ";
896 foreach($errorClasses as $class){
897 $eClasses .= $class." ";
898 }
900 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));
901 $this->FAIdebianMirror = "auto";
902 return($this->getFAIreleases());
903 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
905 $eClasses = " ";
906 foreach($errorClasses as $class){
907 $eClasses .= $class." ";
908 }
910 $this->unresolved_classes = $errorClasses;
911 $this->FAIdebianMirror = "auto";
912 //$this->FAIclass= array();
913 print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. Server was reset to 'auto'."),$eClasses));
914 }
915 return($ret);
916 }
918 /* Save data to object */
919 function save_object()
920 {
921 plugin::save_object();
923 /* Save group radio buttons */
924 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
925 $this->bootmode= $_POST["bootmode"];
926 }
928 /* Save kernel parameters */
929 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
930 $this->customParameters= $_POST["customParameters"];
931 }
933 }
936 /* Save to LDAP */
937 function save()
938 {
940 /* Depending on the baseobject (Ogroup / WS) we
941 * use another set of objectClasses
942 * In case of WS itself, we use "array("GOhard", "FAIobject");"
943 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
944 */
945 if(isset($this->parent->by_object['ogroup'])){
946 $this->objectclasses = array("gotoWorkstationTemplate");
947 }elseif(isset($this->parent->by_object['workgeneric'])){
948 $this->objectclasses = array("GOhard");
949 }elseif(isset($this->parent->by_object['servgeneric'])){
950 $this->objectclasses = array("GOhard");
951 }else{
952 print "Object Type Configuration : unknown";
953 exit();
954 }
956 if($this->fai_activated){
957 $this->objectclasses [] = "FAIobject";
958 }
960 /* Find proper terminal path for tftp configuration
961 FIXME: This is suboptimal when the default has changed to
962 another location! */
963 if (($this->gotoTerminalPath == "default")){
964 $ldap= $this->config->get_ldap_link();
966 /* Strip relevant part from dn, keep trailing ',' */
967 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
968 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
970 /* Walk from top to base and try to load default values for
971 'gotoTerminalPath'. Abort when an entry is found. */
972 while (TRUE){
973 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
975 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
976 $this->config->current['BASE'], array('gotoTerminalPath'));
977 $attrs= $ldap->fetch();
978 if (isset($attrs['gotoTerminalPath'])){
979 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
980 break;
981 }
983 /* Nothing left? */
984 if ($tmp == ""){
985 break;
986 }
987 }
988 }
990 /* Add semi automatic values */
991 // FIXME: LDAP Server may not be set here...
992 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
994 switch ($this->bootmode){
995 case "D":
996 $this->gotoKernelParameters.= " debug";
997 break;
998 case "G":
999 $this->gotoKernelParameters.= " splash=silent";
1000 break;
1001 }
1002 if ($this->customParameters != ""){
1003 $this->gotoKernelParameters.= " o ".$this->customParameters;
1004 }
1006 plugin::save();
1009 if($this->fai_activated){
1011 unset( $this->attrs['FAIrelease'] );
1013 $str = "";
1015 if($this->FAIdebianMirror == "inherited"){
1017 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1019 }else{
1021 foreach($this->FAIclass as $class){
1022 $str .= $class." ";
1023 }
1024 $str .= ":" . $this->FAIrelease;
1025 $this->attrs['FAIclass']= "";
1026 $this->attrs['FAIclass']= trim($str);
1028 if(empty($this->attrs['FAIclass'])){
1029 $this->attrs['FAIclass'] = array();
1030 }
1031 }
1033 /* if mirror == none stop saving this attribute */
1034 if($this->FAIdebianMirror == "none"){
1035 $this->FAIdebianMirror = "";
1036 }
1037 }
1039 /* Add missing arrays */
1040 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1041 if (isset ($this->$val) && count ($this->$val) != 0){
1043 $this->attrs["$val"]= array_unique($this->$val);
1044 }
1045 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1046 }
1048 /* Strip out 'default' values */
1049 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1050 $this->attrs['gotoLdapServer']= array();
1051 }
1053 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1054 $this->attrs['gotoBootKernel']= array();
1055 }
1057 $ldap= $this->config->get_ldap_link();
1058 $ldap->cd($this->dn);
1060 /* Get FAIstate from object, the generic tab could have changed it during execute */
1061 if($this->fai_activated){
1062 $ldap->cat($this->dn,array("FAIstate"));
1063 $checkFAIstate = $ldap->fetch();
1065 /* Remove FAI objects if no FAI class is selected */
1066 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1067 $this->attrs['FAIclass'] = array();
1068 $this->attrs['FAIdebianMirror'] = array();
1069 }
1070 }
1072 /* prepare share settings */
1073 $tmp = array();
1074 foreach($this->gotoShares as $name => $settings){
1075 $tmp2= split("\|",$name);
1076 $name = $tmp2[0];
1077 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1078 }
1079 $this->attrs['gotoShare']=$tmp;
1081 $this->cleanup();
1082 $ldap->modify ($this->attrs);
1084 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1085 $this->handle_post_events("modify");
1086 }
1088 /* Add value to array, check if unique */
1089 function add_list (&$array, $value)
1090 {
1091 if ($value != ""){
1092 $array[]= $value;
1093 sort($array);
1094 array_unique ($array);
1095 }
1096 }
1099 /* Delete value to array, check if unique */
1100 function del_list (&$array, $list)
1101 {
1102 $tmp= array();
1103 foreach ($array as $mod){
1104 if (!in_array($mod, $list)){
1105 $tmp[]= $mod;
1106 }
1107 }
1108 $array= $tmp;
1109 }
1111 /* Generate ListBox frindly output for the defined shares
1112 * Possibly Add or remove an attribute here,
1113 */
1114 function printOutAssignedShares()
1115 {
1116 $a_return = array();
1117 if(is_array($this->gotoShares)){
1118 foreach($this->gotoShares as $share){
1119 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1120 }
1121 }
1122 return($a_return);
1123 }
1126 function GetHookElements()
1127 {
1128 $ret = array();
1129 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1130 if(!empty($cmd)){
1131 $res = shell_exec($cmd);
1132 $res2 = trim($res);
1133 if((!$res)){
1134 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1135 }elseif(empty($res2)){
1136 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1137 }else{
1138 $tmp = split("\n",$res);
1139 foreach($tmp as $line){
1140 if(empty($line)) continue;
1141 $ret[]= $line;
1142 }
1143 }
1144 }
1145 return($ret);
1146 }
1148 }
1150 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1151 ?>