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(!isset($tmp2[$this->FAIrelease]) || !$tmp2[$this->FAIrelease]['USE']){
458 foreach($tmp2 as $key => $data){
459 if($data['USE']){
460 $this->FAIrelease = $key;
461 }
462 }
463 }
464 if(!in_array($this->FAIrelease, $tmp2)){
465 # $this->FAIrelease = key($tmp2);
466 }
468 /* Get all Packages for this server/release combination
469 */
471 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
472 $pkgs = array();
473 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
474 }else{
475 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
476 }
478 /* Check each and every single class name
479 */
480 foreach($pkgs as $pkg){
482 /* Class already assigned to the classes list ?
483 * If not ... go on
484 */
485 if(!in_array($pkg,$this->FAIclass)){
487 /* Create the displayed list entry value
488 HKLMOP [-Pl P V T-] or something like that
489 */
490 $str = "";
491 foreach($this->FAIclassInfo[$pkg] as $entry){
492 if(isset($entry['kzl'])){
493 $str .= $entry['kzl']." ";
494 }
495 }
497 /* Append class if everyting was fine
498 */
499 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
500 }
501 }
502 /* Just sort and return new classes list ...
503 ( possibly we should cache the result ... )
504 */
505 natcasesort ($tmp);
506 return($tmp);
507 }
509 function check()
510 {
511 $messages = array();
513 /* Call common method to give check the hook */
514 $messages= plugin::check();
516 /* If there are packages selected, but no mirror show error */
517 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
518 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
519 }
521 return($messages);
522 }
524 function execute()
525 {
527 /* Call parent execute */
528 plugin::execute();
530 /* Do we need to flip is_account state? */
531 if (isset($_POST['modify_state'])){
532 $this->is_account= !$this->is_account;
533 }
535 /* Do we represent a valid terminal? */
536 if (!$this->is_account && $this->parent == NULL){
537 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
538 _("This 'dn' has no terminal features.")."</b>";
539 return ($display);
540 }
542 /* Add module */
543 if (isset ($_POST['add_module']) ){
544 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
545 $this->add_list ($this->gotoModules, $_POST['module']);
546 }
547 }
549 /* Delete module */
550 if (isset ($_POST['delete_module'])){
551 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
552 $this->del_list ($this->gotoModules, $_POST['modules_list']);
553 }
554 }
556 /* FAI class management */
557 if($this->fai_activated && chkacl($this->acl,"FAIclass") == ""){
559 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
560 $found = 0 ;
562 /* If this new class/profile will attach a second partition table
563 * to our list of classes, abort and show a message.
564 */
565 foreach($this->FAIclass as $name){
566 if(isset($this->FAIclassInfo[$name])){
567 foreach($this->FAIclassInfo[$name] as $atr){
568 if(isset($atr['obj'])){
569 if($atr['obj'] == "FAIpartitionTable"){
570 $found ++ ;
571 }
572 }
573 }
574 }
575 }
577 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
578 print_red(_("There is already a profile in your selection that contain partition table configurations."));
579 }else{
580 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
581 }
582 }
584 $sort = false;
585 foreach($_POST as $name => $val){
587 $sort_type = false;
588 if((preg_match("/sort_up/",$name))&&(!$sort)){
589 $sort_type = "sort_up_";
590 }
591 if((preg_match("/sort_down/",$name))&&(!$sort)){
592 $sort_type = "sort_down_";
593 }
595 if(($sort_type)&&(!$sort)){
596 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
597 $sort = true;
599 $last = -1;
600 $change_down = -1;
602 /* Create array with numeric index */
603 $tmp = array();
604 foreach($this->FAIclass as $class){
605 $tmp [] = $class;
606 }
608 /* Walk trough array */
609 foreach($tmp as $key => $faiName){
610 if($faiName == $value){
611 if($sort_type == "sort_up_"){
612 if($last != -1){
613 $change_down= $last;
614 }
615 }else{
616 if(isset($tmp[$key+1])){
617 $change_down = $key;
618 }
619 }
620 }
621 $last = $key;
622 }
624 $tmp2 = array();
625 $skip = false;
627 foreach($tmp as $ky => $vl){
629 if($ky == $change_down){
630 $skip = $vl;
631 }else{
632 $tmp2[$vl] = $vl;
633 }
634 if(($skip != false)&&($ky != $change_down)){
635 $tmp2[$skip] = $skip;
636 $skip =false;
637 }
638 }
639 $this->FAIclass = $tmp2;
640 }
642 if(preg_match("/fai_remove/i",$name)){
643 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
644 unset($this->FAIclass[$value]);
645 }
646 }
647 }
649 /* Show main page */
650 $smarty= get_smarty();
651 $smarty->assign("SelectBoxLdapServer","");
653 /* In this section server shares will be defined
654 * A user can select one of the given shares and a mount point
655 * and attach this combination to his setup.
656 */
657 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
658 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
660 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
661 * This entry will be, a combination of mountPoint and sharedefinitions
662 */
663 if(isset($_POST['gotoShareAdd']) && chkacl($this->acl,"gotoShare") ==""){
664 /* We assign a share to this user, if we don't know where to mount the share */
665 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
666 print_red(_("You must specify a valid mount point."));
667 }else{
668 if(count($this->gotoAvailableShares)){
669 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
670 $s_mount = $_POST['gotoShareMountPoint'];
671 /* Preparing the new assignment */
672 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
673 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
674 }
675 }
676 }
678 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
679 * If there is no defined share selected, we will abort the deletion without any message
680 */
681 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare'])) && chkacl($this->acl,"gotoShare") ==""){
682 unset($this->gotoShares[$_POST['gotoShare']]);
683 }
685 $smarty->assign("gotoShares",$this->printOutAssignedShares());
686 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
687 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
688 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
690 /* Arrays */
691 $tmp = $this->goLdapServerList;
693 /* Create divSelectBox for ldap server selection
694 */
695 $SelectBoxLdapServer = new divSelectBox("LdapServer");
696 $SelectBoxLdapServer->SetHeight(130);
698 /* Set first entry as selected, if $this->gotoLdapServer is empty
699 * or given entry is no longer available ...
700 */
701 $found = false;
702 foreach($tmp as $server){
703 if($this->gotoLdapServer==$server){
704 $found = true;
705 }
706 }
708 /* Add Entries
709 */
710 foreach($tmp as $key => $server){
711 $use ="";
712 if(($this->gotoLdapServer == $server) || ($found == false)) {
713 $found = true;
714 $use = " checked ";
715 };
717 $use .= chkacl($this->acl,"gotoLdapServer");
719 $display = $server;
721 $SelectBoxLdapServer->AddEntry(
722 array(
723 array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
724 "attach"=>"style='border-left:0px;'"),
725 array("string"=>$display)
726 ));
727 }
729 $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
731 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
732 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
733 $smarty->assign("$val", $this->$val);
734 }
736 /* Values */
737 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
738 $smarty->assign($val, $this->$val);
739 $smarty->assign($val."ACL", chkacl($this->acl, $val));
740 }
742 $smarty->assign("fai_activated",$this->fai_activated);
743 if($this->fai_activated){
744 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
745 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
746 $smarty->assign("FAIreleases",$this->getFAIreleases());
747 $smarty->assign("FAIrelease",$this->FAIrelease);
748 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
749 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
750 $smarty->assign("FAIclassKeys",$this->FAIclass);
751 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
753 $div = new divSelectBox("WSFAIscriptClasses");
754 $div -> SetHeight("110");
755 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
756 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
757 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
758 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
760 $i = 1;
762 if($this->FAIdebianMirror == "inherited"){
763 $tmp = $this->InheritedFAIclass;
764 }else{
765 $tmp = $this->FAIclass;
766 }
768 foreach($tmp as $class){
770 $marker = "";
771 if(in_array_ics($class,$this->unresolved_classes)){
772 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
773 }
775 if($this->FAIdebianMirror == "inherited"){
776 $str = "";
777 }else{
778 if($i==1){
779 $str = $str_empty.$str_down.$str_remove;
780 }elseif($i == count($this->FAIclass)){
781 $str = $str_up.$str_empty.$str_remove;
782 }else{
783 $str = $str_up.$str_down.$str_remove;
784 }
785 }
786 $i ++ ;
788 $desc = "";
789 foreach($this->FAIclassInfo[$class] as $types ){
790 if(isset($types['desc'][0])){
791 $desc.= $types['desc'][0]." ";
792 }
793 }
794 if(!empty($desc)){
795 $desc = " [".trim($desc)."]";
796 }
798 $div->AddEntry(array(
799 array("string"=>$class.$desc.$marker),
800 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
801 ));
802 }
803 $smarty->assign("FAIScriptlist",$div->DrawList());
804 }
806 /* Radio button group */
807 if (preg_match("/G/", $this->bootmode)) {
808 $smarty->assign("graphicalbootup", "checked");
809 } else {
810 $smarty->assign("graphicalbootup", "");
811 }
812 if (preg_match("/T/", $this->bootmode)) {
813 $smarty->assign("textbootup", "checked");
814 } else {
815 $smarty->assign("textbootup", "");
816 }
817 if (preg_match("/D/", $this->bootmode)) {
818 $smarty->assign("debugbootup", "checked");
819 } else {
820 $smarty->assign("debugbootup", "");
821 }
823 /* ACL's */
824 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
825 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
826 }
828 /* Show main page */
829 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
830 }
832 function remove_from_parent()
833 {
834 $this->handle_post_events("remove");
835 }
837 function generateDNSyn($release)
838 {
839 $str = "";
840 $tmp = split("\/",$release);
841 $tmp = array_reverse($tmp);
843 $base = ",ou=fai,";
845 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
847 foreach($tmp as $departmentname){
849 $str .= ",ou=".$departmentname;
850 }
851 $ret = array();
852 foreach($arr as $ar){
853 $ret[] = ",ou=".$ar.$str.$base;
854 }
855 return($ret);
856 }
858 function getFAIdebianMirrors()
859 {
860 $ret = array();
862 /* Only add inherit option, if we are part in an object group
863 */
864 if($this->member_of_ogroup) {
865 $ret['inherited']['NAME']="["._("inherited")."]";
866 $ret['inherited']['USE'] = TRUE;
867 }
869 $ret['auto']['NAME']=_("automatic");
870 $ret['auto']['USE'] = TRUE;
871 $secs = array();
873 /* Walk through all available servers
874 and check if they support the currently selected classes
875 if not, dont't add them to our list
876 */
877 foreach($this->FAIServRepConfig as $mirror => $rest){
878 $use = false;
879 if(count($this->FAIclass) == 0){
880 $use = true;
881 }else{
882 $tmp = $this->getFAIreleases();
883 foreach($tmp as $release => $data){
884 if(isset($rest['RELEASE'][$release])){
885 $use = $data['USE'];
886 }
887 }
888 }
890 /* If current server, doesn't support this class
891 remove it from list
892 */
893 $ret[$mirror]['NAME'] = $mirror;
894 $ret[$mirror]['USE'] = $use;
895 }
896 return($ret);
897 }
899 function getFAIreleases()
900 {
901 $ret = array();
903 if($this->FAIdebianMirror == "inherited") {
904 return(array());
905 }
907 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
908 $this->FAIdebianMirror = "auto";
909 }
911 $errorClasses = array();
912 if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
913 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
914 $use = true;
916 if(!count($this->FAIclass) == 0){
917 foreach($this->FAIclass as $class){
918 if(!in_array($class, $sections['PACKAGES'])){
919 $use = false;
920 $errorClasses[$class] = $class;
921 }else{
922 if(isset($errorClasses[$class])){
923 unset($errorClasses[$class]);
924 }
925 }
926 }
927 }
928 $ret[$release]['NAME']=$release;
929 $ret[$release]['USE']=$use;
930 }
931 }
933 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
935 $eClasses = " ";
936 foreach($errorClasses as $class){
937 $eClasses .= $class." ";
938 }
940 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));
941 $this->FAIdebianMirror = "auto";
942 return($this->getFAIreleases());
943 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
945 $eClasses = " ";
946 foreach($errorClasses as $class){
947 $eClasses .= $class." ";
948 }
950 $this->unresolved_classes = $errorClasses;
951 $this->FAIdebianMirror = "auto";
952 //$this->FAIclass= array();
953 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));
954 }
955 return($ret);
956 }
958 /* Save data to object */
959 function save_object()
960 {
961 plugin::save_object();
963 /* Save group radio buttons */
964 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
965 $this->bootmode= $_POST["bootmode"];
966 }
968 /* Save kernel parameters */
969 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
970 $this->customParameters= $_POST["customParameters"];
971 }
973 }
976 /* Save to LDAP */
977 function save()
978 {
980 /* Depending on the baseobject (Ogroup / WS) we
981 * use another set of objectClasses
982 * In case of WS itself, we use "array("GOhard", "FAIobject");"
983 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
984 */
985 if(isset($this->parent->by_object['ogroup'])){
986 $this->objectclasses = array("gotoWorkstationTemplate");
987 }elseif(isset($this->parent->by_object['workgeneric'])){
988 $this->objectclasses = array("GOhard");
989 }elseif(isset($this->parent->by_object['servgeneric'])){
990 $this->objectclasses = array("GOhard");
991 }else{
992 print "Object Type Configuration : unknown";
993 exit();
994 }
996 if($this->fai_activated){
997 $this->objectclasses [] = "FAIobject";
998 }
1000 /* Find proper terminal path for tftp configuration
1001 FIXME: This is suboptimal when the default has changed to
1002 another location! */
1003 if (($this->gotoTerminalPath == "default")){
1004 $ldap= $this->config->get_ldap_link();
1006 /* Strip relevant part from dn, keep trailing ',' */
1007 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
1008 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
1010 /* Walk from top to base and try to load default values for
1011 'gotoTerminalPath'. Abort when an entry is found. */
1012 while (TRUE){
1013 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
1015 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
1016 $this->config->current['BASE'], array('gotoTerminalPath'));
1017 $attrs= $ldap->fetch();
1018 if (isset($attrs['gotoTerminalPath'])){
1019 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
1020 break;
1021 }
1023 /* Nothing left? */
1024 if ($tmp == ""){
1025 break;
1026 }
1027 }
1028 }
1030 /* Add semi automatic values */
1031 // FIXME: LDAP Server may not be set here...
1032 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1034 switch ($this->bootmode){
1035 case "D":
1036 $this->gotoKernelParameters.= " debug";
1037 break;
1038 case "G":
1039 $this->gotoKernelParameters.= " splash=silent";
1040 break;
1041 }
1042 if ($this->customParameters != ""){
1043 $this->gotoKernelParameters.= " o ".$this->customParameters;
1044 }
1046 plugin::save();
1049 if($this->fai_activated){
1051 unset( $this->attrs['FAIrelease'] );
1053 $str = "";
1055 if($this->FAIdebianMirror == "inherited"){
1057 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
1059 }else{
1061 foreach($this->FAIclass as $class){
1062 $str .= $class." ";
1063 }
1064 $str .= ":" . $this->FAIrelease;
1065 $this->attrs['FAIclass']= "";
1066 $this->attrs['FAIclass']= trim($str);
1068 if(empty($this->attrs['FAIclass'])){
1069 $this->attrs['FAIclass'] = array();
1070 }
1071 }
1073 /* if mirror == none stop saving this attribute */
1074 if($this->FAIdebianMirror == "none"){
1075 $this->FAIdebianMirror = "";
1076 }
1077 }
1079 /* Add missing arrays */
1080 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1081 if (isset ($this->$val) && count ($this->$val) != 0){
1083 $this->attrs["$val"]= array_unique($this->$val);
1084 }
1085 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1086 }
1088 /* Strip out 'default' values */
1089 if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1090 $this->attrs['gotoLdapServer']= array();
1091 }
1093 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1094 $this->attrs['gotoBootKernel']= array();
1095 }
1097 $ldap= $this->config->get_ldap_link();
1098 $ldap->cd($this->dn);
1100 /* Get FAIstate from object, the generic tab could have changed it during execute */
1101 if($this->fai_activated){
1102 $ldap->cat($this->dn,array("FAIstate"));
1103 $checkFAIstate = $ldap->fetch();
1105 /* Remove FAI objects if no FAI class is selected */
1106 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1107 $this->attrs['FAIclass'] = array();
1108 $this->attrs['FAIdebianMirror'] = array();
1109 }
1110 }
1112 /* prepare share settings */
1113 $tmp = array();
1114 foreach($this->gotoShares as $name => $settings){
1115 $tmp2= split("\|",$name);
1116 $name = $tmp2[0];
1117 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1118 }
1119 $this->attrs['gotoShare']=$tmp;
1121 $this->cleanup();
1122 $ldap->modify ($this->attrs);
1124 show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1125 $this->handle_post_events("modify");
1126 }
1128 /* Add value to array, check if unique */
1129 function add_list (&$array, $value)
1130 {
1131 if ($value != ""){
1132 $array[]= $value;
1133 sort($array);
1134 array_unique ($array);
1135 }
1136 }
1139 /* Delete value to array, check if unique */
1140 function del_list (&$array, $list)
1141 {
1142 $tmp= array();
1143 foreach ($array as $mod){
1144 if (!in_array($mod, $list)){
1145 $tmp[]= $mod;
1146 }
1147 }
1148 $array= $tmp;
1149 }
1151 /* Generate ListBox frindly output for the defined shares
1152 * Possibly Add or remove an attribute here,
1153 */
1154 function printOutAssignedShares()
1155 {
1156 $a_return = array();
1157 if(is_array($this->gotoShares)){
1158 foreach($this->gotoShares as $share){
1159 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1160 }
1161 }
1162 return($a_return);
1163 }
1166 function GetHookElements()
1167 {
1168 $ret = array();
1169 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1170 if(!empty($cmd)){
1171 $res = shell_exec($cmd);
1172 $res2 = trim($res);
1173 if((!$res)){
1174 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1175 }elseif(empty($res2)){
1176 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1177 }else{
1178 $tmp = split("\n",$res);
1179 foreach($tmp as $line){
1180 if(empty($line)) continue;
1181 $ret[]= $line;
1182 }
1183 }
1184 }
1185 return($ret);
1186 }
1188 }
1190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1191 ?>