Code

7a23abecd58a5092c7c17c939b68b41c732adfeb
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiManagement.inc
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           $this->tabObject->by_object[$type[1]]->FAIstate = $data['FAIstate'];
110           $this->tabObject->read_only = preg_match("/freeze/i", $data['FAIstate']);
112         }else{
113           $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
114         }
115       }
116     }
117   }
120   function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
121   {
122     $headpage = $this->getHeadpage();
123     if(count($target) == 1){
124       $entry = $headpage->getEntry($target[0]);
125       if($entry){
126         $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
127       }
128     }
129   }
131   /*! \brief  Object removal was confirmed, now remove the requested entries.
132    *
133    *  @param  String  'action'  The name of the action which was the used as trigger.
134    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
135    *  @param  Array   'all'     A combination of both 'action' and 'target'.
136    */
137   function removeEntryConfirmed($action="",$target=array(),$all=array(),
138       $altTabClass="",$altTabType="",$altAclCategory="")
139   {
140     $ldap = $this->config->get_ldap_link();
141     $ldap->cd($this->config->current['BASE']);  
142     foreach($this->dns as $key => $dn){
143       $ldap->cat($dn);
144       if($ldap->count()){
145         $attrs = $ldap->fetch();
146         $type= $this->get_type($attrs);
147         management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
149         // Now save changes
150         FAI::save_release_changes_now();
151         $to_del = FAI::clean_up_releases($dn);
152         foreach($to_del as $dn){
153           $ldap->rmdir_recursive($dn);
154         }
155       }
156     }
157   }
160   function editByGroup()
161   {
162     if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
163       $this->dialogObject->save_object();
164       $entry = $this->dialogObject->get_selected();
165       $this->closeDialogs();
166       $data = array_pop($entry);
167       $type = $this->get_type($data);
168       management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
169       $this->tabObject->by_object[$type[1]]->FAIstate = $data['FAIstate'];
170       $this->tabObject->read_only = preg_match("/freeze/i", $data['FAIstate']);
172     }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
173       $this->dialogObject->save_object();
174       $to_delete = $entry = $this->dialogObject->get_selected();
175       $dns = array();
178       // Check FAIstate to ensure that we do not remove frozen objects
179       //  additionally check ACLs
180       $locked = array();
181       $disallowed = array();
182       foreach($to_delete as $obj){
183         if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
184           $locked[] = $obj['dn'];
185         }else{
186           $type = $this->get_type($obj);
187           $acl = $this->ui->get_permissions($obj['dn'], 'acl/'.$type[1]);
188           if(!preg_match("/d/",$acl)){
189             $disallowed[] = $obj['dn']; 
190           }else{
191             $dns[] = $obj['dn'];
192           }
193         }
194       }
196       // Display info dialog about locked and not removeable entries
197       if(count($locked)){
198         msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
199             msgPool::buildList($locked)));
200       }
202       // Display info dialog about not removeable entries due to permissions
203       if(count($disallowed)){
204         msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
205       }
207       // There are entries left to be removed
208       if(count($dns)){  
209         $this->closeDialogs();
210         $this->dns = $dns;
212         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
214         // check locks
215         if ($user= get_multiple_locks($this->dns)){
216           return(gen_locked_message($user,$this->dns));
217         }
219         // Add locks
220         $dns_names = array();
221         foreach($this->dns as $dn){
222           $dns_names[] =LDAP::fix($dn);
223         }
224         add_lock ($this->dns, $this->ui->dn);
226         // Display confirmation dialog.
227         $smarty = get_smarty();
228         $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
229         $smarty->assign("multiple", true);
230         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
231       }else{
232         $this->closeDialogs();
233       }
234     }
235   }
237   
238   protected function saveChanges()
239   {
240     management::saveChanges();
242     // Now save changes
243     FAI::save_release_changes_now();
244     $to_del = FAI::clean_up_releases($this->last_dn);
245     foreach($to_del as $dn){
246       $ldap->rmdir_recursive($dn);
247     }
248   }
250   protected function applyChanges()
251   {
252     management::applyChanges();
254     // Now save changes
255     FAI::save_release_changes_now();
256     $to_del = FAI::clean_up_releases($this->last_dn);
257     foreach($to_del as $dn){
258       $ldap->rmdir_recursive($dn);
259     }
260   }
262   function detectPostActions()
263   {
264     $action = management::detectPostActions();
265     if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
266     if(isset($_POST['CancelBranchName'])) $action['action'] = "cancel";
267     if(isset($_POST['delete_branch_confirm'])) $action['action'] = "removeBranchConfirmed";
268     if(isset($_GET['PerformBranch'])) $action['action'] = "PerformBranch";
269     if(isset($_POST['UseBranchName'])) $action['action'] = "saveBranch";
270     if(isset($_POST['faiGroupHandle_apply']))  $action['action'] = "editByGroup";
271     if(isset($_GET['act']) && $_GET['act'] == "branch_branch")  $action['action'] = "createBranch";
272     if(isset($_GET['act']) && $_GET['act'] == "freeze_branch")  $action['action'] = "createFreeze";
273     if(isset($_GET['act']) && $_GET['act'] == "remove_branch")  $action['action'] = "removeBranch";
275     foreach($_POST as $name => $value){
276       if(preg_match("/^edit_([0-9]*)_([a-z]*)_(x|y)/i", $name)){
277         $id = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\1", $name);
278         $tab = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\2", $name);
279         $headpage = $this->getHeadpage();
280         if(isset($headpage->entries[$id]['GROUPS'][$tab])){
281           $data =$headpage->entries[$id]['GROUPS'][$tab];
282           $type = $this->get_type($data);
283           management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]); 
284         } 
285         break;
286       }
287     }
288     return($action);
289   }
292   function renderList()
293   {
294     $filter = $this->getFilter();
295     $headpage = $this->getHeadpage();
296     $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
298     if(isset($_POST['RELEASE'])){
299       $this->fai_release = get_post('RELEASE');
300     }
301     $headpage->setBase($this->fai_release);
302     $headpage->update();
303     $smarty = get_smarty();
304     $smarty->assign("fai_release", $this->fai_release);
305     $smarty->assign("fai_base", $this->fai_base);
306     $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
307     $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
308     $smarty->assign("allow_create", $c);
309     $smarty->assign("allow_remove", $r);
310     $display = $headpage->render();
311     return($this->getHeader().$display);
312   }
314   function getReleaseList($base = "", $prefix ="")
315   {
316     $list = array();
317     if(empty($base)){
318       $base = $this->fai_base;
319       $list[$base] = "/";
320     }
322     $ldap = $this->config->get_ldap_link();
323     $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
324     $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
326     while($release = $ldap->fetch()){
327       $list[$release['dn']] = $prefix.$release['ou'][0];
329       // Preset to prefered releaes if necessary  
330       if(empty($this->fai_release) && $cfg_rel == $release['dn']){
331         $this->fai_release = $release['dn'];
332       }
334       $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix."&nbsp; "));
335     }
336     return($list);
337   }
340   static function filterProperties($row, $classes)
341   {
342     $objects = array(
343         "FAIpartitionTable"  => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
344           "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
345         "FAIpackageList"     => array("IMG"=> "plugins/fai/images/fai_packages.png",
346           "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
347         "FAIscript"          => array("IMG"=> "plugins/fai/images/fai_script.png",
348           "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
349         "FAIvariable"        => array("IMG"=> "plugins/fai/images/fai_variable.png",
350           "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
351         "FAIhook"            => array("IMG"=> "plugins/fai/images/fai_hook.png",
352           "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
353         "FAIprofile"         => array("IMG"=> "plugins/fai/images/fai_profile.png",
354           "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
355         "FAItemplate"        => array("IMG"=> "plugins/fai/images/fai_template.png",
356           "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"),
357         "opsi_netboot"       => array("IMG"=> "plugins/opsi/images/netboot_package.png",
358           "NAME"=>_("OPSI netboot product") ,     "KZL"=> "ON",  "VAR"=>"ShowOpsiNetboot"),
359         "opsi_local"         => array("IMG"=> "plugins/opsi/images/local_package.png",
360           "NAME"=>_("OPSI localboot product")   ,     "KZL"=> "OL",  "VAR"=>"ShowOpsiLocal"));
362     $icon_list = "";
363     foreach($objects as $type => $type_data){
364       if(in_array($type, $classes)){
365         $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
366           alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
367       }else{
368         $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
369       }
370     }
372     return $icon_list;
373   }
378   function removeBranch()
379   {
380     /* Check if we have a post remove method configured
381      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
382      */
383     if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
384       /* Load permissions for selected 'dn' and check if
385          we're allowed to remove this 'dn' */
386       if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
387         $smarty=get_smarty();
388         $smarty->assign("release_hidden",base64_encode($this->fai_release));
389         $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
390         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
391       } else {
392         msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
393       }
394     }
395   }
398   function removeBranchConfirmed()
399   {
400     /* Check if we have a post remove method configured
401      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
402      */
403     if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
405       if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
406         msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
407       }else{
409         $bb =  $this->fai_release;
410         $ldap = $this->config->get_ldap_link();
412         $br = $this->getBranches();
414         if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
415           $name = $br[$bb];
417           $ldap->cd($bb);
418           $ldap->recursive_remove();
419           $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('applicationRDN'), $bb));
420           $ldap->recursive_remove();
421           $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('mimetypeRDN'), $bb));
422           $ldap->recursive_remove();
424           /* Search for all groups with configured application menus.
425              - First search all groups, to ensure that we only remove entries form whithin groups.
426              - The search für menu configuration for the specified release and collect all those dns.
427              - Remove entries
428            */
429           $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$bb);
430           $ldap->cd($this->config->current['BASE']);
431           $ldap->search("(objectClass=posixGroup)",array("dn"));
433           /* Collect all group dns
434            */
435           $groups = array();
436           while($attrs = $ldap->fetch()){
437             $groups[] = $attrs['dn'];
438           }
441           /* Collect all group menu release dns that match the release we have removed
442            */
443           $dns = array();
444           foreach($groups as $dn){
445             $ldap->cd($dn);
446             $ldap->search("(objectClass=FAIbranch)",array("dn"));
447             while($attrs = $ldap->fetch()){
448               if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
449                 $dns[] = $attrs['dn'];
450               }
451             }
452           }
454           /* Finally remove collected release dns
455            */
456           foreach($dns as $dn){
457             $ldap->cd($dn);
458             $ldap->recursive_remove();
459           }
461           /* Post remove */
462           $this->fai_release = $this->fai_base;
463           $this->lock_name   = $name;
464           $this->lock_dn     = $bb;
465           $this->postremove();
467           $fai_filter = session::get("fai_filter");
468           $fai_filter['fai_release'] = $this->fai_release;
469           session::set("fai_filter",$fai_filter);
471           new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
472         }
473       }
474     }
475   }
478   function createBranch()
479   { 
480     $smarty = get_smarty();
481     $this->dispNewBranch=true;
482     $this->dispNewFreeze=false;
483     $smarty->assign("iframe",false);
484     if(isset($_POST['BranchName'])){
485       $smarty->assign("BranchName", $_POST['BranchName']);
486     }else{
487       $smarty->assign("BranchName","");
488     }
489     return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
490   }
492   function createFreeze()
493   { 
494     $smarty = get_smarty();
495     $this->dispNewFreeze=true;
496     $this->dispNewBranch=false;
497     $smarty->assign("iframe",false);
498     if(isset($_POST['BranchName'])){
499       $smarty->assign("BranchName", $_POST['BranchName']);
500     }else{
501       $smarty->assign("BranchName","");
502     }
503     return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
504   }
508   function PerformBranch()
509   {
510     if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
511       msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
512     }else{
514       /* In order to see error messages we have to reset the error handler.
515          Due to the exit();
516        */
517       restore_error_handler();
519       $this->dispNewBranch = false;
520       $this->dispNewFreeze = false;
522       $LASTPOST = session::get('LASTPOST');
523       $base = $LASTPOST['base'];
524       $_POST  = session::get('LASTPOST');
525       $name = $_POST['BranchName'];
527       $type = $LASTPOST['type'];
528       $ldap = $this->config->get_ldap_link();
530       $baseToUse = $base;
531       if($this->fai_release !=  $this->fai_base){
532         $baseToUse = $this->fai_release;
533       }
535       /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
537       $CurrentReleases  = $this->getBranches();
538       $NewReleaseName   = $name;
539       if(isset($CurrentReleases[$this->fai_release])) {
540         if($this->fai_release != $this->fai_base){
541           $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
542           $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
543         }else{
544           $NewReleaseName   = $name;
545         }
546       }
547       $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),$baseToUse);
548       $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
550       $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),$baseToUse);
551       $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
553       /* Check if source depeartments exist */
554       foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
555         $ldap->cd($this->config->current['BASE']);
556         $ldap->cat($dep);
557         if(!$ldap->count()){
558           $ldap->create_missing_trees($dep);
559         }
560       }
562       /* Print header to have styles included */
563       echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
564         <html>
565         <head>
566         <title></title>
567         <style type="text/css">@import url("themes/default/style.css");</style>
568         <script language="javascript" src="include/focus.js" type="text/javascript"></script>
569         </head>
570         <body style="background: none;margin:3px;color:black">
571         ';
573       new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
575       /* Duplicate group application releases
576        */
577       FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
579       /* Duplicate applications
580        */
581       $ldap->cat($appsrc,array("dn")) ;
582       if($ldap->count()){
583         $ldap->cd ($appdst);
584         $ldap->recursive_remove();
585         FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
586       }
588       /* Duplicate mime types
589        */
590       $ldap->cat($mimesrc,array("dn")) ;
591       if($ldap->count()){
592         $ldap->cd ($mimedst);
593         $ldap->recursive_remove();
594         FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
595       }
597       $attr = array();
598       $attr['objectClass'] = array("organizationalUnit","FAIbranch");
599       $attr['ou']       = $name;
600       $attr['FAIstate'] = $type;
601       $ldap->cd($this->config->current['BASE']);
602       $ldap->cd("ou=".$name.",".$baseToUse);
603       $ldap->cat("ou=".$name.",".$baseToUse);
604       if($ldap->count()){
605         $ldap->modify($attr);
606       }else{
607         $ldap->add($attr);
608       }
610       /* Duplicate fai objects
611        */
612       //      $ldap->cd ("ou=".$name.",".$baseToUse);
613       //      $ldap->recursive_remove();
614       //      FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
616       echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
617         <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
618         <input type='hidden' name='php_c_check' value='1'>
619         </form></div>";
621       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
623       /* Print footer to have valid html */
624       echo "</body></html>";
626       $this->dispNewFreeze = false;
628       /* Postcreate */
630       /* Assign possible attributes */
631       $this->lock_type  = $type;
632       $this->lock_name  = $name;
633       $this->lock_dn    = $baseToUse;
634       $this->postcreate();
636       /* Send daemon event to reload the fai release database
637        */
638       if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
639         $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
640         if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
641           $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
642           $tmp = new $evt['CLASS_NAME']($this->config);
643           $tmp->set_type(TRIGGERED_EVENT);
644           $tmp->add_targets(array("GOSA"));
645           $o_queue = new gosaSupportDaemon();
646           if(!$o_queue->append($tmp)){
647             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
648           }
649         }
650       }else{
651         trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
652         msg_dialog::display(_("Fatal error"),
653             "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
654             FATAL_ERROR_DIALOG);
655       }
656       exit();
657     }
658   }
663   function saveBranch()
664   {
665     if($this->dispNewBranch){
666       $type = "branch";
667     }else{
668       $type = "freeze";
669     }
671     /* Check branch name */
672     $name = $_POST['BranchName'];
673     $is_ok = true;
674     $smarty = get_smarty();
675     $smarty->assign("BranchName",$name);
676     $base= $this->fai_base;
678     /* Check used characters */
679     if(!preg_match("/^[0-9a-z\.]*$/",$name)){
680       msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
681       $is_ok = false;
682     }
684     // Check if this name is already in use 
685     if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
686       msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
687       $is_ok = false;
688     }
690     // Handle errors
691     if(!$is_ok && $this->dispNewFreeze){
692       return($this->createFreeze());
693     }elseif(!$is_ok && $this->dispNewBranch){
694       return($this->createBranch());
695     }
697     // Now create new release
699     if(session::is_set('LASTPOST')){
700       $LASTPOST = session::get('LASTPOST');
701     }else{
702       $LASTPOST = array();
703     }
704     $LASTPOST['base'] = $base;
705     $LASTPOST['type'] = $type;
706     $LASTPOST['BranchName'] = $name;
707     session::set('LASTPOST',$LASTPOST);
708     $smarty->assign("iframe", true);
709     $smarty->assign("plugID", $_GET['plug']);
710     $display  = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
711     return($display);
712  
713   }
716   function CheckNewBranchName($name,$base)
717   {
718     $f = $this->fai_release;
719     if($name == ""){
720       return(false);
721     }elseif(in_array($name,$this->getBranches($f))) {
722       return(false);
723     }elseif(tests::is_department_name_reserved($name,$base)){
724       return(false);
725     }
726     return(true);
727   }
730   /* Get available branches for current base */
731   function getBranches($base = false,$prefix = "")
732   {
733     $ret = array("/"=>$this->fai_base);
734     $ldap = $this->config->get_ldap_link();
735     if(!$base){
736       $base = $this->fai_base;
737     }
738     $tmp = FAI::get_all_releases_from_base($base,true);
739     foreach($tmp as $dn => $name){
740       $ret[$name]=$dn;
741     }
742     ksort($ret);
743     $ret = array_flip($ret);
745     return ($ret);
746   }
749   function get_type($array)
750   {
751     if(!isset($array['objectClass'])) return(array());
752     if(in_array("FAIpartitionTable",$array['objectClass'])){
753       return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
754     }
755     if(in_array("FAIscript",$array['objectClass'])){
756       return(array("tabsScript","faiScript","FAISCRIPTTABS"));
757     }
758     if(in_array("FAItemplate",$array['objectClass'])){
759       return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
760     }
761     if(in_array("FAIhook",$array['objectClass'])){
762       return(array("tabsHook","faiHook","FAIHOOKTABS"));
763     }
764     if(in_array("FAIvariable",$array['objectClass'])){
765       return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
766     }
767     if(in_array("FAIprofile",$array['objectClass'])){
768       return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
769     }
770     if(in_array("FAIpackageList",$array['objectClass'])){
771       return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
772     }
773     return(array());
774   }
775
776 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
777 ?>