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 $div = new divSelectBox("WSFAIscriptClasses");
590 $div -> SetHeight("110");
592 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
594 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
595 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
596 $smarty->assign("FAIrelease" , $this->FAIrelease);
597 $smarty->assign("FAIclasses" , $this->selectable_classes());
599 /* Get classes for release from cache.
600 * Or build cache
601 */
602 if($this->FAIdebianMirror == "inherited"){
603 $release = $this->InheritedFAIrelease;
604 }else{
605 $release = $this->FAIrelease;
606 }
608 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
609 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
611 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
612 if($this->acl_is_writeable("FAIclass")){
613 $str_up = " <input type='image' src='images/lists/sort-up.png' name='sort_up_%s' value='%s'>";
614 $str_down = " <input type='image' src='images/lists/sort-down.png' name='sort_down_%s' value='%s'>";
615 $str_remove = " <input type='image' src='images/lists/trash.png' name='fai_remove_%s' value='%s'>";
616 }else{
617 $str_up=$str_down=$str_remove=$str_empty;
618 }
620 /* Get classes */
621 if($this->FAIdebianMirror == "inherited"){
622 $tmp = $this->InheritedFAIclass;
623 }else{
624 $tmp = $this->FAIclass;
625 }
627 /* Get invalid classes */
628 $invalid = $this->get_invalid_classes($tmp);
630 /* Draw every single entry */
631 $i = 1;
632 if($this->acl_is_readable("FAIclass")){
633 foreach($tmp as $class){
635 /* Mark invalid classes. (Not in selected release)
636 */
637 $marker = "";
638 if(in_array_ics($class,$invalid)){
639 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
640 }
642 /* Create up/down priority icons
643 * Skip this, if we have inherited the FAI classes.
644 */
645 if($this->FAIdebianMirror == "inherited"){
646 $str = "";
647 }else{
648 if($i==1){
649 $str = $str_empty.$str_down.$str_remove;
650 }elseif($i == count($this->FAIclass)){
651 $str = $str_up.$str_empty.$str_remove;
652 }else{
653 $str = $str_up.$str_down.$str_remove;
654 }
655 }
656 $i ++ ;
658 /* Get Description tag
659 * There may be several FAI objects with the same class name,
660 * use the description from FAIprofile, if possible.
661 */
662 $desc = "";
663 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
664 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
665 if(isset($types['Desc'])){
666 $desc= $types['Desc'];
667 if($types['Type'] == "FAIprofile"){
668 break;
669 }
670 }
671 }
672 }
673 if(!empty($desc)){
674 $desc = " [".trim($desc)."]";
675 }
677 $div->AddEntry(array(
678 array("string"=>$class.$desc.$marker),
679 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
680 ));
681 }
682 }// END FAI output generation
683 }// END FAI output generation
684 $smarty->assign("FAIScriptlist",$div->DrawList());
686 /* Radio button group */
687 if (preg_match("/G/", $this->bootmode)) {
688 $smarty->assign("graphicalbootup", "checked");
689 } else {
690 $smarty->assign("graphicalbootup", "");
691 }
692 if (preg_match("/T/", $this->bootmode)) {
693 $smarty->assign("textbootup", "checked");
694 } else {
695 $smarty->assign("textbootup", "");
696 }
697 if (preg_match("/D/", $this->bootmode)) {
698 $smarty->assign("debugbootup", "checked");
699 } else {
700 $smarty->assign("debugbootup", "");
701 }
703 /* Show main page */
704 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
705 }
708 function remove_from_parent()
709 {
710 $this->handle_post_events("remove");
711 new log("remove","workstation/".get_class($this),$this->dn);
712 }
715 /* Save data to object */
716 function save_object()
717 {
718 $old_mirror = $this->FAIdebianMirror;
719 plugin::save_object();
721 /* Update release */
722 if($old_mirror != $this->FAIdebianMirror){
723 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
724 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
725 }
726 }
728 if(isset($_POST['WorkstationStarttabPosted'])){
729 if(isset($_POST['gotoLdap_inherit'])){
730 $this->gotoLdap_inherit = TRUE;
731 }else{
732 $this->gotoLdap_inherit = FALSE;
733 }
735 /* Save group radio buttons */
736 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
737 $this->bootmode= $_POST["bootmode"];
738 }
740 /* Save kernel parameters */
741 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
742 $this->customParameters= $_POST["customParameters"];
743 }
744 }
745 }
748 /* Save to LDAP */
749 function save()
750 {
752 /* Depending on the baseobject (Ogroup / WS) we
753 * use another set of objectClasses
754 * In case of WS itself, we use "array("GOhard", "FAIobject");"
755 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
756 */
757 if(isset($this->parent->by_object['ogroup'])){
758 $this->objectclasses = array("gotoWorkstationTemplate");
759 }elseif(isset($this->parent->by_object['workgeneric'])){
760 $this->objectclasses = array("GOhard");
761 }elseif(isset($this->parent->by_object['servgeneric'])){
762 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
763 }else{
764 msg_dialog::display(_("Fatal error"),
765 "Object Type Configuration is unknown. Please contact the GOsa developers.",
766 FATAL_ERROR_DIALOG);
767 exit();
768 }
770 /* Append FAI class */
771 if($this->fai_activated){
772 $this->objectclasses[] = "FAIobject";
773 }
775 /* Find proper terminal path for tftp configuration
776 FIXME: This is suboptimal when the default has changed to
777 another location! */
778 if (($this->gotoTerminalPath == "default")){
779 $ldap= $this->config->get_ldap_link();
781 /* Strip relevant part from dn, keep trailing ',' */
782 $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
783 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
785 /* Walk from top to base and try to load default values for
786 'gotoTerminalPath'. Abort when an entry is found. */
787 while (TRUE){
788 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
790 $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
791 $this->config->current['BASE'], array('gotoTerminalPath'));
792 $attrs= $ldap->fetch();
793 if (isset($attrs['gotoTerminalPath'])){
794 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
795 break;
796 }
798 /* Nothing left? */
799 if ($tmp == ""){
800 break;
801 }
802 }
803 }
805 /* Add semi automatic values */
806 // FIXME: LDAP Server may not be set here...
807 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
809 switch ($this->bootmode){
810 case "D":
811 $this->gotoKernelParameters.= " debug";
812 break;
813 case "G":
814 $this->gotoKernelParameters.= " splash=silent";
815 break;
816 }
817 if ($this->customParameters != ""){
818 $this->gotoKernelParameters.= " o ".$this->customParameters;
819 }
821 plugin::save();
823 unset( $this->attrs['FAIrelease'] );
824 $str = "";
826 /* Skip FAI attribute handling if not necessary */
827 if($this->fai_activated && !$this->si_fai_action_failed){
828 if($this->FAIdebianMirror == "inherited"){
829 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
830 }else{
831 foreach($this->FAIclass as $class){
832 $str .= $class." ";
833 }
834 $str = trim($str);
835 if(empty($this->attrs['FAIclass'])){
836 $this->attrs['FAIclass'] = array();
837 }else{
838 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
839 }
840 }
841 }
843 /* Add missing arrays */
844 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
845 if (isset ($this->$val) && count ($this->$val) != 0){
847 $this->attrs["$val"]= array_unique($this->$val);
848 }
849 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
850 }
852 /* Prepare list of ldap servers */
853 $this->attrs['gotoLdapServer'] = array();
854 if(!$this->gotoLdap_inherit){
855 $i = 0;
856 foreach($this->gotoLdapServers as $server){
857 $i ++;
858 $this->attrs['gotoLdapServer'][] = $i.":".$server;
859 }
860 }
862 if ($this->attrs['gotoBootKernel'] == "default-inherited"){
863 $this->attrs['gotoBootKernel']= array();
864 }
866 /* if mirror == none stop saving this attribute */
867 if($this->FAIdebianMirror == "none"){
868 $this->FAIdebianMirror = "";
869 }
871 /* Get FAIstate from object, the generic tab could have changed it during execute */
872 $ldap= $this->config->get_ldap_link();
873 $ldap->cd($this->dn);
876 /* Skip FAI attribute handling if not necessary */
877 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
878 $ldap->cat($this->dn,array("FAIstate"));
879 $checkFAIstate = $ldap->fetch();
881 /* Remove FAI objects if no FAI class is selected */
882 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
883 $this->attrs['FAIclass'] = array();
884 $this->attrs['FAIdebianMirror'] = array();
885 }
886 }else{
888 /* Don't touch FAI objects if something went wrong with the si daemon.
889 */
890 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
891 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
892 }
894 /* prepare share settings */
895 $tmp = array();
896 foreach($this->gotoShares as $name => $settings){
897 $tmp2= split("\|",$name);
898 $name = $tmp2[0];
899 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
900 }
901 $this->attrs['gotoShare']=$tmp;
902 $this->cleanup();
903 $ldap->modify ($this->attrs);
904 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
906 if (!$ldap->success()){
907 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
908 }
909 $this->handle_post_events("modify");
911 /* Check if LDAP server has changed */
912 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
913 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
914 $o_queue = new gosaSupportDaemon();
915 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
916 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
917 $macs = array();
919 /* Get list of macAddresses
920 */
921 if(isset($this->parent->by_object['ogroup'])){
923 /* If we are an object group, add all member macs
924 */
925 $p = $this->parent->by_object['ogroup'];
926 foreach($p->memberList as $dn => $obj){
927 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
928 $macs[] = $p->objcache[$dn]['macAddress'];
929 }
930 }
931 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
933 /* We are a workstation. Add current mac.
934 */
935 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
936 if(!empty($mac)){
937 $macs[] = $mac;
938 }
939 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
941 /* We are a server. Add current mac.
942 */
943 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
944 if(!empty($mac)){
945 $macs[] = $mac;
946 }
947 }
949 /* Trigger event for all member objects
950 */
951 foreach($macs as $mac){
952 $tmp = new $evt['CLASS_NAME']($this->config);
953 $tmp->set_type(TRIGGERED_EVENT);
954 $tmp->add_targets(array($mac));
955 if(!$o_queue->append($tmp)){
956 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
957 }
958 }
959 }
960 }
961 }
964 /* Add value to array, check if unique */
965 function add_list (&$array, $value)
966 {
967 if ($value != ""){
968 $array[]= $value;
969 sort($array);
970 array_unique ($array);
971 }
972 }
975 /* Delete value to array, check if unique */
976 function del_list (&$array, $list)
977 {
978 $tmp= array();
979 foreach ($array as $mod){
980 if (!in_array($mod, $list)){
981 $tmp[]= $mod;
982 }
983 }
984 $array= $tmp;
985 }
987 /* Generate ListBox frindly output for the defined shares
988 * Possibly Add or remove an attribute here,
989 */
990 function printOutAssignedShares()
991 {
992 $a_return = array();
993 if(is_array($this->gotoShares)){
994 foreach($this->gotoShares as $share){
995 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
996 }
997 }
998 return($a_return);
999 }
1003 function PrepareForCopyPaste($source)
1004 {
1005 plugin::PrepareForCopyPaste($source);
1006 $source_o = new workstartup ($this->config, $source['dn']);
1007 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1008 "gotoKernelParameters","gotoShares","customParameters") as $attr){
1009 $this->$attr = $source_o->$attr;
1010 }
1011 }
1014 function array_switch_item($ar,$from,$to)
1015 {
1016 if(!is_array($ar)){
1017 return(false);
1018 }
1019 if(!isset($ar[$from])){
1020 return(false);
1021 }
1022 if(!isset($ar[$to])){
1023 return(false);
1024 }
1026 $tmp = $ar[$from];
1027 $ar[$from] = $ar[$to];
1028 $ar[$to] = $tmp;
1029 return($ar);
1030 }
1033 /* Return plugin informations for acl handling */
1034 static function plInfo()
1035 {
1036 return (array(
1037 "plShortName" => _("Startup"),
1038 "plDescription" => _("System startup"),
1039 "plSelfModify" => FALSE,
1040 "plDepends" => array(),
1041 "plPriority" => 9,
1042 "plSection" => array("administration"),
1043 "plCategory" => array("workstation","server","ogroups"),
1045 "plProvidedAcls"=> array(
1046 "gotoLdapServer" => _("Ldap server"),
1047 "gotoBootKernel" => _("Boot kernel"),
1048 "gotoKernelParameters" => _("Kernel parameter"),
1050 "gotoModules" => _("Kernel modules"),
1051 "gotoShare" => _("Shares"),
1053 "FAIclass" => _("FAI classes"),
1054 "FAIdebianMirror" => _("Debian mirror"),
1055 "FAIrelease" => _("Debian release"),
1057 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1058 ));
1059 }
1062 /* Updates release dns
1063 * and reads all classes for the current release,
1064 * if not already done ($this->cache).
1065 */
1066 function update_fai_cache($first_call = FALSE)
1067 {
1068 $force = FALSE;
1069 if(!$this->si_active) return;
1070 $start = microtime(TRUE);
1072 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1074 $this->si_fai_action_failed = FALSE;
1076 /* Get the list of available servers and their releases.
1077 */
1078 if($force || !isset($this->cache['SERVERS'])){
1080 $o_queue = new gosaSupportDaemon();
1081 $tmp = $o_queue->FAI_get_server();
1082 if($o_queue->is_error()){
1083 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1084 $this->si_fai_action_failed = TRUE;
1085 $this->cache = array();
1086 return;
1087 }else{
1088 foreach($tmp as $entry){
1089 $rel = $entry['FAI_RELEASE'];
1090 $this->cache['SERVERS']['auto'][$rel] = $rel;
1091 $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1092 uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1093 uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1094 }
1095 }
1096 }
1098 /* Ensure that our selection is valid, else we get several PHP warnings
1099 if there is no FAI configuration at all.
1100 */
1101 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1102 $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1103 }
1105 /* Build up arrays, without checks */
1106 if(!$first_call){
1108 /* Check if the selected mirror is available */
1109 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1110 $this->FAIdebianMirror = "auto";
1111 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1112 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1113 }
1115 /* Check if the selected release is available */
1116 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1117 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1118 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1119 }
1120 }
1122 /* Get classes for release from cache.
1123 * Or build cache
1124 */
1125 if($this->FAIdebianMirror == "inherited"){
1126 $release = $this->InheritedFAIrelease;
1127 }else{
1128 $release = $this->FAIrelease;
1129 }
1131 if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1133 /* Get the list of available servers and their releases.
1134 */
1135 $o_queue = new gosaSupportDaemon();
1136 $tmp = $o_queue->FAI_get_classes($release);
1137 $this->cache['CLASSES'][$release] = array();
1138 if($o_queue->is_error()){
1139 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1140 $this->si_fai_action_failed = TRUE;
1141 $this->cache=array();
1142 return;
1143 }else{
1144 foreach($tmp as $entry){
1145 $class = $entry['CLASS'];
1146 $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry);
1147 }
1148 }
1150 /* Add object caught from external hook
1151 */
1152 $lines= $this->GetHookElements();
1153 foreach ($lines as $hline){
1154 $entries= split(";", $hline);
1155 $server = $entries['0'];
1156 $url = $entries['1'];
1157 if (!empty($url)){
1159 /* Split releases */
1160 if (isset($entries[2])){
1161 $releases= split(",", $entries[2]);
1163 foreach ($releases as $release_data){
1164 $release_c = preg_replace('/:.*$/', '', $release_data);
1165 $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1166 $classes_c = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1168 if($release_c == $release){
1169 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1170 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1171 foreach ($classes_c as $class){
1172 if ($class != ""){
1173 $this->cache['CLASSES'][$release_c][$class]= array();
1174 }
1175 }
1176 }
1177 }
1178 }
1179 }
1180 }
1181 uksort($this->cache['SERVERS'], 'strnatcasecmp');
1183 /* Only add inherit option, if we are part in an object group
1184 */
1185 if($this->member_of_ogroup){
1186 $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1187 }
1188 }
1190 /* Get list of available kernel for this release
1191 */
1192 if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1194 if($force || !isset($this->cache['KERNELS'][$release])){
1195 $o_queue = new gosaSupportDaemon();
1196 $tmp = $o_queue->FAI_get_kernels($release);
1197 $this->cache['KERNELS'][$release] = array();
1198 foreach($this->gotoBootKernels as $name => $default){
1199 $this->cache['KERNELS'][$release][$name] = $default;
1200 }
1201 foreach($tmp as $kernel){
1202 if(empty($kernel)) continue;
1203 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1204 }
1205 ksort($this->cache['KERNELS'][$release]);
1206 }
1207 }
1210 /* This function return an array containing all
1211 * invalid classes for the selected server/release
1212 */
1213 function get_invalid_classes($classes)
1214 {
1215 $this->update_fai_cache();
1216 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1217 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1218 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1219 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1220 }else{
1221 $release_classes = array();
1222 }
1225 /* Detect all classes that are not valid
1226 * for the selected release
1227 */
1228 $NA = array();
1229 foreach($classes as $class){
1230 if(!isset($release_classes[$class])){
1231 $NA[] = $class;
1232 }
1233 }
1234 return($NA);
1235 }
1238 /* Get all selectable classes for the ui select box
1239 */
1240 function selectable_classes()
1241 {
1242 $this->update_fai_cache();
1244 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1245 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1246 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1247 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1248 }else{
1249 $classes = array();
1250 }
1252 $Abbr ="";
1253 $ret= array();
1254 foreach($classes as $class_name => $class_types){
1255 if(!in_array($class_name,$this->FAIclass)){
1256 foreach($class_types as $type){
1257 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1258 $Abbr .= $type['Abbr']." ";
1259 }
1260 }
1261 $ret[$class_name] = trim($Abbr);
1262 }
1263 }
1264 uksort($ret, 'strnatcasecmp');
1265 return($ret);
1266 }
1269 /* Analyse FAI object and return an array with usefull informations like
1270 * FAIobject type.
1271 */
1272 function analyse_fai_object($attr)
1273 {
1274 $tmp = array();
1275 switch($attr['TYPE']){
1277 case 'FAIpackageList':
1278 $tmp["Type"]= 'FAIpackageList';
1279 $tmp["Abbr"]= 'Pl';
1280 break;
1281 case 'FAItemplate':
1282 $tmp["Type"]= 'FAItemplate';
1283 $tmp["Abbr"]= 'T';
1284 break;
1285 case 'FAIvariable':
1286 $tmp["Type"]= 'FAIvariable';
1287 $tmp["Abbr"]= 'V';
1288 break;
1289 case 'FAIscript':
1290 $tmp["Type"]= 'FAIscript';
1291 $tmp["Abbr"]= 'S';
1292 break;
1293 case 'FAIhook':
1294 $tmp["Type"]= 'FAIhook';
1295 $tmp["Abbr"]= 'H';
1296 break;
1297 case 'FAIpartitionTable':
1298 $tmp["Type"]= 'FAIpartitionTable';
1299 $tmp["Abbr"]= 'Pt';
1300 break;
1301 case 'FAIprofile':
1302 $tmp["Type"]= 'FAIprofile';
1303 $tmp["Abbr"]= 'P';
1304 break;
1305 default: trigger_error("Unknown FAI object type!");;
1306 }
1307 return($tmp);
1308 }
1311 /* Return repository hook output, if possible.
1312 */
1313 function GetHookElements()
1314 {
1315 $ret = array();
1316 $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1317 if(!empty($cmd)){
1318 $res = shell_exec($cmd);
1319 $res2 = trim($res);
1320 if((!$res)){
1321 msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1322 }elseif(empty($res2)){
1323 msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG);
1324 }else{
1325 $tmp = split("\n",$res);
1326 foreach($tmp as $line){
1327 if(empty($line)) continue;
1328 $ret[]= $line;
1329 }
1330 }
1331 }
1332 return($ret);
1333 }
1336 /* This function creates the release name out of a dn
1337 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1338 */
1339 function dn_to_release_name($dn)
1340 {
1341 $relevant = preg_replace("/,".normalizePreg(get_ou("faiBaseRDN")).".*$/","",$dn);
1342 $parts = array_reverse(split("\,",$relevant));
1343 $str ="";
1344 foreach($parts as $part){
1345 $str .= preg_replace("/^ou=/","",$part)."/";
1346 }
1347 return(preg_replace("/\/$/","",$str));
1348 }
1349 }
1351 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1352 ?>