0874a2814a86ac9bb92c3b4b9d9ad98d41428691
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;
54 var $member_of_ogroup = FALSE;
56 var $o_group_dn = "";
58 function workstartup ($config, $dn= NULL, $parent= NULL)
59 {
60 /* Cehck if FAI is activated, else do not save any FAI attributes */
61 $tmp = search_config($config->data,"faiManagement","CLASS");
62 if(!empty($tmp)){
63 $this->fai_activated = TRUE;
64 }else{
65 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
66 $this->objectclasses = array("GOhard");
67 }
69 plugin::plugin ($config, $dn, $parent);
71 if(!isset($this->parent->by_object['ogroup'])){
72 $ldap = $this->config->get_ldap_link();
73 $ldap->cd ($this->config->current['BASE']);
74 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
75 if($ldap->count()){
76 $this->member_of_ogroup = TRUE;
77 $attrs = $ldap->fetch();
78 $this->o_group_dn = $attrs['dn'];
79 }
80 }
82 /* Creating a list of valid Mirrors
83 * none will not be saved to ldap.
84 */
85 $ldap = $this->config->get_ldap_link();
86 $ldap->cd($this->config->current['BASE']);
88 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
89 $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
90 }
93 /* Perform some special FAI stuff, only if it is activated */
94 if($this->fai_activated){
96 $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
97 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
99 $ui = get_userinfo();
100 $res = get_list( "(|(objectClass=FAIpackageList)".
101 "(objectClass=FAItemplate)".
102 "(objectClass=FAIvariable)".
103 "(objectClass=FAIscript)".
104 "(objectClass=FAIhook)".
105 "(objectClass=FAIprofile)".
106 "(objectClass=FAIpartitionTable))",
107 $ui->subtreeACL,$this->config->current['BASE'],
108 array("cn","objectClass","FAIdebianSection","description"));
110 foreach($res as $attr){
111 $cn = $attr['cn'][0];
113 $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
115 if(!isset($attr['description'])){
116 $attr['description'][0] = "";
117 }
119 if(in_array('FAIpackageList',$attr['objectClass'])){
120 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
121 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
122 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
123 $tmp2[$cn]['FAIpackageList']['desc'] = $attr['description'];
124 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
125 }
126 if(in_array('FAItemplate',$attr['objectClass'])){
127 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
128 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
129 $tmp2[$cn]['FAItemplate']['desc'] = $attr['description'];
130 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
131 }
132 if(in_array('FAIvariable',$attr['objectClass'])){
133 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
134 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
135 $tmp2[$cn]['FAIvariable']['desc'] = $attr['description'];
136 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
137 }
138 if(in_array('FAIscript',$attr['objectClass'])){
139 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
140 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
141 $tmp2[$cn]['FAIscript']['desc'] = $attr['description'];
142 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
143 }
144 if(in_array('FAIhook',$attr['objectClass'])){
145 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
146 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
147 $tmp2[$cn]['FAIhook']['desc'] = $attr['description'];
148 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
149 }
150 if(in_array('FAIpartitionTable',$attr['objectClass'])){
151 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
152 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
153 $tmp2[$cn]['FAIpartitionTable']['desc'] = $attr['description'];
154 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
155 }
156 if(in_array('FAIprofile',$attr['objectClass'])){
157 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
158 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
159 $tmp2[$cn]['FAIprofile']['desc'] = $attr['description'];
160 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
161 }
162 }
163 if(is_array($this->FAIclasses)){
164 natcasesort($this->FAIclasses);
165 }
167 if(isset($tmp2)){
168 $this->FAIclassInfo = $tmp2;
169 } else {
170 $this->FAIclassInfo = array();
171 }
173 /* Build up an array like this one :
174 [$url]['SERVER'] = 'srv1-002';
175 [$url]['RELEASE']['siga/rc9.0.2']
176 ['SECTIONS'][0] "main";
177 ['SECTIONS'][1] "non-free";
178 [$url]['RELEASE']['siga/rc9.0.2']
179 ['PACKAGES'][0] "pkg1";
180 ['PACKAGES'][1] "postfix";
181 */
182 $filter= "";
183 $ui= get_userinfo();
184 if (isset($config->current['STRICT_UNITS']) && preg_match('/TRUE/i', $config->current['STRICT_UNITS']) && $ui->gosaUnitTag != ""){ $filter= "(gosaUnitTag=".$ui->gosaUnitTag.")";
185 } $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer)$filter)",array("FAIrepository"));
186 $test = array();
187 while($attr = $ldap->fetch()){
188 if(isset($attr['FAIrepository'])){
190 unset($attr['FAIrepository']['count']);
192 foreach($attr['FAIrepository'] as $rep){
193 $tmp = split("\|",$rep);
195 if(count($tmp)==4){
196 $sections = split(",",$tmp[3]);
197 $release = $tmp[2];
198 $server = $tmp[1];
199 $url = $tmp[0];
201 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
203 /* Result will be cached
204 */
205 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
206 $test[$url]['SERVER'] = $server;
208 /* auto gets all releases/classes
209 */
210 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
211 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
212 }
213 }
214 }
215 }
217 /* Add possible elements from hook */
218 $lines= $this->GetHookElements();
219 foreach ($lines as $hline){
220 $entries= split(";", $hline);
221 if (isset($entries[1]) && !isset($test[$entries[1]])){
222 $test[$entries[1]]['RELEASE']= array();
224 /* Split releases */
225 if (isset($entries[2])){
226 $releases= split(",", $entries[2]);
228 foreach ($releases as $release){
229 $rname= preg_replace('/:.*$/', '', $release);
230 $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
231 $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
232 $test[$entries[1]]['RELEASE'][$rname]= array();
233 $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
234 foreach ($classes as $class){
235 if ($class != ""){
236 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
237 }
238 }
239 }
240 }
241 }
242 }
244 $this->FAIServRepConfig= $test;
245 } // Do FAI stuff end
247 /* Get arrays */
248 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
249 if (isset($this->attrs["$val"]["count"])){
250 for ($i= 0; $i<$this->attrs["count"]; $i++){
251 if (isset($this->attrs["$val"][$i])){
252 array_push($this->$val, $this->attrs["$val"][$i]);
253 }
254 }
255 }
256 sort ($this->$val);
257 $this->$val= array_unique($this->$val);
258 $this->saved_attributes[$val]= $this->$val;
259 }
261 /* Parse Kernel Parameters to decide what boot mode is enabled */
262 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
263 $this->bootmode= "G";
264 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
265 $this->bootmode= "D";
266 } elseif ($this->gotoKernelParameters == "") {
267 $this->bootmode= "G";
268 } else {
269 $this->bootmode= "T";
270 }
271 if (preg_match("/ o /", $this->gotoKernelParameters)){
272 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
273 } else {
274 $this->customParameters= "";
275 }
277 /* Prepare Shares */
278 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
279 unset($this->attrs['gotoShare']['count']);
280 foreach($this->attrs['gotoShare'] as $share){
281 $tmp = $tmp2 = array();
282 $tmp = split("\|",$share);
283 $tmp2['server'] =$tmp[0];
284 $tmp2['name'] =$tmp[1];
285 $tmp2['mountPoint'] =$tmp[2];
286 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
287 }
288 }
290 $this->gotoShareSelections= $config->getShareList(true);
291 $this->gotoAvailableShares= $config->getShareList(false);
292 $tmp2 = array();
295 /* Again some special FAI stuff */
296 if($this->fai_activated){
297 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
298 $tmp = array();
299 $tmp = split(" ",$this->FAIclass);
300 $tmp2 =array();
302 foreach($tmp as $class){
303 if( ":" == $class[0] ) {
304 $this->FAIrelease = substr( $class, 1 );
305 }
306 else
307 $tmp2[$class] = $class;
308 }
309 $this->FAIclass = $tmp2;
310 }
312 if(!is_array($this->FAIclass)){
313 $this->FAIclass =array();
314 }
315 }
317 $this->orig_dn= $this->dn;
319 /* Handle inheritance value "default" */
320 $this->gotoBootKernels= array();
323 /* Load hardware list */
324 if ($this->member_of_ogroup){
326 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
327 $this->FAIdebianMirror = "inherited";
328 }
330 if($this->fai_activated){
331 $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
332 }else{
333 $map= array("gotoLdapServer","gotoBootKernel");
334 }
336 $ldap = $this->config->get_ldap_link();
337 $ldap->cat($this->o_group_dn);
338 $attrs= $ldap->fetch();
340 foreach ($map as $name){
341 if (!isset($attrs[$name][0])){
342 continue;
343 }
345 switch ($name){
346 case 'gotoLdapServer':
347 $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
348 break;
350 case 'gotoBootKernel':
351 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
352 break;
354 case 'FAIclass':
355 $str = split(":",$attrs[$name][0]);
356 $this->InheritedFAIclass = split("\ ",trim($str[0]));
357 $this->InheritedFAIrelease = trim($str[1]);
358 break;
360 case 'FAIdebianMirror':
361 $this->InheritedFAIdebianMirror = $attrs[$name][0];
362 break;
363 }
364 }
365 }
367 /* Get list of boot kernels */
368 if (isset($this->config->data['TABS'])){
369 $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
371 if (!check_command($command)){
372 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
373 get_class($this));
374 } else {
376 $first = false;
377 $fh= popen($command, "r");
378 while (!feof($fh)) {
379 $buffer= trim(fgets($fh, 256));
381 if(!empty($buffer)){
383 $name=$value = $buffer;
384 if(preg_match("/:/",$buffer)){
385 $name = preg_replace("/:.*$/","",$buffer);
386 $value= preg_replace("/^.*:/","",$buffer);
387 $this->gotoBootKernels[$name]= $name.":".$value;
388 }else{
389 $this->gotoBootKernels[$name]= $value;
390 }
391 if($this->gotoBootKernel =="" ){
392 $this->gotoBootKernel = $name;
393 }
395 }
396 }
397 pclose($fh);
398 }
399 }
401 /* Turn to default, if we've nothing to inherit */
402 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
403 $this->gotoBootKernel= "default";
404 }
406 }
409 /* This class is called by the contrucktor ONLY.
410 * It return the available classes for each
411 * Server / Release combination ...
412 * (Release specifies which classes are available)
413 */
414 function getAvailableClassesForThisRelease($release)
415 {
416 /* There could be more than one server providing this release,
417 so use cached result if available
418 */
419 if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release])) {
420 return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
421 }
423 /* Walk through cache and get out what we need.
424 *
425 * Function od : "$this->generateDNSyn($release)"
426 * It returns an array like this one :
427 * array("ou=packges,ou=rc0.9.2,ou=siga,",
428 * "ou=scripts.. "
429 * ...);
430 * This helps us to select the correct classes for each release.
431 * It prevents errors like: 'siga' is selected as release, but all classes
432 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
433 */
434 $tmp2 = $this->generateDNSyn($release) ;
435 $test2 = array();
436 foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){
437 foreach($tmp2 as $dns){
438 if(preg_match("/".$dns."/",$attr['dn'])){
439 $test2[$attr['cn'][0]] = $attr['cn'][0];
440 }
441 }
442 }
443 $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
444 return($test2);
445 }
448 /* Create array to display available classes/profiles in a selectbox
449 * This function only displays the available classes.
450 * If a class is available is defined by these facts :
451 * 1. Is this class available for the selected release ?
452 * - if it is available, check if the release is available for the selected server
453 * (done by $this->getFAIreleases())
454 * 2. Is this class currently not assigned to $this->FAIclass
455 */
456 function selectFriendlyClasses(){
457 $tmp=array();
459 if($this->FAIdebianMirror == "inherited") return($tmp);
461 /* check if the current release exists,
462 else select the first one ..
463 */
464 $tmp2 = $this->getFAIreleases();
465 if(!isset($tmp2[$this->FAIrelease]) || !$tmp2[$this->FAIrelease]['USE']){
466 foreach($tmp2 as $key => $data){
467 if($data['USE']){
468 $this->FAIrelease = $key;
469 }
470 }
471 }
472 if(!in_array($this->FAIrelease, $tmp2)){
473 # $this->FAIrelease = key($tmp2);
474 }
476 /* Get all Packages for this server/release combination
477 */
479 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
480 $pkgs = array();
481 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
482 }else{
483 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
484 }
486 /* Check each and every single class name
487 */
488 foreach($pkgs as $pkg){
490 /* Class already assigned to the classes list ?
491 * If not ... go on
492 */
493 if(!in_array($pkg,$this->FAIclass)){
495 /* Create the displayed list entry value
496 HKLMOP [-Pl P V T-] or something like that
497 */
498 $str = "";
499 foreach($this->FAIclassInfo[$pkg] as $entry){
500 if(isset($entry['kzl'])){
501 $str .= $entry['kzl']." ";
502 }
503 }
505 /* Append class if everyting was fine
506 */
507 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
508 }
509 }
510 /* Just sort and return new classes list ...
511 ( possibly we should cache the result ... )
512 */
513 natcasesort ($tmp);
514 return($tmp);
515 }
517 function check()
518 {
519 $messages = array();
521 /* Call common method to give check the hook */
522 $messages= plugin::check();
524 /* If there are packages selected, but no mirror show error */
525 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
526 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
527 }
529 return($messages);
530 }
532 function execute()
533 {
534 /* Call parent execute */
535 plugin::execute();
537 /* Do we need to flip is_account state? */
538 if (isset($_POST['modify_state'])){
539 $this->is_account= !$this->is_account;
540 }
542 /* Do we represent a valid terminal? */
543 if (!$this->is_account && $this->parent == NULL){
544 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
545 _("This 'dn' has no terminal features.")."</b>";
546 return ($display);
547 }
549 /* Add module */
550 if (isset ($_POST['add_module']) ){
551 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
552 $this->add_list ($this->gotoModules, $_POST['module']);
553 }
554 }
556 /* Delete module */
557 if (isset ($_POST['delete_module'])){
558 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
559 $this->del_list ($this->gotoModules, $_POST['modules_list']);
560 }
561 }
563 /* FAI class management */
564 if($this->fai_activated && chkacl($this->acl,"FAIclass") == ""){
566 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
567 $found = 0 ;
569 /* If this new class/profile will attach a second partition table
570 * to our list of classes, abort and show a message.
571 */
572 foreach($this->FAIclass as $name){
573 if(isset($this->FAIclassInfo[$name])){
574 foreach($this->FAIclassInfo[$name] as $atr){
575 if(isset($atr['obj'])){
576 if($atr['obj'] == "FAIpartitionTable"){
577 $found ++ ;
578 }
579 }
580 }
581 }
582 }
584 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
585 print_red(_("There is already a profile in your selection that contain partition table configurations."));
586 }else{
587 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
588 }
589 }
591 $sort = false;
592 foreach($_POST as $name => $val){
594 $sort_type = false;
595 if((preg_match("/sort_up/",$name))&&(!$sort)){
596 $sort_type = "sort_up_";
597 }
598 if((preg_match("/sort_down/",$name))&&(!$sort)){
599 $sort_type = "sort_down_";
600 }
602 if(($sort_type)&&(!$sort)){
603 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
604 $sort = true;
606 $last = -1;
607 $change_down = -1;
609 /* Create array with numeric index */
610 $tmp = array();
611 foreach($this->FAIclass as $class){
612 $tmp [] = $class;
613 }
615 /* Walk trough array */
616 foreach($tmp as $key => $faiName){
617 if($faiName == $value){
618 if($sort_type == "sort_up_"){
619 if($last != -1){
620 $change_down= $last;
621 }
622 }else{
623 if(isset($tmp[$key+1])){
624 $change_down = $key;
625 }
626 }
627 }
628 $last = $key;
629 }
631 $tmp2 = array();
632 $skip = false;
634 foreach($tmp as $ky => $vl){
636 if($ky == $change_down){
637 $skip = $vl;
638 }else{
639 $tmp2[$vl] = $vl;
640 }
641 if(($skip != false)&&($ky != $change_down)){
642 $tmp2[$skip] = $skip;
643 $skip =false;
644 }
645 }
646 $this->FAIclass = $tmp2;
647 }
649 if(preg_match("/fai_remove/i",$name)){
650 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
651 unset($this->FAIclass[$value]);
652 }
653 }
654 }
656 /* Show main page */
657 $smarty= get_smarty();
658 $smarty->assign("SelectBoxLdapServer","");
660 /* In this section server shares will be defined
661 * A user can select one of the given shares and a mount point
662 * and attach this combination to his setup.
663 */
664 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
665 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
667 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
668 * This entry will be, a combination of mountPoint and sharedefinitions
669 */
670 if(isset($_POST['gotoShareAdd']) && chkacl($this->acl,"gotoShare") ==""){
671 /* We assign a share to this user, if we don't know where to mount the share */
672 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
673 print_red(_("You must specify a valid mount point."));
674 }else{
675 if(count($this->gotoAvailableShares)){
676 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
677 $s_mount = $_POST['gotoShareMountPoint'];
678 /* Preparing the new assignment */
679 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
680 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
681 }
682 }
683 }
685 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
686 * If there is no defined share selected, we will abort the deletion without any message
687 */
688 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare'])) && chkacl($this->acl,"gotoShare") ==""){
689 unset($this->gotoShares[$_POST['gotoShare']]);
690 }
692 $smarty->assign("gotoShares",$this->printOutAssignedShares());
693 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
694 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
695 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
697 /* Arrays */
698 $tmp = $this->goLdapServerList;
700 /* Create divSelectBox for ldap server selection
701 */
702 $SelectBoxLdapServer = new divSelectBox("LdapServer");
703 $SelectBoxLdapServer->SetHeight(130);
705 /* Set first entry as selected, if $this->gotoLdapServer is empty
706 * or given entry is no longer available ...
707 */
708 $found = false;
709 foreach($tmp as $server){
710 if($this->gotoLdapServer==$server){
711 $found = true;
712 }
713 }
715 /* Add Entries
716 */
717 foreach($tmp as $key => $server){
718 $use ="";
719 if(($this->gotoLdapServer == $server) || ($found == false)) {
720 $found = true;
721 $use = " checked ";
722 };
724 $use .= chkacl($this->acl,"gotoLdapServer");
726 $display = $server;
728 $SelectBoxLdapServer->AddEntry(
729 array(
730 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
731 "attach"=>"style='border-left:0px;'"),
732 array("string"=>$display)
733 ));
734 }
736 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
738 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
739 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
740 $smarty->assign("$val", $this->$val);
741 }
743 /* Values */
744 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
745 $smarty->assign($val, $this->$val);
746 $smarty->assign($val."ACL", chkacl($this->acl, $val));
747 }
749 $smarty->assign("fai_activated",$this->fai_activated);
750 if($this->fai_activated){
751 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
752 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
753 $smarty->assign("FAIreleases",$this->getFAIreleases());
754 $smarty->assign("FAIrelease",$this->FAIrelease);
755 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
756 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
757 $smarty->assign("FAIclassKeys",$this->FAIclass);
758 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
760 $div = new divSelectBox("WSFAIscriptClasses");
761 $div -> SetHeight("110");
762 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
763 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
764 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
765 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
767 $i = 1;
769 if($this->FAIdebianMirror == "inherited"){
770 $tmp = $this->InheritedFAIclass;
771 }else{
772 $tmp = $this->FAIclass;
773 }
775 foreach($tmp as $class){
777 $marker = "";
778 if(in_array_ics($class,$this->unresolved_classes)){
779 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
780 }
782 if($this->FAIdebianMirror == "inherited"){
783 $str = "";
784 }else{
785 if($i==1){
786 $str = $str_empty.$str_down.$str_remove;
787 }elseif($i == count($this->FAIclass)){
788 $str = $str_up.$str_empty.$str_remove;
789 }else{
790 $str = $str_up.$str_down.$str_remove;
791 }
792 }
793 $i ++ ;
795 $desc = "";
796 foreach($this->FAIclassInfo[$class] as $types ){
797 if(isset($types['desc'][0])){
798 $desc.= $types['desc'][0]." ";
799 }
800 }
801 if(!empty($desc)){
802 $desc = " [".trim($desc)."]";
803 }
805 $div->AddEntry(array(
806 array("string"=>$class.$desc.$marker),
807 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
808 ));
809 }
810 $smarty->assign("FAIScriptlist",$div->DrawList());
811 }
813 /* Radio button group */
814 if (preg_match("/G/", $this->bootmode)) {
815 $smarty->assign("graphicalbootup", "checked");
816 } else {
817 $smarty->assign("graphicalbootup", "");
818 }
819 if (preg_match("/T/", $this->bootmode)) {
820 $smarty->assign("textbootup", "checked");
821 } else {
822 $smarty->assign("textbootup", "");
823 }
824 if (preg_match("/D/", $this->bootmode)) {
825 $smarty->assign("debugbootup", "checked");
826 } else {
827 $smarty->assign("debugbootup", "");
828 }
830 /* ACL's */
831 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
832 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
833 }
835 /* Show main page */
836 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
837 }
839 function remove_from_parent()
840 {
841 $this->handle_post_events("remove");
842 }
844 function generateDNSyn($release)
845 {
846 $str = "";
847 $tmp = split("\/",$release);
848 $tmp = array_reverse($tmp);
850 $base = ",ou=fai,";
852 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
854 foreach($tmp as $departmentname){
856 $str .= ",ou=".$departmentname;
857 }
858 $ret = array();
859 foreach($arr as $ar){
860 $ret[] = ",ou=".$ar.$str.$base;
861 }
862 return($ret);
863 }
865 function getFAIdebianMirrors()
866 {
867 $ret = array();
869 /* Only add inherit option, if we are part in an object group
870 */
871 if($this->member_of_ogroup) {
872 $ret['inherited']['NAME']="["._("inherited")."]";
873 $ret['inherited']['USE'] = TRUE;
874 }
876 $ret['auto']['NAME']=_("automatic");
877 $ret['auto']['USE'] = TRUE;
878 $secs = array();
880 /* Walk through all available servers
881 and check if they support the currently selected classes
882 if not, dont't add them to our list
883 */
884 foreach($this->FAIServRepConfig as $mirror => $rest){
886 /* Automatically selection is available everytime */
887 if($mirror == "auto"){
888 continue;
889 }
891 $use = false;
892 if(count($this->FAIclass) == 0){
893 $use = true;
894 }else{
895 $tmp = $this->getFAIreleases();
896 foreach($tmp as $release => $data){
897 if(isset($rest['RELEASE'][$release]) && $release == $this->FAIrelease){
898 $use = $data['USE'];
899 }
900 }
901 }
903 /* If current server, doesn't support this class
904 remove it from list
905 */
906 $ret[$mirror]['NAME'] = $mirror;
907 $ret[$mirror]['USE'] = $use;
908 }
909 return($ret);
910 }
912 function getFAIreleases()
913 {
914 $ret = array();
916 if($this->FAIdebianMirror == "inherited") {
917 return(array());
918 }
920 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
921 $this->FAIdebianMirror = "auto";
922 }
924 $errorClasses = array();
925 if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
926 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
927 $use = true;
929 if(!count($this->FAIclass) == 0){
930 foreach($this->FAIclass as $class){
931 if(!in_array($class, $sections['PACKAGES'])){
932 $use = false;
933 $errorClasses[$class] = $class;
934 }else{
935 if(isset($errorClasses[$class])){
936 unset($errorClasses[$class]);
937 }
938 }
939 }
940 }
941 $ret[$release]['NAME']=$release;
942 $ret[$release]['USE']=$use;
943 }
944 }
946 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
948 $eClasses = " ";
949 foreach($errorClasses as $class){
950 $eClasses .= $class." ";
951 }
953 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));
954 $this->FAIdebianMirror = "auto";
955 return($this->getFAIreleases());
956 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
958 $eClasses = " ";
959 foreach($errorClasses as $class){
960 $eClasses .= $class." ";
961 }
963 $this->unresolved_classes = $errorClasses;
964 $this->FAIdebianMirror = "auto";
965 //$this->FAIclass= array();
966 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));
967 }
968 return($ret);
969 }
971 /* Save data to object */
972 function save_object()
973 {
974 plugin::save_object();
976 /* Save group radio buttons */
977 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
978 $this->bootmode= $_POST["bootmode"];
979 }
981 /* Save kernel parameters */
982 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
983 $this->customParameters= $_POST["customParameters"];
984 }
986 }
989 /* Save to LDAP */
990 function save()
991 {
993 /* Depending on the baseobject (Ogroup / WS) we
994 * use another set of objectClasses
995 * In case of WS itself, we use "array("GOhard", "FAIobject");"
996 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
997 */
998 if(isset($this->parent->by_object['ogroup'])){
999 $this->objectclasses = array("gotoWorkstationTemplate");
1000 }elseif(isset($this->parent->by_object['workgeneric'])){
1001 $this->objectclasses = array("GOhard");
1002 }elseif(isset($this->parent->by_object['servgeneric'])){
1003 $this->objectclasses = array("GOhard");
1004 }else{
1005 print "Object Type Configuration : unknown";
1006 exit();
1007 }
1009 if($this->fai_activated){
1010 $this->objectclasses [] = "FAIobject";
1011 }
1013 /* Find proper terminal path for tftp configuration
1014 FIXME: This is suboptimal when the default has changed to
1015 another location! */
1016 if (($this->gotoTerminalPath == "default")){
1017 $ldap= $this->config->get_ldap_link();
1019 /* Strip relevant part from dn, keep trailing ',' */
1020 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
1021 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
1023 /* Walk from top to base and try to load default values for
1024 'gotoTerminalPath'. Abort when an entry is found. */
1025 while (TRUE){
1026 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
1028 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
1029 $this->config->current['BASE'], array('gotoTerminalPath'));
1030 $attrs= $ldap->fetch();
1031 if (isset($attrs['gotoTerminalPath'])){
1032 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
1033 break;
1034 }
1036 /* Nothing left? */
1037 if ($tmp == ""){
1038 break;
1039 }
1040 }
1041 }
1043 /* Add semi automatic values */
1044 // FIXME: LDAP Server may not be set here...
1045 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1047 switch ($this->bootmode){
1048 case "D":
1049 $this->gotoKernelParameters.= " debug";
1050 break;
1051 case "G":
1052 $this->gotoKernelParameters.= " splash=silent";
1053 break;
1054 }
1055 if ($this->customParameters != ""){
1056 $this->gotoKernelParameters.= " o ".$this->customParameters;
1057 }
1059 plugin::save();
1062 if($this->fai_activated){
1064 unset( $this->attrs['FAIrelease'] );
1066 $str = "";
1068 if($this->FAIdebianMirror == "inherited"){
1070 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1072 }else{
1074 foreach($this->FAIclass as $class){
1075 $str .= $class." ";
1076 }
1077 $str .= ":" . $this->FAIrelease;
1078 $this->attrs['FAIclass']= "";
1079 $this->attrs['FAIclass']= trim($str);
1081 if(empty($this->attrs['FAIclass'])){
1082 $this->attrs['FAIclass'] = array();
1083 }
1084 }
1086 /* if mirror == none stop saving this attribute */
1087 if($this->FAIdebianMirror == "none"){
1088 $this->FAIdebianMirror = "";
1089 }
1090 }
1092 /* Add missing arrays */
1093 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1094 if (isset ($this->$val) && count ($this->$val) != 0){
1096 $this->attrs["$val"]= array_unique($this->$val);
1097 }
1098 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1099 }
1101 /* Strip out 'default' values */
1102 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1103 $this->attrs['gotoLdapServer']= array();
1104 }
1106 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1107 $this->attrs['gotoBootKernel']= array();
1108 }
1110 $ldap= $this->config->get_ldap_link();
1111 $ldap->cd($this->dn);
1113 /* Get FAIstate from object, the generic tab could have changed it during execute */
1114 if($this->fai_activated){
1115 $ldap->cat($this->dn,array("FAIstate"));
1116 $checkFAIstate = $ldap->fetch();
1118 /* Remove FAI objects if no FAI class is selected */
1119 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1120 $this->attrs['FAIclass'] = array();
1121 $this->attrs['FAIdebianMirror'] = array();
1122 }
1123 }
1125 /* prepare share settings */
1126 $tmp = array();
1127 foreach($this->gotoShares as $name => $settings){
1128 $tmp2= split("\|",$name);
1129 $name = $tmp2[0];
1130 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1131 }
1132 $this->attrs['gotoShare']=$tmp;
1134 $this->cleanup();
1135 $ldap->modify ($this->attrs);
1137 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1138 $this->handle_post_events("modify");
1139 }
1141 /* Add value to array, check if unique */
1142 function add_list (&$array, $value)
1143 {
1144 if ($value != ""){
1145 $array[]= $value;
1146 sort($array);
1147 array_unique ($array);
1148 }
1149 }
1152 /* Delete value to array, check if unique */
1153 function del_list (&$array, $list)
1154 {
1155 $tmp= array();
1156 foreach ($array as $mod){
1157 if (!in_array($mod, $list)){
1158 $tmp[]= $mod;
1159 }
1160 }
1161 $array= $tmp;
1162 }
1164 /* Generate ListBox frindly output for the defined shares
1165 * Possibly Add or remove an attribute here,
1166 */
1167 function printOutAssignedShares()
1168 {
1169 $a_return = array();
1170 if(is_array($this->gotoShares)){
1171 foreach($this->gotoShares as $share){
1172 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1173 }
1174 }
1175 return($a_return);
1176 }
1179 function GetHookElements()
1180 {
1181 $ret = array();
1182 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1183 if(!empty($cmd)){
1184 $res = shell_exec($cmd);
1185 $res2 = trim($res);
1186 if((!$res)){
1187 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1188 }elseif(empty($res2)){
1189 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1190 }else{
1191 $tmp = split("\n",$res);
1192 foreach($tmp as $line){
1193 if(empty($line)) continue;
1194 $ret[]= $line;
1195 }
1196 }
1197 }
1198 return($ret);
1199 }
1201 }
1203 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1204 ?>