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 /* 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 }
235 $this->update_fai_cache();
237 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
239 /* Check if the current mirror is available
240 */
241 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
242 if(count($this->FAIclass)){
243 msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
244 }
245 $this->FAIdebianMirror = "auto";
246 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
247 $this->cache['CLASSES'] = array();
248 $this->update_fai_cache();
249 }
251 /* Check if the current mirror is available
252 */
253 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
254 $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
255 if(count($this->FAIclass)){
256 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);
257 }
258 $this->FAIrelease = $new_release;
259 $this->cache['CLASSES'] = array();
260 $this->update_fai_cache();
261 }
262 }
263 }
266 function check()
267 {
268 $messages = array();
270 /* Call common method to give check the hook */
271 $messages= plugin::check();
273 /* If there are packages selected, but no mirror show error */
274 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
275 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
276 }
278 return($messages);
279 }
281 function execute()
282 {
283 /* Call parent execute */
284 plugin::execute();
286 if($this->is_account && !$this->view_logged){
287 $this->view_logged = TRUE;
288 new log("view","workstation/".get_class($this),$this->dn);
289 }
291 /* Do we represent a valid terminal? */
292 if (!$this->is_account && $this->parent === NULL){
293 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
294 msgPool::noValidExtension(_("workstation"))."</b>";
295 return ($display);
296 }
298 /* Add module */
299 if (isset ($_POST['add_module'])){
300 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
301 $this->add_list ($this->gotoModules, $_POST['module']);
302 }
303 }
305 /* Delete module */
306 if (isset ($_POST['delete_module'])){
307 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
308 $this->del_list ($this->gotoModules, $_POST['modules_list']);
309 }
310 }
312 /* FAI class management */
313 if($this->fai_activated){
314 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
315 $found = 0 ;
317 /* If this new class/profile will attach a second partition table
318 * to our list of classes, abort and show a message.
319 */
320 foreach($this->FAIclass as $name){
321 if(isset($this->FAIclassInfo[$name])){
322 foreach($this->FAIclassInfo[$name] as $atr){
323 if(isset($atr['obj'])){
324 if($atr['obj'] == "FAIpartitionTable"){
325 $found ++ ;
326 }
327 }
328 }
329 }
330 }
332 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
333 msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
334 }else{
335 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
336 }
337 }
339 $sort = false;
341 /* Move one used class class one position up or down */
342 if($this->acl_is_writeable("FAIclass")){
343 foreach($_POST as $name => $val){
345 $sort_type = false;
346 if((preg_match("/sort_up/",$name))&&(!$sort)){
347 $sort_type = "sort_up_";
348 }
349 if((preg_match("/sort_down/",$name))&&(!$sort)){
350 $sort_type = "sort_down_";
351 }
353 if(($sort_type)&&(!$sort)){
354 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
355 $sort = true;
357 $last = -1;
358 $change_down = -1;
360 /* Create array with numeric index */
361 $tmp = array();
362 foreach($this->FAIclass as $class){
363 $tmp [] = $class;
364 }
366 /* Walk trough array */
367 foreach($tmp as $key => $faiName){
368 if($faiName == $value){
369 if($sort_type == "sort_up_"){
370 if($last != -1){
371 $change_down= $last;
372 }
373 }else{
374 if(isset($tmp[$key+1])){
375 $change_down = $key;
376 }
377 }
378 }
379 $last = $key;
380 }
382 $tmp2 = array();
383 $skip = false;
385 foreach($tmp as $ky => $vl){
387 if($ky == $change_down){
388 $skip = $vl;
389 }else{
390 $tmp2[$vl] = $vl;
391 }
392 if(($skip != false)&&($ky != $change_down)){
393 $tmp2[$skip] = $skip;
394 $skip =false;
395 }
396 }
397 $this->FAIclass = $tmp2;
398 }
400 if(preg_match("/fai_remove/i",$name)){
401 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
402 unset($this->FAIclass[$value]);
403 }
404 }
405 }
407 /* Delete selected class from our list */
408 if($this->acl_is_writeable("FAIclass")){
409 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
410 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
411 unset($this->FAIclass[$_POST['FAIclassSel']]);
412 }
413 }
414 }
415 }// END fai handling
417 /* Show main page */
418 $smarty= get_smarty();
420 /* Assign ACLs to smarty */
421 $tmp = $this->plInfo();
422 foreach($tmp['plProvidedAcls'] as $name => $translation){
423 $smarty->assign($name."ACL",$this->getacl($name));
424 }
426 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
428 /* In this section server shares will be defined
429 * A user can select one of the given shares and a mount point
430 * and attach this combination to his setup.
431 */
432 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
433 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
435 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
436 * This entry will be, a combination of mountPoint and sharedefinitions
437 */
438 if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
439 /* We assign a share to this user, if we don't know where to mount the share */
440 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
441 msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
442 }else{
444 if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
445 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
446 $s_mount = $_POST['gotoShareMountPoint'];
447 /* Preparing the new assignment */
448 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
449 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
450 }
451 }
452 }
454 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
455 * If there is no defined share selected, we will abort the deletion without any message
456 */
457 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
458 unset($this->gotoShares[$_POST['gotoShare']]);
459 }
461 $smarty->assign("gotoShares",$this->printOutAssignedShares());
462 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
463 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
464 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
466 /* Create divSelectBox for ldap server selection
467 */
468 $SelectBoxLdapServer = new divSelectBox("LdapServer");
469 $SelectBoxLdapServer->SetHeight(130);
471 /* Add new ldap server to the list */
472 if($this->acl_is_writeable("gotoLdapServer") &&
473 !$this->gotoLdap_inherit &&
474 isset($_POST['add_ldap_server']) &&
475 isset($_POST['ldap_server_to_add'])){
476 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
477 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
478 if(!in_array($to_add,$this->gotoLdapServers)){
479 $this->gotoLdapServers[] = $to_add;
480 }
481 }
482 }
484 /* Move ldap servers up and down */
485 if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
486 foreach($_POST as $name => $value){
487 if(preg_match("/sort_ldap_up_/",$name)){
488 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
489 $from = $id;
490 $to = $id -1;
491 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
492 if($tmp){
493 $this->gotoLdapServers = $tmp;
494 }
495 break;
496 }
497 if(preg_match("/sort_ldap_down_/",$name)){
498 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
499 $from = $id;
500 $to = $id +1;
501 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
502 if($tmp){
503 $this->gotoLdapServers = $tmp;
504 }
505 break;
506 }
507 if(preg_match("/gotoLdapRemove_/",$name)){
508 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
509 $value = $this->gotoLdapServers[$id];
510 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
511 break;
512 }
513 }
514 }
516 /* Add Entries */
517 if($this->acl_is_readable("gotoLdapServer")){
519 foreach($this->gotoLdapServers as $key => $server){
521 /* Announce missing entries */
522 if(!in_array($server,$this->gotoLdapServerList)){
523 $server = $server." <font style='color:red'>(missing)</font>";
524 }
526 /* Convert old style entry */
527 if (!preg_match('%:ldaps?://%', $server)){
528 $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
530 /* Beautify new style entries */
531 } else {
532 $server= preg_replace("/^[^:]+:/", "", $server);
533 }
535 $SelectBoxLdapServer->AddEntry(
536 array(array("string" => $server),
537 array("string" =>
538 "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'> ".
539 "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'> ".
540 "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
541 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
542 }
543 }
545 if($this->gotoLdap_inherit){
546 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
547 }else{
548 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
549 }
551 $list = array();
552 foreach($this->gotoLdapServerList as $key => $entry){
553 if(!in_array($entry,$this->gotoLdapServers)){
555 /* Convert old style entry */
556 if (!preg_match('%:ldap[s]*://%', $entry)){
557 $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
559 /* Beautify new style entries */
560 } else {
561 $entry= preg_replace("/^[^:]+:/", "", $entry);
562 }
564 $list[$key] = $entry;
565 }
566 }
567 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
568 $smarty->assign("gotoLdapServerList", $list);
569 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
570 $smarty->assign("JS", session::get('js'));
572 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
573 $smarty->assign("$val", $this->$val);
574 }
576 /* Values */
577 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
578 $smarty->assign($val, $this->$val);
579 }
581 $smarty->assign("fai_activated",$this->fai_activated);
583 /* Create FAI output */
584 $this->update_fai_cache();
585 $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
586 $smarty->assign("si_active",$this->si_active);
588 $div = new divSelectBox("WSFAIscriptClasses");
589 $div -> SetHeight("110");
591 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
593 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
594 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
595 $smarty->assign("FAIrelease" , $this->FAIrelease);
596 $smarty->assign("FAIclasses" , $this->selectable_classes());
598 /* Get classes for release from cache.
599 * Or build cache
600 */
601 if($this->FAIdebianMirror == "inherited"){
602 $release = $this->InheritedFAIrelease;
603 }else{
604 $release = $this->FAIrelease;
605 }
607 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
608 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
610 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
611 if($this->acl_is_writeable("FAIclass")){
612 $str_up = " <input type='image' src='images/lists/sort-up.png' name='sort_up_%s' value='%s'>";
613 $str_down = " <input type='image' src='images/lists/sort-down.png' name='sort_down_%s' value='%s'>";
614 $str_remove = " <input type='image' src='images/lists/trash.png' name='fai_remove_%s' value='%s'>";
615 }else{
616 $str_up=$str_down=$str_remove=$str_empty;
617 }
619 /* Get classes */
620 if($this->FAIdebianMirror == "inherited"){
621 $tmp = $this->InheritedFAIclass;
622 }else{
623 $tmp = $this->FAIclass;
624 }
626 /* Get invalid classes */
627 $invalid = $this->get_invalid_classes($tmp);
629 /* Draw every single entry */
630 $i = 1;
631 if($this->acl_is_readable("FAIclass")){
632 foreach($tmp as $class){
634 /* Mark invalid classes. (Not in selected release)
635 */
636 $marker = "";
637 if(in_array_ics($class,$invalid)){
638 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
639 }
641 /* Create up/down priority icons
642 * Skip this, if we have inherited the FAI classes.
643 */
644 if($this->FAIdebianMirror == "inherited"){
645 $str = "";
646 }else{
647 if($i==1){
648 $str = $str_empty.$str_down.$str_remove;
649 }elseif($i == count($this->FAIclass)){
650 $str = $str_up.$str_empty.$str_remove;
651 }else{
652 $str = $str_up.$str_down.$str_remove;
653 }
654 }
655 $i ++ ;
657 /* Get Description tag
658 * There may be several FAI objects with the same class name,
659 * use the description from FAIprofile, if possible.
660 */
661 $desc = "";
662 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
663 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
664 if(isset($types['Desc'])){
665 $desc= $types['Desc'];
666 if($types['Type'] == "FAIprofile"){
667 break;
668 }
669 }
670 }
671 }
672 if(!empty($desc)){
673 $desc = " [".trim($desc)."]";
674 }
676 $div->AddEntry(array(
677 array("string"=>$class.$desc.$marker),
678 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
679 ));
680 }
681 }// END FAI output generation
682 }// END FAI output generation
683 $smarty->assign("FAIScriptlist",$div->DrawList());
685 /* Radio button group */
686 if (preg_match("/G/", $this->bootmode)) {
687 $smarty->assign("graphicalbootup", "checked");
688 } else {
689 $smarty->assign("graphicalbootup", "");
690 }
691 if (preg_match("/T/", $this->bootmode)) {
692 $smarty->assign("textbootup", "checked");
693 } else {
694 $smarty->assign("textbootup", "");
695 }
696 if (preg_match("/D/", $this->bootmode)) {
697 $smarty->assign("debugbootup", "checked");
698 } else {
699 $smarty->assign("debugbootup", "");
700 }
702 /* Show main page */
703 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
704 }
707 function remove_from_parent()
708 {
709 $this->handle_post_events("remove");
710 new log("remove","workstation/".get_class($this),$this->dn);
711 }
714 /* Save data to object */
715 function save_object()
716 {
717 $old_mirror = $this->FAIdebianMirror;
718 plugin::save_object();
720 /* Update release */
721 if($old_mirror != $this->FAIdebianMirror){
722 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
723 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
724 }
725 }
727 if(isset($_POST['WorkstationStarttabPosted'])){
728 if(isset($_POST['gotoLdap_inherit'])){
729 $this->gotoLdap_inherit = TRUE;
730 }else{
731 $this->gotoLdap_inherit = FALSE;
732 }
734 /* Save group radio buttons */
735 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
736 $this->bootmode= $_POST["bootmode"];
737 }
739 /* Save kernel parameters */
740 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
741 $this->customParameters= $_POST["customParameters"];
742 }
743 }
744 }
747 /* Save to LDAP */
748 function save()
749 {
751 /* Depending on the baseobject (Ogroup / WS) we
752 * use another set of objectClasses
753 * In case of WS itself, we use "array("GOhard", "FAIobject");"
754 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
755 */
756 if(isset($this->parent->by_object['ogroup'])){
757 $this->objectclasses = array("gotoWorkstationTemplate");
758 }elseif(isset($this->parent->by_object['workgeneric'])){
759 $this->objectclasses = array("GOhard");
760 }elseif(isset($this->parent->by_object['servgeneric'])){
761 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
762 }else{
763 msg_dialog::display(_("Fatal error"),
764 "Object Type Configuration is unknown. Please contact the GOsa developers.",
765 FATAL_ERROR_DIALOG);
766 exit();
767 }
769 /* Append FAI class */
770 if($this->fai_activated){
771 $this->objectclasses[] = "FAIobject";
772 }
774 /* Find proper terminal path for tftp configuration
775 FIXME: This is suboptimal when the default has changed to
776 another location! */
777 if (($this->gotoTerminalPath == "default")){
778 $ldap= $this->config->get_ldap_link();
780 /* Strip relevant part from dn, keep trailing ',' */
781 $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
782 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
784 /* Walk from top to base and try to load default values for
785 'gotoTerminalPath'. Abort when an entry is found. */
786 while (TRUE){
787 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
789 $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
790 $this->config->current['BASE'], array('gotoTerminalPath'));
791 $attrs= $ldap->fetch();
792 if (isset($attrs['gotoTerminalPath'])){
793 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
794 break;
795 }
797 /* Nothing left? */
798 if ($tmp == ""){
799 break;
800 }
801 }
802 }
804 /* Add semi automatic values */
805 // FIXME: LDAP Server may not be set here...
806 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
808 switch ($this->bootmode){
809 case "D":
810 $this->gotoKernelParameters.= " debug";
811 break;
812 case "G":
813 $this->gotoKernelParameters.= " splash=silent";
814 break;
815 }
816 if ($this->customParameters != ""){
817 $this->gotoKernelParameters.= " o ".$this->customParameters;
818 }
820 plugin::save();
822 unset( $this->attrs['FAIrelease'] );
823 $str = "";
825 /* Skip FAI attribute handling if not necessary */
826 if($this->fai_activated && !$this->si_fai_action_failed){
827 if($this->FAIdebianMirror == "inherited"){
828 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
829 }else{
830 foreach($this->FAIclass as $class){
831 $str .= $class." ";
832 }
833 $str = trim($str);
834 if(empty($this->attrs['FAIclass'])){
835 $this->attrs['FAIclass'] = array();
836 }else{
837 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
838 }
839 }
840 }
842 /* Add missing arrays */
843 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
844 if (isset ($this->$val) && count ($this->$val) != 0){
846 $this->attrs["$val"]= array_unique($this->$val);
847 }
848 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
849 }
851 /* Prepare list of ldap servers */
852 $this->attrs['gotoLdapServer'] = array();
853 if(!$this->gotoLdap_inherit){
854 $i = 0;
855 foreach($this->gotoLdapServers as $server){
856 $i ++;
857 $this->attrs['gotoLdapServer'][] = $i.":".$server;
858 }
859 }
861 if ($this->attrs['gotoBootKernel'] == "default-inherited"){
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 && !$this->si_fai_action_failed && $this->si_active){
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 }else{
887 /* Don't touch FAI objects if something went wrong with the si daemon.
888 */
889 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
890 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
891 }
893 /* prepare share settings */
894 $tmp = array();
895 foreach($this->gotoShares as $name => $settings){
896 $tmp2= split("\|",$name);
897 $name = $tmp2[0];
898 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
899 }
900 $this->attrs['gotoShare']=$tmp;
901 $this->cleanup();
902 $ldap->modify ($this->attrs);
903 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
905 if (!$ldap->success()){
906 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
907 }
908 $this->handle_post_events("modify");
910 /* Check if LDAP server has changed */
911 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
912 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
913 $o_queue = new gosaSupportDaemon();
914 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
915 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
916 $macs = array();
918 /* Get list of macAddresses
919 */
920 if(isset($this->parent->by_object['ogroup'])){
922 /* If we are an object group, add all member macs
923 */
924 $p = $this->parent->by_object['ogroup'];
925 foreach($p->memberList as $dn => $obj){
926 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
927 $macs[] = $p->objcache[$dn]['macAddress'];
928 }
929 }
930 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
932 /* We are a workstation. Add current mac.
933 */
934 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
935 if(!empty($mac)){
936 $macs[] = $mac;
937 }
938 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
940 /* We are a server. Add current mac.
941 */
942 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
943 if(!empty($mac)){
944 $macs[] = $mac;
945 }
946 }
948 /* Trigger event for all member objects
949 */
950 foreach($macs as $mac){
951 $tmp = new $evt['CLASS_NAME']($this->config);
952 $tmp->set_type(TRIGGERED_EVENT);
953 $tmp->add_targets(array($mac));
954 if(!$o_queue->append($tmp)){
955 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
956 }
957 }
958 }
959 }
960 }
963 /* Add value to array, check if unique */
964 function add_list (&$array, $value)
965 {
966 if ($value != ""){
967 $array[]= $value;
968 sort($array);
969 array_unique ($array);
970 }
971 }
974 /* Delete value to array, check if unique */
975 function del_list (&$array, $list)
976 {
977 $tmp= array();
978 foreach ($array as $mod){
979 if (!in_array($mod, $list)){
980 $tmp[]= $mod;
981 }
982 }
983 $array= $tmp;
984 }
986 /* Generate ListBox frindly output for the defined shares
987 * Possibly Add or remove an attribute here,
988 */
989 function printOutAssignedShares()
990 {
991 $a_return = array();
992 if(is_array($this->gotoShares)){
993 foreach($this->gotoShares as $share){
994 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
995 }
996 }
997 return($a_return);
998 }
1002 function PrepareForCopyPaste($source)
1003 {
1004 plugin::PrepareForCopyPaste($source);
1005 $source_o = new workstartup ($this->config, $source['dn']);
1006 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1007 "gotoKernelParameters","gotoShares","customParameters") as $attr){
1008 $this->$attr = $source_o->$attr;
1009 }
1010 }
1013 function array_switch_item($ar,$from,$to)
1014 {
1015 if(!is_array($ar)){
1016 return(false);
1017 }
1018 if(!isset($ar[$from])){
1019 return(false);
1020 }
1021 if(!isset($ar[$to])){
1022 return(false);
1023 }
1025 $tmp = $ar[$from];
1026 $ar[$from] = $ar[$to];
1027 $ar[$to] = $tmp;
1028 return($ar);
1029 }
1032 /* Return plugin informations for acl handling */
1033 static function plInfo()
1034 {
1035 return (array(
1036 "plShortName" => _("Startup"),
1037 "plDescription" => _("System startup"),
1038 "plSelfModify" => FALSE,
1039 "plDepends" => array(),
1040 "plPriority" => 9,
1041 "plSection" => array("administration"),
1042 "plCategory" => array("workstation","server","ogroups"),
1044 "plProvidedAcls"=> array(
1045 "gotoLdapServer" => _("Ldap server"),
1046 "gotoBootKernel" => _("Boot kernel"),
1047 "gotoKernelParameters" => _("Kernel parameter"),
1049 "gotoModules" => _("Kernel modules"),
1050 "gotoShare" => _("Shares"),
1052 "FAIclass" => _("FAI classes"),
1053 "FAIdebianMirror" => _("Debian mirror"),
1054 "FAIrelease" => _("Debian release"),
1056 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1057 ));
1058 }
1061 /* Updates release dns
1062 * and reads all classes for the current release,
1063 * if not already done ($this->cache).
1064 */
1065 function update_fai_cache($first_call = FALSE)
1066 {
1067 $force = FALSE;
1068 if(!$this->si_active) return;
1069 $start = microtime(TRUE);
1071 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1073 $this->si_fai_action_failed = FALSE;
1075 /* Get the list of available servers and their releases.
1076 */
1077 if($force || !isset($this->cache['SERVERS'])){
1079 $o_queue = new gosaSupportDaemon();
1080 $tmp = $o_queue->FAI_get_server();
1081 if($o_queue->is_error()){
1082 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1083 $this->si_fai_action_failed = TRUE;
1084 $this->cache = array();
1085 return;
1086 }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 ?>