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 = "";
50 var $opsi = NULL;
53 function __construct($config,$ui)
54 {
55 $this->config = $config;
57 /* Check if the opsi plugin is installed.
58 */
59 if(class_available("opsi")){
60 $this->opsi = new opsi($this->config);;
61 }
63 $this->fai_base = get_ou("faiBaseRDN").$this->config->current['BASE'];
64 $this->fai_release = $this->fai_base;
65 $this->acl_base = $this->config->current['BASE'];
66 $this->ui = $ui;
67 $this->storagePoints = array(
68 get_ou('faiPartitionRDN'),
69 get_ou('faiPackageRDN'),
70 get_ou('faiScriptRDN'),
71 get_ou('faiVariableRDN'),
72 get_ou('faiHookRDN'),
73 get_ou('faiProfileRDN'),get_ou('faiTemplateRDN'));
75 # // Build filter
76 # if (session::global_is_set(get_class($this)."_filter")){
77 # $filter= session::global_get(get_class($this)."_filter");
78 # } else {
79 $filter = new filter(get_template_path("fai-filter.xml", true));
80 $filter->setObjectStorage($this->storagePoints);
81 # }
82 $this->setFilter($filter);
84 // Build headpage
85 $headpage = new listing(get_template_path("fai-list.xml", true));
86 $headpage->setFilter($filter);
87 $headpage->setBase($this->fai_release);
88 $headpage->registerElementFilter("filterProperties", "faiManagement::filterProperties");
90 // Add copy&paste and snapshot handler.
91 if ($this->config->boolValueIsTrue("main", "copyPaste")){
92 $this->cpHandler = new CopyPasteHandler($this->config);
93 }
94 if($this->config->get_cfg_value("enableSnapshots") == "true"){
95 $this->snapHandler = new SnapshotHandler($this->config);
96 }
98 $this->registerAction("new_profile","newEntry");
99 $this->registerAction("new_template","newEntry");
100 $this->registerAction("new_script","newEntry");
101 $this->registerAction("new_hook","newEntry");
102 $this->registerAction("new_variable","newEntry");
103 $this->registerAction("new_package","newEntry");
104 $this->registerAction("new_partition","newEntry");
106 $this->registerAction("newClassNameSelected","newClassNameSelected");
108 $this->registerAction("saveOpsiProperties","saveOpsiProperties");
110 $this->registerAction("editByGroup","editByGroup");
111 $this->registerAction("createBranch","createBranch");
112 $this->registerAction("createFreeze","createFreeze");
113 $this->registerAction("removeBranch","removeBranch");
114 $this->registerAction("removeBranchConfirmed","removeBranchConfirmed");
115 $this->registerAction("saveBranch","saveBranch");
116 $this->registerAction("PerformBranch","PerformBranch");
117 parent::__construct($config, $ui, "roles", $headpage);
118 }
121 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
122 {
123 /****************
124 Create a new object
125 ****************/
127 $types = array(
128 "new_partition" => "FAIpartitionTable",
129 "new_script" => "FAIscript",
130 "new_hook" => "FAIhook",
131 "new_variable" => "FAIvariable",
132 "new_template" => "FAItemplate",
133 "new_package" => "FAIpackageList");
134 $types_i18n = array(
135 "new_partition" => _("partition table"),
136 "new_script" => _("script"),
137 "new_hook" => _("hook"),
138 "new_variable" => _("variable"),
139 "new_template" => _("template"),
140 "new_package" => _("package list"));
142 if(isset($types[$action])){
143 $type_acl_mapping = array(
144 "FAIpartitionTable" => "faiPartitionTable",
145 "FAIpackageList" => "faiPackage",
146 "FAIscript" => "faiScript",
147 "FAIvariable" => "faiVariable",
148 "FAIhook" => "faiHook",
149 "FAIprofile" => "faiProfile",
150 "FAItemplate" => "faiTemplate");
152 $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$action]]);
153 if(preg_match("/c/",$acl)){
154 $this->dialogObject = new askClassName($this->config,$this->dn,$this->ui,$types[$action]);
155 $this->dialogObject->parent = &$this;
156 }else{
157 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$action]), ERROR_DIALOG);
158 }
159 }
160 if($action == "new_profile"){
161 $this->dn = "new" ;
163 $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
164 if(preg_match("/c/",$acl)){
165 $type= $this->get_type(array("objectClass"=>array("FAIprofile")));
166 $str= management::newEntry('newEntry',array(),array(),$type[0],$type[2],$type[1]);
167 if($str) return($str);
168 $this->tabObject->set_acl_base($this->acl_base);
169 $this->tabObject->by_object[$type[1]]->cn = $name;
170 }else{
171 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
172 }
173 }
174 }
177 function newClassNameSelected()
178 {
179 $this->dialogObject->save_object();
180 if(count($this->dialogObject->check())!=0){
181 foreach($this->dialogObject->check() as $msg){
182 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
183 }
184 }elseif(isset($this->dialogObject->objectClass)){
185 $this->dn = "new" ;
186 $type= $this->get_type(array("objectClass"=>array($this->dialogObject->objectClass)));
187 $name = $this->dialogObject->save();
189 if(class_exists($type[0])){
190 $this->closeDialogs();
191 $str = management::newEntry('newEntry',array(),array(),$type[0],$type[2],$type[1]);
192 if($str) return($str);
193 $this->tabObject->set_acl_base($this->acl_base);
194 $this->tabObject->by_object[$type[1]]->cn = $name;
195 }
196 }
197 }
201 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
202 {
203 $headpage = $this->getHeadpage();
204 if(count($target) == 1){
205 $entry = $headpage->getEntry($target[0]);
206 if($entry){
208 if(in_array("opsi_local", $entry['TYPES']) || in_array("opsi_netboot", $entry['TYPES'])){
209 $name = $entry['cn'];
210 $cfg = $this->opsi->get_product_properties($name);
212 $str = management::editEntry('editEntry',array($name),array(),'tabs_opsiProdConfig','OPSIPRODCONFIG','opsi');
213 if($str) return($str);
214 if(isset($this->tabObject->by_object['opsiProperties'])){
215 $this->tabObject->by_object['opsiProperties']->set_cfg($cfg);
216 $this->tabObject->by_object['opsiProperties']->set_product($name);
217 $this->skipFooter = TRUE;
218 }else{
219 trigger_error("Unknown tab, please check config.");
220 }
222 }else{
223 if(count($entry['GROUPS']) == 1){
224 $data = array_pop($entry['GROUPS']);
225 $type = $this->get_type($data);
226 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
227 if($str) return($str);
228 $this->tabObject->by_object[$type[1]]->FAIstate = $data['FAIstate'];
229 $this->tabObject->read_only = preg_match("/freeze/i", $data['FAIstate']);
231 }else{
232 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
233 }
234 }
235 }
236 }
237 }
240 function saveOpsiProperties()
241 {
242 if($this->tabObject instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
243 $this->tabObject->save_object();
244 $op = $this->tabObject->by_object['opsiProperties'];
245 $name = $op->get_product();
246 $cfg = $op->get_cfg();
247 $this->opsi->set_product_properties($name,$cfg);
248 if($this->opsi->is_error()){
249 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
250 }else{
251 $this->remove_lock();
252 $this->closeDialogs();
253 }
254 }
255 }
258 function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
259 {
260 $headpage = $this->getHeadpage();
261 if(count($target) == 1){
262 $entry = $headpage->getEntry($target[0]);
263 if($entry){
264 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
265 }
266 }
267 }
269 /*! \brief Object removal was confirmed, now remove the requested entries.
270 *
271 * @param String 'action' The name of the action which was the used as trigger.
272 * @param Array 'target' A list of object dns, which should be affected by this method.
273 * @param Array 'all' A combination of both 'action' and 'target'.
274 */
275 function removeEntryConfirmed($action="",$target=array(),$all=array(),
276 $altTabClass="",$altTabType="",$altAclCategory="")
277 {
278 $ldap = $this->config->get_ldap_link();
279 $ldap->cd($this->config->current['BASE']);
280 foreach($this->dns as $key => $dn){
281 $ldap->cat($dn);
282 if($ldap->count()){
283 $attrs = $ldap->fetch();
284 $type= $this->get_type($attrs);
285 $str = management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
286 if($str) return($str);
288 // Now save changes
289 FAI::save_release_changes_now();
290 $to_del = FAI::clean_up_releases($dn);
291 foreach($to_del as $dn){
292 $ldap->rmdir_recursive($dn);
293 }
294 }
295 }
296 }
299 function editByGroup()
300 {
301 if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
302 $this->dialogObject->save_object();
303 $entry = $this->dialogObject->get_selected();
304 $this->closeDialogs();
305 $data = array_pop($entry);
306 $type = $this->get_type($data);
307 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
308 if($str) return($str);
309 $this->tabObject->by_object[$type[1]]->FAIstate = $data['FAIstate'];
310 $this->tabObject->read_only = preg_match("/freeze/i", $data['FAIstate']);
312 }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
313 $this->dialogObject->save_object();
314 $to_delete = $entry = $this->dialogObject->get_selected();
315 $dns = array();
318 // Check FAIstate to ensure that we do not remove frozen objects
319 // additionally check ACLs
320 $locked = array();
321 $disallowed = array();
322 foreach($to_delete as $obj){
323 if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
324 $locked[] = $obj['dn'];
325 }else{
326 $type = $this->get_type($obj);
327 $acl = $this->ui->get_permissions($obj['dn'], 'acl/'.$type[1]);
328 if(!preg_match("/d/",$acl)){
329 $disallowed[] = $obj['dn'];
330 }else{
331 $dns[] = $obj['dn'];
332 }
333 }
334 }
336 // Display info dialog about locked and not removeable entries
337 if(count($locked)){
338 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
339 msgPool::buildList($locked)));
340 }
342 // Display info dialog about not removeable entries due to permissions
343 if(count($disallowed)){
344 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
345 }
347 // There are entries left to be removed
348 if(count($dns)){
349 $this->closeDialogs();
350 $this->dns = $dns;
352 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
354 // check locks
355 if ($user= get_multiple_locks($this->dns)){
356 return(gen_locked_message($user,$this->dns));
357 }
359 // Add locks
360 $dns_names = array();
361 foreach($this->dns as $dn){
362 $dns_names[] =LDAP::fix($dn);
363 }
364 add_lock ($this->dns, $this->ui->dn);
366 // Display confirmation dialog.
367 $smarty = get_smarty();
368 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
369 $smarty->assign("multiple", true);
370 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
371 }else{
372 $this->closeDialogs();
373 }
374 }
375 }
378 protected function saveChanges()
379 {
380 $str = management::saveChanges();
381 if($str) return($str);
383 // Now save changes
384 FAI::save_release_changes_now();
385 $to_del = FAI::clean_up_releases($this->last_dn);
386 foreach($to_del as $dn){
387 $ldap->rmdir_recursive($dn);
388 }
389 }
391 protected function applyChanges()
392 {
393 $str = management::applyChanges();
394 if($str) return($str);
396 // Now save changes
397 FAI::save_release_changes_now();
398 $to_del = FAI::clean_up_releases($this->last_dn);
399 foreach($to_del as $dn){
400 $ldap->rmdir_recursive($dn);
401 }
402 }
404 function detectPostActions()
405 {
406 $action = management::detectPostActions();
407 if(isset($_POST['new_profile'])) $action['action'] = "new_profile";
408 if(isset($_POST['new_template'])) $action['action'] = "new_template";
409 if(isset($_POST['new_script'])) $action['action'] = "new_script";
410 if(isset($_POST['new_hook'])) $action['action'] = "new_hook";
411 if(isset($_POST['new_variable'])) $action['action'] = "new_variable";
412 if(isset($_POST['new_package'])) $action['action'] = "new_package";
413 if(isset($_POST['new_partition'])) $action['action'] = "new_partition";
416 if(isset($_POST['save_properties'])) $action['action'] = "saveOpsiProperties";
417 if(isset($_POST['cancel_properties'])) $action['action'] = "cancel";
419 if(isset($_POST['edit_continue'])) $action['action'] = "newClassNameSelected";
420 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
422 if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
423 if(isset($_POST['CancelBranchName'])) $action['action'] = "cancel";
424 if(isset($_POST['delete_branch_confirm'])) $action['action'] = "removeBranchConfirmed";
425 if(isset($_GET['PerformBranch'])) $action['action'] = "PerformBranch";
426 if(isset($_POST['UseBranchName'])) $action['action'] = "saveBranch";
427 if(isset($_POST['faiGroupHandle_apply'])) $action['action'] = "editByGroup";
428 if(isset($_GET['act']) && $_GET['act'] == "branch_branch") $action['action'] = "createBranch";
429 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch") $action['action'] = "createFreeze";
430 if(isset($_GET['act']) && $_GET['act'] == "remove_branch") $action['action'] = "removeBranch";
432 foreach($_POST as $name => $value){
433 if(preg_match("/^edit_([0-9]*)_([a-z]*)_(x|y)/i", $name)){
434 $id = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\1", $name);
435 $tab = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\2", $name);
436 $headpage = $this->getHeadpage();
437 if(isset($headpage->entries[$id]['GROUPS'][$tab])){
438 $data =$headpage->entries[$id]['GROUPS'][$tab];
439 $type = $this->get_type($data);
440 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
441 if($str) return($str);
442 }
443 break;
444 }
445 }
446 return($action);
447 }
450 function renderList()
451 {
452 $filter = $this->getFilter();
453 $headpage = $this->getHeadpage();
454 $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
456 if(isset($_POST['RELEASE'])){
457 $this->fai_release = get_post('RELEASE');
458 }
459 $headpage->setBase($this->fai_release);
460 $headpage->update();
461 $smarty = get_smarty();
462 $smarty->assign("fai_release", $this->fai_release);
463 $smarty->assign("opsi_available", is_object($this->opsi));
464 $smarty->assign("fai_base", $this->fai_base);
465 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
466 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
467 $smarty->assign("allow_create", $c);
468 $smarty->assign("allow_remove", $r);
469 $display = $headpage->render();
470 return($this->getHeader().$display);
471 }
473 function getReleaseList($base = "", $prefix ="")
474 {
475 $list = array();
476 if(empty($base)){
477 $base = $this->fai_base;
478 $list[$base] = "/";
479 }
481 $ldap = $this->config->get_ldap_link();
482 $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
483 $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
485 while($release = $ldap->fetch()){
486 $list[$release['dn']] = $prefix.$release['ou'][0];
488 // Preset to prefered releaes if necessary
489 if(empty($this->fai_release) && $cfg_rel == $release['dn']){
490 $this->fai_release = $release['dn'];
491 }
493 $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix." "));
494 }
495 return($list);
496 }
499 static function filterProperties($row, $classes)
500 {
501 $objects = array(
502 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
503 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
504 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
505 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
506 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
507 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
508 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
509 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
510 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
511 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
512 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
513 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
514 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
515 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
516 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
517 "NAME"=>_("OPSI netboot product") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
518 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
519 "NAME"=>_("OPSI localboot product") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
521 $icon_list = "";
522 foreach($objects as $type => $type_data){
523 if(in_array($type, $classes)){
524 $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
525 alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
526 }else{
527 $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
528 }
529 }
531 return $icon_list;
532 }
537 function removeBranch()
538 {
539 /* Check if we have a post remove method configured
540 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
541 */
542 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
543 /* Load permissions for selected 'dn' and check if
544 we're allowed to remove this 'dn' */
545 if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
546 $smarty=get_smarty();
547 $smarty->assign("release_hidden",base64_encode($this->fai_release));
548 $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
549 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
550 } else {
551 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
552 }
553 }
554 }
557 function removeBranchConfirmed()
558 {
559 /* Check if we have a post remove method configured
560 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
561 */
562 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
564 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
565 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
566 }else{
568 $bb = $this->fai_release;
569 $ldap = $this->config->get_ldap_link();
571 $br = $this->getBranches();
573 if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
574 $name = $br[$bb];
576 $ldap->cd($bb);
577 $ldap->recursive_remove();
578 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('applicationRDN'), $bb));
579 $ldap->recursive_remove();
580 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('mimetypeRDN'), $bb));
581 $ldap->recursive_remove();
583 /* Search for all groups with configured application menus.
584 - First search all groups, to ensure that we only remove entries form whithin groups.
585 - The search für menu configuration for the specified release and collect all those dns.
586 - Remove entries
587 */
588 $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$bb);
589 $ldap->cd($this->config->current['BASE']);
590 $ldap->search("(objectClass=posixGroup)",array("dn"));
592 /* Collect all group dns
593 */
594 $groups = array();
595 while($attrs = $ldap->fetch()){
596 $groups[] = $attrs['dn'];
597 }
600 /* Collect all group menu release dns that match the release we have removed
601 */
602 $dns = array();
603 foreach($groups as $dn){
604 $ldap->cd($dn);
605 $ldap->search("(objectClass=FAIbranch)",array("dn"));
606 while($attrs = $ldap->fetch()){
607 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
608 $dns[] = $attrs['dn'];
609 }
610 }
611 }
613 /* Finally remove collected release dns
614 */
615 foreach($dns as $dn){
616 $ldap->cd($dn);
617 $ldap->recursive_remove();
618 }
620 /* Post remove */
621 $this->fai_release = $this->fai_base;
622 $this->lock_name = $name;
623 $this->lock_dn = $bb;
624 $this->postremove();
626 $fai_filter = session::get("fai_filter");
627 $fai_filter['fai_release'] = $this->fai_release;
628 session::set("fai_filter",$fai_filter);
630 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
631 }
632 }
633 }
634 }
637 function createBranch()
638 {
639 $smarty = get_smarty();
640 $this->dispNewBranch=true;
641 $this->dispNewFreeze=false;
642 $smarty->assign("iframe",false);
643 if(isset($_POST['BranchName'])){
644 $smarty->assign("BranchName", $_POST['BranchName']);
645 }else{
646 $smarty->assign("BranchName","");
647 }
648 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
649 }
651 function createFreeze()
652 {
653 $smarty = get_smarty();
654 $this->dispNewFreeze=true;
655 $this->dispNewBranch=false;
656 $smarty->assign("iframe",false);
657 if(isset($_POST['BranchName'])){
658 $smarty->assign("BranchName", $_POST['BranchName']);
659 }else{
660 $smarty->assign("BranchName","");
661 }
662 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
663 }
667 function PerformBranch()
668 {
669 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
670 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
671 }else{
673 /* In order to see error messages we have to reset the error handler.
674 Due to the exit();
675 */
676 restore_error_handler();
678 $this->dispNewBranch = false;
679 $this->dispNewFreeze = false;
681 $LASTPOST = session::get('LASTPOST');
682 $base = $LASTPOST['base'];
683 $_POST = session::get('LASTPOST');
684 $name = $_POST['BranchName'];
686 $type = $LASTPOST['type'];
687 $ldap = $this->config->get_ldap_link();
689 $baseToUse = $base;
690 if($this->fai_release != $this->fai_base){
691 $baseToUse = $this->fai_release;
692 }
694 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
696 $CurrentReleases = $this->getBranches();
697 $NewReleaseName = $name;
698 if(isset($CurrentReleases[$this->fai_release])) {
699 if($this->fai_release != $this->fai_base){
700 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
701 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
702 }else{
703 $NewReleaseName = $name;
704 }
705 }
706 $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),$baseToUse);
707 $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
709 $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),$baseToUse);
710 $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
712 /* Check if source depeartments exist */
713 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
714 $ldap->cd($this->config->current['BASE']);
715 $ldap->cat($dep);
716 if(!$ldap->count()){
717 $ldap->create_missing_trees($dep);
718 }
719 }
721 /* Print header to have styles included */
722 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
723 <html>
724 <head>
725 <title></title>
726 <style type="text/css">@import url("themes/default/style.css");</style>
727 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
728 </head>
729 <body style="background: none;margin:3px;color:black">
730 ';
732 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
734 /* Duplicate group application releases
735 */
736 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
738 /* Duplicate applications
739 */
740 $ldap->cat($appsrc,array("dn")) ;
741 if($ldap->count()){
742 $ldap->cd ($appdst);
743 $ldap->recursive_remove();
744 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
745 }
747 /* Duplicate mime types
748 */
749 $ldap->cat($mimesrc,array("dn")) ;
750 if($ldap->count()){
751 $ldap->cd ($mimedst);
752 $ldap->recursive_remove();
753 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
754 }
756 $attr = array();
757 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
758 $attr['ou'] = $name;
759 $attr['FAIstate'] = $type;
760 $ldap->cd($this->config->current['BASE']);
761 $ldap->cd("ou=".$name.",".$baseToUse);
762 $ldap->cat("ou=".$name.",".$baseToUse);
763 if($ldap->count()){
764 $ldap->modify($attr);
765 }else{
766 $ldap->add($attr);
767 }
769 /* Duplicate fai objects
770 */
771 // $ldap->cd ("ou=".$name.",".$baseToUse);
772 // $ldap->recursive_remove();
773 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
775 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
776 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
777 <input type='hidden' name='php_c_check' value='1'>
778 </form></div>";
780 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
782 /* Print footer to have valid html */
783 echo "</body></html>";
785 $this->dispNewFreeze = false;
787 /* Postcreate */
789 /* Assign possible attributes */
790 $this->lock_type = $type;
791 $this->lock_name = $name;
792 $this->lock_dn = $baseToUse;
793 $this->postcreate();
795 /* Send daemon event to reload the fai release database
796 */
797 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
798 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
799 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
800 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
801 $tmp = new $evt['CLASS_NAME']($this->config);
802 $tmp->set_type(TRIGGERED_EVENT);
803 $tmp->add_targets(array("GOSA"));
804 $o_queue = new gosaSupportDaemon();
805 if(!$o_queue->append($tmp)){
806 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
807 }
808 }
809 }else{
810 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
811 msg_dialog::display(_("Fatal error"),
812 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
813 FATAL_ERROR_DIALOG);
814 }
815 exit();
816 }
817 }
822 function saveBranch()
823 {
824 if($this->dispNewBranch){
825 $type = "branch";
826 }else{
827 $type = "freeze";
828 }
830 /* Check branch name */
831 $name = $_POST['BranchName'];
832 $is_ok = true;
833 $smarty = get_smarty();
834 $smarty->assign("BranchName",$name);
835 $base= $this->fai_base;
837 /* Check used characters */
838 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
839 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
840 $is_ok = false;
841 }
843 // Check if this name is already in use
844 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
845 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
846 $is_ok = false;
847 }
849 // Handle errors
850 if(!$is_ok && $this->dispNewFreeze){
851 return($this->createFreeze());
852 }elseif(!$is_ok && $this->dispNewBranch){
853 return($this->createBranch());
854 }
856 // Now create new release
858 if(session::is_set('LASTPOST')){
859 $LASTPOST = session::get('LASTPOST');
860 }else{
861 $LASTPOST = array();
862 }
863 $LASTPOST['base'] = $base;
864 $LASTPOST['type'] = $type;
865 $LASTPOST['BranchName'] = $name;
866 session::set('LASTPOST',$LASTPOST);
867 $smarty->assign("iframe", true);
868 $smarty->assign("plugID", $_GET['plug']);
869 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
870 return($display);
872 }
875 function CheckNewBranchName($name,$base)
876 {
877 $f = $this->fai_release;
878 if($name == ""){
879 return(false);
880 }elseif(in_array($name,$this->getBranches($f))) {
881 return(false);
882 }elseif(tests::is_department_name_reserved($name,$base)){
883 return(false);
884 }
885 return(true);
886 }
889 /* Get available branches for current base */
890 function getBranches($base = false,$prefix = "")
891 {
892 $ret = array("/"=>$this->fai_base);
893 $ldap = $this->config->get_ldap_link();
894 if(!$base){
895 $base = $this->fai_base;
896 }
897 $tmp = FAI::get_all_releases_from_base($base,true);
898 foreach($tmp as $dn => $name){
899 $ret[$name]=$dn;
900 }
901 ksort($ret);
902 $ret = array_flip($ret);
904 return ($ret);
905 }
908 function get_type($array)
909 {
910 if(!isset($array['objectClass'])) return(array());
911 if(in_array("FAIpartitionTable",$array['objectClass'])){
912 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
913 }
914 if(in_array("FAIscript",$array['objectClass'])){
915 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
916 }
917 if(in_array("FAItemplate",$array['objectClass'])){
918 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
919 }
920 if(in_array("FAIhook",$array['objectClass'])){
921 return(array("tabsHook","faiHook","FAIHOOKTABS"));
922 }
923 if(in_array("FAIvariable",$array['objectClass'])){
924 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
925 }
926 if(in_array("FAIprofile",$array['objectClass'])){
927 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
928 }
929 if(in_array("FAIpackageList",$array['objectClass'])){
930 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
931 }
932 return(array());
933 }
936 /* Check if the given FAI class is used in this release
937 */
938 static function check_class_name($oc,$name,$dn)
939 {
940 $base = FAI::get_release_dn($dn);
942 if($oc == "FAIprofile"){
943 $f = "";
944 $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
945 foreach($ocs as $oc){
946 $f .= "(objectClass=".$oc.")";
947 }
948 $res = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);
949 }else{
950 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
951 }
952 $delete = array();
953 $used = array();
954 foreach($res as $object){
955 $used[$object['cn'][0]]= $object['cn'][0];
956 }
957 return($used);
958 }
961 }
962 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
963 ?>