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