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::display(_("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::display(_("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 }else{
911 /* Don't touch FAI objects if something went wrong with the si daemon.
912 */
913 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
914 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
915 }
917 /* prepare share settings */
918 $tmp = array();
919 foreach($this->gotoShares as $name => $settings){
920 $tmp2= split("\|",$name);
921 $name = $tmp2[0];
922 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
923 }
924 $this->attrs['gotoShare']=$tmp;
925 $this->cleanup();
926 $ldap->modify ($this->attrs);
927 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
929 if (!$ldap->success()){
930 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
931 }
932 $this->handle_post_events("modify");
934 /* Check if LDAP server has changed */
935 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
936 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
937 $o_queue = new gosaSupportDaemon();
938 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
939 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
940 $macs = array();
942 /* Get list of macAddresses
943 */
944 if(isset($this->parent->by_object['ogroup'])){
946 /* If we are an object group, add all member macs
947 */
948 $p = $this->parent->by_object['ogroup'];
949 foreach($p->memberList as $dn => $obj){
950 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
951 $macs[] = $p->objcache[$dn]['macAddress'];
952 }
953 }
954 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
956 /* We are a workstation. Add current mac.
957 */
958 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
959 if(!empty($mac)){
960 $macs[] = $mac;
961 }
962 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
964 /* We are a server. Add current mac.
965 */
966 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
967 if(!empty($mac)){
968 $macs[] = $mac;
969 }
970 }
972 /* Trigger event for all member objects
973 */
974 foreach($macs as $mac){
975 $tmp = new $evt['CLASS_NAME']($this->config);
976 $tmp->set_type(TRIGGERED_EVENT);
977 $tmp->add_targets(array($mac));
978 if(!$o_queue->append($tmp)){
979 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
980 }
981 }
982 }
983 }
984 }
987 /* Add value to array, check if unique */
988 function add_list (&$array, $value)
989 {
990 if ($value != ""){
991 $array[]= $value;
992 sort($array);
993 array_unique ($array);
994 }
995 }
998 /* Delete value to array, check if unique */
999 function del_list (&$array, $list)
1000 {
1001 $tmp= array();
1002 foreach ($array as $mod){
1003 if (!in_array($mod, $list)){
1004 $tmp[]= $mod;
1005 }
1006 }
1007 $array= $tmp;
1008 }
1010 /* Generate ListBox frindly output for the defined shares
1011 * Possibly Add or remove an attribute here,
1012 */
1013 function printOutAssignedShares()
1014 {
1015 $a_return = array();
1016 if(is_array($this->gotoShares)){
1017 foreach($this->gotoShares as $share){
1018 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1019 }
1020 }
1021 return($a_return);
1022 }
1026 function PrepareForCopyPaste($source)
1027 {
1028 plugin::PrepareForCopyPaste($source);
1029 $source_o = new workstartup ($this->config, $source['dn']);
1030 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1031 "gotoKernelParameters","gotoShares","customParameters") as $attr){
1032 $this->$attr = $source_o->$attr;
1033 }
1034 }
1037 function array_switch_item($ar,$from,$to)
1038 {
1039 if(!is_array($ar)){
1040 return(false);
1041 }
1042 if(!isset($ar[$from])){
1043 return(false);
1044 }
1045 if(!isset($ar[$to])){
1046 return(false);
1047 }
1049 $tmp = $ar[$from];
1050 $ar[$from] = $ar[$to];
1051 $ar[$to] = $tmp;
1052 return($ar);
1053 }
1056 /* Return plugin informations for acl handling */
1057 static function plInfo()
1058 {
1059 return (array(
1060 "plShortName" => _("Startup"),
1061 "plDescription" => _("System startup"),
1062 "plSelfModify" => FALSE,
1063 "plDepends" => array(),
1064 "plPriority" => 9,
1065 "plSection" => array("administration"),
1066 "plCategory" => array("workstation","server","ogroups"),
1068 "plProvidedAcls"=> array(
1069 "gotoLdapServer" => _("Ldap server"),
1070 "gotoBootKernel" => _("Boot kernel"),
1071 "gotoKernelParameters" => _("Kernel parameter"),
1073 "gotoModules" => _("Kernel modules"),
1074 "gotoShare" => _("Shares"),
1076 "FAIclass" => _("FAI classes"),
1077 "FAIdebianMirror" => _("Debian mirror"),
1078 "FAIrelease" => _("Debian release"),
1080 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1081 ));
1082 }
1085 /* Updates release dns
1086 * and reads all classes for the current release,
1087 * if not already done ($this->cache).
1088 */
1089 function update_fai_cache($first_call = FALSE)
1090 {
1091 $force = FALSE;
1092 if(!$this->si_active) return;
1093 $start = microtime(TRUE);
1095 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1097 $this->si_fai_action_failed = FALSE;
1099 /* Get the list of available servers and their releases.
1100 */
1101 if($force || !isset($this->cache['SERVERS'])){
1103 /* Only add inherit option, if we are part in an object group
1104 */
1105 if($this->member_of_ogroup){
1106 $this->cache['SERVERS']['inherited']=array();
1107 }
1109 $o_queue = new gosaSupportDaemon();
1110 $tmp = $o_queue->FAI_get_server();
1111 if($o_queue->is_error()){
1112 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1113 $this->si_fai_action_failed = TRUE;
1114 $this->cache = array();
1115 return;
1116 }else{
1117 foreach($tmp as $entry){
1118 $rel = $entry['RELEASE'];
1119 $this->cache['SERVERS']['auto'][$rel] = $rel;
1120 $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1121 }
1122 }
1123 }
1125 /* Build up arrays, without checks */
1126 if(!$first_call){
1128 /* Check if the selected mirror is available */
1129 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1130 $this->FAIdebianMirror = "auto";
1131 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1132 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1133 }
1135 /* Check if the selected release is available */
1136 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1137 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1138 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1139 }
1140 }
1142 /* Get classes for release from cache.
1143 * Or build cache
1144 */
1145 if($this->FAIdebianMirror == "inherited"){
1146 $release = $this->InheritedFAIrelease;
1147 }else{
1148 $release = $this->FAIrelease;
1149 }
1151 if($force || !isset($this->cache['CLASSES'][$release])){
1153 /* Get the list of available servers and their releases.
1154 */
1155 $o_queue = new gosaSupportDaemon();
1156 $tmp = $o_queue->FAI_get_classes($release);
1157 $this->cache['CLASSES'][$release] = array();
1158 if($o_queue->is_error()){
1159 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1160 $this->si_fai_action_failed = TRUE;
1161 $this->cache=array();
1162 return;
1163 }else{
1164 foreach($tmp as $entry){
1165 $class = $entry['CLASS'];
1166 $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry);
1167 }
1168 }
1170 /* Add object caught from external hook
1171 */
1172 $lines= $this->GetHookElements();
1173 foreach ($lines as $hline){
1174 $entries= split(";", $hline);
1175 $server = $entries['0'];
1176 $url = $entries['1'];
1177 if (!empty($url)){
1179 /* Split releases */
1180 if (isset($entries[2])){
1181 $releases= split(",", $entries[2]);
1183 foreach ($releases as $release_data){
1184 $release_c = preg_replace('/:.*$/', '', $release_data);
1185 $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1186 $classes_c = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1188 if($release_c == $release){
1189 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1190 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1191 foreach ($classes_c as $class){
1192 if ($class != ""){
1193 $this->cache['CLASSES'][$release_c][$class]= array();
1194 }
1195 }
1196 }
1197 }
1198 }
1199 }
1200 }
1201 }
1203 /* Get list of available kernel for this release
1204 */
1205 if($force || !isset($this->cache['KERNELS'][$release])){
1206 $o_queue = new gosaSupportDaemon();
1207 $tmp = $o_queue->FAI_get_kernels($release);
1208 $this->cache['KERNELS'][$release] = array();
1209 foreach($this->gotoBootKernels as $name => $default){
1210 $this->cache['KERNELS'][$release][$name] = $default;
1211 }
1212 foreach($tmp as $kernel){
1213 if(empty($kernel)) continue;
1214 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1215 }
1216 }
1217 ksort($this->cache['KERNELS'][$release]);
1218 }
1221 /* This function return an array containing all
1222 * invalid classes for the selected server/release
1223 */
1224 function get_invalid_classes($classes)
1225 {
1226 $this->update_fai_cache();
1227 if($this->FAIdebianMirror == "inherited"){
1228 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1229 }else{
1230 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1231 }
1234 /* Detect all classes that are not valid
1235 * for the selected release
1236 */
1237 $NA = array();
1238 foreach($classes as $class){
1239 if(!isset($release_classes[$class])){
1240 $NA[] = $class;
1241 }
1242 }
1243 return($NA);
1244 }
1247 /* Get all selectable classes for the ui select box
1248 */
1249 function selectable_classes()
1250 {
1251 $this->update_fai_cache();
1253 if($this->FAIdebianMirror == "inherited"){
1254 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1255 }else{
1256 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1257 }
1259 $Abbr ="";
1260 $ret= array();
1261 foreach($classes as $class_name => $class_types){
1262 if(!in_array($class_name,$this->FAIclass)){
1263 foreach($class_types as $type){
1264 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1265 $Abbr .= $type['Abbr']." ";
1266 }
1267 }
1268 $ret[$class_name] = trim($Abbr);
1269 }
1270 }
1271 uksort($ret, 'strnatcasecmp');
1272 return($ret);
1273 }
1276 /* Analyse FAI object and return an array with usefull informations like
1277 * FAIobject type.
1278 */
1279 function analyse_fai_object($attr)
1280 {
1281 $tmp = array();
1282 switch($attr['TYPE']){
1284 case 'FAIpackageList':
1285 $tmp["Type"]= 'FAIpackageList';
1286 $tmp["Abbr"]= 'Pl';
1287 break;
1288 case 'FAItemplate':
1289 $tmp["Type"]= 'FAItemplate';
1290 $tmp["Abbr"]= 'T';
1291 break;
1292 case 'FAIvariable':
1293 $tmp["Type"]= 'FAIvariable';
1294 $tmp["Abbr"]= 'V';
1295 break;
1296 case 'FAIscript':
1297 $tmp["Type"]= 'FAIscript';
1298 $tmp["Abbr"]= 'S';
1299 break;
1300 case 'FAIhook':
1301 $tmp["Type"]= 'FAIhook';
1302 $tmp["Abbr"]= 'H';
1303 break;
1304 case 'FAIpartitionTable':
1305 $tmp["Type"]= 'FAIpartitionTable';
1306 $tmp["Abbr"]= 'Pt';
1307 break;
1308 case 'FAIprofile':
1309 $tmp["Type"]= 'FAIprofile';
1310 $tmp["Abbr"]= 'P';
1311 break;
1312 default: trigger_error("Unknown FAI object type!");;
1313 }
1314 return($tmp);
1315 }
1318 /* Return repository hook output, if possible.
1319 */
1320 function GetHookElements()
1321 {
1322 $ret = array();
1323 $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1324 if(!empty($cmd)){
1325 $res = shell_exec($cmd);
1326 $res2 = trim($res);
1327 if((!$res)){
1328 msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("REPOSITORY_HOOK", $cmd), ERROR_DIALOG);
1329 }elseif(empty($res2)){
1330 msg_dialog::display(_("Configuration error"), _("REPOSITORY_HOOK returned no result!"), ERROR_DIALOG);
1331 }else{
1332 $tmp = split("\n",$res);
1333 foreach($tmp as $line){
1334 if(empty($line)) continue;
1335 $ret[]= $line;
1336 }
1337 }
1338 }
1339 return($ret);
1340 }
1343 /* This function creates the release name out of a dn
1344 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1345 */
1346 function dn_to_release_name($dn)
1347 {
1348 $relevant = preg_replace("/,".normalizePreg(get_ou("faiou")).".*$/","",$dn);
1349 $parts = array_reverse(split("\,",$relevant));
1350 $str ="";
1351 foreach($parts as $part){
1352 $str .= preg_replace("/^ou=/","",$part)."/";
1353 }
1354 return(preg_replace("/\/$/","",$str));
1355 }
1356 }
1358 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1359 ?>