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 $orig_dn = "";
33 var $ignore_account = TRUE;
35 /* FAI class selection */
36 var $FAIclass = array(); // The currently selected classes
37 var $FAIrelease = "";
38 var $FAIdebianMirror = "auto";
39 var $si_active = FALSE;
40 var $si_fai_action_failed = FALSE;
42 var $cache = array(); // Used as cache in fai mehtods
44 var $FAIstatus = "";
45 var $FAIclasses = array();
47 var $view_logged = FALSE;
49 /* FAI class selection */
50 var $InheritedFAIclass = array();
51 var $InheritedFAIrelease = "";
52 var $InheritedFAIdebianMirror= "auto";
54 var $CopyPasteVars = array("gotoModules","gotoShares");
55 var $fai_activated = FALSE;
56 var $o_group_dn = "";
57 var $member_of_ogroup = FALSE;
59 function workstartup (&$config, $dn= NULL, $parent= NULL)
60 {
61 /* Check if FAI is active */
62 $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
63 if(!empty($tmp) && class_available("faiManagement")){
64 $this->fai_activated = TRUE;
65 }else{
66 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
67 $this->objectclasses = array("GOhard");
68 }
70 plugin::plugin ($config, $dn, $parent);
72 /* Check for si daemon */
73 $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
75 /* Check object group membership */
76 if(!isset($this->parent->by_object['ogroup'])){
77 $ldap = $this->config->get_ldap_link();
78 $ldap->cd ($this->config->current['BASE']);
79 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
80 if($ldap->count()){
81 $this->member_of_ogroup = TRUE;
82 $attrs = $ldap->fetch();
83 $this->o_group_dn = $attrs['dn'];
84 }
85 }
87 /* Creating a list of valid Mirrors
88 * none will not be saved to ldap.
89 */
90 $ldap = $this->config->get_ldap_link();
91 $ldap->cd($this->config->current['BASE']);
92 $ui = get_userinfo();
93 foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){
94 if($ui->get_category_permissions($data['dn'],"server",TRUE)){
95 for($i = 0; $i < $data['goLdapBase']['count']; $i ++){
96 $name = $data["cn"][0].":".$data["goLdapBase"][$i];
97 $this->gotoLdapServerList[]= $name;
98 }
99 }
100 }
102 /* Get list of assigned ldap servers
103 */
104 if(isset($this->attrs['gotoLdapServer'])){
105 unset($this->attrs['gotoLdapServer']['count']);
106 sort($this->attrs['gotoLdapServer']);
107 foreach($this->attrs['gotoLdapServer'] as $value){
108 $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
109 }
110 }
111 natcasesort($this->gotoLdapServerList);
113 if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
114 $this->gotoLdap_inherit = TRUE;
115 }
117 /* FAI Initialization
118 Skip this if FAI is not activated
119 */
120 if($this->fai_activated) {
122 /* Parse used FAIclasses (stored as string).
123 * The single classes are seperated by ' '.
124 * There is also the release type given, after first
125 * occurrence of ':'.
126 */
127 $this->FAIclass =array();
128 if(isset($this->attrs['FAIclass'][0])){
129 $tmp = split(" ",$this->attrs['FAIclass'][0]);
130 $tmp2 =array();
132 foreach($tmp as $class){
133 if( ":" == $class[0] ) {
134 $this->FAIrelease = trim(substr($class, 1));
135 }else{
136 $tmp2[$class] = $class;
137 }
138 }
139 $this->FAIclass = $tmp2;
140 }
141 }
143 /* Get arrays */
144 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
145 if (isset($this->attrs["$val"]["count"])){
146 for ($i= 0; $i<$this->attrs["count"]; $i++){
147 if (isset($this->attrs["$val"][$i])){
148 array_push($this->$val, $this->attrs["$val"][$i]);
149 }
150 }
151 }
152 sort ($this->$val);
153 $this->$val= array_unique($this->$val);
154 }
156 /* Prepare Shares */
157 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
158 unset($this->attrs['gotoShare']['count']);
159 foreach($this->attrs['gotoShare'] as $share){
160 $tmp = $tmp2 = array();
161 $tmp = split("\|",$share);
162 $tmp2['server'] =$tmp[0];
163 $tmp2['name'] =$tmp[1];
164 $tmp2['mountPoint'] =$tmp[2];
165 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
166 }
167 }
169 $this->gotoShareSelections= $config->getShareList(true);
170 $this->gotoAvailableShares= $config->getShareList(false);
171 $tmp2 = array();
174 $this->orig_dn= $this->dn;
176 /* Handle inheritance value "default" */
177 if ($this->member_of_ogroup){
178 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
179 }
181 /* If we are member in an object group,
182 * we have to handle inherited values.
183 * So you can see what is inherited.
184 */
185 if ($this->member_of_ogroup){
187 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
188 $this->FAIdebianMirror = "inherited";
189 }
191 if($this->fai_activated){
192 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
193 }else{
194 $map= array("gotoBootKernel");
195 }
197 $ldap = $this->config->get_ldap_link();
198 $ldap->cat($this->o_group_dn);
199 $attrs= $ldap->fetch();
201 foreach ($map as $name){
202 if (!isset($attrs[$name][0])){
203 continue;
204 }
206 switch ($name){
207 case 'gotoBootKernel':
208 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
209 break;
211 case 'FAIclass':
212 $str = split(":",$attrs[$name][0]);
213 $this->InheritedFAIclass = split("\ ",trim($str[0]));
214 $this->InheritedFAIrelease = trim($str[1]);
215 break;
217 case 'FAIdebianMirror':
218 $this->InheritedFAIdebianMirror = $attrs[$name][0];
219 break;
220 }
221 }
222 }
224 $this->update_fai_cache();
226 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
228 /* Check if the current mirror is available
229 */
230 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
231 if(count($this->FAIclass)){
232 msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
233 }
234 $this->FAIdebianMirror = "auto";
235 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
236 $this->cache['CLASSES'] = array();
237 $this->update_fai_cache();
238 }
240 /* Check if the current mirror is available
241 */
242 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
243 $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
244 if(count($this->FAIclass)){
245 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);
246 }
247 $this->FAIrelease = $new_release;
248 $this->cache['CLASSES'] = array();
249 $this->update_fai_cache();
250 }
251 }
252 }
255 function check()
256 {
257 $messages = array();
259 /* Call common method to give check the hook */
260 $messages= plugin::check();
262 /* If there are packages selected, but no mirror show error */
263 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
264 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
265 }
267 return($messages);
268 }
270 function execute()
271 {
272 /* Call parent execute */
273 plugin::execute();
275 if($this->is_account && !$this->view_logged){
276 $this->view_logged = TRUE;
277 new log("view","workstation/".get_class($this),$this->dn);
278 }
280 /* Do we represent a valid terminal? */
281 if (!$this->is_account && $this->parent === NULL){
282 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
283 msgPool::noValidExtension(_("workstation"))."</b>";
284 return ($display);
285 }
287 /* Add module */
288 if (isset ($_POST['add_module'])){
289 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
290 $this->add_list ($this->gotoModules, $_POST['module']);
291 }
292 }
294 /* Delete module */
295 if (isset ($_POST['delete_module'])){
296 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
297 $this->del_list ($this->gotoModules, $_POST['modules_list']);
298 }
299 }
301 /* FAI class management */
302 if($this->fai_activated){
303 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
304 $found = 0 ;
306 /* If this new class/profile will attach a second partition table
307 * to our list of classes, abort and show a message.
308 */
309 foreach($this->FAIclass as $name){
310 if(isset($this->FAIclassInfo[$name])){
311 foreach($this->FAIclassInfo[$name] as $atr){
312 if(isset($atr['obj'])){
313 if($atr['obj'] == "FAIpartitionTable"){
314 $found ++ ;
315 }
316 }
317 }
318 }
319 }
321 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
322 msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
323 }else{
324 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
325 }
326 }
328 $sort = false;
330 /* Move one used class class one position up or down */
331 if($this->acl_is_writeable("FAIclass")){
332 foreach($_POST as $name => $val){
334 $sort_type = false;
335 if((preg_match("/sort_up/",$name))&&(!$sort)){
336 $sort_type = "sort_up_";
337 }
338 if((preg_match("/sort_down/",$name))&&(!$sort)){
339 $sort_type = "sort_down_";
340 }
342 if(($sort_type)&&(!$sort)){
343 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
344 $sort = true;
346 $last = -1;
347 $change_down = -1;
349 /* Create array with numeric index */
350 $tmp = array();
351 foreach($this->FAIclass as $class){
352 $tmp [] = $class;
353 }
355 /* Walk trough array */
356 foreach($tmp as $key => $faiName){
357 if($faiName == $value){
358 if($sort_type == "sort_up_"){
359 if($last != -1){
360 $change_down= $last;
361 }
362 }else{
363 if(isset($tmp[$key+1])){
364 $change_down = $key;
365 }
366 }
367 }
368 $last = $key;
369 }
371 $tmp2 = array();
372 $skip = false;
374 foreach($tmp as $ky => $vl){
376 if($ky == $change_down){
377 $skip = $vl;
378 }else{
379 $tmp2[$vl] = $vl;
380 }
381 if(($skip != false)&&($ky != $change_down)){
382 $tmp2[$skip] = $skip;
383 $skip =false;
384 }
385 }
386 $this->FAIclass = $tmp2;
387 }
389 if(preg_match("/fai_remove/i",$name)){
390 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
391 unset($this->FAIclass[$value]);
392 if($this->FAIclass == array()){
393 /* class list is emtpy. Check whether the system is part of an object group and set
394 the FAI mirror to "inherited" in this case. */
395 if ($this->member_of_ogroup){
396 $this->FAIdebianMirror = "inherited";
397 }
398 }
399 }
400 }
401 }
403 /* Delete selected class from our list */
404 if($this->acl_is_writeable("FAIclass")){
405 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
406 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
407 unset($this->FAIclass[$_POST['FAIclassSel']]);
408 }
409 }
410 }
411 }// END fai handling
413 /* Show main page */
414 $smarty= get_smarty();
416 /* Assign ACLs to smarty */
417 $tmp = $this->plInfo();
418 foreach($tmp['plProvidedAcls'] as $name => $translation){
419 $smarty->assign($name."ACL",$this->getacl($name));
420 }
422 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
424 /* In this section server shares will be defined
425 * A user can select one of the given shares and a mount point
426 * and attach this combination to his setup.
427 */
428 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
429 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
431 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
432 * This entry will be, a combination of mountPoint and sharedefinitions
433 */
434 if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
435 /* We assign a share to this user, if we don't know where to mount the share */
436 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
437 msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
438 }else{
440 if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
441 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
442 $s_mount = $_POST['gotoShareMountPoint'];
443 /* Preparing the new assignment */
444 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
445 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
446 }
447 }
448 }
450 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
451 * If there is no defined share selected, we will abort the deletion without any message
452 */
453 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
454 unset($this->gotoShares[$_POST['gotoShare']]);
455 }
457 $smarty->assign("gotoShares",$this->printOutAssignedShares());
458 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
459 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
460 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
462 /* Create divSelectBox for ldap server selection
463 */
464 $SelectBoxLdapServer = new divSelectBox("LdapServer");
465 $SelectBoxLdapServer->SetHeight(130);
467 /* Add new ldap server to the list */
468 if($this->acl_is_writeable("gotoLdapServer") &&
469 !$this->gotoLdap_inherit &&
470 isset($_POST['add_ldap_server']) &&
471 isset($_POST['ldap_server_to_add'])){
472 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
473 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
474 if(!in_array($to_add,$this->gotoLdapServers)){
475 $this->gotoLdapServers[] = $to_add;
476 }
477 }
478 }
480 /* Move ldap servers up and down */
481 if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
482 foreach($_POST as $name => $value){
483 if(preg_match("/sort_ldap_up_/",$name)){
484 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
485 $from = $id;
486 $to = $id -1;
487 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
488 if($tmp){
489 $this->gotoLdapServers = $tmp;
490 }
491 break;
492 }
493 if(preg_match("/sort_ldap_down_/",$name)){
494 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
495 $from = $id;
496 $to = $id +1;
497 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
498 if($tmp){
499 $this->gotoLdapServers = $tmp;
500 }
501 break;
502 }
503 if(preg_match("/gotoLdapRemove_/",$name)){
504 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
505 $value = $this->gotoLdapServers[$id];
506 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
507 break;
508 }
509 }
510 }
512 /* Add Entries */
513 if($this->acl_is_readable("gotoLdapServer")){
515 foreach($this->gotoLdapServers as $key => $server){
517 /* Announce missing entries */
518 if(!in_array($server,$this->gotoLdapServerList)){
519 $server = $server." <font style='color:red'>(missing)</font>";
520 }
522 /* Convert old style entry */
523 if (!preg_match('%:ldaps?://%', $server)){
524 $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
526 /* Beautify new style entries */
527 } else {
528 $server= preg_replace("/^[^:]+:/", "", $server);
529 }
531 $SelectBoxLdapServer->AddEntry(
532 array(array("string" => $server),
533 array("string" =>
534 "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'> ".
535 "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'> ".
536 "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
537 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
538 }
539 }
541 if($this->gotoLdap_inherit){
542 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
543 }else{
544 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
545 }
547 $list = array();
548 foreach($this->gotoLdapServerList as $key => $entry){
549 if(!in_array($entry,$this->gotoLdapServers)){
551 /* Convert old style entry */
552 if (!preg_match('%:ldap[s]*://%', $entry)){
553 $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
555 /* Beautify new style entries */
556 } else {
557 $entry= preg_replace("/^[^:]+:/", "", $entry);
558 }
560 $list[$key] = $entry;
561 }
562 }
563 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
564 $smarty->assign("gotoLdapServerList", $list);
565 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
566 $smarty->assign("JS", session::get('js'));
568 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
569 $smarty->assign("$val", $this->$val);
570 }
572 /* Values */
573 foreach(array("gotoBootKernel","gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
574 $smarty->assign($val, $this->$val);
575 }
577 $smarty->assign("fai_activated",$this->fai_activated);
579 /* Create FAI output */
580 $this->update_fai_cache();
581 $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
582 $smarty->assign("si_active",$this->si_active);
584 $div = new divSelectBox("WSFAIscriptClasses");
585 $div -> SetHeight("110");
587 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
589 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
590 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
591 $smarty->assign("FAIrelease" , $this->FAIrelease);
592 $smarty->assign("FAIclasses" , $this->selectable_classes());
594 /* Get classes for release from cache.
595 * Or build cache
596 */
597 if($this->FAIdebianMirror == "inherited"){
598 $release = $this->InheritedFAIrelease;
599 }else{
600 $release = $this->FAIrelease;
601 }
603 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
604 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
606 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
607 if($this->acl_is_writeable("FAIclass")){
608 $str_up = " <input type='image' src='images/lists/sort-up.png' name='sort_up_%s' value='%s'>";
609 $str_down = " <input type='image' src='images/lists/sort-down.png' name='sort_down_%s' value='%s'>";
610 $str_remove = " <input type='image' src='images/lists/trash.png' name='fai_remove_%s' value='%s'>";
611 }else{
612 $str_up=$str_down=$str_remove=$str_empty;
613 }
615 /* Get classes */
616 if($this->FAIdebianMirror == "inherited"){
617 $tmp = $this->InheritedFAIclass;
618 }else{
619 $tmp = $this->FAIclass;
620 }
622 /* Get invalid classes */
623 $invalid = $this->get_invalid_classes($tmp);
625 /* Draw every single entry */
626 $i = 1;
627 if($this->acl_is_readable("FAIclass")){
628 foreach($tmp as $class){
630 /* Mark invalid classes. (Not in selected release)
631 */
632 $marker = "";
633 if(in_array_ics($class,$invalid)){
634 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
635 }
637 /* Create up/down priority icons
638 * Skip this, if we have inherited the FAI classes.
639 */
640 if($this->FAIdebianMirror == "inherited"){
641 $str = "";
642 }else{
643 if($i==1){
644 $str = $str_empty.$str_down.$str_remove;
645 }elseif($i == count($this->FAIclass)){
646 $str = $str_up.$str_empty.$str_remove;
647 }else{
648 $str = $str_up.$str_down.$str_remove;
649 }
650 }
651 $i ++ ;
653 /* Get Description tag
654 * There may be several FAI objects with the same class name,
655 * use the description from FAIprofile, if possible.
656 */
657 $desc = "";
658 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
659 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
660 if(isset($types['Desc'])){
661 $desc= $types['Desc'];
662 if($types['Type'] == "FAIprofile"){
663 break;
664 }
665 }
666 }
667 }
668 if(!empty($desc)){
669 $desc = " [".trim($desc)."]";
670 }
672 $div->AddEntry(array(
673 array("string"=>$class.$desc.$marker),
674 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
675 ));
676 }
677 }// END FAI output generation
678 }// END FAI output generation
679 $smarty->assign("FAIScriptlist",$div->DrawList());
681 /* Radio button group */
682 if (preg_match("/G/", $this->bootmode)) {
683 $smarty->assign("graphicalbootup", "checked");
684 } else {
685 $smarty->assign("graphicalbootup", "");
686 }
687 if (preg_match("/T/", $this->bootmode)) {
688 $smarty->assign("textbootup", "checked");
689 } else {
690 $smarty->assign("textbootup", "");
691 }
692 if (preg_match("/D/", $this->bootmode)) {
693 $smarty->assign("debugbootup", "checked");
694 } else {
695 $smarty->assign("debugbootup", "");
696 }
698 /* Show main page */
699 $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters);
700 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
701 }
704 function remove_from_parent()
705 {
706 $this->handle_post_events("remove");
707 new log("remove","workstation/".get_class($this),$this->dn);
708 }
711 /* Save data to object */
712 function save_object()
713 {
714 $old_mirror = $this->FAIdebianMirror;
715 plugin::save_object();
717 /* Update release */
718 if($old_mirror != $this->FAIdebianMirror){
719 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
720 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
721 }
722 }
724 if(isset($_POST['WorkstationStarttabPosted'])){
725 if(isset($_POST['gotoLdap_inherit'])){
726 $this->gotoLdap_inherit = TRUE;
727 }else{
728 $this->gotoLdap_inherit = FALSE;
729 }
731 /* Save group radio buttons */
732 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
733 $this->bootmode= $_POST["bootmode"];
734 }
735 }
736 }
739 /* Save to LDAP */
740 function save()
741 {
743 /* Depending on the baseobject (Ogroup / WS) we
744 * use another set of objectClasses
745 * In case of WS itself, we use "array("GOhard", "FAIobject");"
746 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
747 */
748 if(isset($this->parent->by_object['ogroup'])){
749 $this->objectclasses = array("gotoWorkstationTemplate");
750 }elseif(isset($this->parent->by_object['workgeneric'])){
751 $this->objectclasses = array("GOhard");
752 }elseif(isset($this->parent->by_object['servgeneric'])){
753 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
754 }else{
755 msg_dialog::display(_("Fatal error"),
756 "Object Type Configuration is unknown. Please contact the GOsa developers.",
757 FATAL_ERROR_DIALOG);
758 exit();
759 }
761 /* Append FAI class */
762 if($this->fai_activated){
763 $this->objectclasses[] = "FAIobject";
764 }
766 /* Find proper terminal path for tftp configuration
767 FIXME: This is suboptimal when the default has changed to
768 another location! */
769 if (($this->gotoTerminalPath == "default")){
770 $ldap= $this->config->get_ldap_link();
772 /* Strip relevant part from dn, keep trailing ',' */
773 $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
774 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
776 /* Walk from top to base and try to load default values for
777 'gotoTerminalPath'. Abort when an entry is found. */
778 while (TRUE){
779 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
781 $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
782 $this->config->current['BASE'], array('gotoTerminalPath'));
783 $attrs= $ldap->fetch();
784 if (isset($attrs['gotoTerminalPath'])){
785 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
786 break;
787 }
789 /* Nothing left? */
790 if ($tmp == ""){
791 break;
792 }
793 }
794 }
796 if ($this->gotoKernelParameters == "") {
797 /* Add semi automatic values if empty */
798 // FIXME: LDAP Server may not be set here...
799 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
801 switch ($this->bootmode){
802 case "D":
803 $this->gotoKernelParameters.= " debug";
804 break;
805 case "G":
806 $this->gotoKernelParameters.= " splash=silent";
807 break;
808 }
809 }
811 plugin::save();
813 unset( $this->attrs['FAIrelease'] );
814 $str = "";
816 /* Skip FAI attribute handling if not necessary */
817 if($this->fai_activated && !$this->si_fai_action_failed){
818 if($this->FAIdebianMirror == "inherited"){
819 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
820 }else{
821 foreach($this->FAIclass as $class){
822 $str .= $class." ";
823 }
824 $str = trim($str);
825 if(empty($this->attrs['FAIclass'])){
826 $this->attrs['FAIclass'] = array();
827 }else{
828 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
829 }
830 }
831 }
833 /* Add missing arrays */
834 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
835 if (isset ($this->$val) && count ($this->$val) != 0){
837 $this->attrs["$val"]= array_unique($this->$val);
838 }
839 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
840 }
842 /* Prepare list of ldap servers */
843 $this->attrs['gotoLdapServer'] = array();
844 if(!$this->gotoLdap_inherit){
845 $i = 0;
846 foreach($this->gotoLdapServers as $server){
847 $i ++;
848 $this->attrs['gotoLdapServer'][] = $i.":".$server;
849 }
850 }
852 if ($this->attrs['gotoBootKernel'] == "default-inherited"){
853 $this->attrs['gotoBootKernel']= array();
854 }
856 /* if mirror == none stop saving this attribute */
857 if($this->FAIdebianMirror == "none"){
858 $this->FAIdebianMirror = "";
859 }
861 /* Get FAIstate from object, the generic tab could have changed it during execute */
862 $ldap= $this->config->get_ldap_link();
863 $ldap->cd($this->dn);
866 /* Skip FAI attribute handling if not necessary */
867 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
868 $ldap->cat($this->dn,array("FAIstate"));
869 $checkFAIstate = $ldap->fetch();
871 /* Remove FAI objects if no FAI class is selected */
872 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
873 $this->attrs['FAIclass'] = array();
874 $this->attrs['FAIdebianMirror'] = array();
875 }
876 }else{
878 /* Don't touch FAI objects if something went wrong with the si daemon.
879 */
880 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
881 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
882 }
884 /* prepare share settings */
885 $tmp = array();
886 foreach($this->gotoShares as $name => $settings){
887 $tmp2= split("\|",$name);
888 $name = $tmp2[0];
889 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
890 }
891 $this->attrs['gotoShare']=$tmp;
892 $this->cleanup();
893 $ldap->modify ($this->attrs);
894 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
896 if (!$ldap->success()){
897 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
898 }
899 $this->handle_post_events("modify");
901 /* Check if LDAP server has changed */
902 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
903 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
904 $o_queue = new gosaSupportDaemon();
905 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
906 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
907 $macs = array();
909 /* Get list of macAddresses
910 */
911 if(isset($this->parent->by_object['ogroup'])){
913 /* If we are an object group, add all member macs
914 */
915 $p = $this->parent->by_object['ogroup'];
916 foreach($p->memberList as $dn => $obj){
917 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
918 $macs[] = $p->objcache[$dn]['macAddress'];
919 }
920 }
921 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
923 /* We are a workstation. Add current mac.
924 */
925 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
926 if(!empty($mac)){
927 $macs[] = $mac;
928 }
929 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
931 /* We are a server. Add current mac.
932 */
933 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
934 if(!empty($mac)){
935 $macs[] = $mac;
936 }
937 }
939 /* Trigger event for all member objects
940 */
941 foreach($macs as $mac){
942 $tmp = new $evt['CLASS_NAME']($this->config);
943 $tmp->set_type(TRIGGERED_EVENT);
944 $tmp->add_targets(array($mac));
945 if(!$o_queue->append($tmp)){
946 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
947 }
948 }
949 }
950 }
951 }
954 /* Add value to array, check if unique */
955 function add_list (&$array, $value)
956 {
957 if ($value != ""){
958 $array[]= $value;
959 sort($array);
960 array_unique ($array);
961 }
962 }
965 /* Delete value to array, check if unique */
966 function del_list (&$array, $list)
967 {
968 $tmp= array();
969 foreach ($array as $mod){
970 if (!in_array($mod, $list)){
971 $tmp[]= $mod;
972 }
973 }
974 $array= $tmp;
975 }
977 /* Generate ListBox frindly output for the defined shares
978 * Possibly Add or remove an attribute here,
979 */
980 function printOutAssignedShares()
981 {
982 $a_return = array();
983 if(is_array($this->gotoShares)){
984 foreach($this->gotoShares as $share){
985 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
986 }
987 }
988 return($a_return);
989 }
993 function PrepareForCopyPaste($source)
994 {
995 plugin::PrepareForCopyPaste($source);
996 $source_o = new workstartup ($this->config, $source['dn']);
997 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
998 "gotoKernelParameters","gotoShares") as $attr){
999 $this->$attr = $source_o->$attr;
1000 }
1001 }
1004 function array_switch_item($ar,$from,$to)
1005 {
1006 if(!is_array($ar)){
1007 return(false);
1008 }
1009 if(!isset($ar[$from])){
1010 return(false);
1011 }
1012 if(!isset($ar[$to])){
1013 return(false);
1014 }
1016 $tmp = $ar[$from];
1017 $ar[$from] = $ar[$to];
1018 $ar[$to] = $tmp;
1019 return($ar);
1020 }
1023 /* Return plugin informations for acl handling */
1024 static function plInfo()
1025 {
1026 return (array(
1027 "plShortName" => _("Startup"),
1028 "plDescription" => _("System startup"),
1029 "plSelfModify" => FALSE,
1030 "plDepends" => array(),
1031 "plPriority" => 9,
1032 "plSection" => array("administration"),
1033 "plCategory" => array("workstation","server","ogroups"),
1035 "plProvidedAcls"=> array(
1036 "gotoLdapServer" => _("Ldap server"),
1037 "gotoBootKernel" => _("Boot kernel"),
1038 "gotoKernelParameters" => _("Kernel parameter"),
1040 "gotoModules" => _("Kernel modules"),
1041 "gotoShare" => _("Shares"),
1043 "FAIclass" => _("FAI classes"),
1044 "FAIdebianMirror" => _("Debian mirror"),
1045 "FAIrelease" => _("Debian release"),
1047 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1048 ));
1049 }
1052 /* Updates release dns
1053 * and reads all classes for the current release,
1054 * if not already done ($this->cache).
1055 */
1056 function update_fai_cache($first_call = FALSE)
1057 {
1058 $force = FALSE;
1059 if(!$this->si_active) return;
1060 $start = microtime(TRUE);
1062 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1064 $this->si_fai_action_failed = FALSE;
1066 /* Get the list of available servers and their releases.
1067 */
1068 if($force || !isset($this->cache['SERVERS'])){
1070 $o_queue = new gosaSupportDaemon();
1071 $tmp = $o_queue->FAI_get_server();
1072 if($o_queue->is_error()){
1073 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1074 $this->si_fai_action_failed = TRUE;
1075 $this->cache = array();
1076 return;
1077 }else{
1079 foreach($tmp as $entry){
1080 $rel = $entry['FAI_RELEASE'];
1081 $this->cache['SERVERS']['auto'][$rel] = $rel;
1082 $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1083 uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1084 uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1085 }
1086 }
1087 }
1089 /* Ensure that our selection is valid, else we get several PHP warnings
1090 if there is no FAI configuration at all.
1091 */
1092 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1093 $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1094 }
1096 /* Build up arrays, without checks */
1097 if(!$first_call){
1099 /* Check if the selected mirror is available */
1100 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1101 $this->FAIdebianMirror = "auto";
1102 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1103 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1104 }
1106 /* Check if the selected release is available */
1107 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1109 if($this->FAIrelease != ""){
1110 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1111 }
1112 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1113 }
1114 }
1116 /* Get classes for release from cache.
1117 * Or build cache
1118 */
1119 if($this->FAIdebianMirror == "inherited"){
1120 $release = $this->InheritedFAIrelease;
1121 }else{
1122 $release = $this->FAIrelease;
1123 }
1125 if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1127 /* Get the list of available servers and their releases.
1128 */
1129 $o_queue = new gosaSupportDaemon();
1130 $tmp = $o_queue->FAI_get_classes($release);
1131 $this->cache['CLASSES'][$release] = array();
1132 if($o_queue->is_error()){
1133 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1134 $this->si_fai_action_failed = TRUE;
1135 $this->cache=array();
1136 return;
1137 }else{
1138 foreach($tmp as $entry){
1139 $class = $entry['CLASS'];
1140 $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry);
1141 }
1142 }
1144 /* Add object caught from external hook
1145 */
1146 $lines= $this->GetHookElements();
1147 foreach ($lines as $hline){
1148 $entries= split(";", $hline);
1149 $server = $entries['0'];
1150 $url = $entries['1'];
1151 if (!empty($url)){
1153 /* Split releases */
1154 if (isset($entries[2])){
1155 $releases= split(",", $entries[2]);
1157 foreach ($releases as $release_data){
1158 $release_c = preg_replace('/:.*$/', '', $release_data);
1159 $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1160 $classes_c = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1162 if($release_c == $release){
1163 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1164 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1165 foreach ($classes_c as $class){
1166 if ($class != ""){
1167 $this->cache['CLASSES'][$release_c][$class]= array();
1168 }
1169 }
1170 }
1171 }
1172 }
1173 }
1174 }
1175 uksort($this->cache['SERVERS'], 'strnatcasecmp');
1177 /* Only add inherit option, if we are part in an object group
1178 */
1179 if($this->member_of_ogroup){
1180 $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1181 }
1182 }
1184 /* Get list of available kernel for this release
1185 */
1186 if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1188 if($force || !isset($this->cache['KERNELS'][$release])){
1189 $o_queue = new gosaSupportDaemon();
1190 $tmp = $o_queue->FAI_get_kernels($release);
1191 $this->cache['KERNELS'][$release] = array();
1192 foreach($this->gotoBootKernels as $name => $default){
1193 $this->cache['KERNELS'][$release][$name] = $default;
1194 }
1195 foreach($tmp as $kernel){
1196 if(empty($kernel)) continue;
1197 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1198 }
1199 ksort($this->cache['KERNELS'][$release]);
1200 }
1201 }
1204 /* This function return an array containing all
1205 * invalid classes for the selected server/release
1206 */
1207 function get_invalid_classes($classes)
1208 {
1209 $this->update_fai_cache();
1210 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1211 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1212 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1213 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1214 }else{
1215 $release_classes = array();
1216 }
1219 /* Detect all classes that are not valid
1220 * for the selected release
1221 */
1222 $NA = array();
1223 foreach($classes as $class){
1224 if(!isset($release_classes[$class])){
1225 $NA[] = $class;
1226 }
1227 }
1228 return($NA);
1229 }
1232 /* Get all selectable classes for the ui select box
1233 */
1234 function selectable_classes()
1235 {
1236 $this->update_fai_cache();
1238 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1239 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1240 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1241 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1242 }else{
1243 $classes = array();
1244 }
1246 $Abbr ="";
1247 $ret= array();
1248 foreach($classes as $class_name => $class_types){
1249 if(!in_array($class_name,$this->FAIclass)){
1250 foreach($class_types as $type){
1251 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1252 $Abbr .= $type['Abbr']." ";
1253 }
1254 }
1255 $ret[$class_name] = trim($Abbr);
1256 }
1257 }
1258 uksort($ret, 'strnatcasecmp');
1259 return($ret);
1260 }
1263 /* Analyse FAI object and return an array with usefull informations like
1264 * FAIobject type.
1265 */
1266 function analyse_fai_object($attr)
1267 {
1268 $tmp = array();
1269 switch($attr['TYPE']){
1271 case 'FAIpackageList':
1272 $tmp["Type"]= 'FAIpackageList';
1273 $tmp["Abbr"]= 'Pl';
1274 break;
1275 case 'FAItemplate':
1276 $tmp["Type"]= 'FAItemplate';
1277 $tmp["Abbr"]= 'T';
1278 break;
1279 case 'FAIvariable':
1280 $tmp["Type"]= 'FAIvariable';
1281 $tmp["Abbr"]= 'V';
1282 break;
1283 case 'FAIscript':
1284 $tmp["Type"]= 'FAIscript';
1285 $tmp["Abbr"]= 'S';
1286 break;
1287 case 'FAIhook':
1288 $tmp["Type"]= 'FAIhook';
1289 $tmp["Abbr"]= 'H';
1290 break;
1291 case 'FAIpartitionTable':
1292 $tmp["Type"]= 'FAIpartitionTable';
1293 $tmp["Abbr"]= 'Pt';
1294 break;
1295 case 'FAIprofile':
1296 $tmp["Type"]= 'FAIprofile';
1297 $tmp["Abbr"]= 'P';
1298 break;
1299 default: trigger_error("Unknown FAI object type!");;
1300 }
1301 return($tmp);
1302 }
1305 /* Return repository hook output, if possible.
1306 */
1307 function GetHookElements()
1308 {
1309 $ret = array();
1310 $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1311 if(!empty($cmd)){
1312 $res = shell_exec($cmd);
1313 $res2 = trim($res);
1314 if((!$res)){
1315 msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1316 }elseif(empty($res2)){
1317 msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG);
1318 }else{
1319 $tmp = split("\n",$res);
1320 foreach($tmp as $line){
1321 if(empty($line)) continue;
1322 $ret[]= $line;
1323 }
1324 }
1325 }
1326 return($ret);
1327 }
1330 /* This function creates the release name out of a dn
1331 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1332 */
1333 function dn_to_release_name($dn)
1334 {
1335 $relevant = preg_replace("/,".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$dn);
1336 $parts = array_reverse(split("\,",$relevant));
1337 $str ="";
1338 foreach($parts as $part){
1339 $str .= preg_replace("/^ou=/","",$part)."/";
1340 }
1341 return(preg_replace("/\/$/","",$str));
1342 }
1343 }
1345 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1346 ?>