1 <?php
2 class workstartup extends plugin
3 {
4 /* Ldap server list */
5 var $gotoLdapServers = array();
6 var $gotoLdapServerList = array();
7 var $gotoLdap_inherit = FALSE;
9 /* Generic terminal attributes */
10 # This is disabled as long there is no possiblilty to set these parameters
11 #var $bootmode = "G";
12 var $bootmode = "";
13 var $gotoBootKernel = "default-inherited";
14 var $gotoKernelParameters = "";
15 var $gotoLdapServer = "default-inherited";
16 var $gotoModules = array();
17 var $gotoAutoFs = array();
18 var $gotoFilesystem = array();
19 var $gotoTerminalPath = "";
20 var $gotoBootKernels = array();
22 /* attribute list for save action */
23 var $attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters",
24 "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
25 var $objectclasses = array("GOhard", "FAIobject");
27 /* Share */
28 var $gotoShares = array();// Currently Share Option
29 var $gotoShare = ""; // currently selected Share Option
30 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
31 var $gotoAvailableShares= array();// Available Shares for this account
33 /* Helper */
34 var $orig_dn = "";
35 var $ignore_account = TRUE;
37 /* FAI class selection */
38 var $FAIclass = array(); // The currently selected classes
39 var $FAIrelease = "";
40 var $FAIdebianMirror = "auto";
41 var $si_active = FALSE;
42 var $si_fai_action_failed = FALSE;
44 var $cache = array(); // Used as cache in fai mehtods
46 var $FAIstatus = "";
47 var $FAIclasses = array();
49 var $view_logged = FALSE;
51 /* FAI class selection */
52 var $InheritedFAIclass = array();
53 var $InheritedFAIrelease = "";
54 var $InheritedFAIdebianMirror= "auto";
56 var $CopyPasteVars = array("gotoModules","gotoShares");
57 var $fai_activated = FALSE;
58 var $o_group_dn = "";
59 var $member_of_ogroup = FALSE;
61 function workstartup (&$config, $dn= NULL, $parent= NULL)
62 {
63 /* Check if FAI is active */
64 $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
65 if(!empty($tmp) && class_available("faiManagement")){
66 $this->fai_activated = TRUE;
67 }else{
68 $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
69 $this->objectclasses = array("GOhard");
70 }
72 plugin::plugin ($config, $dn, $parent);
74 /* Check for si daemon */
75 $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
77 /* Check object group membership */
78 if(!isset($this->parent->by_object['ogroup'])){
79 $ldap = $this->config->get_ldap_link();
80 $ldap->cd ($this->config->current['BASE']);
81 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
82 if($ldap->count()){
83 $this->member_of_ogroup = TRUE;
84 $attrs = $ldap->fetch();
85 $this->o_group_dn = $attrs['dn'];
86 }
87 }
89 /* Creating a list of valid Mirrors
90 * none will not be saved to ldap.
91 */
92 $ldap = $this->config->get_ldap_link();
93 $ldap->cd($this->config->current['BASE']);
94 $ui = get_userinfo();
95 foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){
96 if($ui->get_category_permissions($data['dn'],"server",TRUE)){
97 for($i = 0; $i < $data['goLdapBase']['count']; $i ++){
98 $name = $data["cn"][0].":".$data["goLdapBase"][$i];
99 $this->gotoLdapServerList[]= $name;
100 }
101 }
102 }
104 /* Get list of assigned ldap servers
105 */
106 if(isset($this->attrs['gotoLdapServer'])){
107 unset($this->attrs['gotoLdapServer']['count']);
108 sort($this->attrs['gotoLdapServer']);
109 foreach($this->attrs['gotoLdapServer'] as $value){
110 $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
111 }
112 }
113 natcasesort($this->gotoLdapServerList);
115 if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
116 $this->gotoLdap_inherit = TRUE;
117 }
119 /* FAI Initialization
120 Skip this if FAI is not activated
121 */
122 if($this->fai_activated) {
124 /* Parse used FAIclasses (stored as string).
125 * The single classes are seperated by ' '.
126 * There is also the release type given, after first
127 * occurrence of ':'.
128 */
129 $this->FAIclass =array();
130 if(isset($this->attrs['FAIclass'][0])){
131 $tmp = explode(" ",$this->attrs['FAIclass'][0]);
132 $tmp2 =array();
134 foreach($tmp as $class){
135 if( ":" == $class[0] ) {
136 $this->FAIrelease = trim(substr($class, 1));
137 }else{
138 $tmp2[$class] = $class;
139 }
140 }
141 $this->FAIclass = $tmp2;
142 }
143 }
145 /* Get arrays */
146 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
147 if (isset($this->attrs["$val"]["count"])){
148 for ($i= 0; $i<$this->attrs["count"]; $i++){
149 if (isset($this->attrs["$val"][$i])){
150 array_push($this->$val, $this->attrs["$val"][$i]);
151 }
152 }
153 }
154 sort ($this->$val);
155 $this->$val= array_unique($this->$val);
156 }
158 /* Prepare Shares */
159 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
160 unset($this->attrs['gotoShare']['count']);
161 foreach($this->attrs['gotoShare'] as $share){
162 $tmp = $tmp2 = array();
163 $tmp = explode("|",$share);
164 $tmp2['server'] =$tmp[0];
165 $tmp2['name'] =$tmp[1];
166 $tmp2['mountPoint'] =$tmp[2];
167 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
168 }
169 }
171 $this->gotoShareSelections= $config->getShareList(true);
172 $this->gotoAvailableShares= $config->getShareList(false);
173 $tmp2 = array();
176 $this->orig_dn= $this->dn;
178 /* Handle inheritance value "default" */
179 if ($this->member_of_ogroup){
180 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
181 }
183 /* If we are member in an object group,
184 * we have to handle inherited values.
185 * So you can see what is inherited.
186 */
187 if ($this->member_of_ogroup){
189 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
190 $this->FAIdebianMirror = "inherited";
191 }
193 if($this->fai_activated){
194 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
195 }else{
196 $map= array("gotoBootKernel");
197 }
199 $ldap = $this->config->get_ldap_link();
200 $ldap->cat($this->o_group_dn);
201 $attrs= $ldap->fetch();
203 foreach ($map as $name){
204 if (!isset($attrs[$name][0])){
205 continue;
206 }
208 switch ($name){
209 case 'gotoBootKernel':
210 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
211 break;
213 case 'FAIclass':
214 $str = explode(":",$attrs[$name][0]);
215 $this->InheritedFAIclass = explode(" ",trim($str[0]));
216 $this->InheritedFAIrelease = trim($str[1]);
217 break;
219 case 'FAIdebianMirror':
220 $this->InheritedFAIdebianMirror = $attrs[$name][0];
221 break;
222 }
223 }
224 }
226 $this->update_fai_cache();
228 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
230 /* Check if the current mirror is available
231 */
232 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
233 if(count($this->FAIclass)){
234 msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
235 }
236 $this->FAIdebianMirror = "auto";
237 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
238 $this->cache['CLASSES'] = array();
239 $this->update_fai_cache();
240 }
242 /* Check if the current mirror is available
243 */
244 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
245 $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
246 if(count($this->FAIclass)){
247 msg_dialog::display(_("Error"), sprintf(_("FAI release '%s' is not available on mirror '%s' - setting to release '%s'!"), $this->FAIrelease, $this->FAIdebianMirror,$new_release), ERROR_DIALOG);
248 }
249 $this->FAIrelease = $new_release;
250 $this->cache['CLASSES'] = array();
251 $this->update_fai_cache();
252 }
253 }
256 // Prepare lists
257 $this->ldapList = new sortableListing(array(),array(), TRUE);
258 $this->ldapList->setDeleteable(true);
259 $this->ldapList->setEditable(false);
260 $this->ldapList->setWidth("100%");
261 $this->ldapList->setHeight("100px");
262 $this->ldapList->setHeader(array(_("LDAP server")));
263 $this->ldapList->setDefaultSortColumn(0);
265 $this->faiList = new sortableListing(array(),array(), TRUE);
266 $this->faiList->setDeleteable(true);
267 $this->faiList->setEditable(false);
268 $this->faiList->setWidth("100%");
269 $this->faiList->setHeight("160px");
270 $this->faiList->setColspecs(array('50%','50%'));
271 $this->faiList->setHeader(array(_("Name"),_("Classes")));
272 $this->faiList->setDefaultSortColumn(0);
274 }
277 function check()
278 {
279 $messages = array();
281 /* Call common method to give check the hook */
282 $messages= plugin::check();
284 /* If there are packages selected, but no mirror show error */
285 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
286 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
287 }
289 return($messages);
290 }
292 function execute()
293 {
294 /* Call parent execute */
295 plugin::execute();
297 if($this->is_account && !$this->view_logged){
298 $this->view_logged = TRUE;
299 new log("view","workstation/".get_class($this),$this->dn);
300 }
302 /* Do we represent a valid terminal? */
303 if (!$this->is_account && $this->parent === NULL){
304 $display= image("images/small-error.png")."<b>".msgPool::noValidExtension(_("workstation"))."</b>";
305 return ($display);
306 }
308 /* Add module */
309 if (isset ($_POST['add_module'])){
310 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
311 $this->add_list ($this->gotoModules, $_POST['module']);
312 }
313 }
315 /* Delete module */
316 if (isset ($_POST['delete_module'])){
317 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
318 $this->del_list ($this->gotoModules, $_POST['modules_list']);
319 }
320 }
322 /* FAI class management */
323 if($this->fai_activated){
324 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
325 $found = 0 ;
327 /* If this new class/profile will attach a second partition table
328 * to our list of classes, abort and show a message.
329 */
330 foreach($this->FAIclass as $name){
331 if(isset($this->FAIclassInfo[$name])){
332 foreach($this->FAIclassInfo[$name] as $atr){
333 if(isset($atr['obj'])){
334 if($atr['obj'] == "FAIpartitionTable"){
335 $found ++ ;
336 }
337 }
338 }
339 }
340 }
342 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
343 msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
344 }else{
345 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
346 }
347 }
350 $this->faiList->save_object();
351 $action = $this->faiList->getAction();
352 if($action['action'] == 'delete'){
353 $id = $this->faiList->getKey($action['targets'][0]);
354 unset($this->FAIclass[$id]);
355 }
356 if($action['action'] == 'reorder'){
357 $this->FAIclass= $this->faiList->getMaintainedData();
358 }
360 /* Move one used class class one position up or down */
361 if($this->acl_is_writeable("FAIclass")){
362 foreach($_POST as $name => $val){
365 if(preg_match("/fai_remove/i",$name)){
366 $value = postDecode(preg_replace("/fai_remove_/i","",$name));
367 unset($this->FAIclass[$value]);
368 }
369 }
370 }
372 /* Delete selected class from our list */
373 if($this->acl_is_writeable("FAIclass")){
374 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
375 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
376 unset($this->FAIclass[$_POST['FAIclassSel']]);
377 }
378 }
379 }
380 }// END fai handling
382 /* Show main page */
383 $smarty= get_smarty();
385 /* Assign ACLs to smarty */
386 $tmp = $this->plInfo();
387 foreach($tmp['plProvidedAcls'] as $name => $translation){
388 $smarty->assign($name."ACL",$this->getacl($name));
389 }
391 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
393 /* In this section server shares will be defined
394 * A user can select one of the given shares and a mount point
395 * and attach this combination to his setup.
396 */
397 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
398 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
400 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
401 * This entry will be, a combination of mountPoint and sharedefinitions
402 */
403 if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
404 /* We assign a share to this user, if we don't know where to mount the share */
405 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
406 msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
407 }else{
409 if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
410 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
411 $s_mount = $_POST['gotoShareMountPoint'];
412 /* Preparing the new assignment */
413 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
414 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
415 }
416 }
417 }
419 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
420 * If there is no defined share selected, we will abort the deletion without any message
421 */
422 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
423 unset($this->gotoShares[$_POST['gotoShare']]);
424 }
426 $smarty->assign("gotoShares",$this->printOutAssignedShares());
427 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
428 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
429 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
431 $this->ldapList->setAcl($this->getacl('gotoLdapServer'));
433 /* Add new ldap server to the list */
434 if($this->acl_is_writeable("gotoLdapServer") &&
435 !$this->gotoLdap_inherit &&
436 isset($_POST['add_ldap_server']) &&
437 isset($_POST['ldap_server_to_add'])){
438 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
439 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
440 if(!in_array($to_add,$this->gotoLdapServers)){
441 $this->gotoLdapServers[] = $to_add;
442 }
443 }
444 }
446 /* Move ldap servers up and down */
447 $this->ldapList->save_object();
448 $action = $this->ldapList->getAction();
449 if($action['action'] == 'reorder'){
450 $this->gotoLdapServers = array_values($this->ldapList->getMaintainedData());
451 }
452 if($action['action'] == 'delete'){
453 $id = $this->ldapList->getKey($action['targets'][0]);
454 $value = $this->gotoLdapServers[$id];
455 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
456 }
458 /* Add Entries */
459 $data = $lData = array();
460 foreach($this->gotoLdapServers as $key => $server){
461 $data[$key]=$server;
463 /* Announce missing entries */
464 if(!in_array($server,$this->gotoLdapServerList)){
465 $server = $server." <font style='color:red'>(missing)</font>";
466 }
468 /* Convert old style entry */
469 if (!preg_match('%:ldaps?://%', $server)){
470 $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
471 } else {
472 $server= preg_replace("/^[^:]+:/", "", $server);
473 $lData[$key] = array('data'=>array($server));
474 }
475 }
476 $this->ldapList->setListData($data,$lData);
477 $this->ldapList->update();
478 $smarty->assign("usePrototype", "true");
480 if($this->gotoLdap_inherit){
481 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
482 }else{
483 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
484 }
486 $list = array();
487 foreach($this->gotoLdapServerList as $key => $entry){
488 if(!in_array($entry,$this->gotoLdapServers)){
490 /* Convert old style entry */
491 if (!preg_match('%:ldap[s]*://%', $entry)){
492 $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
494 /* Beautify new style entries */
495 } else {
496 $entry= preg_replace("/^[^:]+:/", "", $entry);
497 }
499 $list[$key] = $entry;
500 }
501 }
502 $smarty->assign("gotoLdapServers", $this->ldapList->render());
503 $smarty->assign("gotoLdapServerList", $list);
504 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
505 $smarty->assign("JS", session::get('js'));
507 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
508 $smarty->assign("$val", $this->$val);
509 }
511 /* Values */
512 foreach(array("gotoBootKernel","gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
513 $smarty->assign($val, $this->$val);
514 }
516 $smarty->assign("fai_activated",$this->fai_activated);
518 /* Create FAI output */
519 $this->update_fai_cache();
520 $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
521 $smarty->assign("si_active",$this->si_active);
523 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
525 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
526 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
527 $smarty->assign("FAIrelease" , $this->FAIrelease);
528 $smarty->assign("FAIclasses" , $this->selectable_classes());
530 /* Get classes for release from cache.
531 * Or build cache
532 */
533 if($this->FAIdebianMirror == "inherited"){
534 $release = $this->InheritedFAIrelease;
535 }else{
536 $release = $this->FAIrelease;
537 }
539 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
540 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
542 /* Get classes */
543 if($this->FAIdebianMirror == "inherited"){
544 $tmp = $this->InheritedFAIclass;
545 }else{
546 $tmp = $this->FAIclass;
547 }
549 /* Get invalid classes */
550 $invalid = $this->get_invalid_classes($tmp);
551 $data = $lData = array();
553 /* Draw every single entry */
554 $i = 1;
555 if($this->acl_is_readable("FAIclass")){
556 foreach($tmp as $class){
558 /* Mark invalid classes. (Not in selected release)
559 */
560 $marker = "";
561 if(in_array_ics($class,$invalid)){
562 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
563 }
565 $i ++ ;
567 /* Get Description tag
568 * There may be several FAI objects with the same class name,
569 * use the description from FAIprofile, if possible.
570 */
571 $desc = "";
573 $objects = array(
574 "Pl" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png"),
575 "Pt" => array("IMG"=> "plugins/fai/images/fai_packages.png"),
576 "S" => array("IMG"=> "plugins/fai/images/fai_script.png"),
577 "V" => array("IMG"=> "plugins/fai/images/fai_variable.png"),
578 "H" => array("IMG"=> "plugins/fai/images/fai_hook.png"),
579 "P" => array("IMG"=> "plugins/fai/images/fai_profile.png"),
580 "T" => array("IMG"=> "plugins/fai/images/fai_template.png"));
582 if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
583 $desc ="";
584 foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
585 if(isset($types['Abbr'])){
586 $desc.= image($objects[$types['Abbr']]['IMG']);
587 if($types['Type'] == "FAIprofile"){
588 break;
589 }
590 }
591 }
592 }
593 if(!empty($desc)){
594 $desc = " ".trim($desc)."";
595 }
597 $data[$class] = $class;
598 $lData[$class] = array('data' => array($class,$desc));
599 }
600 }// END FAI output generation
601 }// END FAI output generation
603 $this->faiList->setAcl('rwcdm');
604 $this->faiList->setReorderable($this->FAIdebianMirror != "inherited");
605 $this->faiList->setListData($data,$lData);
606 $this->faiList->update();
608 $smarty->assign("FAIScriptlist", $this->faiList->render());
610 /* Radio button group */
611 if (preg_match("/G/", $this->bootmode)) {
612 $smarty->assign("graphicalbootup", "checked");
613 } else {
614 $smarty->assign("graphicalbootup", "");
615 }
616 if (preg_match("/T/", $this->bootmode)) {
617 $smarty->assign("textbootup", "checked");
618 } else {
619 $smarty->assign("textbootup", "");
620 }
621 if (preg_match("/D/", $this->bootmode)) {
622 $smarty->assign("debugbootup", "checked");
623 } else {
624 $smarty->assign("debugbootup", "");
625 }
627 /* Show main page */
628 $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters);
629 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
630 }
633 function remove_from_parent()
634 {
635 $this->handle_post_events("remove");
636 new log("remove","workstation/".get_class($this),$this->dn);
637 }
640 /* Save data to object */
641 function save_object()
642 {
643 $old_mirror = $this->FAIdebianMirror;
644 plugin::save_object();
646 /* Update release */
647 if($old_mirror != $this->FAIdebianMirror){
648 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
649 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
650 }
651 }
653 if(isset($_POST['WorkstationStarttabPosted'])){
654 if(isset($_POST['gotoLdap_inherit'])){
655 $this->gotoLdap_inherit = TRUE;
656 }else{
657 $this->gotoLdap_inherit = FALSE;
658 }
660 /* Save group radio buttons */
661 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
662 $this->bootmode= $_POST["bootmode"];
663 }
664 }
665 }
668 /* Save to LDAP */
669 function save()
670 {
672 /* Depending on the baseobject (Ogroup / WS) we
673 * use another set of objectClasses
674 * In case of WS itself, we use "array("GOhard", "FAIobject");"
675 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
676 */
677 if(isset($this->parent->by_object['ogroup'])){
678 $this->objectclasses = array("gotoWorkstationTemplate");
679 }elseif(isset($this->parent->by_object['workgeneric'])){
680 $this->objectclasses = array("GOhard");
681 }elseif(isset($this->parent->by_object['servgeneric'])){
682 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
683 }else{
684 msg_dialog::display(_("Fatal error"),
685 "Object Type Configuration is unknown. Please contact the GOsa developers.",
686 FATAL_ERROR_DIALOG);
687 exit();
688 }
690 /* Append FAI class */
691 if($this->fai_activated){
692 $this->objectclasses[] = "FAIobject";
693 }
695 /* Find proper terminal path for tftp configuration
696 FIXME: This is suboptimal when the default has changed to
697 another location! */
698 if (($this->gotoTerminalPath == "default")){
699 $ldap= $this->config->get_ldap_link();
701 /* Strip relevant part from dn, keep trailing ',' */
702 $tmp= preg_replace("/^cn=[^,]+,".preg_quote(get_ou('terminalRDN'), '/')."/i", "", $this->dn);
703 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
705 /* Walk from top to base and try to load default values for
706 'gotoTerminalPath'. Abort when an entry is found. */
707 while (TRUE){
708 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
710 $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
711 $this->config->current['BASE'], array('gotoTerminalPath'));
712 $attrs= $ldap->fetch();
713 if (isset($attrs['gotoTerminalPath'])){
714 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
715 break;
716 }
718 /* Nothing left? */
719 if ($tmp == ""){
720 break;
721 }
722 }
723 }
725 plugin::save();
727 unset( $this->attrs['FAIrelease'] );
728 $str = "";
730 /* Skip FAI attribute handling if not necessary */
731 if($this->fai_activated && !$this->si_fai_action_failed){
732 if($this->FAIdebianMirror == "inherited"){
733 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
734 }else{
735 foreach($this->FAIclass as $class){
736 $str .= $class." ";
737 }
738 $str = trim($str);
739 if(empty($this->attrs['FAIclass'])){
740 $this->attrs['FAIclass'] = array();
741 }else{
742 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
743 }
744 }
745 }
747 /* Add missing arrays */
748 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
749 if (isset ($this->$val) && count ($this->$val) != 0){
751 $this->attrs["$val"]= array_unique($this->$val);
752 }
753 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
754 }
756 /* Prepare list of ldap servers */
757 $this->attrs['gotoLdapServer'] = array();
758 if(!$this->gotoLdap_inherit){
759 $i = 0;
760 foreach($this->gotoLdapServers as $server){
761 $i ++;
762 $this->attrs['gotoLdapServer'][] = $i.":".$server;
763 }
764 }
766 if ($this->attrs['gotoBootKernel'] == "default-inherited"){
767 $this->attrs['gotoBootKernel']= array();
768 }
770 /* if mirror == none stop saving this attribute */
771 if($this->FAIdebianMirror == "none"){
772 $this->FAIdebianMirror = "";
773 }
775 /* Get FAIstate from object, the generic tab could have changed it during execute */
776 $ldap= $this->config->get_ldap_link();
777 $ldap->cd($this->dn);
780 /* Skip FAI attribute handling if not necessary */
781 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
782 $ldap->cat($this->dn,array("FAIstate"));
783 $checkFAIstate = $ldap->fetch();
785 /* Remove FAI objects if no FAI class is selected */
786 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
787 $this->attrs['FAIclass'] = array();
788 $this->attrs['FAIdebianMirror'] = array();
789 }
790 }else{
792 /* Don't touch FAI objects if something went wrong with the si daemon.
793 */
794 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
795 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
796 }
798 /* prepare share settings */
799 $tmp = array();
800 foreach($this->gotoShares as $name => $settings){
801 $tmp2= explode("|",$name);
802 $name = $tmp2[0];
803 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
804 }
805 $this->attrs['gotoShare']=$tmp;
806 $this->cleanup();
807 $ldap->modify ($this->attrs);
808 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
810 if (!$ldap->success()){
811 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
812 }
813 $this->handle_post_events("modify");
815 /* Check if LDAP server has changed */
816 if ($this->si_active && (isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent") || $this->gotoLdap_inherit)){
817 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
818 $o_queue = new gosaSupportDaemon();
819 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
820 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
821 $macs = array();
823 /* Get list of macAddresses
824 */
825 if(isset($this->parent->by_object['ogroup'])){
827 /* If we are an object group, add all member macs
828 */
829 $p = $this->parent->by_object['ogroup'];
830 foreach($p->memberList as $dn => $obj){
831 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
832 $macs[] = $p->objcache[$dn]['macAddress'];
833 }
834 }
835 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
837 /* We are a workstation. Add current mac.
838 */
839 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
840 if(!empty($mac)){
841 $macs[] = $mac;
842 }
843 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
845 /* We are a server. Add current mac.
846 */
847 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
848 if(!empty($mac)){
849 $macs[] = $mac;
850 }
851 }
853 /* Trigger event for all member objects
854 */
855 foreach($macs as $mac){
856 $tmp = new $evt['CLASS_NAME']($this->config);
857 $tmp->set_type(TRIGGERED_EVENT);
858 $tmp->add_targets(array($mac));
859 if(!$o_queue->append($tmp)){
860 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
861 }
862 }
863 }
864 }
865 }
868 /* Add value to array, check if unique */
869 function add_list (&$array, $value)
870 {
871 if ($value != ""){
872 $array[]= $value;
873 sort($array);
874 array_unique ($array);
875 }
876 }
879 /* Delete value to array, check if unique */
880 function del_list (&$array, $list)
881 {
882 $tmp= array();
883 foreach ($array as $mod){
884 if (!in_array($mod, $list)){
885 $tmp[]= $mod;
886 }
887 }
888 $array= $tmp;
889 }
891 /* Generate ListBox frindly output for the defined shares
892 * Possibly Add or remove an attribute here,
893 */
894 function printOutAssignedShares()
895 {
896 $a_return = array();
897 if(is_array($this->gotoShares)){
898 foreach($this->gotoShares as $share){
899 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
900 }
901 }
902 return($a_return);
903 }
907 function PrepareForCopyPaste($source)
908 {
909 plugin::PrepareForCopyPaste($source);
910 $source_o = new workstartup ($this->config, $source['dn']);
911 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
912 "gotoKernelParameters","gotoShares","gotoLdapServers","gotoLdapServerList",
913 "gotoLdap_inherit") as $attr){
914 $this->$attr = $source_o->$attr;
915 }
916 }
919 function array_switch_item($ar,$from,$to)
920 {
921 if(!is_array($ar)){
922 return(false);
923 }
924 if(!isset($ar[$from])){
925 return(false);
926 }
927 if(!isset($ar[$to])){
928 return(false);
929 }
931 $tmp = $ar[$from];
932 $ar[$from] = $ar[$to];
933 $ar[$to] = $tmp;
934 return($ar);
935 }
938 /* Return plugin informations for acl handling */
939 static function plInfo()
940 {
941 return (array(
942 "plShortName" => _("Startup"),
943 "plDescription" => _("System startup"),
944 "plSelfModify" => FALSE,
945 "plDepends" => array(),
946 "plPriority" => 9,
947 "plSection" => array("administration"),
948 "plCategory" => array("workstation","server","ogroups"),
950 "plProvidedAcls"=> array(
951 "gotoLdapServer" => _("Ldap server"),
952 "gotoBootKernel" => _("Boot kernel"),
953 "bootmode" => _("Boot mode"),
954 "gotoKernelParameters" => _("Kernel parameter"),
956 "gotoModules" => _("Kernel modules"),
957 "gotoShare" => _("Shares"),
959 "FAIclass" => _("FAI classes"),
960 "FAIdebianMirror" => _("Debian mirror"),
961 "FAIrelease" => _("Debian release"),
963 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
964 ));
965 }
968 /* Updates release dns
969 * and reads all classes for the current release,
970 * if not already done ($this->cache).
971 */
972 function update_fai_cache($first_call = FALSE)
973 {
974 $force = FALSE;
975 if(!$this->si_active) return;
976 $start = microtime(TRUE);
978 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
980 $this->si_fai_action_failed = FALSE;
982 /* Get the list of available servers and their releases.
983 */
984 if($force || !isset($this->cache['SERVERS'])){
986 $o_queue = new gosaSupportDaemon();
987 $tmp = $o_queue->FAI_get_server();
988 if($o_queue->is_error()){
989 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
990 $this->si_fai_action_failed = TRUE;
991 $this->cache = array();
992 return;
993 }else{
995 foreach($tmp as $entry){
996 $rel = $entry['FAI_RELEASE'];
997 $this->cache['SERVERS']['auto'][$rel] = $rel;
998 $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
999 uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1000 uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1001 }
1002 }
1003 }
1005 /* Ensure that our selection is valid, else we get several PHP warnings
1006 if there is no FAI configuration at all.
1007 */
1008 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1009 $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1010 }
1012 /* Build up arrays, without checks */
1013 if(!$first_call){
1015 /* Check if the selected mirror is available */
1016 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1017 $this->FAIdebianMirror = "auto";
1018 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1019 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1020 }
1022 /* Check if the selected release is available */
1023 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1025 if($this->FAIrelease != ""){
1026 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1027 }
1028 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1029 }
1030 }
1032 /* Get classes for release from cache.
1033 * Or build cache
1034 */
1035 if($this->FAIdebianMirror == "inherited"){
1036 $release = $this->InheritedFAIrelease;
1037 }else{
1038 $release = $this->FAIrelease;
1039 }
1041 if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1043 /* Get the list of available servers and their releases.
1044 */
1045 $o_queue = new gosaSupportDaemon();
1046 $tmp = $o_queue->FAI_get_classes($release);
1048 $this->cache['CLASSES'][$release] = array();
1049 if($o_queue->is_error()){
1050 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1051 $this->si_fai_action_failed = TRUE;
1052 $this->cache=array();
1053 return;
1054 }else{
1055 foreach($tmp as $entry){
1056 $class = $entry['CLASS'];
1057 $this->cache['CLASSES'][$release][$class][] = $this->analyse_fai_object($entry);
1058 }
1059 }
1061 /* Add object caught from external hook
1062 */
1063 $lines= $this->GetHookElements();
1064 foreach ($lines as $hline){
1065 $entries= explode(";", $hline);
1066 $server = $entries['0'];
1067 $url = $entries['1'];
1068 if (!empty($url)){
1070 /* Split releases */
1071 if (isset($entries[2])){
1072 $releases= explode(",", $entries[2]);
1074 foreach ($releases as $release_data){
1075 $release_c = preg_replace('/:.*$/', '', $release_data);
1076 $sections_c = explode(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1077 $classes_c = explode('|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1079 if($release_c == $release){
1080 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1081 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1082 foreach ($classes_c as $class){
1083 if ($class != ""){
1084 $this->cache['CLASSES'][$release_c][$class]= array();
1085 }
1086 }
1087 }
1088 }
1089 }
1090 }
1091 }
1092 uksort($this->cache['SERVERS'], 'strnatcasecmp');
1094 /* Only add inherit option, if we are part in an object group
1095 */
1096 if($this->member_of_ogroup){
1097 $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1098 }
1099 }
1101 /* Get list of available kernel for this release
1102 */
1103 if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1105 if($force || !isset($this->cache['KERNELS'][$release])){
1106 $o_queue = new gosaSupportDaemon();
1107 $tmp = $o_queue->FAI_get_kernels($release);
1108 $this->cache['KERNELS'][$release] = array();
1109 foreach($this->gotoBootKernels as $name => $default){
1110 $this->cache['KERNELS'][$release][$name] = $default;
1111 }
1112 foreach($tmp as $kernel){
1113 if(empty($kernel)) continue;
1114 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1115 }
1116 ksort($this->cache['KERNELS'][$release]);
1117 }
1118 }
1121 /* This function return an array containing all
1122 * invalid classes for the selected server/release
1123 */
1124 function get_invalid_classes($classes)
1125 {
1126 $this->update_fai_cache();
1127 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1128 $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1129 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1130 $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1131 }else{
1132 $release_classes = array();
1133 }
1136 /* Detect all classes that are not valid
1137 * for the selected release
1138 */
1139 $NA = array();
1140 foreach($classes as $class){
1141 if(!isset($release_classes[$class])){
1142 $NA[] = $class;
1143 }
1144 }
1145 return($NA);
1146 }
1149 /* Get all selectable classes for the ui select box
1150 */
1151 function selectable_classes()
1152 {
1153 $this->update_fai_cache();
1155 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1156 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1157 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1158 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1159 }else{
1160 $classes = array();
1161 }
1163 $Abbr ="";
1164 $ret= array();
1165 foreach($classes as $class_name => $class_types){
1166 if(!in_array($class_name,$this->FAIclass)){
1167 $Abbr = "";
1168 foreach($class_types as $type){
1169 if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1170 $Abbr .= $type['Abbr']." ";
1171 }
1172 }
1173 $ret[$class_name] = trim($Abbr);
1174 }
1175 }
1176 uksort($ret, 'strnatcasecmp');
1177 return($ret);
1178 }
1181 /* Analyse FAI object and return an array with usefull informations like
1182 * FAIobject type.
1183 */
1184 function analyse_fai_object($attr)
1185 {
1186 $tmp = array();
1187 switch($attr['TYPE']){
1189 case 'FAIpackageList':
1190 $tmp["Type"]= 'FAIpackageList';
1191 $tmp["Abbr"]= 'Pl';
1192 break;
1193 case 'FAItemplate':
1194 $tmp["Type"]= 'FAItemplate';
1195 $tmp["Abbr"]= 'T';
1196 break;
1197 case 'FAIvariable':
1198 $tmp["Type"]= 'FAIvariable';
1199 $tmp["Abbr"]= 'V';
1200 break;
1201 case 'FAIscript':
1202 $tmp["Type"]= 'FAIscript';
1203 $tmp["Abbr"]= 'S';
1204 break;
1205 case 'FAIhook':
1206 $tmp["Type"]= 'FAIhook';
1207 $tmp["Abbr"]= 'H';
1208 break;
1209 case 'FAIpartitionTable':
1210 $tmp["Type"]= 'FAIpartitionTable';
1211 $tmp["Abbr"]= 'Pt';
1212 break;
1213 case 'FAIprofile':
1214 $tmp["Type"]= 'FAIprofile';
1215 $tmp["Abbr"]= 'P';
1216 break;
1217 default: trigger_error("Unknown FAI object type!");;
1218 }
1219 return($tmp);
1220 }
1223 /* Return repository hook output, if possible.
1224 */
1225 function GetHookElements()
1226 {
1227 $ret = array();
1228 $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1229 if(!empty($cmd)){
1230 $res = shell_exec($cmd);
1231 $res2 = trim($res);
1232 if((!$res)){
1233 msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1234 }elseif(empty($res2)){
1235 msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG);
1236 }else{
1237 $tmp = preg_split("/\n/",$res);
1238 foreach($tmp as $line){
1239 if(empty($line)) continue;
1240 $ret[]= $line;
1241 }
1242 }
1243 }
1244 return($ret);
1245 }
1248 /* This function creates the release name out of a dn
1249 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1250 */
1251 function dn_to_release_name($dn)
1252 {
1253 $relevant = preg_replace("/,".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$dn);
1254 $parts = array_reverse(explode(",",$relevant));
1255 $str ="";
1256 foreach($parts as $part){
1257 $str .= preg_replace("/^ou=/","",$part)."/";
1258 }
1259 return(preg_replace("/\/$/","",$str));
1260 }
1261 }
1263 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1264 ?>