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