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", "FAIstate", "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 $FAIstate = "";
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) && class_available("faiManagement")){
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 = $this->config->get_cfg_value("gosaSupportURI") != "";
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 $ui = get_userinfo();
94 foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){
95 if($ui->get_category_permissions($data['dn'],"server",TRUE)){
96 for($i = 0; $i < $data['goLdapBase']['count']; $i ++){
97 $name = $data["cn"][0].":".$data["goLdapBase"][$i];
98 $this->gotoLdapServerList[]= $name;
99 }
100 }
101 }
103 /* Get list of assigned ldap servers
104 */
105 if(isset($this->attrs['gotoLdapServer'])){
106 unset($this->attrs['gotoLdapServer']['count']);
107 sort($this->attrs['gotoLdapServer']);
108 foreach($this->attrs['gotoLdapServer'] as $value){
109 $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
110 }
111 }
112 natcasesort($this->gotoLdapServerList);
114 if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
115 $this->gotoLdap_inherit = TRUE;
116 }
118 /* FAI Initialization
119 Skip this if FAI is not activated
120 */
121 if($this->fai_activated) {
123 /* Parse used FAIclasses (stored as string).
124 * The single classes are seperated by ' '.
125 * There is also the release type given, after first
126 * occurrence of ':'.
127 */
128 $this->FAIclass =array();
129 if(isset($this->attrs['FAIclass'][0])){
130 $tmp = split(" ",$this->attrs['FAIclass'][0]);
131 $tmp2 =array();
133 foreach($tmp as $class){
134 if( ":" == $class[0] ) {
135 $this->FAIrelease = trim(substr($class, 1));
136 }else{
137 $tmp2[$class] = $class;
138 }
139 }
140 $this->FAIclass = $tmp2;
141 }
142 }
144 /* Get arrays */
145 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
146 if (isset($this->attrs["$val"]["count"])){
147 for ($i= 0; $i<$this->attrs["count"]; $i++){
148 if (isset($this->attrs["$val"][$i])){
149 array_push($this->$val, $this->attrs["$val"][$i]);
150 }
151 }
152 }
153 sort ($this->$val);
154 $this->$val= array_unique($this->$val);
155 }
157 /* Prepare Shares */
158 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
159 unset($this->attrs['gotoShare']['count']);
160 foreach($this->attrs['gotoShare'] as $share){
161 $tmp = $tmp2 = array();
162 $tmp = split("\|",$share);
163 $tmp2['server'] =$tmp[0];
164 $tmp2['name'] =$tmp[1];
165 $tmp2['mountPoint'] =$tmp[2];
166 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
167 }
168 }
170 $this->gotoShareSelections= $config->getShareList(true);
171 $this->gotoAvailableShares= $config->getShareList(false);
172 $tmp2 = array();
175 $this->orig_dn= $this->dn;
177 /* Handle inheritance value "default" */
178 if ($this->member_of_ogroup){
179 $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
180 }
182 /* If we are member in an object group,
183 * we have to handle inherited values.
184 * So you can see what is inherited.
185 */
186 if ($this->member_of_ogroup){
188 if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
189 $this->FAIdebianMirror = "inherited";
190 }
192 if($this->fai_activated){
193 $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
194 }else{
195 $map= array("gotoBootKernel");
196 }
198 $ldap = $this->config->get_ldap_link();
199 $ldap->cat($this->o_group_dn);
200 $attrs= $ldap->fetch();
202 foreach ($map as $name){
203 if (!isset($attrs[$name][0])){
204 continue;
205 }
207 switch ($name){
208 case 'gotoBootKernel':
209 $this->gotoBootKernels['default-inherited']= _("inherited").' ['.$attrs[$name][0].']' ;
210 break;
212 case 'FAIclass':
213 $str = split(":",$attrs[$name][0]);
214 $this->InheritedFAIclass = split("\ ",trim($str[0]));
215 $this->InheritedFAIrelease = trim($str[1]);
216 break;
218 case 'FAIdebianMirror':
219 $this->InheritedFAIdebianMirror = $attrs[$name][0];
220 break;
221 }
222 }
223 }
225 $this->update_fai_cache();
227 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
229 /* Check if the current mirror is available
230 */
231 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
232 if(count($this->FAIclass)){
233 msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
234 }
235 $this->FAIdebianMirror = "auto";
236 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
237 $this->cache['CLASSES'] = array();
238 $this->update_fai_cache();
239 }
241 /* Check if the current mirror is available
242 */
243 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
244 $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
245 if(count($this->FAIclass)){
246 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);
247 }
248 $this->FAIrelease = $new_release;
249 $this->cache['CLASSES'] = array();
250 $this->update_fai_cache();
251 }
252 }
253 }
256 function check()
257 {
258 $messages = array();
260 /* Call common method to give check the hook */
261 $messages= plugin::check();
263 /* If there are packages selected, but no mirror show error */
264 if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
265 $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
266 }
268 return($messages);
269 }
271 function execute()
272 {
273 /* Call parent execute */
274 plugin::execute();
276 if($this->is_account && !$this->view_logged){
277 $this->view_logged = TRUE;
278 new log("view","workstation/".get_class($this),$this->dn);
279 }
281 /* Do we represent a valid terminal? */
282 if (!$this->is_account && $this->parent === NULL){
283 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
284 msgPool::noValidExtension(_("workstation"))."</b>";
285 return ($display);
286 }
288 /* Add module */
289 if (isset ($_POST['add_module'])){
290 if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
291 $this->add_list ($this->gotoModules, $_POST['module']);
292 }
293 }
295 /* Delete module */
296 if (isset ($_POST['delete_module'])){
297 if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
298 $this->del_list ($this->gotoModules, $_POST['modules_list']);
299 }
300 }
302 /* FAI class management */
303 if($this->fai_activated){
304 if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
305 $found = 0 ;
307 /* If this new class/profile will attach a second partition table
308 * to our list of classes, abort and show a message.
309 */
310 foreach($this->FAIclass as $name){
311 # FIXME: Where does FAIclassInfo come from??
312 if(isset($this->FAIclassInfo[$name])){
313 foreach($this->FAIclassInfo[$name] as $atr){
314 if(isset($atr['obj'])){
315 if($atr['obj'] == "FAIpartitionTable"){
316 $found ++ ;
317 }
318 }
319 }
320 }
321 }
323 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
324 msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
325 }else{
326 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
327 }
328 }
330 $sort = false;
332 /* Move one used class class one position up or down */
333 if($this->acl_is_writeable("FAIclass")){
334 foreach($_POST as $name => $val){
336 $sort_type = false;
337 if((preg_match("/sort_up/",$name))&&(!$sort)){
338 $sort_type = "sort_up_";
339 }
340 if((preg_match("/sort_down/",$name))&&(!$sort)){
341 $sort_type = "sort_down_";
342 }
344 if(($sort_type)&&(!$sort)){
345 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
346 $sort = true;
348 $last = -1;
349 $change_down = -1;
351 /* Create array with numeric index */
352 $tmp = array();
353 foreach($this->FAIclass as $class){
354 $tmp [] = $class;
355 }
357 /* Walk trough array */
358 foreach($tmp as $key => $faiName){
359 if($faiName == $value){
360 if($sort_type == "sort_up_"){
361 if($last != -1){
362 $change_down= $last;
363 }
364 }else{
365 if(isset($tmp[$key+1])){
366 $change_down = $key;
367 }
368 }
369 }
370 $last = $key;
371 }
373 $tmp2 = array();
374 $skip = false;
376 foreach($tmp as $ky => $vl){
378 if($ky == $change_down){
379 $skip = $vl;
380 }else{
381 $tmp2[$vl] = $vl;
382 }
383 if(($skip != false)&&($ky != $change_down)){
384 $tmp2[$skip] = $skip;
385 $skip =false;
386 }
387 }
388 $this->FAIclass = $tmp2;
389 }
391 if(preg_match("/fai_remove/i",$name)){
392 $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
393 unset($this->FAIclass[$value]);
394 if($this->FAIclass == array()){
395 /* class list is emtpy. Check whether the system is part of an object group and set
396 the FAI mirror to "inherited" in this case. */
397 if ($this->member_of_ogroup){
398 $this->FAIdebianMirror = "inherited";
399 }
400 }
401 }
402 }
403 }
405 /* Delete selected class from our list */
406 if($this->acl_is_writeable("FAIclass")){
407 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
408 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
409 unset($this->FAIclass[$_POST['FAIclassSel']]);
410 }
411 }
412 }
413 }// END fai handling
415 /* Show main page */
416 $smarty= get_smarty();
418 /* Assign ACLs to smarty */
419 $tmp = $this->plInfo();
420 foreach($tmp['plProvidedAcls'] as $name => $translation){
421 $smarty->assign($name."ACL",$this->getacl($name));
422 }
424 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
426 /* In this section server shares will be defined
427 * A user can select one of the given shares and a mount point
428 * and attach this combination to his setup.
429 */
430 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
431 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
433 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
434 * This entry will be, a combination of mountPoint and sharedefinitions
435 */
436 if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
437 /* We assign a share to this user, if we don't know where to mount the share */
438 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
439 msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
440 }else{
442 if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
443 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
444 $s_mount = $_POST['gotoShareMountPoint'];
445 /* Preparing the new assignment */
446 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
447 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
448 }
449 }
450 }
452 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
453 * If there is no defined share selected, we will abort the deletion without any message
454 */
455 if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
456 unset($this->gotoShares[$_POST['gotoShare']]);
457 }
459 $smarty->assign("gotoShares",$this->printOutAssignedShares());
460 $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
461 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
462 $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
464 /* Create divSelectBox for ldap server selection
465 */
466 $SelectBoxLdapServer = new divSelectBox("LdapServer");
467 $SelectBoxLdapServer->SetHeight(130);
469 /* Add new ldap server to the list */
470 if($this->acl_is_writeable("gotoLdapServer") &&
471 !$this->gotoLdap_inherit &&
472 isset($_POST['add_ldap_server']) &&
473 isset($_POST['ldap_server_to_add'])){
474 if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
475 $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
476 if(!in_array($to_add,$this->gotoLdapServers)){
477 $this->gotoLdapServers[] = $to_add;
478 }
479 }
480 }
482 /* Move ldap servers up and down */
483 if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
484 foreach($_POST as $name => $value){
485 if(preg_match("/sort_ldap_up_/",$name)){
486 $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
487 $from = $id;
488 $to = $id -1;
489 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
490 if($tmp){
491 $this->gotoLdapServers = $tmp;
492 }
493 break;
494 }
495 if(preg_match("/sort_ldap_down_/",$name)){
496 $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
497 $from = $id;
498 $to = $id +1;
499 $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
500 if($tmp){
501 $this->gotoLdapServers = $tmp;
502 }
503 break;
504 }
505 if(preg_match("/gotoLdapRemove_/",$name)){
506 $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
507 $value = $this->gotoLdapServers[$id];
508 $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
509 break;
510 }
511 }
512 }
514 /* Add Entries */
515 if($this->acl_is_readable("gotoLdapServer")){
517 foreach($this->gotoLdapServers as $key => $server){
519 /* Announce missing entries */
520 if(!in_array($server,$this->gotoLdapServerList)){
521 $server = $server." <font style='color:red'>(missing)</font>";
522 }
524 /* Convert old style entry */
525 if (!preg_match('%:ldaps?://%', $server)){
526 $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
528 /* Beautify new style entries */
529 } else {
530 $server= preg_replace("/^[^:]+:/", "", $server);
531 }
533 $SelectBoxLdapServer->AddEntry(
534 array(array("string" => $server),
535 array("string" =>
536 "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'> ".
537 "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'> ".
538 "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
539 "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
540 }
541 }
543 if($this->gotoLdap_inherit){
544 $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
545 }else{
546 $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
547 }
549 $list = array();
550 foreach($this->gotoLdapServerList as $key => $entry){
551 if(!in_array($entry,$this->gotoLdapServers)){
553 /* Convert old style entry */
554 if (!preg_match('%:ldap[s]*://%', $entry)){
555 $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
557 /* Beautify new style entries */
558 } else {
559 $entry= preg_replace("/^[^:]+:/", "", $entry);
560 }
562 $list[$key] = $entry;
563 }
564 }
565 $smarty->assign("gotoLdapServers", $SelectBoxLdapServer->DrawList());
566 $smarty->assign("gotoLdapServerList", $list);
567 $smarty->assign("gotoLdap_inherit", $this->gotoLdap_inherit);
568 $smarty->assign("JS", session::get('js'));
570 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
571 $smarty->assign("$val", $this->$val);
572 }
574 /* Values */
575 foreach(array("gotoBootKernel","gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
576 $smarty->assign($val, $this->$val);
577 }
579 $smarty->assign("fai_activated",$this->fai_activated);
581 /* Create FAI output */
582 $this->update_fai_cache();
583 $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
584 $smarty->assign("si_active",$this->si_active);
586 $div = new divSelectBox("WSFAIscriptClasses");
587 $div -> SetHeight("110");
589 if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
591 $smarty->assign("FAIservers" , $this->cache['SERVERS']);
592 $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
593 $smarty->assign("FAIrelease" , $this->FAIrelease);
594 $smarty->assign("FAIclasses" , $this->selectable_classes());
596 /* Get classes for release from cache.
597 * Or build cache
598 */
599 if($this->FAIdebianMirror == "inherited"){
600 $release = $this->InheritedFAIrelease;
601 }else{
602 $release = $this->FAIrelease;
603 }
605 $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
606 $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
608 $str_empty = " <img src='images/empty.png' alt=\"\" width='7'>";
609 if($this->acl_is_writeable("FAIclass")){
610 $str_up = " <input type='image' src='images/lists/sort-up.png' name='sort_up_%s' value='%s'>";
611 $str_down = " <input type='image' src='images/lists/sort-down.png' name='sort_down_%s' value='%s'>";
612 $str_remove = " <input type='image' src='images/lists/trash.png' name='fai_remove_%s' value='%s'>";
613 }else{
614 $str_up=$str_down=$str_remove=$str_empty;
615 }
617 /* Get classes */
618 if($this->FAIdebianMirror == "inherited"){
619 $tmp = $this->InheritedFAIclass;
620 }else{
621 $tmp = $this->FAIclass;
622 }
624 /* Get invalid classes */
625 $invalid = $this->get_invalid_classes($tmp);
627 /* Draw every single entry */
628 $i = 1;
629 if($this->acl_is_readable("FAIclass")){
630 foreach($tmp as $class){
631 /* Mark invalid classes. (Not in selected release)
632 */
633 $marker = "";
634 if(in_array_ics($class,$invalid)){
635 $marker = " <font color='red'>("._("Not available in current setup").")</font>";
636 }
638 /* Create up/down priority icons
639 * Skip this, if we have inherited the FAI classes.
640 */
641 if($this->FAIdebianMirror == "inherited"){
642 $str = "";
643 }else{
644 if($i==1){
645 $str = $str_empty.$str_down.$str_remove;
646 }elseif($i == count($this->FAIclass)){
647 $str = $str_up.$str_empty.$str_remove;
648 }else{
649 $str = $str_up.$str_down.$str_remove;
650 }
651 }
652 $i ++ ;
654 /* Get used FAI types from the class
655 */
656 if(!$marker) {
657 $types = $this->get_fai_types_string($class, true);
658 }
659 else {
660 $types = "";
661 }
663 $div->AddEntry(array(
664 array("string"=>$class.$marker),
665 array("string"=>$types),
666 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
667 ));
668 }
669 }// END FAI output generation
670 }// END FAI output generation
671 $smarty->assign("FAIScriptlist",$div->DrawList());
673 /* Radio button group */
674 if (preg_match("/G/", $this->bootmode)) {
675 $smarty->assign("graphicalbootup", "checked");
676 } else {
677 $smarty->assign("graphicalbootup", "");
678 }
679 if (preg_match("/T/", $this->bootmode)) {
680 $smarty->assign("textbootup", "checked");
681 } else {
682 $smarty->assign("textbootup", "");
683 }
684 if (preg_match("/D/", $this->bootmode)) {
685 $smarty->assign("debugbootup", "checked");
686 } else {
687 $smarty->assign("debugbootup", "");
688 }
690 /* Show main page */
691 $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters);
692 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
693 }
696 function remove_from_parent()
697 {
698 /* Cancel if there's nothing to do here */
699 if ((!$this->acl_is_removeable())){
700 return;
701 }
703 /* Remove and write to LDAP */
704 plugin::remove_from_parent();
705 $ldap = $this->config->get_ldap_link();
706 $ldap->cd($this->dn);
707 $this->cleanup();
708 $this->attrs['gotoModules'] = array();
709 $ldap->modify($this->attrs);
710 $this->handle_post_events("remove");
711 new log("remove","workstation/".get_class($this),$this->dn);
712 }
715 /* Save data to object */
716 function save_object()
717 {
718 $old_mirror = $this->FAIdebianMirror;
719 plugin::save_object();
721 /* Update release */
722 if($old_mirror != $this->FAIdebianMirror){
723 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
724 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
725 }
726 }
728 /* Clear FAI class list if FAI mirror has been set to inherited */
729 if($this->FAIdebianMirror == "inherited"){
730 $this->FAIclass =array();
731 }
733 if(isset($_POST['WorkstationStarttabPosted'])){
734 if(isset($_POST['gotoLdap_inherit'])){
735 $this->gotoLdap_inherit = TRUE;
736 }else{
737 $this->gotoLdap_inherit = FALSE;
738 }
740 /* Save group radio buttons */
741 if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
742 $this->bootmode= $_POST["bootmode"];
743 }
744 }
745 }
748 /* Save to LDAP */
749 function save()
750 {
752 /* Depending on the baseobject (Ogroup / WS) we
753 * use another set of objectClasses
754 * In case of WS itself, we use "array("GOhard", "FAIobject");"
755 * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
756 */
757 if(isset($this->parent->by_object['ogroup'])){
758 $this->objectclasses = array("gotoWorkstationTemplate");
759 }elseif(isset($this->parent->by_object['workgeneric'])){
760 $this->objectclasses = array("GOhard");
761 }elseif(isset($this->parent->by_object['servgeneric'])){
762 $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
763 }else{
764 msg_dialog::display(_("Fatal error"),
765 "Object Type Configuration is unknown. Please contact the GOsa developers.",
766 FATAL_ERROR_DIALOG);
767 exit();
768 }
770 /* Append FAI class */
771 if($this->fai_activated){
772 $this->objectclasses[] = "FAIobject";
773 }
775 /* Find proper terminal path for tftp configuration
776 FIXME: This is suboptimal when the default has changed to
777 another location! */
778 if (($this->gotoTerminalPath == "default")){
779 $ldap= $this->config->get_ldap_link();
781 /* Strip relevant part from dn, keep trailing ',' */
782 $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
783 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
785 /* Walk from top to base and try to load default values for
786 'gotoTerminalPath'. Abort when an entry is found. */
787 while (TRUE){
788 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
790 $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
791 $this->config->current['BASE'], array('gotoTerminalPath'));
792 $attrs= $ldap->fetch();
793 if (isset($attrs['gotoTerminalPath'])){
794 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
795 break;
796 }
798 /* Nothing left? */
799 if ($tmp == ""){
800 break;
801 }
802 }
803 }
805 if ($this->gotoKernelParameters == "") {
806 /* Add semi automatic values if empty */
807 // FIXME: LDAP Server may not be set here...
808 $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
810 switch ($this->bootmode){
811 case "D":
812 $this->gotoKernelParameters.= " debug";
813 break;
814 case "G":
815 $this->gotoKernelParameters.= " splash=silent";
816 break;
817 }
818 }
820 plugin::save();
822 unset( $this->attrs['FAIrelease'] );
823 $str = "";
825 /* Skip FAI attribute handling if not necessary */
826 if($this->fai_activated && !$this->si_fai_action_failed){
827 if($this->FAIdebianMirror == "inherited"){
828 $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] = $this->attrs['FAIdebianMirror'] = array();
829 }else{
830 foreach($this->FAIclass as $class){
831 $str .= $class." ";
832 }
833 $str = trim($str);
834 if(empty($this->attrs['FAIclass'])){
835 $this->attrs['FAIclass'] = array();
836 }else{
837 $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
838 }
839 }
840 }
842 /* Add missing arrays */
843 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
844 if (isset ($this->$val) && count ($this->$val) != 0){
846 $this->attrs["$val"]= array_unique($this->$val);
847 }
848 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
849 }
851 /* Prepare list of ldap servers */
852 $this->attrs['gotoLdapServer'] = array();
853 if(!$this->gotoLdap_inherit){
854 $i = 0;
855 foreach($this->gotoLdapServers as $server){
856 $i ++;
857 $this->attrs['gotoLdapServer'][] = $i.":".$server;
858 }
859 }
861 if ($this->gotoBootKernel == "default-inherited"){
862 $this->attrs['gotoBootKernel']= array();
863 }
865 /* if mirror == none stop saving this attribute */
866 if($this->FAIdebianMirror == "none"){
867 $this->FAIdebianMirror = "";
868 }
870 /* Get FAIstate from object, the generic tab could have changed it during execute */
871 $ldap= $this->config->get_ldap_link();
872 $ldap->cd($this->dn);
875 /* Skip FAI attribute handling if not necessary */
876 if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
877 $ldap->cat($this->dn,array("FAIstate"));
878 $checkFAIstate = $ldap->fetch();
880 /* Remove FAI objects if no FAI class is selected */
881 if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
882 $this->attrs['FAIclass'] = array();
883 $this->attrs['FAIdebianMirror'] = array();
884 }
885 }else{
887 /* Don't touch FAI objects if something went wrong with the si daemon.
888 */
889 if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
890 if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
891 }
893 /* prepare share settings */
894 $tmp = array();
895 foreach($this->gotoShares as $name => $settings){
896 $tmp2= split("\|",$name);
897 $name = $tmp2[0];
898 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
899 }
900 $this->attrs['gotoShare']=$tmp;
901 $this->cleanup();
902 $ldap->modify ($this->attrs);
903 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
905 if (!$ldap->success()){
906 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
907 }
908 $this->handle_post_events("modify");
910 /* Check if LDAP server has changed */
911 if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
912 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
913 $o_queue = new gosaSupportDaemon();
914 if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
915 $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
916 $macs = array();
918 /* Get list of macAddresses
919 */
920 if(isset($this->parent->by_object['ogroup'])){
922 /* If we are an object group, add all member macs
923 */
924 $p = $this->parent->by_object['ogroup'];
925 foreach($p->memberList as $dn => $obj){
926 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
927 $macs[] = $p->objcache[$dn]['macAddress'];
928 }
929 }
930 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
932 /* We are a workstation. Add current mac.
933 */
934 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
935 if(!empty($mac)){
936 $macs[] = $mac;
937 }
938 }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
940 /* We are a server. Add current mac.
941 */
942 $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
943 if(!empty($mac)){
944 $macs[] = $mac;
945 }
946 }
948 /* Trigger event for all member objects
949 */
950 foreach($macs as $mac){
951 $tmp = new $evt['CLASS_NAME']($this->config);
952 $tmp->set_type(TRIGGERED_EVENT);
953 $tmp->add_targets(array($mac));
954 if(!$o_queue->append($tmp)){
955 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
956 }
957 }
958 }
959 }
960 }
963 /* Add value to array, check if unique */
964 function add_list (&$array, $value)
965 {
966 if ($value != ""){
967 $array[]= $value;
968 sort($array);
969 array_unique ($array);
970 }
971 }
974 /* Delete value to array, check if unique */
975 function del_list (&$array, $list)
976 {
977 $tmp= array();
978 foreach ($array as $mod){
979 if (!in_array($mod, $list)){
980 $tmp[]= $mod;
981 }
982 }
983 $array= $tmp;
984 }
986 /* Generate ListBox frindly output for the defined shares
987 * Possibly Add or remove an attribute here,
988 */
989 function printOutAssignedShares()
990 {
991 $a_return = array();
992 if(is_array($this->gotoShares)){
993 foreach($this->gotoShares as $share){
994 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
995 }
996 }
997 return($a_return);
998 }
1002 function PrepareForCopyPaste($source)
1003 {
1004 plugin::PrepareForCopyPaste($source);
1006 $source_o = new workstartup ($this->config, $source['dn']);
1007 foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1008 "FAIstate", "FAIrelease", "gotoKernelParameters","gotoShares",
1009 "gotoLdapServers", "gotoLdap_inherit") as $attr){
1010 $this->$attr = $source_o->$attr;
1011 }
1012 if (isset($source['FAIstate'])) {
1013 $this->attrs['FAIstate'] = $source['FAIstate'];
1014 }
1015 }
1018 function array_switch_item($ar,$from,$to)
1019 {
1020 if(!is_array($ar)){
1021 return(false);
1022 }
1023 if(!isset($ar[$from])){
1024 return(false);
1025 }
1026 if(!isset($ar[$to])){
1027 return(false);
1028 }
1030 $tmp = $ar[$from];
1031 $ar[$from] = $ar[$to];
1032 $ar[$to] = $tmp;
1033 return($ar);
1034 }
1037 /* Return plugin informations for acl handling */
1038 static function plInfo()
1039 {
1040 return (array(
1041 "plShortName" => _("Startup"),
1042 "plDescription" => _("System startup"),
1043 "plSelfModify" => FALSE,
1044 "plDepends" => array(),
1045 "plPriority" => 9,
1046 "plSection" => array("administration"),
1047 "plCategory" => array("workstation","server","ogroups"),
1049 "plProvidedAcls"=> array(
1050 "gotoLdapServer" => _("Ldap server"),
1051 "gotoBootKernel" => _("Boot kernel"),
1052 "gotoKernelParameters" => _("Kernel parameter"),
1054 "gotoModules" => _("Kernel modules"),
1055 "gotoShare" => _("Shares"),
1057 "FAIclass" => _("FAI classes"),
1058 "FAIdebianMirror" => _("Debian mirror"),
1059 "FAIrelease" => _("Debian release"),
1061 "FAIstatus" => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1062 ));
1063 }
1065 /* Function to find bad classes */
1066 function update_bad_classes($release)
1067 {
1069 if(!isset($this->cache['BAD_CLASSES'][$release])) {
1070 /* Find "bad" classes */
1071 $ui = get_userinfo();
1072 $ldap = $this->config->get_ldap_link();
1074 /* Convert release name to a valid ldap uri component */
1075 $release_components = split('/', $release);
1076 $release_components = array_reverse($release_components);
1077 for($i=0;$i<sizeof($release_components);$i++) {
1078 $release_components[$i] = "ou=" . $release_components[$i];
1079 }
1080 $release_dn_part = join(',', $release_components);
1082 /* Limit the base to the release in the faiBase */
1083 $base = sprintf("%s,%s%s", $release_dn_part, get_ou('faiBaseRDN'), $this->config->current['BASE']);
1085 /* Build a list of all fai classes, that don't have the unittag of the user
1086 * and are not freezed or removed. The classes will be filtered by this
1087 * list. Its needed to specify each objectClass (FAIpackageList etc.) because
1088 * FAIClass would match sub-objects, too, which would lead to an array that
1089 * is much bigger then needed */
1090 $filter = sprintf('(&(|(objectClass=FAItemplate)(objectClass=FAIpackageList)(objectClass=FAIprofile)(objectClass=FAIscript)(objectClass=FAIpartitionTable)(objectClass=FAIHook)(objectClass=FAIvariable)(objectClass=FAItemplate))(&(!(gosaUnitTag=%s))(&(!(FAIstate=*removed*))(!(FAIstate=*freeze*)))))', $ui->gosaUnitTag);
1091 $ldap->cd($base);
1092 $ldap->search(sprintf("$filter", $ui->gosaUnitTag));
1094 $this->cache['BAD_CLASSES'][$release] = array();
1095 while ($entry = $ldap->fetch()) {
1096 $classname = $entry['cn'][0];
1097 if (!in_array($classname, $this->cache['BAD_CLASSES'][$release])) {
1098 array_push($this->cache['BAD_CLASSES'][$release], $classname);
1099 }
1100 }
1101 }
1102 }
1104 /* Updates release dns
1105 * and reads all classes for the current release,
1106 * if not already done ($this->cache).
1107 */
1108 function update_fai_cache($first_call = FALSE)
1109 {
1110 $force = FALSE;
1111 if(!$this->si_active) return;
1112 $start = microtime(TRUE);
1114 if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1116 $this->si_fai_action_failed = FALSE;
1118 /* Get the list of available servers and their releases.
1119 */
1120 if($force || !isset($this->cache['SERVERS'])){
1122 $o_queue = new gosaSupportDaemon();
1123 $servers = $o_queue->FAI_get_server();
1124 if($o_queue->is_error()){
1125 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1126 $this->si_fai_action_failed = TRUE;
1127 $this->cache = array();
1128 return;
1129 }else{
1131 $base = $this->config->current['BASE'];
1132 $ldap = $this->config->get_ldap_link();
1133 foreach($servers as $server){
1134 /* Dont show servers that have a different unittag as the user*/
1135 $ui = get_userinfo();
1136 if ($ui->gosaUnitTag != $server['TAG']) {
1137 continue;
1138 }
1140 $rel = $server['FAI_RELEASE'];
1141 $this->cache['SERVERS']['auto'][$rel] = $rel;
1142 $this->cache['SERVERS'][$server['SERVER']][$rel] = $rel;
1143 uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1144 uksort($this->cache['SERVERS'][$server['SERVER']], 'strnatcasecmp');
1145 }
1146 }
1147 }
1149 /* Ensure that our selection is valid, else we get several PHP warnings
1150 if there is no FAI configuration at all.
1151 */
1152 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1153 $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1154 }
1156 /* Build up arrays, without checks */
1157 if(!$first_call){
1159 /* Check if the selected mirror is available */
1160 if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1161 $this->FAIdebianMirror = "auto";
1162 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1163 trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1164 }
1166 /* Check if the selected release is available */
1167 if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1169 if($this->FAIrelease != ""){
1170 trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1171 }
1172 $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1173 }
1174 }
1176 /* Get classes for release from cache.
1177 * Or build cache
1178 */
1179 if($this->FAIdebianMirror == "inherited"){
1180 $release = $this->InheritedFAIrelease;
1181 }else{
1182 $release = $this->FAIrelease;
1183 }
1185 if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1187 /* Get the list of available servers and their releases.
1188 */
1189 $o_queue = new gosaSupportDaemon();
1190 $classes = $o_queue->FAI_get_classes($release);
1191 $this->cache['CLASSES'][$release] = array();
1192 if($o_queue->is_error()){
1193 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1194 $this->si_fai_action_failed = TRUE;
1195 $this->cache=array();
1196 return;
1197 }else{
1198 foreach($classes as $class){
1199 $classname = $class['CLASS'];
1200 $this->update_bad_classes($release);
1201 if(isset($this->cache['BAD_CLASSES'][$release])){
1202 /* Skip classes that are in the array of bad classes */
1203 if (in_array($classname, $this->cache['BAD_CLASSES'][$release])) {
1204 continue;
1205 }
1206 }
1207 if (!isset($this->cache['CLASSES'][$release][$classname])) {
1208 $this->cache['CLASSES'][$release][$classname] = array();
1209 }
1210 array_push($this->cache['CLASSES'][$release][$classname], $this->analyse_fai_object($class));
1211 }
1212 }
1214 /* Add object caught from external hook
1215 */
1216 $lines= $this->GetHookElements();
1217 foreach ($lines as $hline){
1218 $entries= split(";", $hline);
1219 $server = $entries['0'];
1220 $url = $entries['1'];
1221 if (!empty($url)){
1223 /* Split releases */
1224 if (isset($entries[2])){
1225 $releases= split(",", $entries[2]);
1227 foreach ($releases as $release_data){
1228 $release_c = preg_replace('/:.*$/', '', $release_data);
1229 $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1230 $classes_c = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1232 if($release_c == $release){
1233 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1234 $this->cache['SERVERS']['auto'][$release_c]=$release_c;
1235 foreach ($classes_c as $class){
1236 if ($class != ""){
1237 $this->cache['CLASSES'][$release_c][$class]= array();
1238 }
1239 }
1240 }
1241 }
1242 }
1243 }
1244 }
1245 uksort($this->cache['SERVERS'], 'strnatcasecmp');
1247 /* Only add inherit option, if we are part in an object group
1248 */
1249 if($this->member_of_ogroup){
1250 $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1251 }
1252 }
1254 /* Get list of available kernel for this release
1255 */
1256 if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1258 if($force || !isset($this->cache['KERNELS'][$release])){
1259 $o_queue = new gosaSupportDaemon();
1260 $tmp = $o_queue->FAI_get_kernels($release);
1261 $this->cache['KERNELS'][$release] = array();
1262 foreach($this->gotoBootKernels as $name => $default){
1263 $this->cache['KERNELS'][$release][$name] = $default;
1264 }
1265 foreach($tmp as $kernel){
1266 if(empty($kernel)) continue;
1267 $this->cache['KERNELS'][$release][$kernel]=$kernel;
1268 }
1269 ksort($this->cache['KERNELS'][$release]);
1270 }
1271 }
1273 /* Detect the release and get all classes for it */
1274 function get_classes() {
1275 $this->update_fai_cache();
1277 if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1278 $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1279 }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1280 $classes = $this->cache['CLASSES'][$this->FAIrelease];
1281 }else{
1282 $classes = array();
1283 }
1285 return $classes;
1286 }
1288 /* This function return an array containing all
1289 * invalid classes for the selected server/release
1290 */
1291 function get_invalid_classes($classes)
1292 {
1293 $release_classes = $this->get_classes();
1295 /* Detect all classes that are not valid
1296 * for the selected release
1297 */
1298 $NA = array();
1299 foreach($classes as $class){
1300 if(!isset($release_classes[$class])){
1301 $NA[] = $class;
1302 }
1303 }
1304 return($NA);
1305 }
1307 function get_fai_types_string($class_name, $image=FALSE) {
1308 $classes = $this->get_classes();
1310 $result = array();
1312 if ($image) {
1313 # Pre-fill the array fields with an empty image so that
1314 # everything looks fine if the type in this position
1315 # doesn't exist in that class
1316 for ($i=0; $i<6; $i++) {
1317 $result[$i] = "<img src='images/empty.png' width='17'> ";
1318 }
1319 }
1321 foreach($classes[$class_name] as $type) {
1322 $index = $type['index'];
1323 if ($image) {
1324 $string = "<img src='".$type['img']."' width='17' title='".$type['desc']."'> ";
1325 }
1326 else {
1327 $string = $type['Abbr'];
1328 }
1330 $result[$index] = $string;
1331 }
1332 return join(' ', $result);
1334 }
1336 /* Get all selectable classes for the ui select box
1337 */
1338 function selectable_classes()
1339 {
1340 $classes = $this->get_classes();
1342 $ret= array();
1343 foreach($classes as $class_name => $class_types) {
1344 if (!in_array($class_name, $this->FAIclass)) {
1345 $ret[$class_name] = $this->get_fai_types_string($class_name);
1346 }
1347 }
1348 uksort($ret, 'strnatcasecmp');
1349 return($ret);
1350 }
1353 /* Analyse FAI object and return an array with usefull informations like
1354 * FAIobject type.
1355 */
1356 function analyse_fai_object($attr)
1357 {
1358 $result = array();
1359 switch($attr['TYPE']){
1360 case 'FAIpartitionTable':
1361 $result["Type"]= 'FAIpartitionTable';
1362 $result["Abbr"]= 'Pt';
1363 $result["img"]= 'plugins/fai/images/fai_partitionTable.png';
1364 $result["desc"] = _('Partition table');
1365 $result["index"]= 0;
1366 break;
1367 case 'FAIpackageList':
1368 $result["Type"]= 'FAIpackageList';
1369 $result["Abbr"]= 'Pl';
1370 $result["img"] = 'plugins/fai/images/fai_packages.png';
1371 $result["desc"] = _('Package list');
1372 $result["index"] = 1;
1373 break;
1374 case 'FAIscript':
1375 $result["Type"]= 'FAIscript';
1376 $result["Abbr"]= 'S';
1377 $result["img"]= 'plugins/fai/images/fai_script.png';
1378 $result["desc"] = _('Scripts');
1379 $result["index"] = 2;
1380 break;
1381 case 'FAIvariable':
1382 $result["Type"]= 'FAIvariable';
1383 $result["Abbr"]= 'V';
1384 $result["img"]= 'plugins/fai/images/fai_variable.png';
1385 $result["desc"] = _('Variables');
1386 $result["index"]= 3;
1387 break;
1388 case 'FAIhook':
1389 $result["Type"]= 'FAIhook';
1390 $result["Abbr"]= 'H';
1391 $result["img"]= 'plugins/fai/images/fai_hook.png';
1392 $result["desc"] = _('Hooks');
1393 $result["index"]= 4;
1394 break;
1395 case 'FAIprofile':
1396 $result["Type"]= 'FAIprofile';
1397 $result["Abbr"]= 'P';
1398 $result["img"]= 'plugins/fai/images/fai_profile.png';
1399 $result["desc"]= _('Profile');
1400 $result["index"] = 5;
1401 break;
1402 case 'FAItemplate':
1403 $result["Type"]= 'FAItemplate';
1404 $result["Abbr"]= 'T';
1405 $result["img"] = 'plugins/fai/images/fai_template.png';
1406 $result["desc"]= _('Templates');
1407 $result["index"] = 6;
1408 break;
1409 default: trigger_error("Unknown FAI object type!");;
1410 }
1411 return($result);
1412 }
1415 /* Return repository hook output, if possible.
1416 */
1417 function GetHookElements()
1418 {
1419 $ret = array();
1420 $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1421 if(!empty($cmd)){
1422 $res = shell_exec($cmd);
1423 $res2 = trim($res);
1424 if((!$res)){
1425 msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1426 }elseif(empty($res2)){
1427 msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG);
1428 }else{
1429 $tmp = split("\n",$res);
1430 foreach($tmp as $line){
1431 if(empty($line)) continue;
1432 $ret[]= $line;
1433 }
1434 }
1435 }
1436 return($ret);
1437 }
1440 /* This function creates the release name out of a dn
1441 * e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1442 */
1443 function dn_to_release_name($dn)
1444 {
1445 $relevant = preg_replace("/,".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$dn);
1446 $parts = array_reverse(split("\,",$relevant));
1447 $str ="";
1448 foreach($parts as $part){
1449 $str .= preg_replace("/^ou=/","",$part)."/";
1450 }
1451 return(preg_replace("/\/$/","",$str));
1452 }
1453 }
1455 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1456 ?>