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)){
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 = isset($this->config->current['GOSA_SI']) && !empty($this->config->current['GOSA_SI']);
76 /* Check object group membership */
77 if(!isset($this->parent->by_object['ogroup'])){
78 $ldap = $this->config->get_ldap_link();
79 $ldap->cd ($this->config->current['BASE']);
80 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
81 if($ldap->count()){
82 $this->member_of_ogroup = TRUE;
83 $attrs = $ldap->fetch();
84 $this->o_group_dn = $attrs['dn'];
85 }
86 }
88 /* Creating a list of valid Mirrors
89 * none will not be saved to ldap.
90 */
91 $ldap = $this->config->get_ldap_link();
92 $ldap->cd($this->config->current['BASE']);
93 foreach($this->config->data['SERVERS']['LDAP'] as $server) {
94 $this->gotoLdapServerList[]= $server;
95 }
97 /* Get list of assigned ldap servers
98 */
99 if(isset($this->attrs['gotoLdapServer'])){
100 unset($this->attrs['gotoLdapServer']['count']);
101 sort($this->attrs['gotoLdapServer']);
102 foreach($this->attrs['gotoLdapServer'] as $value){
103 $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
104 }
105 }
106 natcasesort($this->gotoLdapServerList);
108 if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
109 $this->gotoLdap_inherit = TRUE;
110 }
112 /* FAI Initialization
113 Skip this if FAI is not activated
114 */
115 if($this->fai_activated) {
117 $this->update_fai_cache(TRUE);
119 /* Parse used FAIclasses (stored as string).
120 * The single classes are seperated by ' '.
121 * There is also the release type given, after first
122 * occurrence of ':'.
123 */
124 $this->FAIclass =array();
125 if(isset($this->attrs['FAIclass'][0])){
126 $tmp = split(" ",$this->attrs['FAIclass'][0]);
127 $tmp2 =array();
129 foreach($tmp as $class){
130 if( ":" == $class[0] ) {
131 $this->FAIrelease = trim(substr($class, 1));
132 }else{
133 $tmp2[$class] = $class;
134 }
135 }
136 $this->FAIclass = $tmp2;
137 }
138 }
140 /* Get arrays */
141 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
142 if (isset($this->attrs["$val"]["count"])){
143 for ($i= 0; $i<$this->attrs["count"]; $i++){
144 if (isset($this->attrs["$val"][$i])){
145 array_push($this->$val, $this->attrs["$val"][$i]);
146 }
147 }
148 }
149 sort ($this->$val);
150 $this->$val= array_unique($this->$val);
151 }
153 /* Parse Kernel Parameters to decide what boot mode is enabled */
154 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
155 $this->bootmode= "G";
156 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
157 $this->bootmode= "D";
158 } elseif ($this->gotoKernelParameters == "") {
159 $this->bootmode= "G";
160 } else {
161 $this->bootmode= "T";
162 }
163 if (preg_match("/ o /", $this->gotoKernelParameters)){
164 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
165 } else {
166 $this->customParameters= "";
167 }
169 /* Prepare Shares */
170 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
171 unset($this->attrs['gotoShare']['count']);
172 foreach($this->attrs['gotoShare'] as $share){
173 $tmp = $tmp2 = array();
174 $tmp = split("\|",$share);
175 $tmp2['server'] =$tmp[0];
176 $tmp2['name'] =$tmp[1];
177 $tmp2['mountPoint'] =$tmp[2];
178 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
179 }
180 }
182 $this->gotoShareSelections= $config->getShareList(true);
183 $this->gotoAvailableShares= $config->getShareList(false);
184 $tmp2 = array();
187 $this->orig_dn= $this->dn;
189 /* Handle inheritance value "default" */
190 if ($this->member_of_ogroup){
191 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
192 }
194 /* If we are member in an object group,
195 * we have to handle inherited values.
196 * So you can see what is inherited.
197 */
198 if ($this->member_of_ogroup){
200 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
201 $this->FAIdebianMirror = "inherited";
202 }
204 if($this->fai_activated){
205 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
206 }else{
207 $map= array("gotoBootKernel");
208 }
210 $ldap = $this->config->get_ldap_link();
211 $ldap->cat($this->o_group_dn);
212 $attrs= $ldap->fetch();
214 foreach ($map as $name){
215 if (!isset($attrs[$name][0])){
216 continue;
217 }
219 switch ($name){
220 case 'gotoBootKernel':
221 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
222 break;
224 case 'FAIclass':
225 $str = split(":",$attrs[$name][0]);
226 $this->InheritedFAIclass = split("\ ",trim($str[0]));
227 $this->InheritedFAIrelease = trim($str[1]);
228 break;
230 case 'FAIdebianMirror':
231 $this->InheritedFAIdebianMirror = $attrs[$name][0];
232 break;
233 }
234 }
235 }
238 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
240 /* Check if the current mirror is available
241 */
242 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
243 if(count($this->FAIclass)){
244 msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
245 }
246 $this->FAIdebianMirror = "auto";
247 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
248 $this->cache =array();
249 $this->update_fai_cache();
251 }
253 /* Check if the current mirror is available
254 */
255 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
256 $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
257 if(count($this->FAIclass)){
258 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);
259 }
260 $this->FAIrelease = $new_release;
261 $this->cache =array();
262 $this->update_fai_cache();
263 }
264 }
266 # /* Get list of boot kernels */
267 # if (isset($this->config->data['TABS'])){
268 # $command= $this->config->search(get_class($this), "KERNELS",array('tabs'));
269 # if (!check_command($command)){
270 # $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
271 # get_class($this));
272 # } else {
273 # $fh= popen($command, "r");
274 # while (!feof($fh)) {
275 # $buffer= trim(fgets($fh, 256));
276 # if(!empty($buffer)){
277 # $name=$value = $buffer;
278 # if(preg_match("/:/",$buffer)){
279 # $name = preg_replace("/:.*$/","",$buffer);
280 # $value= preg_replace("/^.*:/","",$buffer);
281 # $this->gotoBootKernels[$name]= $name.":".$value;
282 # }else{
283 # $this->gotoBootKernels[$name]= $value;
284 # }
285 # }
286 # }
287 # pclose($fh);
288 # }
289 # }
290 #
291 # /* Turn to default, if we've nothing to inherit */
292 # if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
293 # $this->gotoBootKernel= "default";
294 # }
295 }
298 function check()
299 {
300 $messages = array();
302 /* Call common method to give check the hook */
303 $messages= plugin::check();
305 /* If there are packages selected, but no mirror show error */
306 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
307 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
308 }
310 return($messages);
311 }
313 function execute()
314 {
315 /* Call parent execute */
316 plugin::execute();
318 if($this->is_account && !$this->view_logged){
319 $this->view_logged = TRUE;
320 new log("view","workstation/".get_class($this),$this->dn);
321 }
323 /* Do we need to flip is_account state? */
324 if(isset($_POST['modify_state'])){
325 if($this->is_account && $this->acl_is_removeable()){
326 $this->is_account= FALSE;
327 }elseif(!$this->is_account && $this->acl_is_createable()){
328 $this->is_account= TRUE;
329 }
330 }
332 /* Do we represent a valid terminal? */
333 if (!$this->is_account && $this->parent === NULL){
334 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
335 msgPool::noValidExtension(_("workstation"))."</b>";
336 return ($display);
337 }
339 /* Add module */
340 if (isset ($_POST['add_module'])){
341 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
342 $this->add_list ($this->gotoModules, $_POST['module']);
343 }
344 }
346 /* Delete module */
347 if (isset ($_POST['delete_module'])){
348 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
349 $this->del_list ($this->gotoModules, $_POST['modules_list']);
350 }
351 }
353 /* FAI class management */
354 if($this->fai_activated){
355 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
356 $found = 0 ;
358 /* If this new class/profile will attach a second partition table
359 * to our list of classes, abort and show a message.
360 */
361 foreach($this->FAIclass as $name){
362 if(isset($this->FAIclassInfo[$name])){
363 foreach($this->FAIclassInfo[$name] as $atr){
364 if(isset($atr['obj'])){
365 if($atr['obj'] == "FAIpartitionTable"){
366 $found ++ ;
367 }
368 }
369 }
370 }
371 }
373 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
374 msg_dialog(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
375 }else{
376 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
377 }
378 }
380 $sort = false;
382 /* Move one used class class one position up or down */
383 if($this->acl_is_writeable("FAIclass")){
384 foreach($_POST as $name => $val){
386 $sort_type = false;
387 if((preg_match("/sort_up/",$name))&&(!$sort)){
388 $sort_type = "sort_up_";
389 }
390 if((preg_match("/sort_down/",$name))&&(!$sort)){
391 $sort_type = "sort_down_";
392 }
394 if(($sort_type)&&(!$sort)){
395 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
396 $sort = true;
398 $last = -1;
399 $change_down = -1;
401 /* Create array with numeric index */
402 $tmp = array();
403 foreach($this->FAIclass as $class){
404 $tmp [] = $class;
405 }
407 /* Walk trough array */
408 foreach($tmp as $key => $faiName){
409 if($faiName == $value){
410 if($sort_type == "sort_up_"){
411 if($last != -1){
412 $change_down= $last;
413 }
414 }else{
415 if(isset($tmp[$key+1])){
416 $change_down = $key;
417 }
418 }
419 }
420 $last = $key;
421 }
423 $tmp2 = array();
424 $skip = false;
426 foreach($tmp as $ky => $vl){
428 if($ky == $change_down){
429 $skip = $vl;
430 }else{
431 $tmp2[$vl] = $vl;
432 }
433 if(($skip != false)&&($ky != $change_down)){
434 $tmp2[$skip] = $skip;
435 $skip =false;
436 }
437 }
438 $this->FAIclass = $tmp2;
439 }
441 if(preg_match("/fai_remove/i",$name)){
442 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
443 unset($this->FAIclass[$value]);
444 }
445 }
446 }
448 /* Delete selected class from our list */
449 if($this->acl_is_writeable("FAIclass")){
450 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
451 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
452 unset($this->FAIclass[$_POST['FAIclassSel']]);
453 }
454 }
455 }
456 }// END fai handling
458 /* Show main page */
459 $smarty= get_smarty();
461 /* Assign ACLs to smarty */
462 $tmp = $this->plInfo();
463 foreach($tmp['plProvidedAcls'] as $name => $translation){
464 $smarty->assign($name."ACL",$this->getacl($name));
465 }
467 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
469 /* In this section server shares will be defined
470 * A user can select one of the given shares and a mount point
471 * and attach this combination to his setup.
472 */
473 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
474 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
476 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
477 * This entry will be, a combination of mountPoint and sharedefinitions
478 */
479 if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
480 /* We assign a share to this user, if we don't know where to mount the share */
481 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
482 msg_dialog(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
483 }else{
484 if(count($this->gotoAvailableShares)){
485 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
486 $s_mount = $_POST['gotoShareMountPoint'];
487 /* Preparing the new assignment */
488 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
489 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
490 }
491 }
492 }
494 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
495 * If there is no defined share selected, we will abort the deletion without any message
496 */
497 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
498 unset($this->gotoShares[$_POST['gotoShare']]);
499 }
501 $smarty->assign("gotoShares",$this->printOutAssignedShares());
502 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
503 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
504 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
506 /* Create divSelectBox for ldap server selection
507 */
508 $SelectBoxLdapServer = new divSelectBox("LdapServer");
509 $SelectBoxLdapServer->SetHeight(130);
511 /* Add new ldap server to the list */
512 if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){
513 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
514 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
515 if(!in_array($to_add,$this->gotoLdapServers)){
516 $this->gotoLdapServers[] = $to_add;
517 }
518 }
519 }
521 /* Move ldap servers up and down */
522 if(!$this->gotoLdap_inherit){
523 foreach($_POST as $name => $value){
524 if(preg_match("/sort_ldap_up_/",$name)){
525 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
526 $from = $id;
527 $to = $id -1;
528 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
529 if($tmp){
530 $this->gotoLdapServers = $tmp;
531 }
532 break;
533 }
534 if(preg_match("/sort_ldap_down_/",$name)){
535 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
536 $from = $id;
537 $to = $id +1;
538 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
539 if($tmp){
540 $this->gotoLdapServers = $tmp;
541 }
542 break;
543 }
544 if(preg_match("/gotoLdapRemove_/",$name)){
545 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
546 $value = $this->gotoLdapServers[$id];
547 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
548 break;
549 }
550 }
551 }
553 /* Add Entries */
554 foreach($this->gotoLdapServers as $key => $server){
555 /* Announce missing entries */
556 if(!in_array($server,$this->gotoLdapServerList)){
557 $server = $server." <font style='color:red'>(missing)</font>";
558 }
560 /* Convert old style entry */
561 if (!preg_match('%:ldap://%', $server)){
562 $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
564 /* Beautify new style entries */
565 } else {
566 $server= preg_replace("/^[^:]+:/", "", $server);
567 }
569 $SelectBoxLdapServer->AddEntry(
570 array(array("string" => $server),
571 array("string" =>
572 "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'> ".
573 "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'> ".
574 "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
575 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
576 }
578 if($this->gotoLdap_inherit){
579 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
580 }else{
581 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
582 }
584 $list = array();
585 foreach($this->gotoLdapServerList as $key => $entry){
586 if(!in_array($entry,$this->gotoLdapServers)){
588 /* Convert old style entry */
589 if (!preg_match('%:ldap://%', $entry)){
590 $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
592 /* Beautify new style entries */
593 } else {
594 $entry= preg_replace("/^[^:]+:/", "", $entry);
595 }
597 $list[$key] = $entry;
598 }
599 }
600 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
601 $smarty->assign("gotoLdapServerList", $list);
602 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
603 $smarty->assign("JS", session::get('js'));
605 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
606 $smarty->assign("$val", $this->$val);
607 }
609 /* Values */
610 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
611 $smarty->assign($val, $this->$val);
612 }
614 $smarty->assign("fai_activated",$this->fai_activated);
616 /* Create FAI output */
617 $this->update_fai_cache();
618 $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
619 $smarty->assign("si_active",$this->si_active);
621 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
623 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
624 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
625 $smarty->assign("FAIrelease" , $this->FAIrelease);
626 $smarty->assign("FAIclasses" , $this->selectable_classes());
628 /* Get classes for release from cache.
629 * Or build cache
630 */
631 if($this->FAIdebianMirror == "inherited"){
632 $release = $this->InheritedFAIrelease;
633 }else{
634 $release = $this->FAIrelease;
635 }
637 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
638 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
640 $div = new divSelectBox("WSFAIscriptClasses");
641 $div -> SetHeight("110");
642 $str_up = " <input type='image' src='images/lists/sort-up.png' name='sort_up_%s' value='%s'>";
643 $str_down = " <input type='image' src='images/lists/sort-down.png' name='sort_down_%s' value='%s'>";
644 $str_remove = " <input type='image' src='images/lists/trash.png' name='fai_remove_%s' value='%s'>";
645 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
647 /* Get classes */
648 if($this->FAIdebianMirror == "inherited"){
649 $tmp = $this->InheritedFAIclass;
650 }else{
651 $tmp = $this->FAIclass;
652 }
654 /* Get invalid classes */
655 $invalid = $this->get_invalid_classes($tmp);
657 /* Draw every single entry */
658 $i = 1;
659 foreach($tmp as $class){
661 /* Mark invalid classes. (Not in selected release)
662 */
663 $marker = "";
664 if(in_array_ics($class,$invalid)){
665 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
666 }
668 /* Create up/down priority icons
669 * Skip this, if we have inherited the FAI classes.
670 */
671 if($this->FAIdebianMirror == "inherited"){
672 $str = "";
673 }else{
674 if($i==1){
675 $str = $str_empty.$str_down.$str_remove;
676 }elseif($i == count($this->FAIclass)){
677 $str = $str_up.$str_empty.$str_remove;
678 }else{
679 $str = $str_up.$str_down.$str_remove;
680 }
681 }
682 $i ++ ;
684 /* Get Description tag
685 * There may be several FAI objects with the same class name,
686 * use the description from FAIprofile, if possible.
687 */
688 $desc = "";
689 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
690 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
691 if(isset($types['Desc'])){
692 $desc= $types['Desc'];
693 if($types['Type'] == "FAIprofile"){
694 break;
695 }
696 }
697 }
698 }
699 if(!empty($desc)){
700 $desc = " [".trim($desc)."]";
701 }
703 $div->AddEntry(array(
704 array("string"=>$class.$desc.$marker),
705 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
706 ));
707 }
708 $smarty->assign("FAIScriptlist",$div->DrawList());
709 }// END FAI output generation
711 /* Radio button group */
712 if (preg_match("/G/", $this->bootmode)) {
713 $smarty->assign("graphicalbootup", "checked");
714 } else {
715 $smarty->assign("graphicalbootup", "");
716 }
717 if (preg_match("/T/", $this->bootmode)) {
718 $smarty->assign("textbootup", "checked");
719 } else {
720 $smarty->assign("textbootup", "");
721 }
722 if (preg_match("/D/", $this->bootmode)) {
723 $smarty->assign("debugbootup", "checked");
724 } else {
725 $smarty->assign("debugbootup", "");
726 }
728 /* Show main page */
729 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
730 }
733 function remove_from_parent()
734 {
735 $this->handle_post_events("remove");
736 new log("remove","workstation/".get_class($this),$this->dn);
737 }
740 /* Save data to object */
741 function save_object()
742 {
743 $old_mirror = $this->FAIdebianMirror;
744 plugin::save_object();
746 /* Update release */
747 if($old_mirror != $this->FAIdebianMirror){
748 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
749 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
750 }
751 }
753 if(isset($_POST['WorkstationStarttabPosted'])){
754 if(isset($_POST['gotoLdap_inherit'])){
755 $this->gotoLdap_inherit = TRUE;
756 }else{
757 $this->gotoLdap_inherit = FALSE;
758 }
760 /* Save group radio buttons */
761 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
762 $this->bootmode= $_POST["bootmode"];
763 }
765 /* Save kernel parameters */
766 if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
767 $this->customParameters= $_POST["customParameters"];
768 }
769 }
770 }
773 /* Save to LDAP */
774 function save()
775 {
777 /* Depending on the baseobject (Ogroup / WS) we
778 * use another set of objectClasses
779 * In case of WS itself, we use "array("GOhard", "FAIobject");"
780 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
781 */
782 if(isset($this->parent->by_object['ogroup'])){
783 $this->objectclasses = array("gotoWorkstationTemplate");
784 }elseif(isset($this->parent->by_object['workgeneric'])){
785 $this->objectclasses = array("GOhard");
786 }elseif(isset($this->parent->by_object['servgeneric'])){
787 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
788 }else{
789 print "Object Type Configuration : unknown";
790 exit();
791 }
793 /* Append FAI class */
794 if($this->fai_activated){
795 $this->objectclasses[] = "FAIobject";
796 }
798 /* Find proper terminal path for tftp configuration
799 FIXME: This is suboptimal when the default has changed to
800 another location! */
801 if (($this->gotoTerminalPath == "default")){
802 $ldap= $this->config->get_ldap_link();
804 /* Strip relevant part from dn, keep trailing ',' */
805 $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalou')."/i", "", $this->dn);
806 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
808 /* Walk from top to base and try to load default values for
809 'gotoTerminalPath'. Abort when an entry is found. */
810 while (TRUE){
811 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
813 $ldap->cat("cn=default,".get_ou('terminalou').$tmp.
814 $this->config->current['BASE'], array('gotoTerminalPath'));
815 $attrs= $ldap->fetch();
816 if (isset($attrs['gotoTerminalPath'])){
817 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
818 break;
819 }
821 /* Nothing left? */
822 if ($tmp == ""){
823 break;
824 }
825 }
826 }
828 /* Add semi automatic values */
829 // FIXME: LDAP Server may not be set here...
830 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
832 switch ($this->bootmode){
833 case "D":
834 $this->gotoKernelParameters.= " debug";
835 break;
836 case "G":
837 $this->gotoKernelParameters.= " splash=silent";
838 break;
839 }
840 if ($this->customParameters != ""){
841 $this->gotoKernelParameters.= " o ".$this->customParameters;
842 }
844 plugin::save();
846 unset( $this->attrs['FAIrelease'] );
847 $str = "";
849 /* Skip FAI attribute handling if not necessary */
850 if($this->fai_activated && !$this->si_fai_action_failed){
851 if($this->FAIdebianMirror == "inherited"){
852 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
853 }else{
854 foreach($this->FAIclass as $class){
855 $str .= $class." ";
856 }
857 $str = trim($str);
858 if(empty($this->attrs['FAIclass'])){
859 $this->attrs['FAIclass'] = array();
860 }else{
861 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
862 }
863 }
864 }
866 /* Add missing arrays */
867 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
868 if (isset ($this->$val) && count ($this->$val) != 0){
870 $this->attrs["$val"]= array_unique($this->$val);
871 }
872 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
873 }
875 /* Prepare list of ldap servers */
876 $this->attrs['gotoLdapServer'] = array();
877 if(!$this->gotoLdap_inherit){
878 $i = 0;
879 foreach($this->gotoLdapServers as $server){
880 $i ++;
881 $this->attrs['gotoLdapServer'][] = $i.":".$server;
882 }
883 }
885 if ($this->attrs['gotoBootKernel'] == "default-inherited"){
886 $this->attrs['gotoBootKernel']= array();
887 }
889 /* if mirror == none stop saving this attribute */
890 if($this->FAIdebianMirror == "none"){
891 $this->FAIdebianMirror = "";
892 }
894 /* Get FAIstate from object, the generic tab could have changed it during execute */
895 $ldap= $this->config->get_ldap_link();
896 $ldap->cd($this->dn);
899 /* Skip FAI attribute handling if not necessary */
900 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
901 $ldap->cat($this->dn,array("FAIstate"));
902 $checkFAIstate = $ldap->fetch();
904 /* Remove FAI objects if no FAI class is selected */
905 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
906 $this->attrs['FAIclass'] = array();
907 $this->attrs['FAIdebianMirror'] = array();
908 }
909 }
912 /* prepare share settings */
913 $tmp = array();
914 foreach($this->gotoShares as $name => $settings){
915 $tmp2= split("\|",$name);
916 $name = $tmp2[0];
917 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
918 }
919 $this->attrs['gotoShare']=$tmp;
920 $this->cleanup();
921 $ldap->modify ($this->attrs);
922 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
924 if (!$ldap->success()){
925 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
926 }
927 $this->handle_post_events("modify");
929 /* Check if LDAP server has changed */
930 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
931 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
932 $o_queue = new gosaSupportDaemon();
933 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
934 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
935 $macs = array();
937 /* Get list of macAddresses
938 */
939 if(isset($this->parent->by_object['ogroup'])){
941 /* If we are an object group, add all member macs
942 */
943 $p = $this->parent->by_object['ogroup'];
944 foreach($p->memberList as $dn => $obj){
945 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
946 $macs[] = $p->objcache[$dn]['macAddress'];
947 }
948 }
949 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
951 /* We are a workstation. Add current mac.
952 */
953 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
954 if(!empty($mac)){
955 $macs[] = $mac;
956 }
957 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
959 /* We are a server. Add current mac.
960 */
961 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
962 if(!empty($mac)){
963 $macs[] = $mac;
964 }
965 }
967 /* Trigger event for all member objects
968 */
969 foreach($macs as $mac){
970 $tmp = new $evt['CLASS_NAME']($this->config);
971 $tmp->set_type(TRIGGERED_EVENT);
972 $tmp->add_targets(array($mac));
973 if(!$o_queue->append($tmp)){
974 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
975 }
976 }
977 }
978 }
979 }
982 /* Add value to array, check if unique */
983 function add_list (&$array, $value)
984 {
985 if ($value != ""){
986 $array[]= $value;
987 sort($array);
988 array_unique ($array);
989 }
990 }
993 /* Delete value to array, check if unique */
994 function del_list (&$array, $list)
995 {
996 $tmp= array();
997 foreach ($array as $mod){
998 if (!in_array($mod, $list)){
999 $tmp[]= $mod;
1000 }
1001 }
1002 $array= $tmp;
1003 }
1005 /* Generate ListBox frindly output for the defined shares
1006 * Possibly Add or remove an attribute here,
1007 */
1008 function printOutAssignedShares()
1009 {
1010 $a_return = array();
1011 if(is_array($this->gotoShares)){
1012 foreach($this->gotoShares as $share){
1013 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1014 }
1015 }
1016 return($a_return);
1017 }
1021 function PrepareForCopyPaste($source)
1022 {
1023 plugin::PrepareForCopyPaste($source);
1024 $source_o = new workstartup ($this->config, $source['dn']);
1025 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1026 "gotoKernelParameters","gotoShares","customParameters") as $attr){
1027 $this->$attr = $source_o->$attr;
1028 }
1029 }
1032 function array_switch_item($ar,$from,$to)
1033 {
1034 if(!is_array($ar)){
1035 return(false);
1036 }
1037 if(!isset($ar[$from])){
1038 return(false);
1039 }
1040 if(!isset($ar[$to])){
1041 return(false);
1042 }
1044 $tmp = $ar[$from];
1045 $ar[$from] = $ar[$to];
1046 $ar[$to] = $tmp;
1047 return($ar);
1048 }
1051 /* Return plugin informations for acl handling */
1052 static function plInfo()
1053 {
1054 return (array(
1055 "plShortName" => _("Startup"),
1056 "plDescription" => _("System startup"),
1057 "plSelfModify" => FALSE,
1058 "plDepends" => array(),
1059 "plPriority" => 9,
1060 "plSection" => array("administration"),
1061 "plCategory" => array("workstation","server","ogroups"),
1063 "plProvidedAcls"=> array(
1064 "gotoLdapServer" => _("Ldap server"),
1065 "gotoBootKernel" => _("Boot kernel"),
1066 "gotoKernelParameters" => _("Kernel parameter"),
1068 "gotoModules" => _("Kernel modules"),
1069 "gotoShare" => _("Shares"),
1071 "FAIclass" => _("FAI classes"),
1072 "FAIdebianMirror" => _("Debian mirror"),
1073 "FAIrelease" => _("Debian release"),
1075 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1076 ));
1077 }
1080 /* Updates release dns
1081 * and reads all classes for the current release,
1082 * if not already done ($this->cache).
1083 */
1084 function update_fai_cache($first_call = FALSE)
1085 {
1086 $force = FALSE;
1087 if(!$this->si_active) return;
1088 $start = microtime(TRUE);
1090 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1092 $this->si_fai_action_failed = FALSE;
1094 /* Get the list of available servers and their releases.
1095 */
1096 if($force || !isset($this->cache['SERVERS'])){
1098 /* Only add inherit option, if we are part in an object group
1099 */
1100 if($this->member_of_ogroup){
1101 $this->cache['SERVERS']['inherited']=array();
1102 }
1104 $o_queue = new gosaSupportDaemon();
1105 $tmp = $o_queue->FAI_get_server();
1106 if($o_queue->is_error()){
1107 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1108 $this->si_fai_action_failed = TRUE;
1109 $this->cache = array();
1110 return;
1111 }else{
1112 foreach($tmp as $entry){
1113 $rel = $entry['RELEASE'];
1114 $this->cache['SERVERS']['auto'][$rel] = $rel;
1115 $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1116 }
1117 }
1118 }
1120 /* Build up arrays, without checks */
1121 if(!$first_call){
1123 /* Check if the selected mirror is available */
1124 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1125 $this->FAIdebianMirror = "auto";
1126 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1127 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1128 }
1130 /* Check if the selected release is available */
1131 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1132 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1133 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1134 }
1135 }
1137 /* Get classes for release from cache.
1138 * Or build cache
1139 */
1140 if($this->FAIdebianMirror == "inherited"){
1141 $release = $this->InheritedFAIrelease;
1142 }else{
1143 $release = $this->FAIrelease;
1144 }
1146 if($force || !isset($this->cache['CLASSES'][$release])){
1148 /* Get the list of available servers and their releases.
1149 */
1150 $o_queue = new gosaSupportDaemon();
1151 $tmp = $o_queue->FAI_get_classes($release);
1152 $this->cache['CLASSES'][$release] = array();
1153 if($o_queue->is_error()){
1154 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1155 $this->si_fai_action_failed = TRUE;
1156 $this->cache=array();
1157 return;
1158 }else{
1159 foreach($tmp as $entry){
1160 $class = $entry['CLASS'];
1161 $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry);
1162 }
1163 }
1165 /* Add object caught from external hook
1166 */
1167 $lines= $this->GetHookElements();
1168 foreach ($lines as $hline){
1169 $entries= split(";", $hline);
1170 $server = $entries['0'];
1171 $url = $entries['1'];
1172 if (!empty($url)){
1174 /* Split releases */
1175 if (isset($entries[2])){
1176 $releases= split(",", $entries[2]);
1178 foreach ($releases as $release_data){
1179 $release_c = preg_replace('/:.*$/', '', $release_data);
1180 $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1181 $classes_c = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1183 if($release_c == $release){
1184 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1185 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1186 foreach ($classes_c as $class){
1187 if ($class != ""){
1188 $this->cache['CLASSES'][$release_c][$class]= array();
1189 }
1190 }
1191 }
1192 }
1193 }
1194 }
1195 }
1196 }
1198 /* Get list of available kernel for this release
1199 */
1200 if($force || !isset($this->cache['KERNELS'][$release])){
1201 $o_queue = new gosaSupportDaemon();
1202 $tmp = $o_queue->FAI_get_kernels($release);
1203 $this->cache['KERNELS'][$release] = array();
1204 foreach($this->gotoBootKernels as $name => $default){
1205 $this->cache['KERNELS'][$release][$name] = $default;
1206 }
1207 foreach($tmp as $kernel){
1208 if(empty($kernel)) continue;
1209 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1210 }
1211 }
1212 ksort($this->cache['KERNELS'][$release]);
1213 }
1216 /* This function return an array containing all
1217 * invalid classes for the selected server/release
1218 */
1219 function get_invalid_classes($classes)
1220 {
1221 $this->update_fai_cache();
1222 if($this->FAIdebianMirror == "inherited"){
1223 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1224 }else{
1225 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1226 }
1229 /* Detect all classes that are not valid
1230 * for the selected release
1231 */
1232 $NA = array();
1233 foreach($classes as $class){
1234 if(!isset($release_classes[$class])){
1235 $NA[] = $class;
1236 }
1237 }
1238 return($NA);
1239 }
1242 /* Get all selectable classes for the ui select box
1243 */
1244 function selectable_classes()
1245 {
1246 $this->update_fai_cache();
1248 if($this->FAIdebianMirror == "inherited"){
1249 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1250 }else{
1251 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1252 }
1254 $Abbr ="";
1255 $ret= array();
1256 foreach($classes as $class_name => $class_types){
1257 if(!in_array($class_name,$this->FAIclass)){
1258 foreach($class_types as $type){
1259 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1260 $Abbr .= $type['Abbr']." ";
1261 }
1262 }
1263 $ret[$class_name] = trim($Abbr);
1264 }
1265 }
1266 uksort($ret, 'strnatcasecmp');
1267 return($ret);
1268 }
1271 /* Analyse FAI object and return an array with usefull informations like
1272 * FAIobject type.
1273 */
1274 function analyse_fai_object($attr)
1275 {
1276 $tmp = array();
1277 switch($attr['TYPE']){
1279 case 'FAIpackageList':
1280 $tmp["Type"]= 'FAIpackageList';
1281 $tmp["Abbr"]= 'Pl';
1282 break;
1283 case 'FAItemplate':
1284 $tmp["Type"]= 'FAItemplate';
1285 $tmp["Abbr"]= 'T';
1286 break;
1287 case 'FAIvariable':
1288 $tmp["Type"]= 'FAIvariable';
1289 $tmp["Abbr"]= 'V';
1290 break;
1291 case 'FAIscript':
1292 $tmp["Type"]= 'FAIscript';
1293 $tmp["Abbr"]= 'S';
1294 break;
1295 case 'FAIhook':
1296 $tmp["Type"]= 'FAIhook';
1297 $tmp["Abbr"]= 'H';
1298 break;
1299 case 'FAIpartitionTable':
1300 $tmp["Type"]= 'FAIpartitionTable';
1301 $tmp["Abbr"]= 'Pt';
1302 break;
1303 case 'FAIprofile':
1304 $tmp["Type"]= 'FAIprofile';
1305 $tmp["Abbr"]= 'P';
1306 break;
1307 default: trigger_error("Unknown FAI object type!");;
1308 }
1309 return($tmp);
1310 }
1313 /* Return repository hook output, if possible.
1314 */
1315 function GetHookElements()
1316 {
1317 $ret = array();
1318 $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1319 if(!empty($cmd)){
1320 $res = shell_exec($cmd);
1321 $res2 = trim($res);
1322 if((!$res)){
1323 msg_dialog(_("Configuration error"), msgPool::cmdexecfailed("REPOSITORY_HOOK", $cmd), ERROR_DIALOG);
1324 }elseif(empty($res2)){
1325 msg_dialog(_("Configuration error"), _("REPOSITORY_HOOK returned no result!"), ERROR_DIALOG);
1326 }else{
1327 $tmp = split("\n",$res);
1328 foreach($tmp as $line){
1329 if(empty($line)) continue;
1330 $ret[]= $line;
1331 }
1332 }
1333 }
1334 return($ret);
1335 }
1338 /* This function creates the release name out of a dn
1339 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1340 */
1341 function dn_to_release_name($dn)
1342 {
1343 $relevant = preg_replace("/,".normalizePreg(get_ou("faiou")).".*$/","",$dn);
1344 $parts = array_reverse(split("\,",$relevant));
1345 $str ="";
1346 foreach($parts as $part){
1347 $str .= preg_replace("/^ou=/","",$part)."/";
1348 }
1349 return(preg_replace("/\/$/","",$str));
1350 }
1351 }
1353 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1354 ?>