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("remove_multiple","removeEntryRequested");
100 $this->registerAction("new_profile","newEntry");
101 $this->registerAction("new_template","newEntry");
102 $this->registerAction("new_script","newEntry");
103 $this->registerAction("new_hook","newEntry");
104 $this->registerAction("new_variable","newEntry");
105 $this->registerAction("new_package","newEntry");
106 $this->registerAction("new_partition","newEntry");
108 $this->registerAction("newClassNameSelected","newClassNameSelected");
110 $this->registerAction("saveOpsiProperties","saveOpsiProperties");
112 $this->registerAction("editByGroup","editByGroup");
113 $this->registerAction("createBranch","createBranch");
114 $this->registerAction("createFreeze","createFreeze");
115 $this->registerAction("removeBranch","removeBranch");
116 $this->registerAction("removeBranchConfirmed","removeBranchConfirmed");
117 $this->registerAction("saveBranch","saveBranch");
118 $this->registerAction("PerformBranch","PerformBranch");
119 parent::__construct($config, $ui, "roles", $headpage);
120 }
123 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
124 {
125 /****************
126 Create a new object
127 ****************/
129 $types = array(
130 "new_partition" => "FAIpartitionTable",
131 "new_script" => "FAIscript",
132 "new_hook" => "FAIhook",
133 "new_variable" => "FAIvariable",
134 "new_template" => "FAItemplate",
135 "new_package" => "FAIpackageList");
136 $types_i18n = array(
137 "new_partition" => _("partition table"),
138 "new_script" => _("script"),
139 "new_hook" => _("hook"),
140 "new_variable" => _("variable"),
141 "new_template" => _("template"),
142 "new_package" => _("package list"));
144 if(isset($types[$action])){
145 $type_acl_mapping = array(
146 "FAIpartitionTable" => "faiPartitionTable",
147 "FAIpackageList" => "faiPackage",
148 "FAIscript" => "faiScript",
149 "FAIvariable" => "faiVariable",
150 "FAIhook" => "faiHook",
151 "FAIprofile" => "faiProfile",
152 "FAItemplate" => "faiTemplate");
154 $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$action]]);
155 if(preg_match("/c/",$acl)){
156 $this->dialogObject = new askClassName($this->config,$this->dn,$this->ui,$types[$action]);
157 $this->dialogObject->parent = &$this;
158 }else{
159 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$action]), ERROR_DIALOG);
160 }
161 }
162 if($action == "new_profile"){
163 $this->dn = "new" ;
165 $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
166 if(preg_match("/c/",$acl)){
167 $type= $this->get_type(array("objectClass"=>array("FAIprofile")));
168 $str= management::newEntry('newEntry',array(),array(),$type[0],$type[2],$type[1]);
169 if($str) return($str);
170 $this->tabObject->set_acl_base($this->acl_base);
171 $this->tabObject->by_object[$type[1]]->cn = $name;
172 }else{
173 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
174 }
175 }
176 }
179 function newClassNameSelected()
180 {
181 $this->dialogObject->save_object();
182 if(count($this->dialogObject->check())!=0){
183 foreach($this->dialogObject->check() as $msg){
184 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
185 }
186 }elseif(isset($this->dialogObject->objectClass)){
187 $this->dn = "new" ;
188 $type= $this->get_type(array("objectClass"=>array($this->dialogObject->objectClass)));
189 $name = $this->dialogObject->save();
191 if(class_exists($type[0])){
192 $this->closeDialogs();
193 $str = management::newEntry('newEntry',array(),array(),$type[0],$type[2],$type[1]);
194 if($str) return($str);
195 $this->tabObject->set_acl_base($this->acl_base);
196 $this->tabObject->by_object[$type[1]]->cn = $name;
197 }
198 }
199 }
203 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
204 {
205 $headpage = $this->getHeadpage();
206 if(count($target) == 1){
207 $entry = $headpage->getEntry($target[0]);
208 if($entry){
210 if(in_array("opsi_local", $entry['TYPES']) || in_array("opsi_netboot", $entry['TYPES'])){
211 $name = $entry['cn'];
212 $cfg = $this->opsi->get_product_properties($name);
214 $str = management::editEntry('editEntry',array($name),array(),'tabs_opsiProdConfig','OPSIPRODCONFIG','opsi');
215 if($str) return($str);
216 if(isset($this->tabObject->by_object['opsiProperties'])){
217 $this->tabObject->by_object['opsiProperties']->set_cfg($cfg);
218 $this->tabObject->by_object['opsiProperties']->set_product($name);
219 $this->skipFooter = TRUE;
220 }else{
221 trigger_error("Unknown tab, please check config.");
222 }
224 }else{
225 if(count($entry['GROUPS']) == 1){
226 $data = array_pop($entry['GROUPS']);
227 $type = $this->get_type($data);
228 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
229 if($str) return($str);
230 $this->tabObject->by_object[$type[1]]->FAIstate = $data['FAIstate'];
231 $this->tabObject->read_only = preg_match("/freeze/i", $data['FAIstate']);
233 }else{
234 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
235 }
236 }
237 }
238 }
239 }
242 function saveOpsiProperties()
243 {
244 if($this->tabObject instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
245 $this->tabObject->save_object();
246 $op = $this->tabObject->by_object['opsiProperties'];
247 $name = $op->get_product();
248 $cfg = $op->get_cfg();
249 $this->opsi->set_product_properties($name,$cfg);
250 if($this->opsi->is_error()){
251 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
252 }else{
253 $this->remove_lock();
254 $this->closeDialogs();
255 }
256 }
257 }
260 function removeFAIObjects($to_delete)
261 {
262 // Do not allow to remove objects with state freeezed
263 $errors=array();
264 foreach($to_delete as $obj){
265 if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
266 $errors[] = $obj['dn'];
267 }else{
268 $this->dns[] = $obj['dn'];
269 }
270 }
271 if(count($errors)){
272 msg_dialog::display(_("Branch locked"),
273 sprintf(_("The following entries are locked, you can't remove them %s."),msgPool::buildList($errors)),INFO_DIALOG);
274 }
276 // Check entry locking
277 if(count($this->dns)){
278 if ($user= get_multiple_locks($this->dns)){
279 return(gen_locked_message($user,$this->dns));
280 }
281 if(count($this->dns)){
282 $smarty = get_smarty();
283 $dns_names = array();
284 foreach($this->dns as $dn){
285 add_lock ($dn, $this->ui->dn);
286 $dns_names[] = LDAP::fix($dn);
287 }
288 $smarty->assign("info",msgPool::deleteInfo($dns_names,_("FAI object")));
289 $smarty->assign("multiple", true);
290 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
291 }
292 }
294 }
296 function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
297 {
299 $this->closeDialogs();
300 if($action == "remove_multiple"){
302 /* Collect objects to delete and check if objects are freezed
303 */
304 $headpage = $this->getHeadpage();
305 $to_delete = array();
306 foreach($target as $id){
307 $object = $headpage->getEntry($id);
308 if(in_array("FAKE_OC_FAI", $object['objectClass'])){
309 foreach($object['GROUPS'] as $entry){
310 array_push($to_delete, $entry);
311 }
312 }
313 }
314 return($this->removeFAIObjects($to_delete));
316 }else{
318 // Try to remove a single object, only FAI objects can be removed!
319 $headpage = $this->getHeadpage();
320 if(count($target) == 1){
321 $entry = $headpage->getEntry($target[0]);
322 if($entry && !in_array("FAKE_OC_OPSI",$entry['objectClass'])){
323 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
324 }
325 }
326 }
327 }
329 /*! \brief Object removal was confirmed, now remove the requested entries.
330 *
331 * @param String 'action' The name of the action which was the used as trigger.
332 * @param Array 'target' A list of object dns, which should be affected by this method.
333 * @param Array 'all' A combination of both 'action' and 'target'.
334 */
335 function removeEntryConfirmed($action="",$target=array(),$all=array(),
336 $altTabClass="",$altTabType="",$altAclCategory="")
337 {
338 $ldap = $this->config->get_ldap_link();
339 $ldap->cd($this->config->current['BASE']);
341 foreach($this->dns as $key => $dn){
342 $ldap->cat($dn);
343 if($ldap->count()){
344 $attrs = $ldap->fetch();
345 $type= $this->get_type($attrs);
346 $str = management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
347 if($str) return($str);
349 // Now save changes
350 FAI::save_release_changes_now();
351 $to_del = FAI::clean_up_releases($dn);
352 foreach($to_del as $dn){
353 $ldap->rmdir_recursive($dn);
354 }
355 }
356 }
357 }
360 function editByGroup()
361 {
362 if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
363 $this->dialogObject->save_object();
364 $entry = $this->dialogObject->get_selected();
365 $this->closeDialogs();
366 $data = array_pop($entry);
367 $type = $this->get_type($data);
368 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
369 if($str) return($str);
370 $this->tabObject->by_object[$type[1]]->FAIstate = $data['FAIstate'];
371 $this->tabObject->read_only = preg_match("/freeze/i", $data['FAIstate']);
372 }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
373 $this->dialogObject->save_object();
374 $to_delete = $entry = $this->dialogObject->get_selected();
375 return($this->removeFAIObjects($to_delete));
376 }
377 }
380 protected function saveChanges()
381 {
382 $str = management::saveChanges();
383 if($str) return($str);
385 // Now save changes
386 FAI::save_release_changes_now();
387 $to_del = FAI::clean_up_releases($this->last_dn);
388 foreach($to_del as $dn){
389 $ldap->rmdir_recursive($dn);
390 }
391 }
393 protected function applyChanges()
394 {
395 $str = management::applyChanges();
396 if($str) return($str);
398 // Now save changes
399 FAI::save_release_changes_now();
400 $to_del = FAI::clean_up_releases($this->last_dn);
401 foreach($to_del as $dn){
402 $ldap->rmdir_recursive($dn);
403 }
404 }
406 function detectPostActions()
407 {
408 $action = management::detectPostActions();
409 if(isset($_POST['remove_multiple'])) $action['action'] = "remove";
410 if(isset($_POST['new_profile'])) $action['action'] = "new_profile";
411 if(isset($_POST['new_template'])) $action['action'] = "new_template";
412 if(isset($_POST['new_script'])) $action['action'] = "new_script";
413 if(isset($_POST['new_hook'])) $action['action'] = "new_hook";
414 if(isset($_POST['new_variable'])) $action['action'] = "new_variable";
415 if(isset($_POST['new_package'])) $action['action'] = "new_package";
416 if(isset($_POST['new_partition'])) $action['action'] = "new_partition";
419 if(isset($_POST['save_properties'])) $action['action'] = "saveOpsiProperties";
420 if(isset($_POST['cancel_properties'])) $action['action'] = "cancel";
422 if(isset($_POST['edit_continue'])) $action['action'] = "newClassNameSelected";
423 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
425 if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
426 if(isset($_POST['CancelBranchName'])) $action['action'] = "cancel";
427 if(isset($_POST['delete_branch_confirm'])) $action['action'] = "removeBranchConfirmed";
428 if(isset($_GET['PerformBranch'])) $action['action'] = "PerformBranch";
429 if(isset($_POST['UseBranchName'])) $action['action'] = "saveBranch";
430 if(isset($_POST['faiGroupHandle_apply'])) $action['action'] = "editByGroup";
431 if(isset($_GET['act']) && $_GET['act'] == "branch_branch") $action['action'] = "createBranch";
432 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch") $action['action'] = "createFreeze";
433 if(isset($_GET['act']) && $_GET['act'] == "remove_branch") $action['action'] = "removeBranch";
435 foreach($_POST as $name => $value){
436 if(preg_match("/^edit_([0-9]*)_([a-z]*)_(x|y)/i", $name)){
437 $id = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\1", $name);
438 $tab = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\2", $name);
439 $headpage = $this->getHeadpage();
440 if(isset($headpage->entries[$id]['GROUPS'][$tab])){
441 $data =$headpage->entries[$id]['GROUPS'][$tab];
442 $type = $this->get_type($data);
443 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
444 if($str) return($str);
445 }
446 break;
447 }
448 }
449 return($action);
450 }
453 function renderList()
454 {
455 $filter = $this->getFilter();
456 $headpage = $this->getHeadpage();
457 $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
459 if(isset($_POST['RELEASE'])){
460 $this->fai_release = get_post('RELEASE');
461 }
462 $headpage->setBase($this->fai_release);
463 $headpage->update();
464 $smarty = get_smarty();
465 $smarty->assign("fai_release", $this->fai_release);
466 $smarty->assign("opsi_available", is_object($this->opsi));
467 $smarty->assign("fai_base", $this->fai_base);
468 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
469 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
470 $smarty->assign("allow_create", $c);
471 $smarty->assign("allow_remove", $r);
472 $display = $headpage->render();
473 return($this->getHeader().$display);
474 }
476 function getReleaseList($base = "", $prefix ="")
477 {
478 $list = array();
479 if(empty($base)){
480 $base = $this->fai_base;
481 $list[$base] = "/";
482 }
484 $ldap = $this->config->get_ldap_link();
485 $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
486 $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
488 while($release = $ldap->fetch()){
489 $list[$release['dn']] = $prefix.$release['ou'][0];
491 // Preset to prefered releaes if necessary
492 if(empty($this->fai_release) && $cfg_rel == $release['dn']){
493 $this->fai_release = $release['dn'];
494 }
496 $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix." "));
497 }
498 return($list);
499 }
502 static function filterProperties($row, $classes)
503 {
504 $objects = array(
505 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
506 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
507 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
508 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
509 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
510 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
511 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
512 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
513 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
514 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
515 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
516 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
517 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
518 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
519 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
520 "NAME"=>_("OPSI netboot product") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
521 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
522 "NAME"=>_("OPSI localboot product") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
524 $icon_list = "";
525 foreach($objects as $type => $type_data){
526 if(in_array($type, $classes)){
527 $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
528 alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
529 }else{
530 $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
531 }
532 }
534 return $icon_list;
535 }
540 function removeBranch()
541 {
542 /* Check if we have a post remove method configured
543 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
544 */
545 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
546 /* Load permissions for selected 'dn' and check if
547 we're allowed to remove this 'dn' */
548 if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
549 $smarty=get_smarty();
550 $smarty->assign("release_hidden",base64_encode($this->fai_release));
551 $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
552 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
553 } else {
554 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
555 }
556 }
557 }
560 function removeBranchConfirmed()
561 {
562 /* Check if we have a post remove method configured
563 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
564 */
565 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
567 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
568 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
569 }else{
571 $bb = $this->fai_release;
572 $ldap = $this->config->get_ldap_link();
574 $br = $this->getBranches();
576 if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
577 $name = $br[$bb];
579 $ldap->cd($bb);
580 $ldap->recursive_remove();
581 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('applicationRDN'), $bb));
582 $ldap->recursive_remove();
583 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('mimetypeRDN'), $bb));
584 $ldap->recursive_remove();
586 /* Search for all groups with configured application menus.
587 - First search all groups, to ensure that we only remove entries form whithin groups.
588 - The search für menu configuration for the specified release and collect all those dns.
589 - Remove entries
590 */
591 $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$bb);
592 $ldap->cd($this->config->current['BASE']);
593 $ldap->search("(objectClass=posixGroup)",array("dn"));
595 /* Collect all group dns
596 */
597 $groups = array();
598 while($attrs = $ldap->fetch()){
599 $groups[] = $attrs['dn'];
600 }
603 /* Collect all group menu release dns that match the release we have removed
604 */
605 $dns = array();
606 foreach($groups as $dn){
607 $ldap->cd($dn);
608 $ldap->search("(objectClass=FAIbranch)",array("dn"));
609 while($attrs = $ldap->fetch()){
610 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
611 $dns[] = $attrs['dn'];
612 }
613 }
614 }
616 /* Finally remove collected release dns
617 */
618 foreach($dns as $dn){
619 $ldap->cd($dn);
620 $ldap->recursive_remove();
621 }
623 /* Post remove */
624 $this->fai_release = $this->fai_base;
625 $this->lock_name = $name;
626 $this->lock_dn = $bb;
627 $this->postremove();
629 $fai_filter = session::get("fai_filter");
630 $fai_filter['fai_release'] = $this->fai_release;
631 session::set("fai_filter",$fai_filter);
633 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
634 }
635 }
636 }
637 }
640 function createBranch()
641 {
642 $smarty = get_smarty();
643 $this->dispNewBranch=true;
644 $this->dispNewFreeze=false;
645 $smarty->assign("iframe",false);
646 if(isset($_POST['BranchName'])){
647 $smarty->assign("BranchName", $_POST['BranchName']);
648 }else{
649 $smarty->assign("BranchName","");
650 }
651 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
652 }
654 function createFreeze()
655 {
656 $smarty = get_smarty();
657 $this->dispNewFreeze=true;
658 $this->dispNewBranch=false;
659 $smarty->assign("iframe",false);
660 if(isset($_POST['BranchName'])){
661 $smarty->assign("BranchName", $_POST['BranchName']);
662 }else{
663 $smarty->assign("BranchName","");
664 }
665 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
666 }
670 function PerformBranch()
671 {
672 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
673 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
674 }else{
676 /* In order to see error messages we have to reset the error handler.
677 Due to the exit();
678 */
679 restore_error_handler();
681 $this->dispNewBranch = false;
682 $this->dispNewFreeze = false;
684 $LASTPOST = session::get('LASTPOST');
685 $base = $LASTPOST['base'];
686 $_POST = session::get('LASTPOST');
687 $name = $_POST['BranchName'];
689 $type = $LASTPOST['type'];
690 $ldap = $this->config->get_ldap_link();
692 $baseToUse = $base;
693 if($this->fai_release != $this->fai_base){
694 $baseToUse = $this->fai_release;
695 }
697 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
699 $CurrentReleases = $this->getBranches();
700 $NewReleaseName = $name;
701 if(isset($CurrentReleases[$this->fai_release])) {
702 if($this->fai_release != $this->fai_base){
703 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
704 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
705 }else{
706 $NewReleaseName = $name;
707 }
708 }
709 $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),$baseToUse);
710 $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
712 $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),$baseToUse);
713 $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
715 /* Check if source depeartments exist */
716 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
717 $ldap->cd($this->config->current['BASE']);
718 $ldap->cat($dep);
719 if(!$ldap->count()){
720 $ldap->create_missing_trees($dep);
721 }
722 }
724 /* Print header to have styles included */
725 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
726 <html>
727 <head>
728 <title></title>
729 <style type="text/css">@import url("themes/default/style.css");</style>
730 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
731 </head>
732 <body style="background: none;margin:3px;color:black">
733 ';
735 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
737 /* Duplicate group application releases
738 */
739 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
741 /* Duplicate applications
742 */
743 $ldap->cat($appsrc,array("dn")) ;
744 if($ldap->count()){
745 $ldap->cd ($appdst);
746 $ldap->recursive_remove();
747 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
748 }
750 /* Duplicate mime types
751 */
752 $ldap->cat($mimesrc,array("dn")) ;
753 if($ldap->count()){
754 $ldap->cd ($mimedst);
755 $ldap->recursive_remove();
756 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
757 }
759 $attr = array();
760 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
761 $attr['ou'] = $name;
762 $attr['FAIstate'] = $type;
763 $ldap->cd($this->config->current['BASE']);
764 $ldap->cd("ou=".$name.",".$baseToUse);
765 $ldap->cat("ou=".$name.",".$baseToUse);
766 if($ldap->count()){
767 $ldap->modify($attr);
768 }else{
769 $ldap->add($attr);
770 }
772 /* Duplicate fai objects
773 */
774 // $ldap->cd ("ou=".$name.",".$baseToUse);
775 // $ldap->recursive_remove();
776 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
778 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
779 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
780 <input type='hidden' name='php_c_check' value='1'>
781 </form></div>";
783 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
785 /* Print footer to have valid html */
786 echo "</body></html>";
788 $this->dispNewFreeze = false;
790 /* Postcreate */
792 /* Assign possible attributes */
793 $this->lock_type = $type;
794 $this->lock_name = $name;
795 $this->lock_dn = $baseToUse;
796 $this->postcreate();
798 /* Send daemon event to reload the fai release database
799 */
800 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
801 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
802 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
803 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
804 $tmp = new $evt['CLASS_NAME']($this->config);
805 $tmp->set_type(TRIGGERED_EVENT);
806 $tmp->add_targets(array("GOSA"));
807 $o_queue = new gosaSupportDaemon();
808 if(!$o_queue->append($tmp)){
809 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
810 }
811 }
812 }else{
813 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
814 msg_dialog::display(_("Fatal error"),
815 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
816 FATAL_ERROR_DIALOG);
817 }
818 exit();
819 }
820 }
825 function saveBranch()
826 {
827 if($this->dispNewBranch){
828 $type = "branch";
829 }else{
830 $type = "freeze";
831 }
833 /* Check branch name */
834 $name = $_POST['BranchName'];
835 $is_ok = true;
836 $smarty = get_smarty();
837 $smarty->assign("BranchName",$name);
838 $base= $this->fai_base;
840 /* Check used characters */
841 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
842 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
843 $is_ok = false;
844 }
846 // Check if this name is already in use
847 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
848 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
849 $is_ok = false;
850 }
852 // Handle errors
853 if(!$is_ok && $this->dispNewFreeze){
854 return($this->createFreeze());
855 }elseif(!$is_ok && $this->dispNewBranch){
856 return($this->createBranch());
857 }
859 // Now create new release
861 if(session::is_set('LASTPOST')){
862 $LASTPOST = session::get('LASTPOST');
863 }else{
864 $LASTPOST = array();
865 }
866 $LASTPOST['base'] = $base;
867 $LASTPOST['type'] = $type;
868 $LASTPOST['BranchName'] = $name;
869 session::set('LASTPOST',$LASTPOST);
870 $smarty->assign("iframe", true);
871 $smarty->assign("plugID", $_GET['plug']);
872 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
873 return($display);
875 }
878 function CheckNewBranchName($name,$base)
879 {
880 $f = $this->fai_release;
881 if($name == ""){
882 return(false);
883 }elseif(in_array($name,$this->getBranches($f))) {
884 return(false);
885 }elseif(tests::is_department_name_reserved($name,$base)){
886 return(false);
887 }
888 return(true);
889 }
892 /* Get available branches for current base */
893 function getBranches($base = false,$prefix = "")
894 {
895 $ret = array("/"=>$this->fai_base);
896 $ldap = $this->config->get_ldap_link();
897 if(!$base){
898 $base = $this->fai_base;
899 }
900 $tmp = FAI::get_all_releases_from_base($base,true);
901 foreach($tmp as $dn => $name){
902 $ret[$name]=$dn;
903 }
904 ksort($ret);
905 $ret = array_flip($ret);
907 return ($ret);
908 }
911 function get_type($array)
912 {
913 if(!isset($array['objectClass'])) return(array());
914 if(in_array("FAIpartitionTable",$array['objectClass'])){
915 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
916 }
917 if(in_array("FAIscript",$array['objectClass'])){
918 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
919 }
920 if(in_array("FAItemplate",$array['objectClass'])){
921 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
922 }
923 if(in_array("FAIhook",$array['objectClass'])){
924 return(array("tabsHook","faiHook","FAIHOOKTABS"));
925 }
926 if(in_array("FAIvariable",$array['objectClass'])){
927 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
928 }
929 if(in_array("FAIprofile",$array['objectClass'])){
930 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
931 }
932 if(in_array("FAIpackageList",$array['objectClass'])){
933 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
934 }
935 return(array());
936 }
939 /* Check if the given FAI class is used in this release
940 */
941 static function check_class_name($oc,$name,$dn)
942 {
943 $base = FAI::get_release_dn($dn);
945 if($oc == "FAIprofile"){
946 $f = "";
947 $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
948 foreach($ocs as $oc){
949 $f .= "(objectClass=".$oc.")";
950 }
951 $res = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);
952 }else{
953 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
954 }
955 $delete = array();
956 $used = array();
957 foreach($res as $object){
958 $used[$object['cn'][0]]= $object['cn'][0];
959 }
960 return($used);
961 }
964 }
965 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
966 ?>