d8b8f15bb563e4c0e54f1c93fa257eeb4819beae
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_roleManagement.inc 14742 2009-11-04 13:18:33Z hickert $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class faiManagement extends management
24 {
25 var $plHeadline = "Software deployment";
26 var $plDescription = "Manage software packages and deployment reciepes";
27 var $plIcon = "plugins/fai/images/plugin.png";
29 // Tab definition
30 protected $tabClass = "roletabs";
31 protected $tabType = "ROLETABS";
32 protected $aclCategory = "roles";
33 protected $aclPlugin = "role";
34 protected $objectName = "role";
36 // Attributes Managed by this plugin can be used in post events
37 protected $attributes = array("lock_type","lock_name","lock_dn");
39 var $dispNewBranch=false;
40 var $dispNewFreeze=false;
42 var $fai_release = ""; // The currently selected release while in release management mode!
43 var $fai_base = "";
44 var $acl_base = "";
46 var $lock_type = "";
47 var $lock_dn = "";
48 var $lock_name = "";
51 function __construct($config,$ui)
52 {
53 $this->config = $config;
54 $this->fai_base = get_ou("faiBaseRDN").$this->config->current['BASE'];
55 $this->fai_release = $this->fai_base;
56 $this->acl_base = $this->config->current['BASE'];
57 $this->ui = $ui;
58 $this->storagePoints = array(
59 get_ou('faiPartitionRDN'),
60 get_ou('faiPackageRDN'),
61 get_ou('faiScriptRDN'),
62 get_ou('faiVariableRDN'),
63 get_ou('faiHookRDN'),
64 get_ou('faiProfileRDN'),get_ou('faiTemplateRDN'));
66 # // Build filter
67 # if (session::global_is_set(get_class($this)."_filter")){
68 # $filter= session::global_get(get_class($this)."_filter");
69 # } else {
70 $filter = new filter(get_template_path("fai-filter.xml", true));
71 $filter->setObjectStorage($this->storagePoints);
72 # }
73 $this->setFilter($filter);
75 // Build headpage
76 $headpage = new listing(get_template_path("fai-list.xml", true));
77 $headpage->setFilter($filter);
78 $headpage->setBase($this->fai_release);
79 $headpage->registerElementFilter("filterProperties", "faiManagement::filterProperties");
81 // Add copy&paste and snapshot handler.
82 if ($this->config->boolValueIsTrue("main", "copyPaste")){
83 $this->cpHandler = new CopyPasteHandler($this->config);
84 }
85 if($this->config->get_cfg_value("enableSnapshots") == "true"){
86 $this->snapHandler = new SnapshotHandler($this->config);
87 }
88 $this->registerAction("editByGroup","editByGroup");
89 $this->registerAction("createBranch","createBranch");
90 $this->registerAction("createFreeze","createFreeze");
91 $this->registerAction("removeBranch","removeBranch");
92 $this->registerAction("removeBranchConfirmed","removeBranchConfirmed");
93 $this->registerAction("saveBranch","saveBranch");
94 $this->registerAction("PerformBranch","PerformBranch");
95 parent::__construct($config, $ui, "roles", $headpage);
96 }
99 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
100 {
101 $headpage = $this->getHeadpage();
102 if(count($target) == 1){
103 $entry = $headpage->getEntry($target[0]);
104 if($entry){
105 if(count($entry['GROUPS']) == 1){
106 $data = array_pop($entry['GROUPS']);
107 $type = $this->get_type($data);
108 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
109 }else{
110 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
111 }
112 }
113 }
114 }
117 function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
118 {
119 $headpage = $this->getHeadpage();
120 if(count($target) == 1){
121 $entry = $headpage->getEntry($target[0]);
122 if($entry){
123 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
124 }
125 }
126 }
128 /*! \brief Object removal was confirmed, now remove the requested entries.
129 *
130 * @param String 'action' The name of the action which was the used as trigger.
131 * @param Array 'target' A list of object dns, which should be affected by this method.
132 * @param Array 'all' A combination of both 'action' and 'target'.
133 */
134 function removeEntryConfirmed($action="",$target=array(),$all=array(),
135 $altTabClass="",$altTabType="",$altAclCategory="")
136 {
137 $ldap = $this->config->get_ldap_link();
138 $ldap->cd($this->config->current['BASE']);
139 foreach($this->dns as $key => $dn){
140 $ldap->cat($dn);
141 if($ldap->count()){
142 $attrs = $ldap->fetch();
143 $type= $this->get_type($attrs);
144 management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
146 // Now save changes
147 FAI::save_release_changes_now();
148 $to_del = FAI::clean_up_releases($dn);
149 foreach($to_del as $dn){
150 $ldap->rmdir_recursive($dn);
151 }
152 }
153 }
154 }
157 function editByGroup()
158 {
159 if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
160 $this->dialogObject->save_object();
161 $entry = $this->dialogObject->get_selected();
162 $this->closeDialogs();
163 $data = array_pop($entry);
164 $type = $this->get_type($data);
165 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
166 }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
167 $this->dialogObject->save_object();
168 $to_delete = $entry = $this->dialogObject->get_selected();
169 $dns = array();
172 // Check FAIstate to ensure that we do not remove frozen objects
173 // additionally check ACLs
174 $locked = array();
175 $disallowed = array();
176 foreach($to_delete as $obj){
177 if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
178 $locked[] = $obj['dn'];
179 }else{
180 $type = $this->get_type($obj);
181 $acl = $this->ui->get_permissions($obj['dn'], 'acl/'.$type[1]);
182 if(!preg_match("/d/",$acl)){
183 $disallowed[] = $obj['dn'];
184 }else{
185 $dns[] = $obj['dn'];
186 }
187 }
188 }
190 // Display info dialog about locked and not removeable entries
191 if(count($locked)){
192 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
193 msgPool::buildList($locked)));
194 }
196 // Display info dialog about not removeable entries due to permissions
197 if(count($disallowed)){
198 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
199 }
201 // There are entries left to be removed
202 if(count($dns)){
203 $this->closeDialogs();
204 $this->dns = $dns;
206 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
208 // check locks
209 if ($user= get_multiple_locks($this->dns)){
210 return(gen_locked_message($user,$this->dns));
211 }
213 // Add locks
214 $dns_names = array();
215 foreach($this->dns as $dn){
216 $dns_names[] =LDAP::fix($dn);
217 }
218 add_lock ($this->dns, $this->ui->dn);
220 // Display confirmation dialog.
221 $smarty = get_smarty();
222 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
223 $smarty->assign("multiple", true);
224 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
225 }else{
226 $this->closeDialogs();
227 }
228 }
229 }
232 protected function saveChanges()
233 {
234 management::saveChanges();
236 // Now save changes
237 FAI::save_release_changes_now();
238 $to_del = FAI::clean_up_releases($this->last_dn);
239 foreach($to_del as $dn){
240 $ldap->rmdir_recursive($dn);
241 }
242 }
244 protected function applyChanges()
245 {
246 management::applyChanges();
248 // Now save changes
249 FAI::save_release_changes_now();
250 $to_del = FAI::clean_up_releases($this->last_dn);
251 foreach($to_del as $dn){
252 $ldap->rmdir_recursive($dn);
253 }
254 }
256 function detectPostActions()
257 {
258 $action = management::detectPostActions();
259 if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
260 if(isset($_POST['CancelBranchName'])) $action['action'] = "cancel";
261 if(isset($_POST['delete_branch_confirm'])) $action['action'] = "removeBranchConfirmed";
262 if(isset($_GET['PerformBranch'])) $action['action'] = "PerformBranch";
263 if(isset($_POST['UseBranchName'])) $action['action'] = "saveBranch";
264 if(isset($_POST['faiGroupHandle_apply'])) $action['action'] = "editByGroup";
265 if(isset($_GET['act']) && $_GET['act'] == "branch_branch") $action['action'] = "createBranch";
266 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch") $action['action'] = "createFreeze";
267 if(isset($_GET['act']) && $_GET['act'] == "remove_branch") $action['action'] = "removeBranch";
269 foreach($_POST as $name => $value){
270 if(preg_match("/^edit_([0-9]*)_([a-z]*)_(x|y)/i", $name)){
271 $id = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\1", $name);
272 $tab = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\2", $name);
273 $headpage = $this->getHeadpage();
274 if(isset($headpage->entries[$id]['GROUPS'][$tab])){
275 $data =$headpage->entries[$id]['GROUPS'][$tab];
276 $type = $this->get_type($data);
277 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
278 }
279 break;
280 }
281 }
282 return($action);
283 }
286 function renderList()
287 {
288 $filter = $this->getFilter();
289 $headpage = $this->getHeadpage();
290 $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
292 if(isset($_POST['RELEASE'])){
293 $this->fai_release = get_post('RELEASE');
294 }
295 $headpage->setBase($this->fai_release);
296 $headpage->update();
297 $smarty = get_smarty();
298 $smarty->assign("fai_release", $this->fai_release);
299 $smarty->assign("fai_base", $this->fai_base);
300 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
301 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
302 $smarty->assign("allow_create", $c);
303 $smarty->assign("allow_remove", $r);
304 $display = $headpage->render();
305 return($this->getHeader().$display);
306 }
308 function getReleaseList($base = "", $prefix ="")
309 {
310 $list = array();
311 if(empty($base)){
312 $base = $this->fai_base;
313 $list[$base] = "/";
314 }
316 $ldap = $this->config->get_ldap_link();
317 $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
318 $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
320 while($release = $ldap->fetch()){
321 $list[$release['dn']] = $prefix.$release['ou'][0];
323 // Preset to prefered releaes if necessary
324 if(empty($this->fai_release) && $cfg_rel == $release['dn']){
325 $this->fai_release = $release['dn'];
326 }
328 $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix." "));
329 }
330 return($list);
331 }
334 static function filterProperties($row, $classes)
335 {
336 $objects = array(
337 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
338 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
339 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
340 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
341 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
342 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
343 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
344 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
345 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
346 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
347 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
348 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
349 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
350 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
351 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
352 "NAME"=>_("OPSI netboot product") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
353 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
354 "NAME"=>_("OPSI localboot product") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
356 $icon_list = "";
357 foreach($objects as $type => $type_data){
358 if(in_array($type, $classes)){
359 $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
360 alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
361 }else{
362 $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
363 }
364 }
366 return $icon_list;
367 }
372 function removeBranch()
373 {
374 /* Check if we have a post remove method configured
375 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
376 */
377 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
378 /* Load permissions for selected 'dn' and check if
379 we're allowed to remove this 'dn' */
380 if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
381 $smarty=get_smarty();
382 $smarty->assign("release_hidden",base64_encode($this->fai_release));
383 $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
384 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
385 } else {
386 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
387 }
388 }
389 }
392 function removeBranchConfirmed()
393 {
394 /* Check if we have a post remove method configured
395 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
396 */
397 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
399 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
400 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
401 }else{
403 $bb = $this->fai_release;
404 $ldap = $this->config->get_ldap_link();
406 $br = $this->getBranches();
408 if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
409 $name = $br[$bb];
411 $ldap->cd($bb);
412 $ldap->recursive_remove();
413 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('applicationRDN'), $bb));
414 $ldap->recursive_remove();
415 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('mimetypeRDN'), $bb));
416 $ldap->recursive_remove();
418 /* Search for all groups with configured application menus.
419 - First search all groups, to ensure that we only remove entries form whithin groups.
420 - The search für menu configuration for the specified release and collect all those dns.
421 - Remove entries
422 */
423 $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$bb);
424 $ldap->cd($this->config->current['BASE']);
425 $ldap->search("(objectClass=posixGroup)",array("dn"));
427 /* Collect all group dns
428 */
429 $groups = array();
430 while($attrs = $ldap->fetch()){
431 $groups[] = $attrs['dn'];
432 }
435 /* Collect all group menu release dns that match the release we have removed
436 */
437 $dns = array();
438 foreach($groups as $dn){
439 $ldap->cd($dn);
440 $ldap->search("(objectClass=FAIbranch)",array("dn"));
441 while($attrs = $ldap->fetch()){
442 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
443 $dns[] = $attrs['dn'];
444 }
445 }
446 }
448 /* Finally remove collected release dns
449 */
450 foreach($dns as $dn){
451 $ldap->cd($dn);
452 $ldap->recursive_remove();
453 }
455 /* Post remove */
456 $this->fai_release = $this->fai_base;
457 $this->lock_name = $name;
458 $this->lock_dn = $bb;
459 $this->postremove();
461 $fai_filter = session::get("fai_filter");
462 $fai_filter['fai_release'] = $this->fai_release;
463 session::set("fai_filter",$fai_filter);
465 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
466 }
467 }
468 }
469 }
472 function createBranch()
473 {
474 $smarty = get_smarty();
475 $this->dispNewBranch=true;
476 $this->dispNewFreeze=false;
477 $smarty->assign("iframe",false);
478 if(isset($_POST['BranchName'])){
479 $smarty->assign("BranchName", $_POST['BranchName']);
480 }else{
481 $smarty->assign("BranchName","");
482 }
483 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
484 }
486 function createFreeze()
487 {
488 $smarty = get_smarty();
489 $this->dispNewFreeze=true;
490 $this->dispNewBranch=false;
491 $smarty->assign("iframe",false);
492 if(isset($_POST['BranchName'])){
493 $smarty->assign("BranchName", $_POST['BranchName']);
494 }else{
495 $smarty->assign("BranchName","");
496 }
497 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
498 }
502 function PerformBranch()
503 {
504 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
505 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
506 }else{
508 /* In order to see error messages we have to reset the error handler.
509 Due to the exit();
510 */
511 restore_error_handler();
513 $this->dispNewBranch = false;
514 $this->dispNewFreeze = false;
516 $LASTPOST = session::get('LASTPOST');
517 $base = $LASTPOST['base'];
518 $_POST = session::get('LASTPOST');
519 $name = $_POST['BranchName'];
521 $type = $LASTPOST['type'];
522 $ldap = $this->config->get_ldap_link();
524 $baseToUse = $base;
525 if($this->fai_release != $this->fai_base){
526 $baseToUse = $this->fai_release;
527 }
529 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
531 $CurrentReleases = $this->getBranches();
532 $NewReleaseName = $name;
533 if(isset($CurrentReleases[$this->fai_release])) {
534 if($this->fai_release != $this->fai_base){
535 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
536 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
537 }else{
538 $NewReleaseName = $name;
539 }
540 }
541 $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),$baseToUse);
542 $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
544 $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),$baseToUse);
545 $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
547 /* Check if source depeartments exist */
548 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
549 $ldap->cd($this->config->current['BASE']);
550 $ldap->cat($dep);
551 if(!$ldap->count()){
552 $ldap->create_missing_trees($dep);
553 }
554 }
556 /* Print header to have styles included */
557 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
558 <html>
559 <head>
560 <title></title>
561 <style type="text/css">@import url("themes/default/style.css");</style>
562 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
563 </head>
564 <body style="background: none;margin:3px;color:black">
565 ';
567 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
569 /* Duplicate group application releases
570 */
571 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
573 /* Duplicate applications
574 */
575 $ldap->cat($appsrc,array("dn")) ;
576 if($ldap->count()){
577 $ldap->cd ($appdst);
578 $ldap->recursive_remove();
579 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
580 }
582 /* Duplicate mime types
583 */
584 $ldap->cat($mimesrc,array("dn")) ;
585 if($ldap->count()){
586 $ldap->cd ($mimedst);
587 $ldap->recursive_remove();
588 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
589 }
591 $attr = array();
592 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
593 $attr['ou'] = $name;
594 $attr['FAIstate'] = $type;
595 $ldap->cd($this->config->current['BASE']);
596 $ldap->cd("ou=".$name.",".$baseToUse);
597 $ldap->cat("ou=".$name.",".$baseToUse);
598 if($ldap->count()){
599 $ldap->modify($attr);
600 }else{
601 $ldap->add($attr);
602 }
604 /* Duplicate fai objects
605 */
606 // $ldap->cd ("ou=".$name.",".$baseToUse);
607 // $ldap->recursive_remove();
608 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
610 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
611 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
612 <input type='hidden' name='php_c_check' value='1'>
613 </form></div>";
615 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
617 /* Print footer to have valid html */
618 echo "</body></html>";
620 $this->dispNewFreeze = false;
622 /* Postcreate */
624 /* Assign possible attributes */
625 $this->lock_type = $type;
626 $this->lock_name = $name;
627 $this->lock_dn = $baseToUse;
628 $this->postcreate();
630 /* Send daemon event to reload the fai release database
631 */
632 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
633 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
634 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
635 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
636 $tmp = new $evt['CLASS_NAME']($this->config);
637 $tmp->set_type(TRIGGERED_EVENT);
638 $tmp->add_targets(array("GOSA"));
639 $o_queue = new gosaSupportDaemon();
640 if(!$o_queue->append($tmp)){
641 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
642 }
643 }
644 }else{
645 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
646 msg_dialog::display(_("Fatal error"),
647 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
648 FATAL_ERROR_DIALOG);
649 }
650 exit();
651 }
652 }
657 function saveBranch()
658 {
659 if($this->dispNewBranch){
660 $type = "branch";
661 }else{
662 $type = "freeze";
663 }
665 /* Check branch name */
666 $name = $_POST['BranchName'];
667 $is_ok = true;
668 $smarty = get_smarty();
669 $smarty->assign("BranchName",$name);
670 $base= $this->fai_base;
672 /* Check used characters */
673 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
674 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
675 $is_ok = false;
676 }
678 // Check if this name is already in use
679 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
680 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
681 $is_ok = false;
682 }
684 // Handle errors
685 if(!$is_ok && $this->dispNewFreeze){
686 return($this->createFreeze());
687 }elseif(!$is_ok && $this->dispNewBranch){
688 return($this->createBranch());
689 }
691 // Now create new release
693 if(session::is_set('LASTPOST')){
694 $LASTPOST = session::get('LASTPOST');
695 }else{
696 $LASTPOST = array();
697 }
698 $LASTPOST['base'] = $base;
699 $LASTPOST['type'] = $type;
700 $LASTPOST['BranchName'] = $name;
701 session::set('LASTPOST',$LASTPOST);
702 $smarty->assign("iframe", true);
703 $smarty->assign("plugID", $_GET['plug']);
704 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
705 return($display);
707 }
710 function CheckNewBranchName($name,$base)
711 {
712 $f = $this->fai_release;
713 if($name == ""){
714 return(false);
715 }elseif(in_array($name,$this->getBranches($f))) {
716 return(false);
717 }elseif(tests::is_department_name_reserved($name,$base)){
718 return(false);
719 }
720 return(true);
721 }
724 /* Get available branches for current base */
725 function getBranches($base = false,$prefix = "")
726 {
727 $ret = array("/"=>$this->fai_base);
728 $ldap = $this->config->get_ldap_link();
729 if(!$base){
730 $base = $this->fai_base;
731 }
732 $tmp = FAI::get_all_releases_from_base($base,true);
733 foreach($tmp as $dn => $name){
734 $ret[$name]=$dn;
735 }
736 ksort($ret);
737 $ret = array_flip($ret);
739 return ($ret);
740 }
743 function get_type($array)
744 {
745 if(!isset($array['objectClass'])) return(array());
746 if(in_array("FAIpartitionTable",$array['objectClass'])){
747 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
748 }
749 if(in_array("FAIscript",$array['objectClass'])){
750 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
751 }
752 if(in_array("FAItemplate",$array['objectClass'])){
753 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
754 }
755 if(in_array("FAIhook",$array['objectClass'])){
756 return(array("tabsHook","faiHook","FAIHOOKTABS"));
757 }
758 if(in_array("FAIvariable",$array['objectClass'])){
759 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
760 }
761 if(in_array("FAIprofile",$array['objectClass'])){
762 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
763 }
764 if(in_array("FAIpackageList",$array['objectClass'])){
765 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
766 }
767 return(array());
768 }
769 }
770 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
771 ?>