35aded41f68ba230ee514883d1b7881481ebacdf
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 /* Ldap server list */
10 var $gotoLdapServers = array();
11 var $gotoLdapServerList = array();
12 var $gotoLdap_inherit = FALSE;
14 /* Generic terminal attributes */
15 var $bootmode = "G";
16 var $gotoBootKernel = "default-inherited";
17 var $gotoKernelParameters = "";
18 var $gotoLdapServer = "default-inherited";
19 var $gotoModules = array();
20 var $gotoAutoFs = array();
21 var $gotoFilesystem = array();
22 var $gotoTerminalPath = "";
23 var $gotoBootKernels = array();
25 /* attribute list for save action */
26 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters",
27 "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
28 var $objectclasses = array("GOhard", "FAIobject");
30 /* Share */
31 var $gotoShares = array();// Currently Share Option
32 var $gotoShare = ""; // currently selected Share Option
33 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
34 var $gotoAvailableShares= array();// Available Shares for this account
36 /* Helper */
37 var $customParameters = "";
38 var $orig_dn = "";
39 var $ignore_account = TRUE;
41 /* FAI class selection */
42 var $FAIclass = array(); // The currently selected classes
43 var $FAIrelease = "";
44 var $FAIdebianMirror = "auto";
46 var $cache = array(); // Used as cache in fai mehtods
48 var $FAIstatus = "";
49 var $FAIclasses = array();
51 var $view_logged = FALSE;
53 /* FAI class selection */
54 var $InheritedFAIclass = array();
55 var $InheritedFAIrelease = "";
56 var $InheritedFAIdebianMirror= "auto";
58 var $CopyPasteVars = array("gotoModules","gotoShares");
59 var $fai_activated = FALSE;
60 var $o_group_dn = "";
61 var $member_of_ogroup = FALSE;
63 function workstartup (&$config, $dn= NULL, $parent= NULL)
64 {
65 /* Check if FAI is active */
66 $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
67 if(!empty($tmp)){
68 $this->fai_activated = TRUE;
69 }else{
70 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
71 $this->objectclasses = array("GOhard");
72 }
74 plugin::plugin ($config, $dn, $parent);
76 /* Check object group membership */
77 if(!isset($this->parent->by_object['ogroup'])){
78 $ldap = $this->config->get_ldap_link();
79 $ldap->cd ($this->config->current['BASE']);
80 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
81 if($ldap->count()){
82 $this->member_of_ogroup = TRUE;
83 $attrs = $ldap->fetch();
84 $this->o_group_dn = $attrs['dn'];
85 }
86 }
88 /* Creating a list of valid Mirrors
89 * none will not be saved to ldap.
90 */
91 $ldap = $this->config->get_ldap_link();
92 $ldap->cd($this->config->current['BASE']);
93 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
94 $this->gotoLdapServerList[]= $server;
95 }
97 /* Get list of assigned ldap servers
98 */
99 if(isset($this->attrs['gotoLdapServer'])){
100 unset($this->attrs['gotoLdapServer']['count']);
101 sort($this->attrs['gotoLdapServer']);
102 foreach($this->attrs['gotoLdapServer'] as $value){
103 $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
104 }
105 }
106 if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
107 $this->gotoLdap_inherit = TRUE;
108 }
110 /* FAI Initialization
111 Skip this if FAI is not activated
112 */
113 if($this->fai_activated) {
115 $this->update_fai_cache(TRUE);
117 /* Parse used FAIclasses (stored as string).
118 * The single classes are seperated by ' '.
119 * There is also the release type given, after first
120 * occurrence of ':'.
121 */
122 $this->FAIclass =array();
123 if(isset($this->attrs['FAIclass'][0])){
124 $tmp = split(" ",$this->attrs['FAIclass'][0]);
125 $tmp2 =array();
127 foreach($tmp as $class){
128 if( ":" == $class[0] ) {
129 $this->FAIrelease = trim(substr($class, 1));
130 }else{
131 $tmp2[$class] = $class;
132 }
133 }
134 $this->FAIclass = $tmp2;
135 }
136 }
138 /* Get arrays */
139 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
140 if (isset($this->attrs["$val"]["count"])){
141 for ($i= 0; $i<$this->attrs["count"]; $i++){
142 if (isset($this->attrs["$val"][$i])){
143 array_push($this->$val, $this->attrs["$val"][$i]);
144 }
145 }
146 }
147 sort ($this->$val);
148 $this->$val= array_unique($this->$val);
149 }
151 /* Parse Kernel Parameters to decide what boot mode is enabled */
152 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
153 $this->bootmode= "G";
154 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
155 $this->bootmode= "D";
156 } elseif ($this->gotoKernelParameters == "") {
157 $this->bootmode= "G";
158 } else {
159 $this->bootmode= "T";
160 }
161 if (preg_match("/ o /", $this->gotoKernelParameters)){
162 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
163 } else {
164 $this->customParameters= "";
165 }
167 /* Prepare Shares */
168 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
169 unset($this->attrs['gotoShare']['count']);
170 foreach($this->attrs['gotoShare'] as $share){
171 $tmp = $tmp2 = array();
172 $tmp = split("\|",$share);
173 $tmp2['server'] =$tmp[0];
174 $tmp2['name'] =$tmp[1];
175 $tmp2['mountPoint'] =$tmp[2];
176 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
177 }
178 }
180 $this->gotoShareSelections= $config->getShareList(true);
181 $this->gotoAvailableShares= $config->getShareList(false);
182 $tmp2 = array();
185 $this->orig_dn= $this->dn;
187 /* Handle inheritance value "default" */
188 if ($this->member_of_ogroup){
189 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
190 }
192 /* If we are member in an object group,
193 * we have to handle inherited values.
194 * So you can see what is inherited.
195 */
196 if ($this->member_of_ogroup){
198 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
199 $this->FAIdebianMirror = "inherited";
200 }
202 if($this->fai_activated){
203 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
204 }else{
205 $map= array("gotoBootKernel");
206 }
208 $ldap = $this->config->get_ldap_link();
209 $ldap->cat($this->o_group_dn);
210 $attrs= $ldap->fetch();
212 foreach ($map as $name){
213 if (!isset($attrs[$name][0])){
214 continue;
215 }
217 switch ($name){
218 case 'gotoBootKernel':
219 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
220 break;
222 case 'FAIclass':
223 $str = split(":",$attrs[$name][0]);
224 $this->InheritedFAIclass = split("\ ",trim($str[0]));
225 $this->InheritedFAIrelease = trim($str[1]);
226 break;
228 case 'FAIdebianMirror':
229 $this->InheritedFAIdebianMirror = $attrs[$name][0];
230 break;
231 }
232 }
233 }
236 if($this->fai_activated){
238 /* Check if the current mirror is available
239 */
240 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
241 if(count($this->FAIclass)){
242 print_red(sprintf(_("The selected FAI mirror '%s' is no longer available, the mirror was set to 'auto'."),
243 $this->FAIdebianMirror));
244 }
245 $this->FAIdebianMirror = "auto";
246 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
247 $this->cache =array();
248 $this->update_fai_cache();
250 }
252 /* Check if the current mirror is available
253 */
254 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
255 $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
256 if(count($this->FAIclass)){
257 print_red(sprintf(_("The selected FAI release '%s' is not available for mirror '%s', the release was set to '%s'."),
258 $this->FAIrelease,$this->FAIdebianMirror,$new_release));
259 }
260 $this->FAIrelease = $new_release;
261 $this->cache =array();
262 $this->update_fai_cache();
263 }
264 }
266 /* Get list of boot kernels */
267 if (isset($this->config->data['TABS'])){
268 $command= $this->config->search(get_class($this), "KERNELS",array('tabs'));
269 if (!check_command($command)){
270 $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
271 get_class($this));
272 } else {
273 $fh= popen($command, "r");
274 while (!feof($fh)) {
275 $buffer= trim(fgets($fh, 256));
276 if(!empty($buffer)){
277 $name=$value = $buffer;
278 if(preg_match("/:/",$buffer)){
279 $name = preg_replace("/:.*$/","",$buffer);
280 $value= preg_replace("/^.*:/","",$buffer);
281 $this->gotoBootKernels[$name]= $name.":".$value;
282 }else{
283 $this->gotoBootKernels[$name]= $value;
284 }
285 }
286 }
287 pclose($fh);
288 }
289 }
291 /* Turn to default, if we've nothing to inherit */
292 if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
293 $this->gotoBootKernel= "default";
294 }
295 }
298 function check()
299 {
300 $messages = array();
302 /* Call common method to give check the hook */
303 $messages= plugin::check();
305 /* If there are packages selected, but no mirror show error */
306 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
307 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
308 }
310 return($messages);
311 }
313 function execute()
314 {
315 /* Call parent execute */
316 plugin::execute();
318 if($this->is_account && !$this->view_logged){
319 $this->view_logged = TRUE;
320 new log("view","workstation/".get_class($this),$this->dn);
321 }
323 /* Do we need to flip is_account state? */
324 if(isset($_POST['modify_state'])){
325 if($this->is_account && $this->acl_is_removeable()){
326 $this->is_account= FALSE;
327 }elseif(!$this->is_account && $this->acl_is_createable()){
328 $this->is_account= TRUE;
329 }
330 }
332 /* Do we represent a valid terminal? */
333 if (!$this->is_account && $this->parent === NULL){
334 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
335 _("This 'dn' has no terminal features.")."</b>";
336 return ($display);
337 }
339 /* Add module */
340 if (isset ($_POST['add_module'])){
341 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
342 $this->add_list ($this->gotoModules, $_POST['module']);
343 }
344 }
346 /* Delete module */
347 if (isset ($_POST['delete_module'])){
348 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
349 $this->del_list ($this->gotoModules, $_POST['modules_list']);
350 }
351 }
353 /* FAI class management */
354 if($this->fai_activated){
355 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
356 $found = 0 ;
358 /* If this new class/profile will attach a second partition table
359 * to our list of classes, abort and show a message.
360 */
361 foreach($this->FAIclass as $name){
362 if(isset($this->FAIclassInfo[$name])){
363 foreach($this->FAIclassInfo[$name] as $atr){
364 if(isset($atr['obj'])){
365 if($atr['obj'] == "FAIpartitionTable"){
366 $found ++ ;
367 }
368 }
369 }
370 }
371 }
373 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
374 print_red(_("There is already a profile in your selection that contain partition table configurations."));
375 }else{
376 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
377 }
378 }
380 $sort = false;
382 /* Move one used class class one position up or down */
383 if($this->acl_is_writeable("FAIclass")){
384 foreach($_POST as $name => $val){
386 $sort_type = false;
387 if((preg_match("/sort_up/",$name))&&(!$sort)){
388 $sort_type = "sort_up_";
389 }
390 if((preg_match("/sort_down/",$name))&&(!$sort)){
391 $sort_type = "sort_down_";
392 }
394 if(($sort_type)&&(!$sort)){
395 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
396 $sort = true;
398 $last = -1;
399 $change_down = -1;
401 /* Create array with numeric index */
402 $tmp = array();
403 foreach($this->FAIclass as $class){
404 $tmp [] = $class;
405 }
407 /* Walk trough array */
408 foreach($tmp as $key => $faiName){
409 if($faiName == $value){
410 if($sort_type == "sort_up_"){
411 if($last != -1){
412 $change_down= $last;
413 }
414 }else{
415 if(isset($tmp[$key+1])){
416 $change_down = $key;
417 }
418 }
419 }
420 $last = $key;
421 }
423 $tmp2 = array();
424 $skip = false;
426 foreach($tmp as $ky => $vl){
428 if($ky == $change_down){
429 $skip = $vl;
430 }else{
431 $tmp2[$vl] = $vl;
432 }
433 if(($skip != false)&&($ky != $change_down)){
434 $tmp2[$skip] = $skip;
435 $skip =false;
436 }
437 }
438 $this->FAIclass = $tmp2;
439 }
441 if(preg_match("/fai_remove/i",$name)){
442 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
443 unset($this->FAIclass[$value]);
444 }
445 }
446 }
448 /* Delete selected class from our list */
449 if($this->acl_is_writeable("FAIclass")){
450 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
451 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
452 unset($this->FAIclass[$_POST['FAIclassSel']]);
453 }
454 }
455 }
456 }// END fai handling
458 /* Show main page */
459 $smarty= get_smarty();
461 /* Assign ACLs to smarty */
462 $tmp = $this->plInfo();
463 foreach($tmp['plProvidedAcls'] as $name => $translation){
464 $smarty->assign($name."ACL",$this->getacl($name));
465 }
467 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
469 /* In this section server shares will be defined
470 * A user can select one of the given shares and a mount point
471 * and attach this combination to his setup.
472 */
473 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
474 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
476 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
477 * This entry will be, a combination of mountPoint and sharedefinitions
478 */
479 if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
480 /* We assign a share to this user, if we don't know where to mount the share */
481 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
482 print_red(_("You must specify a valid mount point."));
483 }else{
484 if(count($this->gotoAvailableShares)){
485 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
486 $s_mount = $_POST['gotoShareMountPoint'];
487 /* Preparing the new assignment */
488 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
489 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
490 }
491 }
492 }
494 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
495 * If there is no defined share selected, we will abort the deletion without any message
496 */
497 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
498 unset($this->gotoShares[$_POST['gotoShare']]);
499 }
501 $smarty->assign("gotoShares",$this->printOutAssignedShares());
502 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
503 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
504 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
506 /* Create divSelectBox for ldap server selection
507 */
508 $SelectBoxLdapServer = new divSelectBox("LdapServer");
509 $SelectBoxLdapServer->SetHeight(130);
511 /* Add new ldap server to the list */
512 if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){
513 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
514 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
515 if(!in_array($to_add,$this->gotoLdapServers)){
516 $this->gotoLdapServers[] = $to_add;
517 }
518 }
519 }
521 /* Move ldap servers up and down */
522 if(!$this->gotoLdap_inherit){
523 foreach($_POST as $name => $value){
524 if(preg_match("/sort_ldap_up_/",$name)){
525 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
526 $from = $id;
527 $to = $id -1;
528 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
529 if($tmp){
530 $this->gotoLdapServers = $tmp;
531 }
532 break;
533 }
534 if(preg_match("/sort_ldap_down_/",$name)){
535 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
536 $from = $id;
537 $to = $id +1;
538 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
539 if($tmp){
540 $this->gotoLdapServers = $tmp;
541 }
542 break;
543 }
544 if(preg_match("/gotoLdapRemove_/",$name)){
545 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
546 $value = $this->gotoLdapServers[$id];
547 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
548 break;
549 }
550 }
551 }
553 /* Add Entries
554 */
555 foreach($this->gotoLdapServers as $key => $server){
556 if(!in_array($server,$this->gotoLdapServerList)){
557 $server = $server." <font style='color:red'>(missing)</font>";
558 }
560 $SelectBoxLdapServer->AddEntry(
561 array(array("string" => $server),
562 array("string" =>
563 "<input class='center' type='image' src='images/sort_up.png' name='sort_ldap_up_".$key."'> ".
564 "<input class='center' type='image' src='images/sort_down.png' name='sort_ldap_down_".$key."'> ".
565 "<input class='center' type='image' src='images/edittrash.png' name='gotoLdapRemove_".$key."'>",
566 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
567 }
569 if($this->gotoLdap_inherit){
570 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
571 }else{
572 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
573 }
575 $list = array();
576 foreach($this->gotoLdapServerList as $key => $entry){
577 if(!in_array($entry,$this->gotoLdapServers)){
578 $list[$key] = $entry;
579 }
580 }
581 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
582 $smarty->assign("gotoLdapServerList", $list);
583 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
584 $smarty->assign("JS", session::get('js'));
586 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
587 $smarty->assign("$val", $this->$val);
588 }
590 /* Values */
591 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
592 $smarty->assign($val, $this->$val);
593 }
595 $smarty->assign("fai_activated",$this->fai_activated);
597 /* Create FAI output */
598 if($this->fai_activated){
600 $this->update_fai_cache();
602 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
603 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
604 $smarty->assign("FAIrelease" , $this->FAIrelease);
605 $smarty->assign("FAIclasses" , $this->selectable_classes());
607 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
609 $div = new divSelectBox("WSFAIscriptClasses");
610 $div -> SetHeight("110");
611 $str_up = " <input type='image' src='images/sort_up.png' name='sort_up_%s' value='%s'>";
612 $str_down = " <input type='image' src='images/sort_down.png' name='sort_down_%s' value='%s'>";
613 $str_remove = " <input type='image' src='images/edittrash.png' name='fai_remove_%s' value='%s'>";
614 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
616 /* Get classes */
617 if($this->FAIdebianMirror == "inherited"){
618 $tmp = $this->InheritedFAIclass;
619 }else{
620 $tmp = $this->FAIclass;
621 }
623 /* Get invalid classes */
624 $invalid = $this->get_invalid_classes($tmp);
626 /* Draw every single entry */
627 $i = 1;
628 foreach($tmp as $class){
630 /* Mark invalid classes. (Not in selected release)
631 */
632 $marker = "";
633 if(in_array_ics($class,$invalid)){
634 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
635 }
637 /* Create up/down priority icons
638 * Skip this, if we have inherited the FAI classes.
639 */
640 if($this->FAIdebianMirror == "inherited"){
641 $str = "";
642 }else{
643 if($i==1){
644 $str = $str_empty.$str_down.$str_remove;
645 }elseif($i == count($this->FAIclass)){
646 $str = $str_up.$str_empty.$str_remove;
647 }else{
648 $str = $str_up.$str_down.$str_remove;
649 }
650 }
651 $i ++ ;
653 /* Get Description tag
654 * There may be several FAI objects with the same class name,
655 * use the description from FAIprofile, if possible.
656 */
657 $desc = "";
658 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
659 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
660 if(isset($types['Desc'])){
661 $desc= $types['Desc'];
662 if($types['Type'] == "FAIprofile"){
663 break;
664 }
665 }
666 }
667 }
668 if(!empty($desc)){
669 $desc = " [".trim($desc)."]";
670 }
672 $div->AddEntry(array(
673 array("string"=>$class.$desc.$marker),
674 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
675 ));
676 }
677 $smarty->assign("FAIScriptlist",$div->DrawList());
678 }// END FAI output generation
680 /* Radio button group */
681 if (preg_match("/G/", $this->bootmode)) {
682 $smarty->assign("graphicalbootup", "checked");
683 } else {
684 $smarty->assign("graphicalbootup", "");
685 }
686 if (preg_match("/T/", $this->bootmode)) {
687 $smarty->assign("textbootup", "checked");
688 } else {
689 $smarty->assign("textbootup", "");
690 }
691 if (preg_match("/D/", $this->bootmode)) {
692 $smarty->assign("debugbootup", "checked");
693 } else {
694 $smarty->assign("debugbootup", "");
695 }
697 /* Show main page */
698 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
699 }
702 function remove_from_parent()
703 {
704 $this->handle_post_events("remove");
705 new log("remove","workstation/".get_class($this),$this->dn);
706 }
709 /* Save data to object */
710 function save_object()
711 {
712 $old_mirror = $this->FAIdebianMirror;
713 plugin::save_object();
715 /* Update release */
716 if($old_mirror != $this->FAIdebianMirror){
717 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
718 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
719 }
720 }
722 if(isset($_POST['WorkstationStarttabPosted'])){
723 if(isset($_POST['gotoLdap_inherit'])){
724 $this->gotoLdap_inherit = TRUE;
725 }else{
726 $this->gotoLdap_inherit = FALSE;
727 }
729 /* Save group radio buttons */
730 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
731 $this->bootmode= $_POST["bootmode"];
732 }
734 /* Save kernel parameters */
735 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
736 $this->customParameters= $_POST["customParameters"];
737 }
738 }
739 }
742 /* Save to LDAP */
743 function save()
744 {
746 /* Depending on the baseobject (Ogroup / WS) we
747 * use another set of objectClasses
748 * In case of WS itself, we use "array("GOhard", "FAIobject");"
749 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
750 */
751 if(isset($this->parent->by_object['ogroup'])){
752 $this->objectclasses = array("gotoWorkstationTemplate");
753 }elseif(isset($this->parent->by_object['workgeneric'])){
754 $this->objectclasses = array("GOhard");
755 }elseif(isset($this->parent->by_object['servgeneric'])){
756 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
757 }else{
758 print "Object Type Configuration : unknown";
759 exit();
760 }
762 /* Append FAI class */
763 if($this->fai_activated){
764 $this->objectclasses[] = "FAIobject";
765 }
767 /* Find proper terminal path for tftp configuration
768 FIXME: This is suboptimal when the default has changed to
769 another location! */
770 if (($this->gotoTerminalPath == "default")){
771 $ldap= $this->config->get_ldap_link();
773 /* Strip relevant part from dn, keep trailing ',' */
774 $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalou')."/i", "", $this->dn);
775 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
777 /* Walk from top to base and try to load default values for
778 'gotoTerminalPath'. Abort when an entry is found. */
779 while (TRUE){
780 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
782 $ldap->cat("cn=default,".get_ou('terminalou').$tmp.
783 $this->config->current['BASE'], array('gotoTerminalPath'));
784 $attrs= $ldap->fetch();
785 if (isset($attrs['gotoTerminalPath'])){
786 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
787 break;
788 }
790 /* Nothing left? */
791 if ($tmp == ""){
792 break;
793 }
794 }
795 }
797 /* Add semi automatic values */
798 // FIXME: LDAP Server may not be set here...
799 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
801 switch ($this->bootmode){
802 case "D":
803 $this->gotoKernelParameters.= " debug";
804 break;
805 case "G":
806 $this->gotoKernelParameters.= " splash=silent";
807 break;
808 }
809 if ($this->customParameters != ""){
810 $this->gotoKernelParameters.= " o ".$this->customParameters;
811 }
813 plugin::save();
815 unset( $this->attrs['FAIrelease'] );
817 $str = "";
819 /* Skip FAI attribute handling if not necessary */
820 if($this->fai_activated){
821 if($this->FAIdebianMirror == "inherited"){
822 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
823 }else{
824 foreach($this->FAIclass as $class){
825 $str .= $class." ";
826 }
827 $str .= ":" . $this->FAIrelease;
828 $this->attrs['FAIclass']= "";
829 $this->attrs['FAIclass']= trim($str);
831 if(empty($this->attrs['FAIclass'])){
832 $this->attrs['FAIclass'] = array();
833 }
834 }
835 }
837 /* Add missing arrays */
838 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
839 if (isset ($this->$val) && count ($this->$val) != 0){
841 $this->attrs["$val"]= array_unique($this->$val);
842 }
843 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
844 }
846 /* Prepare list of ldap servers */
847 $this->attrs['gotoLdapServer'] = array();
848 if(!$this->gotoLdap_inherit){
849 $i = 0;
850 foreach($this->gotoLdapServers as $server){
851 $i ++;
852 $this->attrs['gotoLdapServer'][] = $i.":".$server;
853 }
854 }
856 /* Check if LDAP server has changed */
857 $ldap_changed= (isset($this->attrs['gotoLdapServer'])) &&
858 (isset($this->saved_attributes['gotoLdapServer'])) &&
859 ($this->attrs['gotoLdapServer'] != $this->saved_attributes['gotoLdapServer']);
861 if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
862 $this->attrs['gotoBootKernel']= array();
863 }
865 /* if mirror == none stop saving this attribute */
866 if($this->FAIdebianMirror == "none"){
867 $this->FAIdebianMirror = "";
868 }
870 /* Get FAIstate from object, the generic tab could have changed it during execute */
871 $ldap= $this->config->get_ldap_link();
872 $ldap->cd($this->dn);
875 /* Skip FAI attribute handling if not necessary */
876 if($this->fai_activated){
877 $ldap->cat($this->dn,array("FAIstate"));
878 $checkFAIstate = $ldap->fetch();
880 /* Remove FAI objects if no FAI class is selected */
881 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
882 $this->attrs['FAIclass'] = array();
883 $this->attrs['FAIdebianMirror'] = array();
884 }
885 }
888 /* prepare share settings */
889 $tmp = array();
890 foreach($this->gotoShares as $name => $settings){
891 $tmp2= split("\|",$name);
892 $name = $tmp2[0];
893 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
894 }
895 $this->attrs['gotoShare']=$tmp;
897 $this->cleanup();
898 $ldap->modify ($this->attrs);
899 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
901 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
902 $this->handle_post_events("modify");
904 /* Check if LDAP server has changed */
905 if ($ldap_changed){
906 $events = DaemonEvent::get_event_types(SYSETEM_EVENT);
907 $o_queue = new gosaSupportDaemon();
908 if(isset($events['BY_CLASS']['DaemonEvent_reload_ldap_config'])){
909 $evt = $events['BY_CLASS']['DaemonEvent_reload_ldap_config'];
910 $tmp = new $evt['CLASS_NAME']($this->config);
911 $tmp->set_type(TRIGGERED_EVENT);
912 $tmp->add_targets(array($this->parent->by_object['workgeneric']->netConfigDNS->macAddress));
913 if(!$o_queue->append($tmp)){
914 msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
915 $o_queue->get_error()),ERROR_DIALOG);
916 }
917 }
918 }
919 }
922 /* Add value to array, check if unique */
923 function add_list (&$array, $value)
924 {
925 if ($value != ""){
926 $array[]= $value;
927 sort($array);
928 array_unique ($array);
929 }
930 }
933 /* Delete value to array, check if unique */
934 function del_list (&$array, $list)
935 {
936 $tmp= array();
937 foreach ($array as $mod){
938 if (!in_array($mod, $list)){
939 $tmp[]= $mod;
940 }
941 }
942 $array= $tmp;
943 }
945 /* Generate ListBox frindly output for the defined shares
946 * Possibly Add or remove an attribute here,
947 */
948 function printOutAssignedShares()
949 {
950 $a_return = array();
951 if(is_array($this->gotoShares)){
952 foreach($this->gotoShares as $share){
953 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
954 }
955 }
956 return($a_return);
957 }
961 function PrepareForCopyPaste($source)
962 {
963 plugin::PrepareForCopyPaste($source);
964 $source_o = new workstartup ($this->config, $source['dn']);
965 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
966 "gotoKernelParameters","gotoShares","customParameters") as $attr){
967 $this->$attr = $source_o->$attr;
968 }
969 }
972 function array_switch_item($ar,$from,$to)
973 {
974 if(!is_array($ar)){
975 return(false);
976 }
977 if(!isset($ar[$from])){
978 return(false);
979 }
980 if(!isset($ar[$to])){
981 return(false);
982 }
984 $tmp = $ar[$from];
985 $ar[$from] = $ar[$to];
986 $ar[$to] = $tmp;
987 return($ar);
988 }
991 /* Return plugin informations for acl handling */
992 static function plInfo()
993 {
994 return (array(
995 "plShortName" => _("Startup"),
996 "plDescription" => _("System startup"),
997 "plSelfModify" => FALSE,
998 "plDepends" => array(),
999 "plPriority" => 9,
1000 "plSection" => array("administration"),
1001 "plCategory" => array("workstation","server","ogroups"),
1003 "plProvidedAcls"=> array(
1004 "gotoLdapServer" => _("Ldap server"),
1005 "gotoBootKernel" => _("Boot kernel"),
1006 "gotoKernelParameters" => _("Kernel parameter"),
1008 "gotoModules" => _("Kernel modules"),
1009 "gotoShare" => _("Shares"),
1011 "FAIclass" => _("FAI classes"),
1012 "FAIdebianMirror" => _("Debian mirror"),
1013 "FAIrelease" => _("Debian release"),
1015 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1016 ));
1017 }
1020 /* Updates release dns
1021 * and reads all classes for the current release,
1022 * if not already done ($this->cache).
1023 */
1024 function update_fai_cache($first_call = FALSE)
1025 {
1026 $force = FALSE;
1028 /* Get the list of available servers and their releases.
1029 */
1030 if($force || !isset($this->cache['SERVERS'])){
1031 $ldap = $this->config->get_ldap_link();
1032 $ldap->cd($this->config->current['BASE']);
1034 $server_list = get_sub_list("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",
1035 "",get_ou("serverou"),$this->config->current['BASE'],array("FAIrepository"),GL_NO_ACL_CHECK);
1037 /* Only add inherit option, if we are part in an object group
1038 */
1039 if($this->member_of_ogroup){
1040 $this->cache['SERVERS']['inherited']=array();
1041 }
1043 /* Add auto value
1044 */
1045 $this->cache['SERVERS']['auto'] = array();
1046 $sort_by = array("auto");
1047 $server_tmp = array("auto"=>array());
1048 foreach($server_list as $attr){
1049 if(isset($attr['FAIrepository'])){
1050 for($i = 0 ; $i < $attr['FAIrepository']['count'] ; $i ++ ){
1051 $rep = $attr['FAIrepository'][$i];
1052 $tmp = split("\|",$rep);
1053 if(count($tmp)==4){
1054 $sections = split(",",$tmp[3]);
1055 $release = $tmp[2];
1056 $server = $tmp[1];
1057 $url = $tmp[0];
1058 $server_tmp[$url][$release]=$release;
1059 $server_tmp['auto'][$release]=$release;
1060 $sort_by[$url] = $url;
1061 }
1062 }
1063 }
1064 }
1065 natcasesort($sort_by);
1066 foreach($sort_by as $name){
1067 $releases = $server_tmp[$name];
1068 natcasesort($releases);
1069 $this->cache['SERVERS'][$name] = $releases;
1070 }
1071 }
1073 /* Build up arrays, without checks */
1074 if(!$first_call){
1076 /* Check if the selected mirror is available */
1077 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1078 $this->FAIdebianMirror = "auto";
1079 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1080 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1081 }
1083 /* Check if the selected release is available */
1084 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1085 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1086 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1087 }
1088 }
1090 /* Get classes for release from cache.
1091 * Or build cache
1092 */
1093 if($this->FAIdebianMirror == "inherited"){
1094 $release = $this->InheritedFAIrelease;
1095 }else{
1096 $release = $this->FAIrelease;
1097 }
1098 if($force || !isset($this->cache['CLASSES'][$release])){
1100 /* Create a list of available releases.
1101 * $this->cache['RELEASE_DNS'][ou=siga...,c=de] = "siga";
1102 * $this->cache['RELEASE_DNS'][ou=siga,ou=rc1,...,c=de] = "siga/rc1";
1103 */
1104 if($force || !isset($this->cache['RELEASE_DNS'])){
1105 $this->cache['RELEASE_DNS'] = array();
1106 $fai_ou_parts = preg_replace("/\/.*$/","",$this->FAIrelease);
1108 $tmp = get_sub_list("(objectClass=FAIbranch)","",get_ou("faiou"),
1109 $this->config->current['BASE'],array("ou"),GL_NO_ACL_CHECK | GL_SUBSEARCH);
1111 foreach($tmp as $attrs){
1112 if(preg_match("/".normalizePreg(get_ou("faiou"))."/",$attrs['dn'])){
1113 $this->cache['RELEASE_DNS'][$attrs['dn']] = $this->dn_to_release_name($attrs['dn']);
1114 }
1115 }
1116 }
1118 /* Create list of available classes for the currenlty selected release.
1119 */
1120 $base = array_search($release,$this->cache['RELEASE_DNS']);
1121 $this->cache['CLASSES'][$release] = array();
1123 if(class_exists("FAI")){
1124 if(!empty($base)){
1125 $filter = "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)".
1126 "(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)".
1127 "(objectClass=FAIpartitionTable))";
1128 $list = FAI::get_all_objects_for_given_base($base,$filter,TRUE);
1129 foreach($list as $attrs){
1130 $info = $this->analyse_fai_object($attrs);
1131 if(count($info)){
1132 $this->cache['CLASSES'][$release][$attrs['cn'][0]][] = $info;
1133 }
1134 }
1135 }
1136 }else{
1137 print_red(_("Could not load available classes, the fai extension plugin seems not to be installed."));
1138 }
1140 /* Add object caught from external hook
1141 */
1142 $lines= $this->GetHookElements();
1143 foreach ($lines as $hline){
1144 $entries= split(";", $hline);
1145 $server = $entries['0'];
1146 $url = $entries['1'];
1147 if (!empty($url)){
1149 /* Split releases */
1150 if (isset($entries[2])){
1151 $releases= split(",", $entries[2]);
1153 foreach ($releases as $release_data){
1154 $release= preg_replace('/:.*$/', '', $release_data);
1155 $sections = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1156 $classes = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1157 $this->cache['SERVERS'][$url][$release]=$release;
1158 $this->cache['SERVERS']['auto'][$release]=$release;
1159 foreach ($classes as $class){
1160 if ($class != ""){
1161 $this->cache['CLASSES'][$release][$class]= array();
1162 }
1163 }
1164 }
1165 }
1166 }
1167 }
1168 }
1169 }
1172 /* This function return an array containing all
1173 * invalid classes for the selected server/release
1174 */
1175 function get_invalid_classes($classes)
1176 {
1177 $this->update_fai_cache();
1178 if($this->FAIdebianMirror == "inherited"){
1179 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1180 }else{
1181 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1182 }
1185 /* Detect all classes that are not valid
1186 * for the selected release
1187 */
1188 $NA = array();
1189 foreach($classes as $class){
1190 if(!isset($release_classes[$class])){
1191 $NA[] = $class;
1192 }
1193 }
1194 return($NA);
1195 }
1198 /* Get all selectable classes for the ui select box
1199 */
1200 function selectable_classes()
1201 {
1202 $this->update_fai_cache();
1204 if($this->FAIdebianMirror == "inherited"){
1205 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1206 }else{
1207 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1208 }
1210 $Abbr ="";
1211 $ret= array();
1212 foreach($classes as $class_name => $class_types){
1213 if(!in_array($class_name,$this->FAIclass)){
1214 foreach($class_types as $type){
1215 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1216 $Abbr .= $type['Abbr']." ";
1217 }
1218 }
1219 $ret[$class_name] = trim($Abbr);
1220 }
1221 }
1222 uksort($ret, 'strnatcasecmp');
1223 return($ret);
1224 }
1227 /* Analyse FAI object and return an array with usefull informations like
1228 * FAIobject type.
1229 */
1230 function analyse_fai_object($attr)
1231 {
1232 $tmp2 = array();
1233 if(!isset($attr['description'])){
1234 $attr['description'][0] ="";
1235 }
1236 if(in_array('FAIpackageList',$attr['objectClass'])){
1237 $tmp2["Type"] = 'FAIpackageList';
1238 $tmp2["Abbr"] = 'Pl';
1239 $tmp2["Desc"] = $attr['description'][0];
1240 }
1241 if(in_array('FAItemplate',$attr['objectClass'])){
1242 $tmp2["Type"] = 'FAItemplate';
1243 $tmp2["Abbr"] = 'T';
1244 $tmp2["Desc"] = $attr['description'][0];
1245 }
1246 if(in_array('FAIvariable',$attr['objectClass'])){
1247 $tmp2["Type"] = 'FAIvariable';
1248 $tmp2["Abbr"] = 'V';
1249 $tmp2["Desc"] = $attr['description'][0];
1250 }
1251 if(in_array('FAIscript',$attr['objectClass'])){
1252 $tmp2["Type"] = 'FAIscript';
1253 $tmp2["Abbr"] = 'S';
1254 $tmp2["Desc"] = $attr['description'][0];
1255 }
1256 if(in_array('FAIhook',$attr['objectClass'])){
1257 $tmp2["Type"] = 'FAIhook';
1258 $tmp2["Abbr"] = 'H';
1259 $tmp2["Desc"] = $attr['description'][0];
1260 }
1261 if(in_array('FAIpartitionTable',$attr['objectClass'])){
1262 $tmp2["Type"]= 'FAIpartitionTable';
1263 $tmp2["Abbr"]= 'Pt';
1264 $tmp2["Desc"] = $attr['description'][0];
1265 }
1266 if(in_array('FAIprofile',$attr['objectClass'])){
1267 $tmp2["Type"]= 'FAIprofile';
1268 $tmp2["Abbr"]= 'P';
1269 $tmp2["Desc"] = $attr['description'][0];
1270 }
1271 return($tmp2);
1272 }
1275 /* Return repository hook output, if possible.
1276 */
1277 function GetHookElements()
1278 {
1279 $ret = array();
1280 $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1281 if(!empty($cmd)){
1282 $res = shell_exec($cmd);
1283 $res2 = trim($res);
1284 if((!$res)){
1285 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1286 }elseif(empty($res2)){
1287 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1288 }else{
1289 $tmp = split("\n",$res);
1290 foreach($tmp as $line){
1291 if(empty($line)) continue;
1292 $ret[]= $line;
1293 }
1294 }
1295 }
1296 return($ret);
1297 }
1300 /* This function creates the release name out of a dn
1301 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1302 */
1303 function dn_to_release_name($dn)
1304 {
1305 $relevant = preg_replace("/,".normalizePreg(get_ou("faiou")).".*$/","",$dn);
1306 $parts = array_reverse(split("\,",$relevant));
1307 $str ="";
1308 foreach($parts as $part){
1309 $str .= preg_replace("/^ou=/","",$part)."/";
1310 }
1311 return(preg_replace("/\/$/","",$str));
1312 }
1313 }
1315 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1316 ?>