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