1caa42c2be1676fa3083e11b4b76967a2a7d80c2
1 <?php
2 class workstartup extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Manage terminal startup options";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* Generic terminal attributes */
10 var $bootmode = "G";
11 var $goLdapServerList = array("default");
12 var $gotoBootKernel = "default";
13 var $gotoKernelParameters = "";
14 var $gotoLdapServer = "";
15 var $gotoModules = array();
16 var $gotoAutoFs = array();
17 var $gotoFilesystem = array();
18 var $gotoTerminalPath = "";
19 var $FAIstatus = "";
22 /* attribute list for save action */
23 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
24 var $objectclasses = array("GOhard", "FAIobject");
26 /* Share */
27 var $gotoShares = array();// Currently Share Option
28 var $gotoShare = ""; // currently selected Share Option
29 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
30 var $gotoAvailableShares= array();// Available Shares for this account
32 /* Helper */
33 var $customParameters = "";
34 var $orig_dn = "";
35 var $ignore_account = TRUE;
37 /* FAI class selection */
38 var $FAIclass = array();
39 var $FAIclasses = array();
40 var $FAIclassInfo = array();
41 var $FAIrelease = "";
42 var $FAIdebianMirror = "auto";
44 /* Contains all possible server/release/class settings */
45 var $FAIServRepConfig = array();
47 function workstartup ($config, $dn= NULL)
48 {
49 plugin::plugin ($config, $dn);
51 /* Creating a list of valid Mirrors
52 * none will not be saved to ldap.
53 */
54 $ldap = $this->config->get_ldap_link();
55 $ldap->cd($this->config->current['BASE']);
56 $ldap->search("(objectClass=FAIrepositoryServer)",array("FAIrepository"));
58 /* attach all attributes with "index => cn" to avoid multiple entries */
59 $ret = array();
60 $rels = array();
61 $_SESSION['getAvailablePakagesForThisRelease_CACHE'] = array();
62 $_SESSION['getAvailablePakagesForThisRelease_CACHED_CLASSES'] = array();
64 /* Build up an array like this one :
65 [$url]['SERVER'] = 'srv1-002';
66 [$url]['RELEASE']['siga/rc9.0.2']
67 ['SECTIONS'][0] "main";
68 ['SECTIONS'][1] "non-free";
69 [$url]['RELEASE']['siga/rc9.0.2']
70 ['PACKAGES'][0] "pkg1";
71 ['PACKAGES'][1] "postfix";
72 */
73 $test = array();
74 while($attr = $ldap->fetch()){
75 if(isset($attr['FAIrepository'])){
77 unset($attr['FAIrepository']['count']);
79 foreach($attr['FAIrepository'] as $rep){
80 $tmp = split("\|",$rep);
82 if(count($tmp)==4){
83 $sections = split(",",$tmp[3]);
84 $release = $tmp[2];
85 $server = $tmp[1];
86 $url = $tmp[0];
88 $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
89 $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailablePakagesForThisRelease($release);
90 $test[$url]['SERVER'] = $server;
92 /* auto gets all releases/classes
93 */
94 $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
95 $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailablePakagesForThisRelease($release);
96 }
97 }
98 }
99 }
100 $this->FAIServRepConfig =$test;
102 /* Get arrays */
103 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
104 if (isset($this->attrs["$val"]["count"])){
105 for ($i= 0; $i<$this->attrs["count"]; $i++){
106 if (isset($this->attrs["$val"][$i])){
107 array_push($this->$val, $this->attrs["$val"][$i]);
108 }
109 }
110 }
111 sort ($this->$val);
112 $this->$val= array_unique($this->$val);
113 }
115 /* Parse Kernel Parameters to decide what boot mode is enabled */
116 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
117 $this->bootmode= "G";
118 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
119 $this->bootmode= "D";
120 } elseif ($this->gotoKernelParameters == "") {
121 $this->bootmode= "G";
122 } else {
123 $this->bootmode= "T";
124 }
125 if (preg_match("/ o /", $this->gotoKernelParameters)){
126 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
127 } else {
128 $this->customParameters= "";
129 }
131 /* Prepare Shares */
132 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
133 unset($this->attrs['gotoShare']['count']);
134 foreach($this->attrs['gotoShare'] as $share){
135 $tmp = $tmp2 = array();
136 $tmp = split("\|",$share);
137 $tmp2['server'] =$tmp[0];
138 $tmp2['name'] =$tmp[1];
139 $tmp2['mountPoint'] =$tmp[2];
140 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
141 }
142 }
144 $this->gotoShareSelections= $config->getShareList(true);
145 $this->gotoAvailableShares= $config->getShareList(false);
146 $tmp2 = array();
148 $ldap = $this->config->get_ldap_link();
149 $ldap->cd($this->config->current['BASE']);
151 /* Search all FAI objects */
152 $ldap->search("(| (objectClass=FAIpackageList)(objectClass=FAItemplate)
153 (objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)
154 (objectClass=FAIpartitionTable))",array("*"),true);
155 /* Sort all entries, and attach elementtype.
156 * To be able to show the types in the listbox.
157 */
158 while($attr = $ldap->fetch()){
159 $cn = $attr['cn'][0];
160 $tmp2[$cn]['REST'] = $attr;
161 if(in_array('FAIpackageList',$attr['objectClass'])){
162 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
163 $tmp2[$cn]['FAIpackageList']['kzl'] = 'Pl';
164 $tmp2[$cn]['FAIpackageList']['sec'] = $attr['FAIdebianSection'];
165 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
166 }
167 if(in_array('FAItemplate',$attr['objectClass'])){
168 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
169 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
170 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
171 }
172 if(in_array('FAIvariable',$attr['objectClass'])){
173 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
174 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
175 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
176 }
177 if(in_array('FAIscript',$attr['objectClass'])){
178 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
179 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
180 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
181 }
182 if(in_array('FAIhook',$attr['objectClass'])){
183 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
184 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
185 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
186 }
187 if(in_array('FAIpartitionTable',$attr['objectClass'])){
188 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
189 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
190 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
191 }
192 if(in_array('FAIprofile',$attr['objectClass'])){
193 $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile';
194 $tmp2[$cn]['FAIprofile']['kzl']= 'P';
195 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
196 }
197 }
198 if(is_array($this->FAIclasses)){
199 natcasesort($this->FAIclasses);
200 }
202 $this->FAIclassInfo = $tmp2;
204 if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
205 $tmp = array();
206 $tmp = split(" ",$this->FAIclass);
207 $tmp2 =array();
209 foreach($tmp as $class){
210 if( ":" == $class[0] ) {
211 $this->FAIrelease = substr( $class, 1 );
212 }
213 else
214 $tmp2[$class] = $class;
215 }
216 $this->FAIclass = $tmp2;
217 }
219 if(!is_array($this->FAIclass)){
220 $this->FAIclass =array();
221 }
223 $this->orig_dn= $this->dn;
225 }
228 /* This class is called by the contrucktor ONLY.
229 * It return the available classes for each
230 * Server / Release combination ...
231 * (Release specifies which classes are available)
232 */
233 function getAvailablePakagesForThisRelease($release)
234 {
235 /* There could be more than one server providing this release,
236 so use cached result if available
237 */
238 if(isset($_SESSION['getAvailablePakagesForThisRelease_CACHE'][$release])) {
239 return($_SESSION['getAvailablePakagesForThisRelease_CACHE'][$release]);
240 }
242 /* Create cache with all classes
243 */
244 if((!isset($_SESSION['getAvailablePakagesForThisRelease_CACHED_CLASSES'])) ||
245 (!is_array($_SESSION['getAvailablePakagesForThisRelease_CACHED_CLASSES'])) ||
246 (count($_SESSION['getAvailablePakagesForThisRelease_CACHED_CLASSES'] ==0 ))){
248 /* Get ldap connection */
249 $ldap = $this->config->get_ldap_link();
250 $ldap->cd($this->config->current['BASE']);
252 /* Get possible classes ...
253 This would be faste with some kind of caching ...
254 */
255 $ldap->search("(| (objectClass=FAIpackageList)(objectClass=FAItemplate)
256 (objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)
257 (objectClass=FAIpartitionTable))",array("*"),true);
258 /* Sort all entries, and attach elementtype.
259 * To be able to show the types in the listbox.
260 */
261 while($attr = $ldap->fetch()){
262 $_SESSION['getAvailablePakagesForThisRelease_CACHED_CLASSES'][] = $attr;
263 }
264 }
266 /* Walk through cache and get out what we need.
267 *
268 * Function od : "$this->generateDNSyn($release)"
269 * It returns an array like this one :
270 * array("ou=packges,ou=rc0.9.2,ou=siga,",
271 * "ou=scripts.. "
272 * ...);
273 * This helps us to select the correct classes for each release.
274 * It prevents errors like: 'siga' is selected as release, but all classes
275 * with ou='siga' in their dn are shown, also ou=rc...,ou=siga...
276 */
277 $tmp2 = $this->generateDNSyn($release) ;
278 $test2 = array();
279 foreach($_SESSION['getAvailablePakagesForThisRelease_CACHED_CLASSES'] as $attr){
280 foreach($tmp2 as $dns){
281 if(preg_match("/".$dns."/",$attr['dn'])){
282 $test2[$attr['cn'][0]] = $attr['cn'][0];
283 }
284 }
285 }
286 $_SESSION['getAvailablePakagesForThisRelease_CACHE'][$release] = $test2;
287 return($test2);
288 }
290 /* Create array to display available classes/profiles in a selectbox
291 * This function only displays the available classes.
292 * If a class is available is defined by these facts :
293 * 1. Is this class available for the selected release ?
294 * - if it is available, check if the release is available for the selected server
295 * (done by $this->getFAIreleases())
296 * 2. Is this class currently not assigned to $this->FAIclass
297 */
298 function selectFriendlyClasses(){
299 $tmp=array();
301 /* check if the current release exists,
302 else select the first one ..
303 */
304 $tmp2 = $this->getFAIreleases();
305 if(!in_array($this->FAIrelease, $tmp2)){
306 $this->FAIrelease = key($tmp2);
307 }
309 /* Get all Packages for this server/release combination
310 */
311 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
312 $pkgs = array();
313 print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
314 }else{
315 $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
316 }
318 /* Check each and every single class name
319 */
320 foreach($pkgs as $pkg){
322 /* Class already assigned to the classes list ?
323 * If not ... go on
324 */
325 if(!in_array($pkg,$this->FAIclass)){
327 /* Create the displayed list entry value
328 HKLMOP [-Pl P V T-] or something like that
329 */
330 $str = "";
331 foreach($this->FAIclassInfo[$pkg] as $entry){
332 if(isset($entry['kzl'])){
333 $str .= $entry['kzl']." ";
334 }
335 }
337 /* Append class if everyting was fine
338 */
339 $tmp[$pkg] = $pkg." [-".trim($str)."-]";
340 }
341 }
342 /* Just sort and return new classes list ...
343 ( possibly we should cache the result ... )
344 */
345 natcasesort ($tmp);
346 return($tmp);
347 }
349 function check()
350 {
351 $messages = array();
352 /* If there are packages selected, but no mirror show error */
353 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
354 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
355 }
356 return($messages);
357 }
359 function execute()
360 {
361 /* Call parent execute */
362 plugin::execute();
364 /* Do we need to flip is_account state? */
365 if (isset($_POST['modify_state'])){
366 $this->is_account= !$this->is_account;
367 }
369 /* Do we represent a valid terminal? */
370 if (!$this->is_account && $this->parent == NULL){
371 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
372 _("This 'dn' has no terminal features.")."</b>";
373 return ($display);
374 }
376 /* Add module */
377 if (isset ($_POST['add_module'])){
378 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
379 $this->add_list ($this->gotoModules, $_POST['module']);
380 }
381 }
383 /* Delete module */
384 if (isset ($_POST['delete_module'])){
385 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
386 $this->del_list ($this->gotoModules, $_POST['modules_list']);
387 }
388 }
390 /* FAI class management */
391 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
392 $found = 0 ;
394 /* If this new class/profile will attach a second partition table
395 * to our list of classes, abort and show a message.
396 */
397 foreach($this->FAIclass as $name){
398 if(isset($this->FAIclassInfo[$name])){
399 foreach($this->FAIclassInfo[$name] as $atr){
400 if(isset($atr['obj'])){
401 if($atr['obj'] == "FAIpartitionTable"){
402 $found ++ ;
403 }
404 }
405 }
406 }
407 }
409 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
410 print_red(_("There is already a profile in your selection that contain partition table configurations."));
411 }else{
412 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
413 }
414 }
416 $sort = false;
417 foreach($_POST as $name => $val){
419 $sort_type = false;
420 if((preg_match("/sort_up/",$name))&&(!$sort)){
421 $sort_type = "sort_up_";
422 }
423 if((preg_match("/sort_down/",$name))&&(!$sort)){
424 $sort_type = "sort_down_";
425 }
427 if(($sort_type)&&(!$sort)){
428 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
429 $sort = true;
431 $last = -1;
432 $change_down = -1;
434 /* Create array with numeric index */
435 $tmp = array();
436 foreach($this->FAIclass as $class){
437 $tmp [] = $class;
438 }
440 /* Walk trough array */
441 foreach($tmp as $key => $faiName){
442 if($faiName == $value){
443 if($sort_type == "sort_up_"){
444 if($last != -1){
445 $change_down= $last;
446 }
447 }else{
448 if(isset($tmp[$key+1])){
449 $change_down = $key;
450 }
451 }
452 }
453 $last = $key;
454 }
456 $tmp2 = array();
457 $skip = false;
459 foreach($tmp as $ky => $vl){
461 if($ky == $change_down){
462 $skip = $vl;
463 }else{
464 $tmp2[$vl] = $vl;
465 }
466 if(($skip != false)&&($ky != $change_down)){
467 $tmp2[$skip] = $skip;
468 $skip =false;
469 }
470 }
471 $this->FAIclass = $tmp2;
472 }
474 if(preg_match("/fai_remove/i",$name)){
475 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
476 unset($this->FAIclass[$value]);
477 }
478 }
480 /* Delete selected class from our list */
481 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
482 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
483 unset($this->FAIclass[$_POST['FAIclassSel']]);
484 }
485 }
487 /* Show main page */
488 $smarty= get_smarty();
490 /* In this section server shares will be defined
491 * A user can select one of the given shares and a mount point
492 * and attach this combination to his setup.
493 */
494 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
495 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
497 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
498 * This entry will be, a combination of mountPoint and sharedefinitions
499 */
500 if(isset($_POST['gotoShareAdd'])){
501 /* We assign a share to this user, if we don't know where to mount the share */
502 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
503 print_red(_("You must specify a valid mount point."));
504 }else{
505 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
506 $s_mount = $_POST['gotoShareMountPoint'];
507 /* Preparing the new assignment */
508 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
509 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
510 }
511 }
513 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
514 * If there is no defined share selected, we will abort the deletion without any message
515 */
516 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
517 unset($this->gotoShares[$_POST['gotoShare']]);
518 }
520 $smarty->assign("gotoShares",$this->printOutAssignedShares());
521 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
523 /* Arrays */
524 $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
525 $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
526 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
527 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
528 $smarty->assign("$val", $this->$val);
529 }
531 /* Values */
532 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
533 $smarty->assign($val, $this->$val);
534 $smarty->assign($val."ACL", chkacl($this->acl, $val));
535 }
537 $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
538 $smarty->assign("FAIreleases",$this->getFAIreleases());
539 $smarty->assign("FAIrelease",$this->FAIrelease);
540 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
541 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
542 $smarty->assign("FAIclassKeys",$this->FAIclass);
544 $div = new divSelectBox("WSFAIscriptClasses");
545 $div -> SetHeight("110");
546 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
547 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
548 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
549 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
551 $i = 1;
552 foreach($this->FAIclass as $class){
553 if($i==1){
554 $str = $str_empty.$str_down.$str_remove;
555 }elseif($i == count($this->FAIclass)){
556 $str = $str_up.$str_empty.$str_remove;
557 }else{
558 $str = $str_up.$str_down.$str_remove;
559 }
560 $i ++ ;
562 $div->AddEntry(array(
563 array("string"=>$class),
564 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
565 ));
566 }
568 $smarty->assign("FAIScriptlist",$div->DrawList());
570 /* Radio button group */
571 if (preg_match("/G/", $this->bootmode)) {
572 $smarty->assign("graphicalbootup", "checked");
573 } else {
574 $smarty->assign("graphicalbootup", "");
575 }
576 if (preg_match("/T/", $this->bootmode)) {
577 $smarty->assign("textbootup", "checked");
578 } else {
579 $smarty->assign("textbootup", "");
580 }
581 if (preg_match("/D/", $this->bootmode)) {
582 $smarty->assign("debugbootup", "checked");
583 } else {
584 $smarty->assign("debugbootup", "");
585 }
587 /* ACL's */
588 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
589 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
590 }
592 /* Show main page */
593 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
594 }
596 function remove_from_parent()
597 {
598 $this->handle_post_events("remove");
599 }
601 function generateDNSyn($release)
602 {
603 $str = "";
604 $tmp = split("\/",$release);
605 $tmp = array_reverse($tmp);
607 $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
609 foreach($tmp as $departmentname){
611 $str .= ",ou=".$departmentname;
612 }
613 $ret = array();
614 foreach($arr as $ar){
615 $ret[] = ",ou=".$ar.$str;
616 }
617 return($ret);
618 }
620 function getFAIdebianMirrors()
621 {
622 $ret = array();
623 $ret['auto']=_("automatic");
624 $secs = array();
626 /* Walk through all available servers
627 and check if they support the currently selected classes
628 if not, dont't add them to our list
629 */
630 foreach($this->FAIServRepConfig as $mirror => $rest){
632 $use = false;
634 if(count($this->FAIclass) == 0){
635 $use = true;
636 }else{
637 $tmp = $this->getFAIreleases();
638 foreach($tmp as $release){
639 if(isset($rest['RELEASE'][$release])){
640 $use =true;
641 }
642 }
643 }
645 /* If current server, doesn't support this class
646 remove it from list
647 */
648 if($use){
649 $ret[$mirror] = $mirror;
650 }
651 }
652 return($ret);
653 }
655 function getFAIreleases()
656 {
657 $ret = array();
659 if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
660 $this->FAIdebianMirror = "auto";
661 }
663 $errorClasses = "";
665 foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
666 $use = true;
668 if(!count($this->FAIclass) == 0){
669 foreach($this->FAIclass as $class){
670 if(!in_array($class, $sections['PACKAGES'])){
671 $use = false;
672 $errorClasses[$class] = $class;
673 }else{
674 if(isset($errorClasses[$class])){
675 unset($errorClasses[$class]);
676 }
677 }
678 }
679 }
680 if($use){
681 $ret[$release]=$release;
682 }
683 }
684 if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
686 $eClasses = " ";
687 foreach($errorClasses as $class){
688 $eClasses .= $class." ";
689 }
691 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));
692 $this->FAIdebianMirror = "auto";
693 return($this->getFAIreleases());
694 }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
696 $eClasses = "";
697 foreach($errorClasses as $class){
698 $eClasses .= " ".$class;
699 }
701 $this->FAIclass= array();
702 print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. !All classes have been removed from this account, press cancel if you don't want this to be saved."),$eClasses));
703 }
704 return($ret);
705 }
707 /* Save data to object */
708 function save_object()
709 {
710 plugin::save_object();
712 /* Save group radio buttons */
713 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
714 $this->bootmode= $_POST["bootmode"];
715 }
717 /* Save kernel parameters */
718 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
719 $this->customParameters= $_POST["customParameters"];
720 }
721 }
724 /* Save to LDAP */
725 function save()
726 {
728 /* Depending on the baseobject (Ogroup / WS) we
729 * use another set of objectClasses
730 * In case of WS itself, we use "array("GOhard", "FAIobject");"
731 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
732 */
733 if(isset($this->parent->by_object['ogroup'])){
734 $this->objectclasses = array("gotoWorkstationTemplate","GOhard", "FAIobject");
735 }elseif(isset($this->parent->by_object['workgeneric'])){
736 $this->objectclasses = array("GOhard", "FAIobject");
737 }else{
738 print "Object Type Configuration : unknown";
739 exit();
740 }
742 /* Find proper terminal path for tftp configuration
743 FIXME: This is suboptimal when the default has changed to
744 another location! */
745 if ($this->gotoTerminalPath == "default"){
746 $ldap= $this->config->get_ldap_link();
748 /* Strip relevant part from dn, keep trailing ',' */
749 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
750 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
752 /* Walk from top to base and try to load default values for
753 'gotoTerminalPath'. Abort when an entry is found. */
754 while (TRUE){
755 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
757 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
758 $this->config->current['BASE']);
759 $attrs= $ldap->fetch();
760 if (isset($attrs['gotoTerminalPath'])){
761 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
762 break;
763 }
765 /* Nothing left? */
766 if ($tmp == ""){
767 break;
768 }
769 }
770 }
772 /* Add semi automatic values */
773 // FIXME: LDAP Server may not be set here...
774 $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
775 $this->gotoTerminalPath.
776 ",ro,hard,nolock,fg,rsize=8192 ".
777 "ip=::::::dhcp ldap=".base64_encode($this->gotoLdapServer);
779 switch ($this->bootmode){
780 case "D":
781 $this->gotoKernelParameters.= " debug";
782 break;
783 case "G":
784 $this->gotoKernelParameters.= " splash=silent";
785 break;
786 }
787 if ($this->customParameters != ""){
788 $this->gotoKernelParameters.= " o ".$this->customParameters;
789 }
791 plugin::save();
793 unset( $this->attrs['FAIrelease'] );
795 $str = "";
796 foreach($this->FAIclass as $class){
797 $str .= $class." ";
798 }
799 $str .= ":" . $this->FAIrelease;
800 $this->attrs['FAIclass']= "";
801 $this->attrs['FAIclass']= trim($str);
803 if(empty($this->attrs['FAIclass'])){
804 $this->attrs['FAIclass'] = array();
805 }
807 /* Add missing arrays */
808 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
809 if (isset ($this->$val) && count ($this->$val) != 0){
811 $this->attrs["$val"]= array_unique($this->$val);
812 }
813 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
814 }
815 /* Strip out 'default' values */
816 if ($this->attrs['gotoLdapServer'] == "default"){
817 unset ($this->attrs['gotoLdapServer']);
818 }
820 /* if mirror == none stop saving this attribute */
821 if($this->FAIdebianMirror == "none"){
822 $this->FAIdebianMirror = "";
823 }
825 if((count($this->attrs['FAIclass'])==0)&&(empty($this->FAIdebianMirror))){
826 $tmp = array();
827 foreach($this->attrs['objectClass'] as $class){
828 if($class != "FAIobject"){
829 $tmp[] = $class;
830 }
831 }
832 $this->attrs['objectClass'] = $tmp;
833 $this->attrs['FAIclass'] = array();
834 $this->attrs['FAIdebianMirror'] = array();
835 }
837 /* prepare share settings */
838 $tmp = array();
839 foreach($this->gotoShares as $name => $settings){
840 $tmp2= split("\|",$name);
841 $name = $tmp2[0];
842 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
843 }
844 $this->attrs['gotoShare']=$tmp;
846 $ldap= $this->config->get_ldap_link();
847 $ldap->cd($this->dn);
848 $this->cleanup();
849 $ldap->modify ($this->attrs);
851 show_ldap_error($ldap->get_error());
852 $this->handle_post_events("modify");
853 }
855 /* Add value to array, check if unique */
856 function add_list (&$array, $value)
857 {
858 if ($value != ""){
859 $array[]= $value;
860 sort($array);
861 array_unique ($array);
862 }
863 }
866 /* Delete value to array, check if unique */
867 function del_list (&$array, $list)
868 {
869 $tmp= array();
870 foreach ($array as $mod){
871 if (!in_array($mod, $list)){
872 $tmp[]= $mod;
873 }
874 }
875 $array= $tmp;
876 }
878 /* Generate ListBox frindly output for the defined shares
879 * Possibly Add or remove an attribute here,
880 */
881 function printOutAssignedShares()
882 {
883 $a_return = array();
884 if(is_array($this->gotoShares)){
885 foreach($this->gotoShares as $share){
886 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
887 }
888 }
889 return($a_return);
890 }
892 }
894 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
895 ?>