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 # This is disabled as long there is no possiblilty to set these parameters
11 #var $bootmode = "G";
12 var $bootmode = "";
13 var $gotoBootKernel = "default-inherited";
14 var $gotoKernelParameters = "";
15 var $gotoLdapServer = "default-inherited";
16 var $gotoModules = array();
17 var $gotoAutoFs = array();
18 var $gotoFilesystem = array();
19 var $gotoTerminalPath = "";
20 var $gotoBootKernels = array();
22 /* attribute list for save action */
23 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters",
24 "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
25 var $objectclasses = array("GOhard", "FAIobject");
27 /* Share */
28 var $gotoShares = array();// Currently Share Option
29 var $gotoShare = ""; // currently selected Share Option
30 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
31 var $gotoAvailableShares= array();// Available Shares for this account
33 /* Helper */
34 var $orig_dn = "";
35 var $ignore_account = TRUE;
37 /* FAI class selection */
38 var $FAIclass = array(); // The currently selected classes
39 var $FAIrelease = "";
40 var $FAIdebianMirror = "auto";
41 var $si_active = FALSE;
42 var $si_fai_action_failed = FALSE;
44 var $cache = array(); // Used as cache in fai mehtods
46 var $FAIstatus = "";
47 var $FAIclasses = array();
49 var $view_logged = FALSE;
51 /* FAI class selection */
52 var $InheritedFAIclass = array();
53 var $InheritedFAIrelease = "";
54 var $InheritedFAIdebianMirror= "auto";
56 var $CopyPasteVars = array("gotoModules","gotoShares");
57 var $fai_activated = FALSE;
58 var $o_group_dn = "";
59 var $member_of_ogroup = FALSE;
61 function workstartup (&$config, $dn= NULL, $parent= NULL)
62 {
63 /* Check if FAI is active */
64 $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
65 if(!empty($tmp) && class_available("faiManagement")){
66 $this->fai_activated = TRUE;
67 }else{
68 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
69 $this->objectclasses = array("GOhard");
70 }
72 plugin::plugin ($config, $dn, $parent);
74 /* Check for si daemon */
75 $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
77 /* Check object group membership */
78 if(!isset($this->parent->by_object['ogroup'])){
79 $ldap = $this->config->get_ldap_link();
80 $ldap->cd ($this->config->current['BASE']);
81 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
82 if($ldap->count()){
83 $this->member_of_ogroup = TRUE;
84 $attrs = $ldap->fetch();
85 $this->o_group_dn = $attrs['dn'];
86 }
87 }
89 /* Creating a list of valid Mirrors
90 * none will not be saved to ldap.
91 */
92 $ldap = $this->config->get_ldap_link();
93 $ldap->cd($this->config->current['BASE']);
94 $ui = get_userinfo();
95 foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){
96 if($ui->get_category_permissions($data['dn'],"server",TRUE)){
97 for($i = 0; $i < $data['goLdapBase']['count']; $i ++){
98 $name = $data["cn"][0].":".$data["goLdapBase"][$i];
99 $this->gotoLdapServerList[]= $name;
100 }
101 }
102 }
104 /* Get list of assigned ldap servers
105 */
106 if(isset($this->attrs['gotoLdapServer'])){
107 unset($this->attrs['gotoLdapServer']['count']);
108 sort($this->attrs['gotoLdapServer']);
109 foreach($this->attrs['gotoLdapServer'] as $value){
110 $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
111 }
112 }
113 natcasesort($this->gotoLdapServerList);
115 if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
116 $this->gotoLdap_inherit = TRUE;
117 }
119 /* FAI Initialization
120 Skip this if FAI is not activated
121 */
122 if($this->fai_activated) {
124 /* Parse used FAIclasses (stored as string).
125 * The single classes are seperated by ' '.
126 * There is also the release type given, after first
127 * occurrence of ':'.
128 */
129 $this->FAIclass =array();
130 if(isset($this->attrs['FAIclass'][0])){
131 $tmp = explode(" ",$this->attrs['FAIclass'][0]);
132 $tmp2 =array();
134 foreach($tmp as $class){
135 if( ":" == $class[0] ) {
136 $this->FAIrelease = trim(substr($class, 1));
137 }else{
138 $tmp2[$class] = $class;
139 }
140 }
141 $this->FAIclass = $tmp2;
142 }
143 }
145 /* Get arrays */
146 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
147 if (isset($this->attrs["$val"]["count"])){
148 for ($i= 0; $i<$this->attrs["count"]; $i++){
149 if (isset($this->attrs["$val"][$i])){
150 array_push($this->$val, $this->attrs["$val"][$i]);
151 }
152 }
153 }
154 sort ($this->$val);
155 $this->$val= array_unique($this->$val);
156 }
158 /* Prepare Shares */
159 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
160 unset($this->attrs['gotoShare']['count']);
161 foreach($this->attrs['gotoShare'] as $share){
162 $tmp = $tmp2 = array();
163 $tmp = explode("|",$share);
164 $tmp2['server'] =$tmp[0];
165 $tmp2['name'] =$tmp[1];
166 $tmp2['mountPoint'] =$tmp[2];
167 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
168 }
169 }
171 $this->gotoShareSelections= $config->getShareList(true);
172 $this->gotoAvailableShares= $config->getShareList(false);
173 $tmp2 = array();
176 $this->orig_dn= $this->dn;
178 /* Handle inheritance value "default" */
179 if ($this->member_of_ogroup){
180 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
181 }
183 /* If we are member in an object group,
184 * we have to handle inherited values.
185 * So you can see what is inherited.
186 */
187 if ($this->member_of_ogroup){
189 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
190 $this->FAIdebianMirror = "inherited";
191 }
193 if($this->fai_activated){
194 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
195 }else{
196 $map= array("gotoBootKernel");
197 }
199 $ldap = $this->config->get_ldap_link();
200 $ldap->cat($this->o_group_dn);
201 $attrs= $ldap->fetch();
203 foreach ($map as $name){
204 if (!isset($attrs[$name][0])){
205 continue;
206 }
208 switch ($name){
209 case 'gotoBootKernel':
210 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
211 break;
213 case 'FAIclass':
214 $str = explode(":",$attrs[$name][0]);
215 $this->InheritedFAIclass = explode(" ",trim($str[0]));
216 $this->InheritedFAIrelease = trim($str[1]);
217 break;
219 case 'FAIdebianMirror':
220 $this->InheritedFAIdebianMirror = $attrs[$name][0];
221 break;
222 }
223 }
224 }
226 $this->update_fai_cache();
228 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
230 /* Check if the current mirror is available
231 */
232 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
233 if(count($this->FAIclass)){
234 msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
235 }
236 $this->FAIdebianMirror = "auto";
237 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
238 $this->cache['CLASSES'] = array();
239 $this->update_fai_cache();
240 }
242 /* Check if the current mirror is available
243 */
244 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
245 $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
246 if(count($this->FAIclass)){
247 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);
248 }
249 $this->FAIrelease = $new_release;
250 $this->cache['CLASSES'] = array();
251 $this->update_fai_cache();
252 }
253 }
254 }
257 function check()
258 {
259 $messages = array();
261 /* Call common method to give check the hook */
262 $messages= plugin::check();
264 /* If there are packages selected, but no mirror show error */
265 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
266 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
267 }
269 return($messages);
270 }
272 function execute()
273 {
274 /* Call parent execute */
275 plugin::execute();
277 if($this->is_account && !$this->view_logged){
278 $this->view_logged = TRUE;
279 new log("view","workstation/".get_class($this),$this->dn);
280 }
282 /* Do we represent a valid terminal? */
283 if (!$this->is_account && $this->parent === NULL){
284 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
285 msgPool::noValidExtension(_("workstation"))."</b>";
286 return ($display);
287 }
289 /* Add module */
290 if (isset ($_POST['add_module'])){
291 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
292 $this->add_list ($this->gotoModules, $_POST['module']);
293 }
294 }
296 /* Delete module */
297 if (isset ($_POST['delete_module'])){
298 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
299 $this->del_list ($this->gotoModules, $_POST['modules_list']);
300 }
301 }
303 /* FAI class management */
304 if($this->fai_activated){
305 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
306 $found = 0 ;
308 /* If this new class/profile will attach a second partition table
309 * to our list of classes, abort and show a message.
310 */
311 foreach($this->FAIclass as $name){
312 if(isset($this->FAIclassInfo[$name])){
313 foreach($this->FAIclassInfo[$name] as $atr){
314 if(isset($atr['obj'])){
315 if($atr['obj'] == "FAIpartitionTable"){
316 $found ++ ;
317 }
318 }
319 }
320 }
321 }
323 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
324 msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
325 }else{
326 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
327 }
328 }
330 $sort = false;
332 /* Move one used class class one position up or down */
333 if($this->acl_is_writeable("FAIclass")){
334 foreach($_POST as $name => $val){
336 $sort_type = false;
337 if((preg_match("/sort_up/",$name))&&(!$sort)){
338 $sort_type = "sort_up_";
339 }
340 if((preg_match("/sort_down/",$name))&&(!$sort)){
341 $sort_type = "sort_down_";
342 }
344 if(($sort_type)&&(!$sort)){
345 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
346 $sort = true;
348 $last = -1;
349 $change_down = -1;
351 /* Create array with numeric index */
352 $tmp = array();
353 foreach($this->FAIclass as $class){
354 $tmp [] = $class;
355 }
357 /* Walk trough array */
358 foreach($tmp as $key => $faiName){
359 if($faiName == $value){
360 if($sort_type == "sort_up_"){
361 if($last != -1){
362 $change_down= $last;
363 }
364 }else{
365 if(isset($tmp[$key+1])){
366 $change_down = $key;
367 }
368 }
369 }
370 $last = $key;
371 }
373 $tmp2 = array();
374 $skip = false;
376 foreach($tmp as $ky => $vl){
378 if($ky == $change_down){
379 $skip = $vl;
380 }else{
381 $tmp2[$vl] = $vl;
382 }
383 if(($skip != false)&&($ky != $change_down)){
384 $tmp2[$skip] = $skip;
385 $skip =false;
386 }
387 }
388 $this->FAIclass = $tmp2;
389 }
391 if(preg_match("/fai_remove/i",$name)){
392 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
393 unset($this->FAIclass[$value]);
394 }
395 }
396 }
398 /* Delete selected class from our list */
399 if($this->acl_is_writeable("FAIclass")){
400 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
401 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
402 unset($this->FAIclass[$_POST['FAIclassSel']]);
403 }
404 }
405 }
406 }// END fai handling
408 /* Show main page */
409 $smarty= get_smarty();
411 /* Assign ACLs to smarty */
412 $tmp = $this->plInfo();
413 foreach($tmp['plProvidedAcls'] as $name => $translation){
414 $smarty->assign($name."ACL",$this->getacl($name));
415 }
417 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
419 /* In this section server shares will be defined
420 * A user can select one of the given shares and a mount point
421 * and attach this combination to his setup.
422 */
423 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
424 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
426 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
427 * This entry will be, a combination of mountPoint and sharedefinitions
428 */
429 if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
430 /* We assign a share to this user, if we don't know where to mount the share */
431 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
432 msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
433 }else{
435 if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
436 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
437 $s_mount = $_POST['gotoShareMountPoint'];
438 /* Preparing the new assignment */
439 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
440 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
441 }
442 }
443 }
445 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
446 * If there is no defined share selected, we will abort the deletion without any message
447 */
448 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
449 unset($this->gotoShares[$_POST['gotoShare']]);
450 }
452 $smarty->assign("gotoShares",$this->printOutAssignedShares());
453 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
454 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
455 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
457 /* Create divSelectBox for ldap server selection
458 */
459 $SelectBoxLdapServer = new divSelectBox("LdapServer");
460 $SelectBoxLdapServer->SetHeight(100);
462 /* Add new ldap server to the list */
463 if($this->acl_is_writeable("gotoLdapServer") &&
464 !$this->gotoLdap_inherit &&
465 isset($_POST['add_ldap_server']) &&
466 isset($_POST['ldap_server_to_add'])){
467 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
468 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
469 if(!in_array($to_add,$this->gotoLdapServers)){
470 $this->gotoLdapServers[] = $to_add;
471 }
472 }
473 }
475 /* Move ldap servers up and down */
476 if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
477 foreach($_POST as $name => $value){
478 if(preg_match("/sort_ldap_up_/",$name)){
479 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
480 $from = $id;
481 $to = $id -1;
482 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
483 if($tmp){
484 $this->gotoLdapServers = $tmp;
485 }
486 break;
487 }
488 if(preg_match("/sort_ldap_down_/",$name)){
489 $id = preg_replace("/^sort_ldap_down_([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("/gotoLdapRemove_/",$name)){
499 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
500 $value = $this->gotoLdapServers[$id];
501 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
502 break;
503 }
504 }
505 }
507 /* Add Entries */
508 if($this->acl_is_readable("gotoLdapServer")){
510 foreach($this->gotoLdapServers as $key => $server){
512 /* Announce missing entries */
513 if(!in_array($server,$this->gotoLdapServerList)){
514 $server = $server." <font style='color:red'>(missing)</font>";
515 }
517 /* Convert old style entry */
518 if (!preg_match('%:ldaps?://%', $server)){
519 $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
521 /* Beautify new style entries */
522 } else {
523 $server= preg_replace("/^[^:]+:/", "", $server);
524 }
526 $SelectBoxLdapServer->AddEntry(
527 array(
528 array(
529 "string" => $server),
530 array("string" =>
531 "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'> ".
532 "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'> ".
533 "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
534 "attach" => "style='text-align:right;width:60px;border-right:0px;'")));
535 }
536 }
538 if($this->gotoLdap_inherit){
539 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
540 }else{
541 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
542 }
544 $list = array();
545 foreach($this->gotoLdapServerList as $key => $entry){
546 if(!in_array($entry,$this->gotoLdapServers)){
548 /* Convert old style entry */
549 if (!preg_match('%:ldap[s]*://%', $entry)){
550 $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
552 /* Beautify new style entries */
553 } else {
554 $entry= preg_replace("/^[^:]+:/", "", $entry);
555 }
557 $list[$key] = $entry;
558 }
559 }
560 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
561 $smarty->assign("gotoLdapServerList", $list);
562 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
563 $smarty->assign("JS", session::get('js'));
565 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
566 $smarty->assign("$val", $this->$val);
567 }
569 /* Values */
570 foreach(array("gotoBootKernel","gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
571 $smarty->assign($val, $this->$val);
572 }
574 $smarty->assign("fai_activated",$this->fai_activated);
576 /* Create FAI output */
577 $this->update_fai_cache();
578 $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
579 $smarty->assign("si_active",$this->si_active);
581 $div = new divSelectBox("WSFAIscriptClasses");
582 $div -> SetHeight("100");
584 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
586 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
587 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
588 $smarty->assign("FAIrelease" , $this->FAIrelease);
589 $smarty->assign("FAIclasses" , $this->selectable_classes());
591 /* Get classes for release from cache.
592 * Or build cache
593 */
594 if($this->FAIdebianMirror == "inherited"){
595 $release = $this->InheritedFAIrelease;
596 }else{
597 $release = $this->FAIrelease;
598 }
600 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
601 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
603 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
604 if($this->acl_is_writeable("FAIclass")){
605 $str_up = " <input type='image' src='images/lists/sort-up.png' name='sort_up_%s' value='%s'>";
606 $str_down = " <input type='image' src='images/lists/sort-down.png' name='sort_down_%s' value='%s'>";
607 $str_remove = " <input type='image' src='images/lists/trash.png' name='fai_remove_%s' value='%s'>";
608 }else{
609 $str_up=$str_down=$str_remove=$str_empty;
610 }
612 /* Get classes */
613 if($this->FAIdebianMirror == "inherited"){
614 $tmp = $this->InheritedFAIclass;
615 }else{
616 $tmp = $this->FAIclass;
617 }
619 /* Get invalid classes */
620 $invalid = $this->get_invalid_classes($tmp);
622 /* Draw every single entry */
623 $i = 1;
624 if($this->acl_is_readable("FAIclass")){
625 foreach($tmp as $class){
627 /* Mark invalid classes. (Not in selected release)
628 */
629 $marker = "";
630 if(in_array_ics($class,$invalid)){
631 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
632 }
634 /* Create up/down priority icons
635 * Skip this, if we have inherited the FAI classes.
636 */
637 if($this->FAIdebianMirror == "inherited"){
638 $str = "";
639 }else{
640 if($i==1){
641 $str = $str_empty.$str_down.$str_remove;
642 }elseif($i == count($this->FAIclass)){
643 $str = $str_up.$str_empty.$str_remove;
644 }else{
645 $str = $str_up.$str_down.$str_remove;
646 }
647 }
648 $i ++ ;
650 /* Get Description tag
651 * There may be several FAI objects with the same class name,
652 * use the description from FAIprofile, if possible.
653 */
654 $desc = "";
656 $objects = array(
657 "Pl" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png"),
658 "Pt" => array("IMG"=> "plugins/fai/images/fai_packages.png"),
659 "S" => array("IMG"=> "plugins/fai/images/fai_script.png"),
660 "V" => array("IMG"=> "plugins/fai/images/fai_variable.png"),
661 "H" => array("IMG"=> "plugins/fai/images/fai_hook.png"),
662 "P" => array("IMG"=> "plugins/fai/images/fai_profile.png"),
663 "T" => array("IMG"=> "plugins/fai/images/fai_template.png"));
665 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
666 $desc ="";
667 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
668 if(isset($types['Abbr'])){
669 $desc.= "<img src='".$objects[$types['Abbr']]['IMG']."' class='center'> ";
670 if($types['Type'] == "FAIprofile"){
671 break;
672 }
673 }
674 }
675 }
676 if(!empty($desc)){
677 $desc = " ".trim($desc)."";
678 }
680 $div->AddEntry(array(
681 array("string"=>$class.$marker),
682 array("string"=>$desc),
683 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:60px;border-right:none;'")
684 ));
685 }
686 }// END FAI output generation
687 }// END FAI output generation
688 $smarty->assign("FAIScriptlist",$div->DrawList());
690 /* Radio button group */
691 if (preg_match("/G/", $this->bootmode)) {
692 $smarty->assign("graphicalbootup", "checked");
693 } else {
694 $smarty->assign("graphicalbootup", "");
695 }
696 if (preg_match("/T/", $this->bootmode)) {
697 $smarty->assign("textbootup", "checked");
698 } else {
699 $smarty->assign("textbootup", "");
700 }
701 if (preg_match("/D/", $this->bootmode)) {
702 $smarty->assign("debugbootup", "checked");
703 } else {
704 $smarty->assign("debugbootup", "");
705 }
707 /* Show main page */
708 $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters);
709 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
710 }
713 function remove_from_parent()
714 {
715 $this->handle_post_events("remove");
716 new log("remove","workstation/".get_class($this),$this->dn);
717 }
720 /* Save data to object */
721 function save_object()
722 {
723 $old_mirror = $this->FAIdebianMirror;
724 plugin::save_object();
726 /* Update release */
727 if($old_mirror != $this->FAIdebianMirror){
728 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
729 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
730 }
731 }
733 if(isset($_POST['WorkstationStarttabPosted'])){
734 if(isset($_POST['gotoLdap_inherit'])){
735 $this->gotoLdap_inherit = TRUE;
736 }else{
737 $this->gotoLdap_inherit = FALSE;
738 }
740 /* Save group radio buttons */
741 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
742 $this->bootmode= $_POST["bootmode"];
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=[^,]+,".preg_quote(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 plugin::save();
807 unset( $this->attrs['FAIrelease'] );
808 $str = "";
810 /* Skip FAI attribute handling if not necessary */
811 if($this->fai_activated && !$this->si_fai_action_failed){
812 if($this->FAIdebianMirror == "inherited"){
813 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
814 }else{
815 foreach($this->FAIclass as $class){
816 $str .= $class." ";
817 }
818 $str = trim($str);
819 if(empty($this->attrs['FAIclass'])){
820 $this->attrs['FAIclass'] = array();
821 }else{
822 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
823 }
824 }
825 }
827 /* Add missing arrays */
828 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
829 if (isset ($this->$val) && count ($this->$val) != 0){
831 $this->attrs["$val"]= array_unique($this->$val);
832 }
833 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
834 }
836 /* Prepare list of ldap servers */
837 $this->attrs['gotoLdapServer'] = array();
838 if(!$this->gotoLdap_inherit){
839 $i = 0;
840 foreach($this->gotoLdapServers as $server){
841 $i ++;
842 $this->attrs['gotoLdapServer'][] = $i.":".$server;
843 }
844 }
846 if ($this->attrs['gotoBootKernel'] == "default-inherited"){
847 $this->attrs['gotoBootKernel']= array();
848 }
850 /* if mirror == none stop saving this attribute */
851 if($this->FAIdebianMirror == "none"){
852 $this->FAIdebianMirror = "";
853 }
855 /* Get FAIstate from object, the generic tab could have changed it during execute */
856 $ldap= $this->config->get_ldap_link();
857 $ldap->cd($this->dn);
860 /* Skip FAI attribute handling if not necessary */
861 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
862 $ldap->cat($this->dn,array("FAIstate"));
863 $checkFAIstate = $ldap->fetch();
865 /* Remove FAI objects if no FAI class is selected */
866 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
867 $this->attrs['FAIclass'] = array();
868 $this->attrs['FAIdebianMirror'] = array();
869 }
870 }else{
872 /* Don't touch FAI objects if something went wrong with the si daemon.
873 */
874 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
875 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
876 }
878 /* prepare share settings */
879 $tmp = array();
880 foreach($this->gotoShares as $name => $settings){
881 $tmp2= explode("|",$name);
882 $name = $tmp2[0];
883 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
884 }
885 $this->attrs['gotoShare']=$tmp;
886 $this->cleanup();
887 $ldap->modify ($this->attrs);
888 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
890 if (!$ldap->success()){
891 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
892 }
893 $this->handle_post_events("modify");
895 /* Check if LDAP server has changed */
896 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
897 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
898 $o_queue = new gosaSupportDaemon();
899 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
900 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
901 $macs = array();
903 /* Get list of macAddresses
904 */
905 if(isset($this->parent->by_object['ogroup'])){
907 /* If we are an object group, add all member macs
908 */
909 $p = $this->parent->by_object['ogroup'];
910 foreach($p->memberList as $dn => $obj){
911 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
912 $macs[] = $p->objcache[$dn]['macAddress'];
913 }
914 }
915 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
917 /* We are a workstation. Add current mac.
918 */
919 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
920 if(!empty($mac)){
921 $macs[] = $mac;
922 }
923 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
925 /* We are a server. Add current mac.
926 */
927 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
928 if(!empty($mac)){
929 $macs[] = $mac;
930 }
931 }
933 /* Trigger event for all member objects
934 */
935 foreach($macs as $mac){
936 $tmp = new $evt['CLASS_NAME']($this->config);
937 $tmp->set_type(TRIGGERED_EVENT);
938 $tmp->add_targets(array($mac));
939 if(!$o_queue->append($tmp)){
940 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
941 }
942 }
943 }
944 }
945 }
948 /* Add value to array, check if unique */
949 function add_list (&$array, $value)
950 {
951 if ($value != ""){
952 $array[]= $value;
953 sort($array);
954 array_unique ($array);
955 }
956 }
959 /* Delete value to array, check if unique */
960 function del_list (&$array, $list)
961 {
962 $tmp= array();
963 foreach ($array as $mod){
964 if (!in_array($mod, $list)){
965 $tmp[]= $mod;
966 }
967 }
968 $array= $tmp;
969 }
971 /* Generate ListBox frindly output for the defined shares
972 * Possibly Add or remove an attribute here,
973 */
974 function printOutAssignedShares()
975 {
976 $a_return = array();
977 if(is_array($this->gotoShares)){
978 foreach($this->gotoShares as $share){
979 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
980 }
981 }
982 return($a_return);
983 }
987 function PrepareForCopyPaste($source)
988 {
989 plugin::PrepareForCopyPaste($source);
990 $source_o = new workstartup ($this->config, $source['dn']);
991 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
992 "gotoKernelParameters","gotoShares","gotoLdapServers","gotoLdapServerList",
993 "gotoLdap_inherit") as $attr){
994 $this->$attr = $source_o->$attr;
995 }
996 }
999 function array_switch_item($ar,$from,$to)
1000 {
1001 if(!is_array($ar)){
1002 return(false);
1003 }
1004 if(!isset($ar[$from])){
1005 return(false);
1006 }
1007 if(!isset($ar[$to])){
1008 return(false);
1009 }
1011 $tmp = $ar[$from];
1012 $ar[$from] = $ar[$to];
1013 $ar[$to] = $tmp;
1014 return($ar);
1015 }
1018 /* Return plugin informations for acl handling */
1019 static function plInfo()
1020 {
1021 return (array(
1022 "plShortName" => _("Startup"),
1023 "plDescription" => _("System startup"),
1024 "plSelfModify" => FALSE,
1025 "plDepends" => array(),
1026 "plPriority" => 9,
1027 "plSection" => array("administration"),
1028 "plCategory" => array("workstation","server","ogroups"),
1030 "plProvidedAcls"=> array(
1031 "gotoLdapServer" => _("Ldap server"),
1032 "gotoBootKernel" => _("Boot kernel"),
1033 "gotoKernelParameters" => _("Kernel parameter"),
1035 "gotoModules" => _("Kernel modules"),
1036 "gotoShare" => _("Shares"),
1038 "FAIclass" => _("FAI classes"),
1039 "FAIdebianMirror" => _("Debian mirror"),
1040 "FAIrelease" => _("Debian release"),
1042 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1043 ));
1044 }
1047 /* Updates release dns
1048 * and reads all classes for the current release,
1049 * if not already done ($this->cache).
1050 */
1051 function update_fai_cache($first_call = FALSE)
1052 {
1053 $force = FALSE;
1054 if(!$this->si_active) return;
1055 $start = microtime(TRUE);
1057 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1059 $this->si_fai_action_failed = FALSE;
1061 /* Get the list of available servers and their releases.
1062 */
1063 if($force || !isset($this->cache['SERVERS'])){
1065 $o_queue = new gosaSupportDaemon();
1066 $tmp = $o_queue->FAI_get_server();
1067 if($o_queue->is_error()){
1068 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1069 $this->si_fai_action_failed = TRUE;
1070 $this->cache = array();
1071 return;
1072 }else{
1074 foreach($tmp as $entry){
1075 $rel = $entry['FAI_RELEASE'];
1076 $this->cache['SERVERS']['auto'][$rel] = $rel;
1077 $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1078 uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1079 uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1080 }
1081 }
1082 }
1084 /* Ensure that our selection is valid, else we get several PHP warnings
1085 if there is no FAI configuration at all.
1086 */
1087 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1088 $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1089 }
1091 /* Build up arrays, without checks */
1092 if(!$first_call){
1094 /* Check if the selected mirror is available */
1095 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1096 $this->FAIdebianMirror = "auto";
1097 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1098 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1099 }
1101 /* Check if the selected release is available */
1102 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1104 if($this->FAIrelease != ""){
1105 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1106 }
1107 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1108 }
1109 }
1111 /* Get classes for release from cache.
1112 * Or build cache
1113 */
1114 if($this->FAIdebianMirror == "inherited"){
1115 $release = $this->InheritedFAIrelease;
1116 }else{
1117 $release = $this->FAIrelease;
1118 }
1120 if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1122 /* Get the list of available servers and their releases.
1123 */
1124 $o_queue = new gosaSupportDaemon();
1125 $tmp = $o_queue->FAI_get_classes($release);
1127 $this->cache['CLASSES'][$release] = array();
1128 if($o_queue->is_error()){
1129 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1130 $this->si_fai_action_failed = TRUE;
1131 $this->cache=array();
1132 return;
1133 }else{
1134 foreach($tmp as $entry){
1135 $class = $entry['CLASS'];
1136 $this->cache['CLASSES'][$release][$class][] = $this->analyse_fai_object($entry);
1137 }
1138 }
1140 /* Add object caught from external hook
1141 */
1142 $lines= $this->GetHookElements();
1143 foreach ($lines as $hline){
1144 $entries= explode(";", $hline);
1145 $server = $entries['0'];
1146 $url = $entries['1'];
1147 if (!empty($url)){
1149 /* Split releases */
1150 if (isset($entries[2])){
1151 $releases= explode(",", $entries[2]);
1153 foreach ($releases as $release_data){
1154 $release_c = preg_replace('/:.*$/', '', $release_data);
1155 $sections_c = explode(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1156 $classes_c = explode('|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1158 if($release_c == $release){
1159 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1160 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1161 foreach ($classes_c as $class){
1162 if ($class != ""){
1163 $this->cache['CLASSES'][$release_c][$class]= array();
1164 }
1165 }
1166 }
1167 }
1168 }
1169 }
1170 }
1171 uksort($this->cache['SERVERS'], 'strnatcasecmp');
1173 /* Only add inherit option, if we are part in an object group
1174 */
1175 if($this->member_of_ogroup){
1176 $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1177 }
1178 }
1180 /* Get list of available kernel for this release
1181 */
1182 if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1184 if($force || !isset($this->cache['KERNELS'][$release])){
1185 $o_queue = new gosaSupportDaemon();
1186 $tmp = $o_queue->FAI_get_kernels($release);
1187 $this->cache['KERNELS'][$release] = array();
1188 foreach($this->gotoBootKernels as $name => $default){
1189 $this->cache['KERNELS'][$release][$name] = $default;
1190 }
1191 foreach($tmp as $kernel){
1192 if(empty($kernel)) continue;
1193 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1194 }
1195 ksort($this->cache['KERNELS'][$release]);
1196 }
1197 }
1200 /* This function return an array containing all
1201 * invalid classes for the selected server/release
1202 */
1203 function get_invalid_classes($classes)
1204 {
1205 $this->update_fai_cache();
1206 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1207 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1208 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1209 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1210 }else{
1211 $release_classes = array();
1212 }
1215 /* Detect all classes that are not valid
1216 * for the selected release
1217 */
1218 $NA = array();
1219 foreach($classes as $class){
1220 if(!isset($release_classes[$class])){
1221 $NA[] = $class;
1222 }
1223 }
1224 return($NA);
1225 }
1228 /* Get all selectable classes for the ui select box
1229 */
1230 function selectable_classes()
1231 {
1232 $this->update_fai_cache();
1234 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1235 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1236 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1237 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1238 }else{
1239 $classes = array();
1240 }
1242 $Abbr ="";
1243 $ret= array();
1244 foreach($classes as $class_name => $class_types){
1245 if(!in_array($class_name,$this->FAIclass)){
1246 $Abbr = "";
1247 foreach($class_types as $type){
1248 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1249 $Abbr .= $type['Abbr']." ";
1250 }
1251 }
1252 $ret[$class_name] = trim($Abbr);
1253 }
1254 }
1255 uksort($ret, 'strnatcasecmp');
1256 return($ret);
1257 }
1260 /* Analyse FAI object and return an array with usefull informations like
1261 * FAIobject type.
1262 */
1263 function analyse_fai_object($attr)
1264 {
1265 $tmp = array();
1266 switch($attr['TYPE']){
1268 case 'FAIpackageList':
1269 $tmp["Type"]= 'FAIpackageList';
1270 $tmp["Abbr"]= 'Pl';
1271 break;
1272 case 'FAItemplate':
1273 $tmp["Type"]= 'FAItemplate';
1274 $tmp["Abbr"]= 'T';
1275 break;
1276 case 'FAIvariable':
1277 $tmp["Type"]= 'FAIvariable';
1278 $tmp["Abbr"]= 'V';
1279 break;
1280 case 'FAIscript':
1281 $tmp["Type"]= 'FAIscript';
1282 $tmp["Abbr"]= 'S';
1283 break;
1284 case 'FAIhook':
1285 $tmp["Type"]= 'FAIhook';
1286 $tmp["Abbr"]= 'H';
1287 break;
1288 case 'FAIpartitionTable':
1289 $tmp["Type"]= 'FAIpartitionTable';
1290 $tmp["Abbr"]= 'Pt';
1291 break;
1292 case 'FAIprofile':
1293 $tmp["Type"]= 'FAIprofile';
1294 $tmp["Abbr"]= 'P';
1295 break;
1296 default: trigger_error("Unknown FAI object type!");;
1297 }
1298 return($tmp);
1299 }
1302 /* Return repository hook output, if possible.
1303 */
1304 function GetHookElements()
1305 {
1306 $ret = array();
1307 $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1308 if(!empty($cmd)){
1309 $res = shell_exec($cmd);
1310 $res2 = trim($res);
1311 if((!$res)){
1312 msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1313 }elseif(empty($res2)){
1314 msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG);
1315 }else{
1316 $tmp = preg_split("/\n/",$res);
1317 foreach($tmp as $line){
1318 if(empty($line)) continue;
1319 $ret[]= $line;
1320 }
1321 }
1322 }
1323 return($ret);
1324 }
1327 /* This function creates the release name out of a dn
1328 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1329 */
1330 function dn_to_release_name($dn)
1331 {
1332 $relevant = preg_replace("/,".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$dn);
1333 $parts = array_reverse(explode(",",$relevant));
1334 $str ="";
1335 foreach($parts as $part){
1336 $str .= preg_replace("/^ou=/","",$part)."/";
1337 }
1338 return(preg_replace("/\/$/","",$str));
1339 }
1340 }
1342 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1343 ?>