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= image("images/small-error.png")."<b>".msgPool::noValidExtension(_("workstation"))."</b>";
285 return ($display);
286 }
288 /* Add module */
289 if (isset ($_POST['add_module'])){
290 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
291 $this->add_list ($this->gotoModules, $_POST['module']);
292 }
293 }
295 /* Delete module */
296 if (isset ($_POST['delete_module'])){
297 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
298 $this->del_list ($this->gotoModules, $_POST['modules_list']);
299 }
300 }
302 /* FAI class management */
303 if($this->fai_activated){
304 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
305 $found = 0 ;
307 /* If this new class/profile will attach a second partition table
308 * to our list of classes, abort and show a message.
309 */
310 foreach($this->FAIclass as $name){
311 if(isset($this->FAIclassInfo[$name])){
312 foreach($this->FAIclassInfo[$name] as $atr){
313 if(isset($atr['obj'])){
314 if($atr['obj'] == "FAIpartitionTable"){
315 $found ++ ;
316 }
317 }
318 }
319 }
320 }
322 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
323 msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
324 }else{
325 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
326 }
327 }
329 $sort = false;
331 /* Move one used class class one position up or down */
332 if($this->acl_is_writeable("FAIclass")){
333 foreach($_POST as $name => $val){
335 $sort_type = false;
336 if((preg_match("/sort_up/",$name))&&(!$sort)){
337 $sort_type = "sort_up_";
338 }
339 if((preg_match("/sort_down/",$name))&&(!$sort)){
340 $sort_type = "sort_down_";
341 }
343 if(($sort_type)&&(!$sort)){
344 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
345 $sort = true;
347 $last = -1;
348 $change_down = -1;
350 /* Create array with numeric index */
351 $tmp = array();
352 foreach($this->FAIclass as $class){
353 $tmp [] = $class;
354 }
356 /* Walk trough array */
357 foreach($tmp as $key => $faiName){
358 if($faiName == $value){
359 if($sort_type == "sort_up_"){
360 if($last != -1){
361 $change_down= $last;
362 }
363 }else{
364 if(isset($tmp[$key+1])){
365 $change_down = $key;
366 }
367 }
368 }
369 $last = $key;
370 }
372 $tmp2 = array();
373 $skip = false;
375 foreach($tmp as $ky => $vl){
377 if($ky == $change_down){
378 $skip = $vl;
379 }else{
380 $tmp2[$vl] = $vl;
381 }
382 if(($skip != false)&&($ky != $change_down)){
383 $tmp2[$skip] = $skip;
384 $skip =false;
385 }
386 }
387 $this->FAIclass = $tmp2;
388 }
390 if(preg_match("/fai_remove/i",$name)){
391 $value = base64_decode(preg_replace("/fai_remove_/i","",$name));
392 unset($this->FAIclass[$value]);
393 }
394 }
395 }
397 /* Delete selected class from our list */
398 if($this->acl_is_writeable("FAIclass")){
399 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
400 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
401 unset($this->FAIclass[$_POST['FAIclassSel']]);
402 }
403 }
404 }
405 }// END fai handling
407 /* Show main page */
408 $smarty= get_smarty();
410 /* Assign ACLs to smarty */
411 $tmp = $this->plInfo();
412 foreach($tmp['plProvidedAcls'] as $name => $translation){
413 $smarty->assign($name."ACL",$this->getacl($name));
414 }
416 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
418 /* In this section server shares will be defined
419 * A user can select one of the given shares and a mount point
420 * and attach this combination to his setup.
421 */
422 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
423 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
425 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
426 * This entry will be, a combination of mountPoint and sharedefinitions
427 */
428 if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
429 /* We assign a share to this user, if we don't know where to mount the share */
430 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
431 msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
432 }else{
434 if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
435 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
436 $s_mount = $_POST['gotoShareMountPoint'];
437 /* Preparing the new assignment */
438 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
439 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
440 }
441 }
442 }
444 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
445 * If there is no defined share selected, we will abort the deletion without any message
446 */
447 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
448 unset($this->gotoShares[$_POST['gotoShare']]);
449 }
451 $smarty->assign("gotoShares",$this->printOutAssignedShares());
452 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
453 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
454 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
456 /* Create divSelectBox for ldap server selection
457 */
458 $SelectBoxLdapServer = new divSelectBox("LdapServer");
459 $SelectBoxLdapServer->SetHeight(100);
461 /* Add new ldap server to the list */
462 if($this->acl_is_writeable("gotoLdapServer") &&
463 !$this->gotoLdap_inherit &&
464 isset($_POST['add_ldap_server']) &&
465 isset($_POST['ldap_server_to_add'])){
466 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
467 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
468 if(!in_array($to_add,$this->gotoLdapServers)){
469 $this->gotoLdapServers[] = $to_add;
470 }
471 }
472 }
474 /* Move ldap servers up and down */
475 if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
476 foreach($_POST as $name => $value){
477 if(preg_match("/sort_ldap_up_/",$name)){
478 $id = preg_replace("/^sort_ldap_up_([0-9]*)$/","\\1",$name);
479 $from = $id;
480 $to = $id -1;
481 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
482 if($tmp){
483 $this->gotoLdapServers = $tmp;
484 }
485 break;
486 }
487 if(preg_match("/sort_ldap_down_/",$name)){
488 $id = preg_replace("/^sort_ldap_down_([0-9]*)$/","\\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("/gotoLdapRemove_/",$name)){
498 $id = preg_replace("/^gotoLdapRemove_([0-9]*)$/","\\1",$name);
499 $value = $this->gotoLdapServers[$id];
500 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
501 break;
502 }
503 }
504 }
506 /* Add Entries */
507 if($this->acl_is_readable("gotoLdapServer")){
509 foreach($this->gotoLdapServers as $key => $server){
511 /* Announce missing entries */
512 if(!in_array($server,$this->gotoLdapServerList)){
513 $server = $server." <font style='color:red'>(missing)</font>";
514 }
516 /* Convert old style entry */
517 if (!preg_match('%:ldaps?://%', $server)){
518 $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
520 /* Beautify new style entries */
521 } else {
522 $server= preg_replace("/^[^:]+:/", "", $server);
523 }
525 $SelectBoxLdapServer->AddEntry(
526 array(
527 array(
528 "string" => $server),
529 array("string" =>
530 image('images/lists/sort-up.png',"sort_ldap_up_".$key,'',"top").
531 image('images/lists/sort-down.png',"sort_ldap_down_".$key,'',"bottom").
532 image('images/lists/trash.png',"gotoLdapRemove_".$key),
533 "attach" => "style='text-align:right;width:60px;border-right:0px;'")));
534 }
535 }
537 if($this->gotoLdap_inherit){
538 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
539 }else{
540 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
541 }
543 $list = array();
544 foreach($this->gotoLdapServerList as $key => $entry){
545 if(!in_array($entry,$this->gotoLdapServers)){
547 /* Convert old style entry */
548 if (!preg_match('%:ldap[s]*://%', $entry)){
549 $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
551 /* Beautify new style entries */
552 } else {
553 $entry= preg_replace("/^[^:]+:/", "", $entry);
554 }
556 $list[$key] = $entry;
557 }
558 }
559 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
560 $smarty->assign("gotoLdapServerList", $list);
561 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
562 $smarty->assign("JS", session::get('js'));
564 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
565 $smarty->assign("$val", $this->$val);
566 }
568 /* Values */
569 foreach(array("gotoBootKernel","gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
570 $smarty->assign($val, $this->$val);
571 }
573 $smarty->assign("fai_activated",$this->fai_activated);
575 /* Create FAI output */
576 $this->update_fai_cache();
577 $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
578 $smarty->assign("si_active",$this->si_active);
580 $div = new divSelectBox("WSFAIscriptClasses");
581 $div -> SetHeight("100");
583 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
585 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
586 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
587 $smarty->assign("FAIrelease" , $this->FAIrelease);
588 $smarty->assign("FAIclasses" , $this->selectable_classes());
590 /* Get classes for release from cache.
591 * Or build cache
592 */
593 if($this->FAIdebianMirror == "inherited"){
594 $release = $this->InheritedFAIrelease;
595 }else{
596 $release = $this->FAIrelease;
597 }
599 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
600 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
602 $str_empty = image('images/empty.png');
603 if($this->acl_is_writeable("FAIclass")){
604 $str_up = image('images/lists/sort-up.png','sort_up_%s');
605 $str_down = image('images/lists/sort-down.png','sort_down_%s');
606 $str_remove = image('images/lists/trash.png','fai_remove_%s');
607 }else{
608 $str_up=$str_down=$str_remove=$str_empty;
609 }
611 /* Get classes */
612 if($this->FAIdebianMirror == "inherited"){
613 $tmp = $this->InheritedFAIclass;
614 }else{
615 $tmp = $this->FAIclass;
616 }
618 /* Get invalid classes */
619 $invalid = $this->get_invalid_classes($tmp);
621 /* Draw every single entry */
622 $i = 1;
623 if($this->acl_is_readable("FAIclass")){
624 foreach($tmp as $class){
626 /* Mark invalid classes. (Not in selected release)
627 */
628 $marker = "";
629 if(in_array_ics($class,$invalid)){
630 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
631 }
633 /* Create up/down priority icons
634 * Skip this, if we have inherited the FAI classes.
635 */
636 if($this->FAIdebianMirror == "inherited"){
637 $str = "";
638 }else{
639 if($i==1){
640 $str = $str_empty.$str_down.$str_remove;
641 }elseif($i == count($this->FAIclass)){
642 $str = $str_up.$str_empty.$str_remove;
643 }else{
644 $str = $str_up.$str_down.$str_remove;
645 }
646 }
647 $i ++ ;
649 /* Get Description tag
650 * There may be several FAI objects with the same class name,
651 * use the description from FAIprofile, if possible.
652 */
653 $desc = "";
655 $objects = array(
656 "Pl" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png"),
657 "Pt" => array("IMG"=> "plugins/fai/images/fai_packages.png"),
658 "S" => array("IMG"=> "plugins/fai/images/fai_script.png"),
659 "V" => array("IMG"=> "plugins/fai/images/fai_variable.png"),
660 "H" => array("IMG"=> "plugins/fai/images/fai_hook.png"),
661 "P" => array("IMG"=> "plugins/fai/images/fai_profile.png"),
662 "T" => array("IMG"=> "plugins/fai/images/fai_template.png"));
664 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
665 $desc ="";
666 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
667 if(isset($types['Abbr'])){
668 $desc.= image($objects[$types['Abbr']]['IMG']);
669 if($types['Type'] == "FAIprofile"){
670 break;
671 }
672 }
673 }
674 }
675 if(!empty($desc)){
676 $desc = " ".trim($desc)."";
677 }
679 $div->AddEntry(array(
680 array("string"=>$class.$marker),
681 array("string"=>$desc),
682 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:60px;border-right:none;'")
683 ));
684 }
685 }// END FAI output generation
686 }// END FAI output generation
687 $smarty->assign("FAIScriptlist",$div->DrawList());
689 /* Radio button group */
690 if (preg_match("/G/", $this->bootmode)) {
691 $smarty->assign("graphicalbootup", "checked");
692 } else {
693 $smarty->assign("graphicalbootup", "");
694 }
695 if (preg_match("/T/", $this->bootmode)) {
696 $smarty->assign("textbootup", "checked");
697 } else {
698 $smarty->assign("textbootup", "");
699 }
700 if (preg_match("/D/", $this->bootmode)) {
701 $smarty->assign("debugbootup", "checked");
702 } else {
703 $smarty->assign("debugbootup", "");
704 }
706 /* Show main page */
707 $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters);
708 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
709 }
712 function remove_from_parent()
713 {
714 $this->handle_post_events("remove");
715 new log("remove","workstation/".get_class($this),$this->dn);
716 }
719 /* Save data to object */
720 function save_object()
721 {
722 $old_mirror = $this->FAIdebianMirror;
723 plugin::save_object();
725 /* Update release */
726 if($old_mirror != $this->FAIdebianMirror){
727 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
728 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
729 }
730 }
732 if(isset($_POST['WorkstationStarttabPosted'])){
733 if(isset($_POST['gotoLdap_inherit'])){
734 $this->gotoLdap_inherit = TRUE;
735 }else{
736 $this->gotoLdap_inherit = FALSE;
737 }
739 /* Save group radio buttons */
740 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
741 $this->bootmode= $_POST["bootmode"];
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=[^,]+,".preg_quote(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 plugin::save();
806 unset( $this->attrs['FAIrelease'] );
807 $str = "";
809 /* Skip FAI attribute handling if not necessary */
810 if($this->fai_activated && !$this->si_fai_action_failed){
811 if($this->FAIdebianMirror == "inherited"){
812 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
813 }else{
814 foreach($this->FAIclass as $class){
815 $str .= $class." ";
816 }
817 $str = trim($str);
818 if(empty($this->attrs['FAIclass'])){
819 $this->attrs['FAIclass'] = array();
820 }else{
821 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
822 }
823 }
824 }
826 /* Add missing arrays */
827 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
828 if (isset ($this->$val) && count ($this->$val) != 0){
830 $this->attrs["$val"]= array_unique($this->$val);
831 }
832 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
833 }
835 /* Prepare list of ldap servers */
836 $this->attrs['gotoLdapServer'] = array();
837 if(!$this->gotoLdap_inherit){
838 $i = 0;
839 foreach($this->gotoLdapServers as $server){
840 $i ++;
841 $this->attrs['gotoLdapServer'][] = $i.":".$server;
842 }
843 }
845 if ($this->attrs['gotoBootKernel'] == "default-inherited"){
846 $this->attrs['gotoBootKernel']= array();
847 }
849 /* if mirror == none stop saving this attribute */
850 if($this->FAIdebianMirror == "none"){
851 $this->FAIdebianMirror = "";
852 }
854 /* Get FAIstate from object, the generic tab could have changed it during execute */
855 $ldap= $this->config->get_ldap_link();
856 $ldap->cd($this->dn);
859 /* Skip FAI attribute handling if not necessary */
860 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
861 $ldap->cat($this->dn,array("FAIstate"));
862 $checkFAIstate = $ldap->fetch();
864 /* Remove FAI objects if no FAI class is selected */
865 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
866 $this->attrs['FAIclass'] = array();
867 $this->attrs['FAIdebianMirror'] = array();
868 }
869 }else{
871 /* Don't touch FAI objects if something went wrong with the si daemon.
872 */
873 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
874 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
875 }
877 /* prepare share settings */
878 $tmp = array();
879 foreach($this->gotoShares as $name => $settings){
880 $tmp2= explode("|",$name);
881 $name = $tmp2[0];
882 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
883 }
884 $this->attrs['gotoShare']=$tmp;
885 $this->cleanup();
886 $ldap->modify ($this->attrs);
887 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
889 if (!$ldap->success()){
890 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
891 }
892 $this->handle_post_events("modify");
894 /* Check if LDAP server has changed */
895 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
896 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
897 $o_queue = new gosaSupportDaemon();
898 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
899 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
900 $macs = array();
902 /* Get list of macAddresses
903 */
904 if(isset($this->parent->by_object['ogroup'])){
906 /* If we are an object group, add all member macs
907 */
908 $p = $this->parent->by_object['ogroup'];
909 foreach($p->memberList as $dn => $obj){
910 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
911 $macs[] = $p->objcache[$dn]['macAddress'];
912 }
913 }
914 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
916 /* We are a workstation. Add current mac.
917 */
918 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
919 if(!empty($mac)){
920 $macs[] = $mac;
921 }
922 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
924 /* We are a server. Add current mac.
925 */
926 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
927 if(!empty($mac)){
928 $macs[] = $mac;
929 }
930 }
932 /* Trigger event for all member objects
933 */
934 foreach($macs as $mac){
935 $tmp = new $evt['CLASS_NAME']($this->config);
936 $tmp->set_type(TRIGGERED_EVENT);
937 $tmp->add_targets(array($mac));
938 if(!$o_queue->append($tmp)){
939 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
940 }
941 }
942 }
943 }
944 }
947 /* Add value to array, check if unique */
948 function add_list (&$array, $value)
949 {
950 if ($value != ""){
951 $array[]= $value;
952 sort($array);
953 array_unique ($array);
954 }
955 }
958 /* Delete value to array, check if unique */
959 function del_list (&$array, $list)
960 {
961 $tmp= array();
962 foreach ($array as $mod){
963 if (!in_array($mod, $list)){
964 $tmp[]= $mod;
965 }
966 }
967 $array= $tmp;
968 }
970 /* Generate ListBox frindly output for the defined shares
971 * Possibly Add or remove an attribute here,
972 */
973 function printOutAssignedShares()
974 {
975 $a_return = array();
976 if(is_array($this->gotoShares)){
977 foreach($this->gotoShares as $share){
978 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
979 }
980 }
981 return($a_return);
982 }
986 function PrepareForCopyPaste($source)
987 {
988 plugin::PrepareForCopyPaste($source);
989 $source_o = new workstartup ($this->config, $source['dn']);
990 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
991 "gotoKernelParameters","gotoShares","gotoLdapServers","gotoLdapServerList",
992 "gotoLdap_inherit") as $attr){
993 $this->$attr = $source_o->$attr;
994 }
995 }
998 function array_switch_item($ar,$from,$to)
999 {
1000 if(!is_array($ar)){
1001 return(false);
1002 }
1003 if(!isset($ar[$from])){
1004 return(false);
1005 }
1006 if(!isset($ar[$to])){
1007 return(false);
1008 }
1010 $tmp = $ar[$from];
1011 $ar[$from] = $ar[$to];
1012 $ar[$to] = $tmp;
1013 return($ar);
1014 }
1017 /* Return plugin informations for acl handling */
1018 static function plInfo()
1019 {
1020 return (array(
1021 "plShortName" => _("Startup"),
1022 "plDescription" => _("System startup"),
1023 "plSelfModify" => FALSE,
1024 "plDepends" => array(),
1025 "plPriority" => 9,
1026 "plSection" => array("administration"),
1027 "plCategory" => array("workstation","server","ogroups"),
1029 "plProvidedAcls"=> array(
1030 "gotoLdapServer" => _("Ldap server"),
1031 "gotoBootKernel" => _("Boot kernel"),
1032 "gotoKernelParameters" => _("Kernel parameter"),
1034 "gotoModules" => _("Kernel modules"),
1035 "gotoShare" => _("Shares"),
1037 "FAIclass" => _("FAI classes"),
1038 "FAIdebianMirror" => _("Debian mirror"),
1039 "FAIrelease" => _("Debian release"),
1041 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1042 ));
1043 }
1046 /* Updates release dns
1047 * and reads all classes for the current release,
1048 * if not already done ($this->cache).
1049 */
1050 function update_fai_cache($first_call = FALSE)
1051 {
1052 $force = FALSE;
1053 if(!$this->si_active) return;
1054 $start = microtime(TRUE);
1056 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1058 $this->si_fai_action_failed = FALSE;
1060 /* Get the list of available servers and their releases.
1061 */
1062 if($force || !isset($this->cache['SERVERS'])){
1064 $o_queue = new gosaSupportDaemon();
1065 $tmp = $o_queue->FAI_get_server();
1066 if($o_queue->is_error()){
1067 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1068 $this->si_fai_action_failed = TRUE;
1069 $this->cache = array();
1070 return;
1071 }else{
1073 foreach($tmp as $entry){
1074 $rel = $entry['FAI_RELEASE'];
1075 $this->cache['SERVERS']['auto'][$rel] = $rel;
1076 $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1077 uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1078 uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1079 }
1080 }
1081 }
1083 /* Ensure that our selection is valid, else we get several PHP warnings
1084 if there is no FAI configuration at all.
1085 */
1086 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1087 $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1088 }
1090 /* Build up arrays, without checks */
1091 if(!$first_call){
1093 /* Check if the selected mirror is available */
1094 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1095 $this->FAIdebianMirror = "auto";
1096 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1097 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1098 }
1100 /* Check if the selected release is available */
1101 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1103 if($this->FAIrelease != ""){
1104 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1105 }
1106 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1107 }
1108 }
1110 /* Get classes for release from cache.
1111 * Or build cache
1112 */
1113 if($this->FAIdebianMirror == "inherited"){
1114 $release = $this->InheritedFAIrelease;
1115 }else{
1116 $release = $this->FAIrelease;
1117 }
1119 if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1121 /* Get the list of available servers and their releases.
1122 */
1123 $o_queue = new gosaSupportDaemon();
1124 $tmp = $o_queue->FAI_get_classes($release);
1126 $this->cache['CLASSES'][$release] = array();
1127 if($o_queue->is_error()){
1128 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1129 $this->si_fai_action_failed = TRUE;
1130 $this->cache=array();
1131 return;
1132 }else{
1133 foreach($tmp as $entry){
1134 $class = $entry['CLASS'];
1135 $this->cache['CLASSES'][$release][$class][] = $this->analyse_fai_object($entry);
1136 }
1137 }
1139 /* Add object caught from external hook
1140 */
1141 $lines= $this->GetHookElements();
1142 foreach ($lines as $hline){
1143 $entries= explode(";", $hline);
1144 $server = $entries['0'];
1145 $url = $entries['1'];
1146 if (!empty($url)){
1148 /* Split releases */
1149 if (isset($entries[2])){
1150 $releases= explode(",", $entries[2]);
1152 foreach ($releases as $release_data){
1153 $release_c = preg_replace('/:.*$/', '', $release_data);
1154 $sections_c = explode(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1155 $classes_c = explode('|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1157 if($release_c == $release){
1158 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1159 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1160 foreach ($classes_c as $class){
1161 if ($class != ""){
1162 $this->cache['CLASSES'][$release_c][$class]= array();
1163 }
1164 }
1165 }
1166 }
1167 }
1168 }
1169 }
1170 uksort($this->cache['SERVERS'], 'strnatcasecmp');
1172 /* Only add inherit option, if we are part in an object group
1173 */
1174 if($this->member_of_ogroup){
1175 $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1176 }
1177 }
1179 /* Get list of available kernel for this release
1180 */
1181 if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1183 if($force || !isset($this->cache['KERNELS'][$release])){
1184 $o_queue = new gosaSupportDaemon();
1185 $tmp = $o_queue->FAI_get_kernels($release);
1186 $this->cache['KERNELS'][$release] = array();
1187 foreach($this->gotoBootKernels as $name => $default){
1188 $this->cache['KERNELS'][$release][$name] = $default;
1189 }
1190 foreach($tmp as $kernel){
1191 if(empty($kernel)) continue;
1192 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1193 }
1194 ksort($this->cache['KERNELS'][$release]);
1195 }
1196 }
1199 /* This function return an array containing all
1200 * invalid classes for the selected server/release
1201 */
1202 function get_invalid_classes($classes)
1203 {
1204 $this->update_fai_cache();
1205 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1206 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1207 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1208 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1209 }else{
1210 $release_classes = array();
1211 }
1214 /* Detect all classes that are not valid
1215 * for the selected release
1216 */
1217 $NA = array();
1218 foreach($classes as $class){
1219 if(!isset($release_classes[$class])){
1220 $NA[] = $class;
1221 }
1222 }
1223 return($NA);
1224 }
1227 /* Get all selectable classes for the ui select box
1228 */
1229 function selectable_classes()
1230 {
1231 $this->update_fai_cache();
1233 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1234 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1235 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1236 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1237 }else{
1238 $classes = array();
1239 }
1241 $Abbr ="";
1242 $ret= array();
1243 foreach($classes as $class_name => $class_types){
1244 if(!in_array($class_name,$this->FAIclass)){
1245 $Abbr = "";
1246 foreach($class_types as $type){
1247 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1248 $Abbr .= $type['Abbr']." ";
1249 }
1250 }
1251 $ret[$class_name] = trim($Abbr);
1252 }
1253 }
1254 uksort($ret, 'strnatcasecmp');
1255 return($ret);
1256 }
1259 /* Analyse FAI object and return an array with usefull informations like
1260 * FAIobject type.
1261 */
1262 function analyse_fai_object($attr)
1263 {
1264 $tmp = array();
1265 switch($attr['TYPE']){
1267 case 'FAIpackageList':
1268 $tmp["Type"]= 'FAIpackageList';
1269 $tmp["Abbr"]= 'Pl';
1270 break;
1271 case 'FAItemplate':
1272 $tmp["Type"]= 'FAItemplate';
1273 $tmp["Abbr"]= 'T';
1274 break;
1275 case 'FAIvariable':
1276 $tmp["Type"]= 'FAIvariable';
1277 $tmp["Abbr"]= 'V';
1278 break;
1279 case 'FAIscript':
1280 $tmp["Type"]= 'FAIscript';
1281 $tmp["Abbr"]= 'S';
1282 break;
1283 case 'FAIhook':
1284 $tmp["Type"]= 'FAIhook';
1285 $tmp["Abbr"]= 'H';
1286 break;
1287 case 'FAIpartitionTable':
1288 $tmp["Type"]= 'FAIpartitionTable';
1289 $tmp["Abbr"]= 'Pt';
1290 break;
1291 case 'FAIprofile':
1292 $tmp["Type"]= 'FAIprofile';
1293 $tmp["Abbr"]= 'P';
1294 break;
1295 default: trigger_error("Unknown FAI object type!");;
1296 }
1297 return($tmp);
1298 }
1301 /* Return repository hook output, if possible.
1302 */
1303 function GetHookElements()
1304 {
1305 $ret = array();
1306 $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1307 if(!empty($cmd)){
1308 $res = shell_exec($cmd);
1309 $res2 = trim($res);
1310 if((!$res)){
1311 msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1312 }elseif(empty($res2)){
1313 msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG);
1314 }else{
1315 $tmp = preg_split("/\n/",$res);
1316 foreach($tmp as $line){
1317 if(empty($line)) continue;
1318 $ret[]= $line;
1319 }
1320 }
1321 }
1322 return($ret);
1323 }
1326 /* This function creates the release name out of a dn
1327 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1328 */
1329 function dn_to_release_name($dn)
1330 {
1331 $relevant = preg_replace("/,".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$dn);
1332 $parts = array_reverse(explode(",",$relevant));
1333 $str ="";
1334 foreach($parts as $part){
1335 $str .= preg_replace("/^ou=/","",$part)."/";
1336 }
1337 return(preg_replace("/\/$/","",$str));
1338 }
1339 }
1341 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1342 ?>