1 <?php
2 class workstartup extends plugin
3 {
4 /* Ldap server list */
5 var $gotoLdapServers = array();
6 var $gotoLdapServerList = array();
7 var $gotoLdap_inherit = FALSE;
9 /* Generic terminal attributes */
10 var $bootmode = "G";
11 var $gotoBootKernel = "default-inherited";
12 var $gotoKernelParameters = "";
13 var $gotoLdapServer = "default-inherited";
14 var $gotoModules = array();
15 var $gotoAutoFs = array();
16 var $gotoFilesystem = array();
17 var $gotoTerminalPath = "";
18 var $gotoBootKernels = array();
20 /* attribute list for save action */
21 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters",
22 "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
23 var $objectclasses = array("GOhard", "FAIobject");
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(); // The currently selected classes
38 var $FAIrelease = "";
39 var $FAIdebianMirror = "auto";
40 var $si_active = FALSE;
41 var $si_fai_action_failed = FALSE;
43 var $cache = array(); // Used as cache in fai mehtods
45 var $FAIstatus = "";
46 var $FAIclasses = array();
48 var $view_logged = FALSE;
50 /* FAI class selection */
51 var $InheritedFAIclass = array();
52 var $InheritedFAIrelease = "";
53 var $InheritedFAIdebianMirror= "auto";
55 var $CopyPasteVars = array("gotoModules","gotoShares");
56 var $fai_activated = FALSE;
57 var $o_group_dn = "";
58 var $member_of_ogroup = FALSE;
60 function workstartup (&$config, $dn= NULL, $parent= NULL)
61 {
62 /* Check if FAI is active */
63 $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
64 if(!empty($tmp) && class_available("faiManagement")){
65 $this->fai_activated = TRUE;
66 }else{
67 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
68 $this->objectclasses = array("GOhard");
69 }
71 plugin::plugin ($config, $dn, $parent);
73 /* Check for si daemon */
74 $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
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 natcasesort($this->gotoLdapServerList);
108 if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
109 $this->gotoLdap_inherit = TRUE;
110 }
112 /* FAI Initialization
113 Skip this if FAI is not activated
114 */
115 if($this->fai_activated) {
117 $this->update_fai_cache(TRUE);
119 /* Parse used FAIclasses (stored as string).
120 * The single classes are seperated by ' '.
121 * There is also the release type given, after first
122 * occurrence of ':'.
123 */
124 $this->FAIclass =array();
125 if(isset($this->attrs['FAIclass'][0])){
126 $tmp = split(" ",$this->attrs['FAIclass'][0]);
127 $tmp2 =array();
129 foreach($tmp as $class){
130 if( ":" == $class[0] ) {
131 $this->FAIrelease = trim(substr($class, 1));
132 }else{
133 $tmp2[$class] = $class;
134 }
135 }
136 $this->FAIclass = $tmp2;
137 }
138 }
140 /* Get arrays */
141 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
142 if (isset($this->attrs["$val"]["count"])){
143 for ($i= 0; $i<$this->attrs["count"]; $i++){
144 if (isset($this->attrs["$val"][$i])){
145 array_push($this->$val, $this->attrs["$val"][$i]);
146 }
147 }
148 }
149 sort ($this->$val);
150 $this->$val= array_unique($this->$val);
151 }
153 /* Parse Kernel Parameters to decide what boot mode is enabled */
154 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
155 $this->bootmode= "G";
156 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
157 $this->bootmode= "D";
158 } elseif ($this->gotoKernelParameters == "") {
159 $this->bootmode= "G";
160 } else {
161 $this->bootmode= "T";
162 }
163 if (preg_match("/ o /", $this->gotoKernelParameters)){
164 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
165 } else {
166 $this->customParameters= "";
167 }
169 /* Prepare Shares */
170 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
171 unset($this->attrs['gotoShare']['count']);
172 foreach($this->attrs['gotoShare'] as $share){
173 $tmp = $tmp2 = array();
174 $tmp = split("\|",$share);
175 $tmp2['server'] =$tmp[0];
176 $tmp2['name'] =$tmp[1];
177 $tmp2['mountPoint'] =$tmp[2];
178 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
179 }
180 }
182 $this->gotoShareSelections= $config->getShareList(true);
183 $this->gotoAvailableShares= $config->getShareList(false);
184 $tmp2 = array();
187 $this->orig_dn= $this->dn;
189 /* Handle inheritance value "default" */
190 if ($this->member_of_ogroup){
191 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
192 }
194 /* If we are member in an object group,
195 * we have to handle inherited values.
196 * So you can see what is inherited.
197 */
198 if ($this->member_of_ogroup){
200 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
201 $this->FAIdebianMirror = "inherited";
202 }
204 if($this->fai_activated){
205 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
206 }else{
207 $map= array("gotoBootKernel");
208 }
210 $ldap = $this->config->get_ldap_link();
211 $ldap->cat($this->o_group_dn);
212 $attrs= $ldap->fetch();
214 foreach ($map as $name){
215 if (!isset($attrs[$name][0])){
216 continue;
217 }
219 switch ($name){
220 case 'gotoBootKernel':
221 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
222 break;
224 case 'FAIclass':
225 $str = split(":",$attrs[$name][0]);
226 $this->InheritedFAIclass = split("\ ",trim($str[0]));
227 $this->InheritedFAIrelease = trim($str[1]);
228 break;
230 case 'FAIdebianMirror':
231 $this->InheritedFAIdebianMirror = $attrs[$name][0];
232 break;
233 }
234 }
235 }
238 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
240 /* Check if the current mirror is available
241 */
242 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
243 if(count($this->FAIclass)){
244 msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
245 }
246 $this->FAIdebianMirror = "auto";
247 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
248 $this->cache['CLASSES'] = array();
249 $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 msg_dialog::display(_("Error"), sprintf(_("FAI release '%s' is not available on mirror '%s' - setting to release '%s'!"), $this->FAIrelease, $this->FAIdebianMirror,$new_release), ERROR_DIALOG);
258 }
259 $this->FAIrelease = $new_release;
260 $this->cache['CLASSES'] = array();
261 $this->update_fai_cache();
262 }
263 }
264 }
267 function check()
268 {
269 $messages = array();
271 /* Call common method to give check the hook */
272 $messages= plugin::check();
274 /* If there are packages selected, but no mirror show error */
275 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
276 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
277 }
279 return($messages);
280 }
282 function execute()
283 {
284 /* Call parent execute */
285 plugin::execute();
287 if($this->is_account && !$this->view_logged){
288 $this->view_logged = TRUE;
289 new log("view","workstation/".get_class($this),$this->dn);
290 }
292 /* Do we represent a valid terminal? */
293 if (!$this->is_account && $this->parent === NULL){
294 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
295 msgPool::noValidExtension(_("workstation"))."</b>";
296 return ($display);
297 }
299 /* Add module */
300 if (isset ($_POST['add_module'])){
301 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
302 $this->add_list ($this->gotoModules, $_POST['module']);
303 }
304 }
306 /* Delete module */
307 if (isset ($_POST['delete_module'])){
308 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
309 $this->del_list ($this->gotoModules, $_POST['modules_list']);
310 }
311 }
313 /* FAI class management */
314 if($this->fai_activated){
315 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
316 $found = 0 ;
318 /* If this new class/profile will attach a second partition table
319 * to our list of classes, abort and show a message.
320 */
321 foreach($this->FAIclass as $name){
322 if(isset($this->FAIclassInfo[$name])){
323 foreach($this->FAIclassInfo[$name] as $atr){
324 if(isset($atr['obj'])){
325 if($atr['obj'] == "FAIpartitionTable"){
326 $found ++ ;
327 }
328 }
329 }
330 }
331 }
333 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
334 msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
335 }else{
336 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
337 }
338 }
340 $sort = false;
342 /* Move one used class class one position up or down */
343 if($this->acl_is_writeable("FAIclass")){
344 foreach($_POST as $name => $val){
346 $sort_type = false;
347 if((preg_match("/sort_up/",$name))&&(!$sort)){
348 $sort_type = "sort_up_";
349 }
350 if((preg_match("/sort_down/",$name))&&(!$sort)){
351 $sort_type = "sort_down_";
352 }
354 if(($sort_type)&&(!$sort)){
355 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
356 $sort = true;
358 $last = -1;
359 $change_down = -1;
361 /* Create array with numeric index */
362 $tmp = array();
363 foreach($this->FAIclass as $class){
364 $tmp [] = $class;
365 }
367 /* Walk trough array */
368 foreach($tmp as $key => $faiName){
369 if($faiName == $value){
370 if($sort_type == "sort_up_"){
371 if($last != -1){
372 $change_down= $last;
373 }
374 }else{
375 if(isset($tmp[$key+1])){
376 $change_down = $key;
377 }
378 }
379 }
380 $last = $key;
381 }
383 $tmp2 = array();
384 $skip = false;
386 foreach($tmp as $ky => $vl){
388 if($ky == $change_down){
389 $skip = $vl;
390 }else{
391 $tmp2[$vl] = $vl;
392 }
393 if(($skip != false)&&($ky != $change_down)){
394 $tmp2[$skip] = $skip;
395 $skip =false;
396 }
397 }
398 $this->FAIclass = $tmp2;
399 }
401 if(preg_match("/fai_remove/i",$name)){
402 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
403 unset($this->FAIclass[$value]);
404 }
405 }
406 }
408 /* Delete selected class from our list */
409 if($this->acl_is_writeable("FAIclass")){
410 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
411 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
412 unset($this->FAIclass[$_POST['FAIclassSel']]);
413 }
414 }
415 }
416 }// END fai handling
418 /* Show main page */
419 $smarty= get_smarty();
421 /* Assign ACLs to smarty */
422 $tmp = $this->plInfo();
423 foreach($tmp['plProvidedAcls'] as $name => $translation){
424 $smarty->assign($name."ACL",$this->getacl($name));
425 }
427 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
429 /* In this section server shares will be defined
430 * A user can select one of the given shares and a mount point
431 * and attach this combination to his setup.
432 */
433 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
434 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
436 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
437 * This entry will be, a combination of mountPoint and sharedefinitions
438 */
439 if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
440 /* We assign a share to this user, if we don't know where to mount the share */
441 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
442 msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
443 }else{
445 if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
446 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
447 $s_mount = $_POST['gotoShareMountPoint'];
448 /* Preparing the new assignment */
449 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
450 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
451 }
452 }
453 }
455 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
456 * If there is no defined share selected, we will abort the deletion without any message
457 */
458 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
459 unset($this->gotoShares[$_POST['gotoShare']]);
460 }
462 $smarty->assign("gotoShares",$this->printOutAssignedShares());
463 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
464 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
465 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
467 /* Create divSelectBox for ldap server selection
468 */
469 $SelectBoxLdapServer = new divSelectBox("LdapServer");
470 $SelectBoxLdapServer->SetHeight(130);
472 /* Add new ldap server to the list */
473 if($this->acl_is_writeable("gotoLdapServer") &&
474 !$this->gotoLdap_inherit &&
475 isset($_POST['add_ldap_server']) &&
476 isset($_POST['ldap_server_to_add'])){
477 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
478 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
479 if(!in_array($to_add,$this->gotoLdapServers)){
480 $this->gotoLdapServers[] = $to_add;
481 }
482 }
483 }
485 /* Move ldap servers up and down */
486 if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
487 foreach($_POST as $name => $value){
488 if(preg_match("/sort_ldap_up_/",$name)){
489 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
490 $from = $id;
491 $to = $id -1;
492 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
493 if($tmp){
494 $this->gotoLdapServers = $tmp;
495 }
496 break;
497 }
498 if(preg_match("/sort_ldap_down_/",$name)){
499 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
500 $from = $id;
501 $to = $id +1;
502 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
503 if($tmp){
504 $this->gotoLdapServers = $tmp;
505 }
506 break;
507 }
508 if(preg_match("/gotoLdapRemove_/",$name)){
509 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
510 $value = $this->gotoLdapServers[$id];
511 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
512 break;
513 }
514 }
515 }
517 /* Add Entries */
518 if($this->acl_is_readable("gotoLdapServer")){
520 foreach($this->gotoLdapServers as $key => $server){
522 /* Announce missing entries */
523 if(!in_array($server,$this->gotoLdapServerList)){
524 $server = $server." <font style='color:red'>(missing)</font>";
525 }
527 /* Convert old style entry */
528 if (!preg_match('%:ldaps?://%', $server)){
529 $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
531 /* Beautify new style entries */
532 } else {
533 $server= preg_replace("/^[^:]+:/", "", $server);
534 }
536 $SelectBoxLdapServer->AddEntry(
537 array(array("string" => $server),
538 array("string" =>
539 "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'> ".
540 "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'> ".
541 "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
542 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
543 }
544 }
546 if($this->gotoLdap_inherit){
547 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
548 }else{
549 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
550 }
552 $list = array();
553 foreach($this->gotoLdapServerList as $key => $entry){
554 if(!in_array($entry,$this->gotoLdapServers)){
556 /* Convert old style entry */
557 if (!preg_match('%:ldap[s]*://%', $entry)){
558 $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
560 /* Beautify new style entries */
561 } else {
562 $entry= preg_replace("/^[^:]+:/", "", $entry);
563 }
565 $list[$key] = $entry;
566 }
567 }
568 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
569 $smarty->assign("gotoLdapServerList", $list);
570 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
571 $smarty->assign("JS", session::get('js'));
573 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
574 $smarty->assign("$val", $this->$val);
575 }
577 /* Values */
578 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
579 $smarty->assign($val, $this->$val);
580 }
582 $smarty->assign("fai_activated",$this->fai_activated);
584 /* Create FAI output */
585 $this->update_fai_cache();
586 $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
587 $smarty->assign("si_active",$this->si_active);
589 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
591 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
592 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
593 $smarty->assign("FAIrelease" , $this->FAIrelease);
594 $smarty->assign("FAIclasses" , $this->selectable_classes());
596 /* Get classes for release from cache.
597 * Or build cache
598 */
599 if($this->FAIdebianMirror == "inherited"){
600 $release = $this->InheritedFAIrelease;
601 }else{
602 $release = $this->FAIrelease;
603 }
605 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
606 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
608 $div = new divSelectBox("WSFAIscriptClasses");
609 $div -> SetHeight("110");
610 $str_up = " <input type='image' src='images/lists/sort-up.png' name='sort_up_%s' value='%s'>";
611 $str_down = " <input type='image' src='images/lists/sort-down.png' name='sort_down_%s' value='%s'>";
612 $str_remove = " <input type='image' src='images/lists/trash.png' name='fai_remove_%s' value='%s'>";
613 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
615 /* Get classes */
616 if($this->FAIdebianMirror == "inherited"){
617 $tmp = $this->InheritedFAIclass;
618 }else{
619 $tmp = $this->FAIclass;
620 }
622 /* Get invalid classes */
623 $invalid = $this->get_invalid_classes($tmp);
625 /* Draw every single entry */
626 $i = 1;
627 foreach($tmp as $class){
629 /* Mark invalid classes. (Not in selected release)
630 */
631 $marker = "";
632 if(in_array_ics($class,$invalid)){
633 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
634 }
636 /* Create up/down priority icons
637 * Skip this, if we have inherited the FAI classes.
638 */
639 if($this->FAIdebianMirror == "inherited"){
640 $str = "";
641 }else{
642 if($i==1){
643 $str = $str_empty.$str_down.$str_remove;
644 }elseif($i == count($this->FAIclass)){
645 $str = $str_up.$str_empty.$str_remove;
646 }else{
647 $str = $str_up.$str_down.$str_remove;
648 }
649 }
650 $i ++ ;
652 /* Get Description tag
653 * There may be several FAI objects with the same class name,
654 * use the description from FAIprofile, if possible.
655 */
656 $desc = "";
657 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
658 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
659 if(isset($types['Desc'])){
660 $desc= $types['Desc'];
661 if($types['Type'] == "FAIprofile"){
662 break;
663 }
664 }
665 }
666 }
667 if(!empty($desc)){
668 $desc = " [".trim($desc)."]";
669 }
671 $div->AddEntry(array(
672 array("string"=>$class.$desc.$marker),
673 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
674 ));
675 }
676 $smarty->assign("FAIScriptlist",$div->DrawList());
677 }// END FAI output generation
679 /* Radio button group */
680 if (preg_match("/G/", $this->bootmode)) {
681 $smarty->assign("graphicalbootup", "checked");
682 } else {
683 $smarty->assign("graphicalbootup", "");
684 }
685 if (preg_match("/T/", $this->bootmode)) {
686 $smarty->assign("textbootup", "checked");
687 } else {
688 $smarty->assign("textbootup", "");
689 }
690 if (preg_match("/D/", $this->bootmode)) {
691 $smarty->assign("debugbootup", "checked");
692 } else {
693 $smarty->assign("debugbootup", "");
694 }
696 /* Show main page */
697 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
698 }
701 function remove_from_parent()
702 {
703 $this->handle_post_events("remove");
704 new log("remove","workstation/".get_class($this),$this->dn);
705 }
708 /* Save data to object */
709 function save_object()
710 {
711 $old_mirror = $this->FAIdebianMirror;
712 plugin::save_object();
714 /* Update release */
715 if($old_mirror != $this->FAIdebianMirror){
716 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
717 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
718 }
719 }
721 if(isset($_POST['WorkstationStarttabPosted'])){
722 if(isset($_POST['gotoLdap_inherit'])){
723 $this->gotoLdap_inherit = TRUE;
724 }else{
725 $this->gotoLdap_inherit = FALSE;
726 }
728 /* Save group radio buttons */
729 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
730 $this->bootmode= $_POST["bootmode"];
731 }
733 /* Save kernel parameters */
734 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
735 $this->customParameters= $_POST["customParameters"];
736 }
737 }
738 }
741 /* Save to LDAP */
742 function save()
743 {
745 /* Depending on the baseobject (Ogroup / WS) we
746 * use another set of objectClasses
747 * In case of WS itself, we use "array("GOhard", "FAIobject");"
748 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
749 */
750 if(isset($this->parent->by_object['ogroup'])){
751 $this->objectclasses = array("gotoWorkstationTemplate");
752 }elseif(isset($this->parent->by_object['workgeneric'])){
753 $this->objectclasses = array("GOhard");
754 }elseif(isset($this->parent->by_object['servgeneric'])){
755 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
756 }else{
757 msg_dialog::display(_("Fatal error"),
758 "Object Type Configuration is unknown. Please contact the GOsa developers.",
759 FATAL_ERROR_DIALOG);
760 exit();
761 }
763 /* Append FAI class */
764 if($this->fai_activated){
765 $this->objectclasses[] = "FAIobject";
766 }
768 /* Find proper terminal path for tftp configuration
769 FIXME: This is suboptimal when the default has changed to
770 another location! */
771 if (($this->gotoTerminalPath == "default")){
772 $ldap= $this->config->get_ldap_link();
774 /* Strip relevant part from dn, keep trailing ',' */
775 $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
776 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
778 /* Walk from top to base and try to load default values for
779 'gotoTerminalPath'. Abort when an entry is found. */
780 while (TRUE){
781 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
783 $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
784 $this->config->current['BASE'], array('gotoTerminalPath'));
785 $attrs= $ldap->fetch();
786 if (isset($attrs['gotoTerminalPath'])){
787 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
788 break;
789 }
791 /* Nothing left? */
792 if ($tmp == ""){
793 break;
794 }
795 }
796 }
798 /* Add semi automatic values */
799 // FIXME: LDAP Server may not be set here...
800 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
802 switch ($this->bootmode){
803 case "D":
804 $this->gotoKernelParameters.= " debug";
805 break;
806 case "G":
807 $this->gotoKernelParameters.= " splash=silent";
808 break;
809 }
810 if ($this->customParameters != ""){
811 $this->gotoKernelParameters.= " o ".$this->customParameters;
812 }
814 plugin::save();
816 unset( $this->attrs['FAIrelease'] );
817 $str = "";
819 /* Skip FAI attribute handling if not necessary */
820 if($this->fai_activated && !$this->si_fai_action_failed){
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 = trim($str);
828 if(empty($this->attrs['FAIclass'])){
829 $this->attrs['FAIclass'] = array();
830 }else{
831 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
832 }
833 }
834 }
836 /* Add missing arrays */
837 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
838 if (isset ($this->$val) && count ($this->$val) != 0){
840 $this->attrs["$val"]= array_unique($this->$val);
841 }
842 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
843 }
845 /* Prepare list of ldap servers */
846 $this->attrs['gotoLdapServer'] = array();
847 if(!$this->gotoLdap_inherit){
848 $i = 0;
849 foreach($this->gotoLdapServers as $server){
850 $i ++;
851 $this->attrs['gotoLdapServer'][] = $i.":".$server;
852 }
853 }
855 if ($this->attrs['gotoBootKernel'] == "default-inherited"){
856 $this->attrs['gotoBootKernel']= array();
857 }
859 /* if mirror == none stop saving this attribute */
860 if($this->FAIdebianMirror == "none"){
861 $this->FAIdebianMirror = "";
862 }
864 /* Get FAIstate from object, the generic tab could have changed it during execute */
865 $ldap= $this->config->get_ldap_link();
866 $ldap->cd($this->dn);
869 /* Skip FAI attribute handling if not necessary */
870 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
871 $ldap->cat($this->dn,array("FAIstate"));
872 $checkFAIstate = $ldap->fetch();
874 /* Remove FAI objects if no FAI class is selected */
875 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
876 $this->attrs['FAIclass'] = array();
877 $this->attrs['FAIdebianMirror'] = array();
878 }
879 }else{
881 /* Don't touch FAI objects if something went wrong with the si daemon.
882 */
883 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
884 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
885 }
887 /* prepare share settings */
888 $tmp = array();
889 foreach($this->gotoShares as $name => $settings){
890 $tmp2= split("\|",$name);
891 $name = $tmp2[0];
892 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
893 }
894 $this->attrs['gotoShare']=$tmp;
895 $this->cleanup();
896 $ldap->modify ($this->attrs);
897 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
899 if (!$ldap->success()){
900 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
901 }
902 $this->handle_post_events("modify");
904 /* Check if LDAP server has changed */
905 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
906 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
907 $o_queue = new gosaSupportDaemon();
908 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
909 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
910 $macs = array();
912 /* Get list of macAddresses
913 */
914 if(isset($this->parent->by_object['ogroup'])){
916 /* If we are an object group, add all member macs
917 */
918 $p = $this->parent->by_object['ogroup'];
919 foreach($p->memberList as $dn => $obj){
920 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
921 $macs[] = $p->objcache[$dn]['macAddress'];
922 }
923 }
924 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
926 /* We are a workstation. Add current mac.
927 */
928 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
929 if(!empty($mac)){
930 $macs[] = $mac;
931 }
932 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
934 /* We are a server. Add current mac.
935 */
936 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
937 if(!empty($mac)){
938 $macs[] = $mac;
939 }
940 }
942 /* Trigger event for all member objects
943 */
944 foreach($macs as $mac){
945 $tmp = new $evt['CLASS_NAME']($this->config);
946 $tmp->set_type(TRIGGERED_EVENT);
947 $tmp->add_targets(array($mac));
948 if(!$o_queue->append($tmp)){
949 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
950 }
951 }
952 }
953 }
954 }
957 /* Add value to array, check if unique */
958 function add_list (&$array, $value)
959 {
960 if ($value != ""){
961 $array[]= $value;
962 sort($array);
963 array_unique ($array);
964 }
965 }
968 /* Delete value to array, check if unique */
969 function del_list (&$array, $list)
970 {
971 $tmp= array();
972 foreach ($array as $mod){
973 if (!in_array($mod, $list)){
974 $tmp[]= $mod;
975 }
976 }
977 $array= $tmp;
978 }
980 /* Generate ListBox frindly output for the defined shares
981 * Possibly Add or remove an attribute here,
982 */
983 function printOutAssignedShares()
984 {
985 $a_return = array();
986 if(is_array($this->gotoShares)){
987 foreach($this->gotoShares as $share){
988 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
989 }
990 }
991 return($a_return);
992 }
996 function PrepareForCopyPaste($source)
997 {
998 plugin::PrepareForCopyPaste($source);
999 $source_o = new workstartup ($this->config, $source['dn']);
1000 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1001 "gotoKernelParameters","gotoShares","customParameters") as $attr){
1002 $this->$attr = $source_o->$attr;
1003 }
1004 }
1007 function array_switch_item($ar,$from,$to)
1008 {
1009 if(!is_array($ar)){
1010 return(false);
1011 }
1012 if(!isset($ar[$from])){
1013 return(false);
1014 }
1015 if(!isset($ar[$to])){
1016 return(false);
1017 }
1019 $tmp = $ar[$from];
1020 $ar[$from] = $ar[$to];
1021 $ar[$to] = $tmp;
1022 return($ar);
1023 }
1026 /* Return plugin informations for acl handling */
1027 static function plInfo()
1028 {
1029 return (array(
1030 "plShortName" => _("Startup"),
1031 "plDescription" => _("System startup"),
1032 "plSelfModify" => FALSE,
1033 "plDepends" => array(),
1034 "plPriority" => 9,
1035 "plSection" => array("administration"),
1036 "plCategory" => array("workstation","server","ogroups"),
1038 "plProvidedAcls"=> array(
1039 "gotoLdapServer" => _("Ldap server"),
1040 "gotoBootKernel" => _("Boot kernel"),
1041 "gotoKernelParameters" => _("Kernel parameter"),
1043 "gotoModules" => _("Kernel modules"),
1044 "gotoShare" => _("Shares"),
1046 "FAIclass" => _("FAI classes"),
1047 "FAIdebianMirror" => _("Debian mirror"),
1048 "FAIrelease" => _("Debian release"),
1050 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1051 ));
1052 }
1055 /* Updates release dns
1056 * and reads all classes for the current release,
1057 * if not already done ($this->cache).
1058 */
1059 function update_fai_cache($first_call = FALSE)
1060 {
1061 $force = FALSE;
1062 if(!$this->si_active) return;
1063 $start = microtime(TRUE);
1065 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1067 $this->si_fai_action_failed = FALSE;
1069 /* Get the list of available servers and their releases.
1070 */
1071 if($force || !isset($this->cache['SERVERS'])){
1073 $o_queue = new gosaSupportDaemon();
1074 $tmp = $o_queue->FAI_get_server();
1075 if($o_queue->is_error()){
1076 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1077 $this->si_fai_action_failed = TRUE;
1078 $this->cache = array();
1079 return;
1080 }else{
1081 foreach($tmp as $entry){
1082 $rel = $entry['FAI_RELEASE'];
1083 $this->cache['SERVERS']['auto'][$rel] = $rel;
1084 $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1085 uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1086 uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1087 }
1088 }
1089 }
1091 /* Ensure that our selection is valid, else we get several PHP warnings
1092 if there is no FAI configuration at all.
1093 */
1094 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1095 $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1096 }
1098 /* Build up arrays, without checks */
1099 if(!$first_call){
1101 /* Check if the selected mirror is available */
1102 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1103 $this->FAIdebianMirror = "auto";
1104 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1105 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1106 }
1108 /* Check if the selected release is available */
1109 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1110 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1111 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1112 }
1113 }
1115 /* Get classes for release from cache.
1116 * Or build cache
1117 */
1118 if($this->FAIdebianMirror == "inherited"){
1119 $release = $this->InheritedFAIrelease;
1120 }else{
1121 $release = $this->FAIrelease;
1122 }
1124 if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1126 /* Get the list of available servers and their releases.
1127 */
1128 $o_queue = new gosaSupportDaemon();
1129 $tmp = $o_queue->FAI_get_classes($release);
1130 $this->cache['CLASSES'][$release] = array();
1131 if($o_queue->is_error()){
1132 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1133 $this->si_fai_action_failed = TRUE;
1134 $this->cache=array();
1135 return;
1136 }else{
1137 foreach($tmp as $entry){
1138 $class = $entry['CLASS'];
1139 $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry);
1140 }
1141 }
1143 /* Add object caught from external hook
1144 */
1145 $lines= $this->GetHookElements();
1146 foreach ($lines as $hline){
1147 $entries= split(";", $hline);
1148 $server = $entries['0'];
1149 $url = $entries['1'];
1150 if (!empty($url)){
1152 /* Split releases */
1153 if (isset($entries[2])){
1154 $releases= split(",", $entries[2]);
1156 foreach ($releases as $release_data){
1157 $release_c = preg_replace('/:.*$/', '', $release_data);
1158 $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1159 $classes_c = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1161 if($release_c == $release){
1162 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1163 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1164 foreach ($classes_c as $class){
1165 if ($class != ""){
1166 $this->cache['CLASSES'][$release_c][$class]= array();
1167 }
1168 }
1169 }
1170 }
1171 }
1172 }
1173 }
1174 uksort($this->cache['SERVERS'], 'strnatcasecmp');
1176 /* Only add inherit option, if we are part in an object group
1177 */
1178 if($this->member_of_ogroup){
1179 $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1180 }
1181 }
1183 /* Get list of available kernel for this release
1184 */
1185 if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1187 if($force || !isset($this->cache['KERNELS'][$release])){
1188 $o_queue = new gosaSupportDaemon();
1189 $tmp = $o_queue->FAI_get_kernels($release);
1190 $this->cache['KERNELS'][$release] = array();
1191 foreach($this->gotoBootKernels as $name => $default){
1192 $this->cache['KERNELS'][$release][$name] = $default;
1193 }
1194 foreach($tmp as $kernel){
1195 if(empty($kernel)) continue;
1196 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1197 }
1198 ksort($this->cache['KERNELS'][$release]);
1199 }
1200 }
1203 /* This function return an array containing all
1204 * invalid classes for the selected server/release
1205 */
1206 function get_invalid_classes($classes)
1207 {
1208 $this->update_fai_cache();
1209 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1210 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1211 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1212 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1213 }else{
1214 $release_classes = array();
1215 }
1218 /* Detect all classes that are not valid
1219 * for the selected release
1220 */
1221 $NA = array();
1222 foreach($classes as $class){
1223 if(!isset($release_classes[$class])){
1224 $NA[] = $class;
1225 }
1226 }
1227 return($NA);
1228 }
1231 /* Get all selectable classes for the ui select box
1232 */
1233 function selectable_classes()
1234 {
1235 $this->update_fai_cache();
1237 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1238 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1239 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1240 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1241 }else{
1242 $classes = array();
1243 }
1245 $Abbr ="";
1246 $ret= array();
1247 foreach($classes as $class_name => $class_types){
1248 if(!in_array($class_name,$this->FAIclass)){
1249 foreach($class_types as $type){
1250 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1251 $Abbr .= $type['Abbr']." ";
1252 }
1253 }
1254 $ret[$class_name] = trim($Abbr);
1255 }
1256 }
1257 uksort($ret, 'strnatcasecmp');
1258 return($ret);
1259 }
1262 /* Analyse FAI object and return an array with usefull informations like
1263 * FAIobject type.
1264 */
1265 function analyse_fai_object($attr)
1266 {
1267 $tmp = array();
1268 switch($attr['TYPE']){
1270 case 'FAIpackageList':
1271 $tmp["Type"]= 'FAIpackageList';
1272 $tmp["Abbr"]= 'Pl';
1273 break;
1274 case 'FAItemplate':
1275 $tmp["Type"]= 'FAItemplate';
1276 $tmp["Abbr"]= 'T';
1277 break;
1278 case 'FAIvariable':
1279 $tmp["Type"]= 'FAIvariable';
1280 $tmp["Abbr"]= 'V';
1281 break;
1282 case 'FAIscript':
1283 $tmp["Type"]= 'FAIscript';
1284 $tmp["Abbr"]= 'S';
1285 break;
1286 case 'FAIhook':
1287 $tmp["Type"]= 'FAIhook';
1288 $tmp["Abbr"]= 'H';
1289 break;
1290 case 'FAIpartitionTable':
1291 $tmp["Type"]= 'FAIpartitionTable';
1292 $tmp["Abbr"]= 'Pt';
1293 break;
1294 case 'FAIprofile':
1295 $tmp["Type"]= 'FAIprofile';
1296 $tmp["Abbr"]= 'P';
1297 break;
1298 default: trigger_error("Unknown FAI object type!");;
1299 }
1300 return($tmp);
1301 }
1304 /* Return repository hook output, if possible.
1305 */
1306 function GetHookElements()
1307 {
1308 $ret = array();
1309 $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1310 if(!empty($cmd)){
1311 $res = shell_exec($cmd);
1312 $res2 = trim($res);
1313 if((!$res)){
1314 msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1315 }elseif(empty($res2)){
1316 msg_dialog::display(_("Configuration error"), _("repositoryBranchHook returned no result!"), ERROR_DIALOG);
1317 }else{
1318 $tmp = split("\n",$res);
1319 foreach($tmp as $line){
1320 if(empty($line)) continue;
1321 $ret[]= $line;
1322 }
1323 }
1324 }
1325 return($ret);
1326 }
1329 /* This function creates the release name out of a dn
1330 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1331 */
1332 function dn_to_release_name($dn)
1333 {
1334 $relevant = preg_replace("/,".normalizePreg(get_ou("faiou")).".*$/","",$dn);
1335 $parts = array_reverse(split("\,",$relevant));
1336 $str ="";
1337 foreach($parts as $part){
1338 $str .= preg_replace("/^ou=/","",$part)."/";
1339 }
1340 return(preg_replace("/\/$/","",$str));
1341 }
1342 }
1344 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1345 ?>