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