e3de7caaac3daa2241ee61d7eea795013c78ac4d
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 $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
65 if(!empty($cfg_rel)){
66 $this->fai_release = $cfg_rel;
67 }else{
68 $this->fai_release = $this->fai_base;
69 }
71 $this->acl_base = $this->config->current['BASE'];
72 $this->ui = $ui;
73 $this->storagePoints = array(
74 get_ou('faiPartitionRDN'),
75 get_ou('faiPackageRDN'),
76 get_ou('faiScriptRDN'),
77 get_ou('faiVariableRDN'),
78 get_ou('faiHookRDN'),
79 get_ou('faiProfileRDN'),
80 get_ou('faiTemplateRDN'));
82 // Build filter
83 if (session::global_is_set(get_class($this)."_filter")){
84 $filter= session::global_get(get_class($this)."_filter");
85 } else {
86 $filter = new filter(get_template_path("fai-filter.xml", true));
87 $filter->setObjectStorage($this->storagePoints);
88 }
89 $this->setFilter($filter);
91 // Build headpage
92 $headpage = new listing(get_template_path("fai-list.xml", true));
93 $headpage->setFilter($filter);
94 $headpage->setBase($this->fai_release);
95 $headpage->registerElementFilter("filterProperties", "faiManagement::filterProperties");
97 // Add copy&paste and snapshot handler.
98 if ($this->config->boolValueIsTrue("main", "copyPaste")){
99 $this->cpHandler = new CopyPasteHandler($this->config);
100 }
102 $this->registerAction("remove_multiple","removeEntryRequested");
103 $this->registerAction("new_profile","newEntry");
104 $this->registerAction("new_template","newEntry");
105 $this->registerAction("new_script","newEntry");
106 $this->registerAction("new_hook","newEntry");
107 $this->registerAction("new_variable","newEntry");
108 $this->registerAction("new_package","newEntry");
109 $this->registerAction("new_partition","newEntry");
110 $this->registerAction("newClassNameSelected","newClassNameSelected");
111 $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");
120 parent::__construct($config, $ui, "roles", $headpage);
121 }
124 /*! \brief Act on copy & paste actions here.
125 */
126 function copyPasteHandler($action="",$target=array(),$all=array(),$altTabClass ="",$altTabType="",$altAclCategory="",$altAclPlugin="")
127 {
128 // Collect real dns, the listed objects are grouped by their cn
129 $headpage = $this->getHeadpage();
130 if($action == "copy"){
132 if(count($target) == 1){
134 // We just want to copy a single FAI object, let the user choose entries from the FAI-Group
135 $entry = $headpage->getEntry($target[0]);
136 if(count($entry['GROUPS']) == 1){
137 $data = array_pop($entry['GROUPS']);
138 $type = $this->get_type($data);
139 $this->cpHandler->add_to_queue($g['dn'],"copy",$type[0],$type[2],'fai',$this);
140 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$g['dn'],"Entry copied!");
141 }else{
142 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"copy");
143 }
145 }else{
147 // More than one group was selected, expect that the user wants to copy the complete groups.
148 foreach($target as $t){
149 $entry = $headpage->getEntry($t);
151 // Check for valid FAI objects
152 if(in_array('FAKE_OC_FAI', $entry['objectClass'])){
153 foreach($entry['GROUPS'] as $g){
154 $type = $this->get_type($g);
155 $this->cpHandler->add_to_queue($g['dn'],"copy",$type[0],$type[2],'fai',$this);
156 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$g['dn'],"Entry copied!");
157 }
158 }
159 }
160 }
161 }
163 // Initiate pasting
164 if($action == "paste"){
165 $this->cpPastingStarted = TRUE;
166 }
168 // Display any c&p dialogs, eg. object modifications required before pasting.
169 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
170 $this->cpHandler->SetVar("base",$headpage->getBase());
171 $data = $this->cpHandler->execute();
172 FAI::save_release_changes_now();
173 if(!empty($data)){
174 return($data);
175 }
176 }
178 // Automatically disable pasting process since there is no entry left to paste.
179 if(!$this->cpHandler->entries_queued()){
180 $this->cpPastingStarted = FALSE;
181 }
182 return("");
183 }
186 /*! \brief A new FAI object was requested, let the user specify a name theis object now.
187 */
188 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
189 {
190 $types = array(
191 "new_partition" => "FAIpartitionTable",
192 "new_script" => "FAIscript",
193 "new_hook" => "FAIhook",
194 "new_variable" => "FAIvariable",
195 "new_template" => "FAItemplate",
196 "new_package" => "FAIpackageList");
197 $types_i18n = array(
198 "new_partition" => _("partition table"),
199 "new_script" => _("script"),
200 "new_hook" => _("hook"),
201 "new_variable" => _("variable"),
202 "new_template" => _("template"),
203 "new_package" => _("package list"));
205 if(isset($types[$action])){
206 $type_acl_mapping = array(
207 "FAIpartitionTable" => "faiPartitionTable",
208 "FAIpackageList" => "faiPackage",
209 "FAIscript" => "faiScript",
210 "FAIvariable" => "faiVariable",
211 "FAIhook" => "faiHook",
212 "FAIprofile" => "faiProfile",
213 "FAItemplate" => "faiTemplate");
215 $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$action]]);
216 if(preg_match("/c/",$acl)){
217 $this->dialogObject = new askClassName($this->config,$this->dn,$this->ui,$types[$action]);
218 $this->dialogObject->parent = &$this;
219 }else{
220 msg_dialog::display(_("Permission error"),
221 sprintf(_("You have no permission to create a new %s!"), $types_i18n[$action]), ERROR_DIALOG);
222 }
223 }
224 if($action == "new_profile"){
225 $this->dn = "new" ;
227 $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
228 if(preg_match("/c/",$acl)){
229 $type= $this->get_type(array("objectClass"=>array("FAIprofile")));
230 $str= management::newEntry('newEntry',array(),array(),$type[0],$type[2],$type[1]);
231 if($str) return($str);
232 $this->tabObject->set_acl_base($this->acl_base);
233 $this->tabObject->by_object[$type[1]]->cn = $name;
234 }else{
235 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
236 }
237 }
238 }
241 /*! \brief A new FAI class was requested and the user had a specify a name for it.
242 * Here we check if this name is useable and then open the edit dialogs.
243 */
244 function newClassNameSelected()
245 {
246 $this->dialogObject->save_object();
247 if(count($this->dialogObject->check())!=0){
248 foreach($this->dialogObject->check() as $msg){
249 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
250 }
251 }elseif(isset($this->dialogObject->objectClass)){
252 $this->dn = "new" ;
253 $type= $this->get_type(array("objectClass"=>array($this->dialogObject->objectClass)));
254 $name = $this->dialogObject->save();
256 if(class_exists($type[0])){
257 $this->closeDialogs();
258 $str = management::newEntry('newEntry',array(),array(),$type[0],$type[2],$type[1]);
259 if($str) return($str);
260 $this->tabObject->set_acl_base($this->acl_base);
261 $this->tabObject->by_object[$type[1]]->cn = $name;
262 }
263 }
264 }
267 /*! \brief Edit the selected entry.
268 * If there was a FAI group clicked, display a dialog with all members of the group.
269 */
270 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
271 {
272 $headpage = $this->getHeadpage();
273 if(count($target) == 1){
274 $entry = $headpage->getEntry($target[0]);
275 if($entry){
277 // Edit Opsi objects here
278 if(in_array("opsi_local", $entry['TYPES']) || in_array("opsi_netboot", $entry['TYPES'])){
279 $name = $entry['cn'];
280 $cfg = $this->opsi->get_product_properties($name);
282 $str = management::editEntry('editEntry',array($name),array(),'tabs_opsiProdConfig','OPSIPRODCONFIG','opsi');
283 if($str) return($str);
284 if(isset($this->tabObject->by_object['opsiProperties'])){
285 $this->tabObject->by_object['opsiProperties']->set_cfg($cfg);
286 $this->tabObject->by_object['opsiProperties']->set_product($name);
287 $this->skipFooter = TRUE;
288 }else{
289 trigger_error("Unknown tab, please check config.");
290 }
292 }else{
294 // Edit FAI objects here
295 if(count($entry['GROUPS']) == 1){
296 $data = array_pop($entry['GROUPS']);
297 $type = $this->get_type($data);
298 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
299 if($str) return($str);
300 $this->tabObject->by_object[$type[1]]->FAIstate = $data['FAIstate'];
301 $this->tabObject->read_only = preg_match("/freeze/i", $data['FAIstate']);
303 }else{
304 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
305 }
306 }
307 }
308 }
309 }
312 /*! \brief Save changes made in opsi dialogs.
313 */
314 function saveOpsiProperties()
315 {
316 if($this->tabObject instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
317 $this->tabObject->save_object();
318 $op = $this->tabObject->by_object['opsiProperties'];
319 $name = $op->get_product();
320 $cfg = $op->get_cfg();
321 $this->opsi->set_product_properties($name,$cfg);
322 if($this->opsi->is_error()){
323 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
324 }else{
325 $this->remove_lock();
326 $this->closeDialogs();
327 }
328 }
329 }
332 /*! \brief Someone wants to remove some object(s)
333 * ask for a confirmation now.
334 */
335 function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
336 {
337 $this->closeDialogs();
338 if($action == "remove_multiple"){
340 // Collect objects to delete
341 $headpage = $this->getHeadpage();
342 $to_delete = array();
343 foreach($target as $id){
344 $object = $headpage->getEntry($id);
345 if(in_array("FAKE_OC_FAI", $object['objectClass'])){
346 foreach($object['GROUPS'] as $entry){
347 array_push($to_delete, $entry);
348 }
349 }
350 }
351 return($this->removeFAIObjects($to_delete));
352 }else{
354 // Try to remove a single object, only FAI objects can be removed!
355 $headpage = $this->getHeadpage();
356 if(count($target) == 1){
357 $entry = $headpage->getEntry($target[0]);
358 if($entry && in_array("FAKE_OC_FAI",$entry['objectClass'])){
359 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
360 }
361 }
362 }
363 }
366 /*! \brief Someone wants to remove some object(s)
367 * ask for a confirmation now.
368 */
369 function removeFAIObjects($to_delete)
370 {
371 // Do not allow to remove objects with state freeezed
372 $errors = $disallowed = array();
374 foreach($to_delete as $obj){
375 $type = $this->get_type($obj);
376 $acl = $this->ui->get_permissions($obj['dn'],"fai/".$type[1]);
377 if(!preg_match("/d/",$acl)){
378 $disallowed[] = $obj['dn'];
379 }elseif(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
380 $errors[] = $obj['dn'];
381 }else{
382 $this->dns[] = $obj['dn'];
383 }
384 }
385 if(count($errors)){
386 msg_dialog::display(_("Branch locked"),
387 sprintf(_("The following entries are locked, you can't remove them %s."),msgPool::buildList($errors)),INFO_DIALOG);
388 }
389 if(count($disallowed)){
390 msg_dialog::display(_("Permission error"), msgPool::permDelete($disallowed), ERROR_DIALOG);
391 }
393 // Check entry locking
394 if(count($this->dns)){
395 if ($user= get_multiple_locks($this->dns)){
396 return(gen_locked_message($user,$this->dns));
397 }
398 if(count($this->dns)){
399 $smarty = get_smarty();
400 $dns_names = array();
401 foreach($this->dns as $dn){
402 add_lock ($dn, $this->ui->dn);
403 $dns_names[] = LDAP::fix($dn);
404 }
405 $smarty->assign("info",msgPool::deleteInfo($dns_names,_("FAI object")));
406 $smarty->assign("multiple", true);
407 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
408 }
409 }
410 }
413 /*! \brief Entry removal is confirmed, now remove objects
414 */
415 function removeEntryConfirmed($action="",$target=array(),$all=array(),
416 $altTabClass="",$altTabType="",$altAclCategory="")
417 {
418 $ldap = $this->config->get_ldap_link();
419 $ldap->cd($this->config->current['BASE']);
421 $disallowed = array();
422 foreach($this->dns as $key => $dn){
423 $ldap->cat($dn);
424 if($ldap->count()){
425 $attrs = $ldap->fetch();
426 $type= $this->get_type($attrs);
428 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
429 if(preg_match("/d/",$acl)){
431 // Now save changes
432 management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
433 FAI::save_release_changes_now();
434 $to_del = FAI::clean_up_releases($dn);
435 foreach($to_del as $dn){
436 $ldap->rmdir_recursive($dn);
437 }
439 } else {
440 $disallowed[] = $dn;
441 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
442 }
443 }
444 }
446 /* Normally this shouldn't be reached, send some extra
447 logs to notify the administrator */
448 if(count($disallowed)){
449 msg_dialog::display(_("Permission error"), msgPool::permDelete($disallowed), ERROR_DIALOG);
450 }
451 }
454 /*! \brief Someone clicked on edit/remove for a grouped FAI object.
455 * We are now going to display a dialog to let the user select the entry
456 * he wants to perform the action on.
457 */
458 function editByGroup()
459 {
460 if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
461 $this->dialogObject->save_object();
462 $entry = $this->dialogObject->get_selected();
463 $this->closeDialogs();
464 $data = array_pop($entry);
465 $type = $this->get_type($data);
466 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
467 if($str) return($str);
468 $this->tabObject->by_object[$type[1]]->FAIstate = $data['FAIstate'];
469 $this->tabObject->read_only = preg_match("/freeze/i", $data['FAIstate']);
470 }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
471 $this->dialogObject->save_object();
472 $to_delete = $entry = $this->dialogObject->get_selected();
473 if(count($to_delete)) $this->closeDialogs();
474 return($this->removeFAIObjects($to_delete));
475 }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "copy"){
476 $this->dialogObject->save_object();
477 $entries = $entry = $this->dialogObject->get_selected();
478 if(count($entries)){
479 foreach($entries as $entry){
480 $type = $this->get_type($entry);
481 $this->cpHandler->add_to_queue($entry['dn'],"copy",$type[0],$type[2],'fai',$this);
482 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry['dn'],"Entry copied!");
483 }
484 $this->closeDialogs();
485 }
486 }
487 }
490 /*! \brief Save dialog/object modifications
491 */
492 protected function saveChanges()
493 {
494 $str = management::saveChanges();
495 if($str) return($str);
497 // Now save changes
498 FAI::save_release_changes_now();
499 $to_del = FAI::clean_up_releases($this->last_dn);
500 foreach($to_del as $dn){
501 $ldap->rmdir_recursive($dn);
502 }
503 }
506 /*! \brief Save dialog/object modifications but keep the dialogs opened
507 */
508 protected function applyChanges()
509 {
510 $str = management::applyChanges();
511 if($str) return($str);
513 // Now save changes
514 FAI::save_release_changes_now();
515 $to_del = FAI::clean_up_releases($this->last_dn);
516 foreach($to_del as $dn){
517 $ldap->rmdir_recursive($dn);
518 }
519 }
522 /*! \brief Initiates release removal
523 */
524 function removeBranch()
525 {
526 /* Check if we have a post remove method configured
527 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
528 */
529 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
530 /* Load permissions for selected 'dn' and check if
531 we're allowed to remove this 'dn' */
532 if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
533 $smarty=get_smarty();
534 $smarty->assign("release_hidden",base64_encode($this->fai_release));
535 $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
536 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
537 } else {
538 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
539 }
540 }
541 }
544 /*! \brief Remove a release after removal was confirmed
545 */
546 function removeBranchConfirmed()
547 {
548 /* Check if we have a post remove method configured
549 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
550 */
551 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
553 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
554 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
555 }else{
557 $bb = $this->fai_release;
558 $ldap = $this->config->get_ldap_link();
560 $br = $this->getBranches();
562 if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
563 $name = $br[$bb];
565 $ldap->cd($bb);
566 $ldap->recursive_remove();
567 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('applicationRDN'), $bb));
568 $ldap->recursive_remove();
569 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('mimetypeRDN'), $bb));
570 $ldap->recursive_remove();
572 /* Search for all groups with configured application menus.
573 - First search all groups, to ensure that we only remove entries form whithin groups.
574 - The search für menu configuration for the specified release and collect all those dns.
575 - Remove entries
576 */
577 $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$bb);
578 $ldap->cd($this->config->current['BASE']);
579 $ldap->search("(objectClass=posixGroup)",array("dn"));
581 /* Collect all group dns
582 */
583 $groups = array();
584 while($attrs = $ldap->fetch()){
585 $groups[] = $attrs['dn'];
586 }
589 /* Collect all group menu release dns that match the release we have removed
590 */
591 $dns = array();
592 foreach($groups as $dn){
593 $ldap->cd($dn);
594 $ldap->search("(objectClass=FAIbranch)",array("dn"));
595 while($attrs = $ldap->fetch()){
596 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
597 $dns[] = $attrs['dn'];
598 }
599 }
600 }
602 /* Finally remove collected release dns
603 */
604 foreach($dns as $dn){
605 $ldap->cd($dn);
606 $ldap->recursive_remove();
607 }
609 /* Post remove */
610 $this->fai_release = $this->fai_base;
611 $this->lock_name = $name;
612 $this->lock_dn = $bb;
613 $this->postremove();
615 $fai_filter = session::get("fai_filter");
616 $fai_filter['fai_release'] = $this->fai_release;
617 session::set("fai_filter",$fai_filter);
619 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
620 }
621 }
622 }
623 }
626 /*! \brief Initiates release creation
627 */
628 function createBranch()
629 {
630 if($this->config->search("faiManagement", "POSTCREATE",array('menu','tabs')) == ""){
631 msg_dialog::display(_("Configuration"), msgPool::cmdnotfound(_("POSTCREATE"), get_class()), ERROR_DIALOG);
632 }elseif(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
633 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
634 }else{
635 $smarty = get_smarty();
636 $this->dispNewBranch=true;
637 $this->dispNewFreeze=false;
638 $smarty->assign("iframe",false);
639 if(isset($_POST['BranchName'])){
640 $smarty->assign("BranchName", $_POST['BranchName']);
641 }else{
642 $smarty->assign("BranchName","");
643 }
644 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
645 }
646 }
649 /*! \brief Initiates release creation
650 */
651 function createFreeze()
652 {
653 if($this->config->search("faiManagement", "POSTCREATE",array('menu','tabs')) == ""){
654 msg_dialog::display(_("Configuration"), msgPool::cmdnotfound(_("POSTCREATE"), get_class()), ERROR_DIALOG);
655 }elseif(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
656 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
657 }else{
658 $smarty = get_smarty();
659 $this->dispNewFreeze=true;
660 $this->dispNewBranch=false;
661 $smarty->assign("iframe",false);
662 if(isset($_POST['BranchName'])){
663 $smarty->assign("BranchName", $_POST['BranchName']);
664 }else{
665 $smarty->assign("BranchName","");
666 }
667 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
668 }
669 }
672 /*! \brief Creates a new branch
673 */
674 function PerformBranch()
675 {
676 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
677 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
678 }else{
680 /* In order to see error messages we have to reset the error handler.
681 Due to the exit();
682 */
683 restore_error_handler();
685 $this->dispNewBranch = false;
686 $this->dispNewFreeze = false;
688 $LASTPOST = session::get('LASTPOST');
689 $base = $LASTPOST['base'];
690 $_POST = session::get('LASTPOST');
691 $name = $_POST['BranchName'];
693 $type = $LASTPOST['type'];
694 $ldap = $this->config->get_ldap_link();
696 $baseToUse = $base;
697 if($this->fai_release != $this->fai_base){
698 $baseToUse = $this->fai_release;
699 }
701 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
703 $CurrentReleases = $this->getBranches();
704 $NewReleaseName = $name;
705 if(isset($CurrentReleases[$this->fai_release])) {
706 if($this->fai_release != $this->fai_base){
707 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
708 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
709 }else{
710 $NewReleaseName = $name;
711 }
712 }
713 $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),$baseToUse);
714 $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
716 $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),$baseToUse);
717 $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
719 /* Check if source depeartments exist */
720 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
721 $ldap->cd($this->config->current['BASE']);
722 $ldap->cat($dep);
723 if(!$ldap->count()){
724 $ldap->create_missing_trees($dep);
725 }
726 }
728 /* Print header to have styles included */
729 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
730 <html>
731 <head>
732 <title></title>
733 <style type="text/css">@import url("themes/default/style.css");</style>
734 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
735 </head>
736 <body style="background: none;margin:3px;color:black">
737 ';
739 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
741 /* Duplicate group application releases
742 */
743 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
745 /* Duplicate applications
746 */
747 $ldap->cat($appsrc,array("dn")) ;
748 if($ldap->count()){
749 $ldap->cd ($appdst);
750 $ldap->recursive_remove();
751 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
752 }
754 /* Duplicate mime types
755 */
756 $ldap->cat($mimesrc,array("dn")) ;
757 if($ldap->count()){
758 $ldap->cd ($mimedst);
759 $ldap->recursive_remove();
760 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
761 }
763 $attr = array();
764 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
765 $attr['ou'] = $name;
766 $attr['FAIstate'] = $type;
767 $ldap->cd($this->config->current['BASE']);
768 $ldap->cd("ou=".$name.",".$baseToUse);
769 $ldap->cat("ou=".$name.",".$baseToUse);
770 if($ldap->count()){
771 $ldap->modify($attr);
772 }else{
773 $ldap->add($attr);
774 }
776 /* Duplicate fai objects
777 */
778 // $ldap->cd ("ou=".$name.",".$baseToUse);
779 // $ldap->recursive_remove();
780 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
782 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
783 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
784 <input type='hidden' name='php_c_check' value='1'>
785 </form></div>";
787 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
789 /* Print footer to have valid html */
790 echo "</body></html>";
792 $this->dispNewFreeze = false;
794 /* Postcreate */
796 /* Assign possible attributes */
797 $this->lock_type = $type;
798 $this->lock_name = $name;
799 $this->lock_dn = $baseToUse;
800 $this->postcreate();
802 /* Send daemon event to reload the fai release database
803 */
804 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
805 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
806 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
807 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
808 $tmp = new $evt['CLASS_NAME']($this->config);
809 $tmp->set_type(TRIGGERED_EVENT);
810 $tmp->add_targets(array("GOSA"));
811 $o_queue = new gosaSupportDaemon();
812 if(!$o_queue->append($tmp)){
813 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
814 }
815 }
816 }else{
817 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
818 msg_dialog::display(_("Fatal error"),
819 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
820 FATAL_ERROR_DIALOG);
821 }
822 exit();
823 }
824 }
827 /*! \brief Creates a new branch, after a useable name was specified.
828 */
829 function saveBranch()
830 {
831 if($this->dispNewBranch){
832 $type = "branch";
833 }else{
834 $type = "freeze";
835 }
837 /* Check branch name */
838 $name = $_POST['BranchName'];
839 $is_ok = true;
840 $smarty = get_smarty();
841 $smarty->assign("BranchName",$name);
842 $base= $this->fai_base;
844 /* Check used characters */
845 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
846 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
847 $is_ok = false;
848 }
850 // Check if this name is already in use
851 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
852 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
853 $is_ok = false;
854 }
856 // Handle errors
857 if(!$is_ok && $this->dispNewFreeze){
858 return($this->createFreeze());
859 }elseif(!$is_ok && $this->dispNewBranch){
860 return($this->createBranch());
861 }
863 // Now create new release
865 if(session::is_set('LASTPOST')){
866 $LASTPOST = session::get('LASTPOST');
867 }else{
868 $LASTPOST = array();
869 }
870 $LASTPOST['base'] = $base;
871 $LASTPOST['type'] = $type;
872 $LASTPOST['BranchName'] = $name;
873 session::set('LASTPOST',$LASTPOST);
874 $smarty->assign("iframe", true);
875 $smarty->assign("plugID", $_GET['plug']);
876 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
877 return($display);
879 }
883 /*! \brief Returns a list of all releases for useable for drop down boxes.
884 * ou=fai... /
885 * ou=siga,ou=fai... siga
886 * ou=1,ou=siga,ou=fai... 1
887 */
888 function getReleaseList($base = "", $prefix ="")
889 {
890 $list = array();
891 if(empty($base)){
892 $base = $this->fai_base;
893 $list[$base] = "/";
894 }
896 $ldap = $this->config->get_ldap_link();
897 $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
899 while($release = $ldap->fetch()){
900 $list[$release['dn']] = $prefix.$release['ou'][0];
901 $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix." "));
902 }
903 return($list);
904 }
907 /*! \brief Returns a list of all releases with full release names
908 * ou=fai... /
909 * ou=siga,ou=fai... siga
910 * ou=1,ou=siga,ou=fai... siga/1
911 */
912 function getBranches($base = false,$prefix = "")
913 {
914 $ret = array("/"=>$this->fai_base);
915 $ldap = $this->config->get_ldap_link();
916 if(!$base){
917 $base = $this->fai_base;
918 }
919 $tmp = FAI::get_all_releases_from_base($base,true);
920 foreach($tmp as $dn => $name){
921 $ret[$name]=$dn;
922 }
923 ksort($ret);
924 $ret = array_flip($ret);
926 return ($ret);
927 }
930 /*! \brief Detects object info like corresponding tab,class,acl
931 * e.g. [0] = tabsPartition
932 * [1] = faiPartitionTable
933 * [2] = FAIPARTITIONTABS
934 */
935 function get_type($array)
936 {
937 if(!isset($array['objectClass'])) return(array());
938 if(in_array("FAIpartitionTable",$array['objectClass'])){
939 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
940 }
941 if(in_array("FAIscript",$array['objectClass'])){
942 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
943 }
944 if(in_array("FAItemplate",$array['objectClass'])){
945 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
946 }
947 if(in_array("FAIhook",$array['objectClass'])){
948 return(array("tabsHook","faiHook","FAIHOOKTABS"));
949 }
950 if(in_array("FAIvariable",$array['objectClass'])){
951 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
952 }
953 if(in_array("FAIprofile",$array['objectClass'])){
954 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
955 }
956 if(in_array("FAIpackageList",$array['objectClass'])){
957 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
958 }
959 return(array());
960 }
963 /*! \brief Checks if the given string can be used as class name
964 */
965 static function check_class_name($oc,$name,$dn)
966 {
967 $base = FAI::get_release_dn($dn);
969 if($oc == "FAIprofile"){
970 $f = "";
971 $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
972 foreach($ocs as $oc){
973 $f .= "(objectClass=".$oc.")";
974 }
975 $res = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);
976 }else{
977 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
978 }
979 $delete = array();
980 $used = array();
981 foreach($res as $object){
982 $used[$object['cn'][0]]= $object['cn'][0];
983 }
984 return($used);
985 }
988 /*! \brief Checks if the given string can be used for a new release
989 */
990 function CheckNewBranchName($name,$base)
991 {
992 $f = $this->fai_release;
993 if($name == ""){
994 return(false);
995 }elseif(in_array($name,$this->getBranches($f))) {
996 return(false);
997 }elseif(tests::is_department_name_reserved($name,$base)){
998 return(false);
999 }
1000 return(true);
1001 }
1004 /*! \brief This filter is used to display small icons for each listed object
1005 * instead of their typ names
1006 */
1007 static function filterProperties($row, $classes)
1008 {
1009 $objects = array(
1010 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
1011 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
1012 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
1013 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
1014 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
1015 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
1016 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
1017 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
1018 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
1019 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
1020 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
1021 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
1022 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
1023 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
1024 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
1025 "NAME"=>_("OPSI netboot product") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
1026 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
1027 "NAME"=>_("OPSI localboot product") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
1029 $icon_list = "";
1030 foreach($objects as $type => $type_data){
1031 if(in_array($type, $classes)){
1032 $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
1033 alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
1034 }else{
1035 $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
1036 }
1037 }
1039 return $icon_list;
1040 }
1043 /*! \brief Overridden render method of class mangement.
1044 * this allows us to add a release selection box.
1045 */
1046 function renderList()
1047 {
1048 $filter = $this->getFilter();
1049 $headpage = $this->getHeadpage();
1050 $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
1052 if(isset($_POST['RELEASE'])){
1053 $this->fai_release = get_post('RELEASE');
1054 }
1055 $headpage->setBase($this->fai_release);
1056 $headpage->update();
1057 $smarty = get_smarty();
1058 $smarty->assign("fai_release", $this->fai_release);
1059 $smarty->assign("opsi_available", is_object($this->opsi));
1060 $smarty->assign("fai_base", $this->fai_base);
1061 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
1062 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
1063 $smarty->assign("allow_create", $c);
1064 $smarty->assign("allow_remove", $r);
1065 $display = $headpage->render();
1066 return($this->getHeader().$display);
1067 }
1070 /*! \brief Convert POST and GET variables into actions.
1071 */
1072 function detectPostActions()
1073 {
1074 $action = management::detectPostActions();
1075 if(isset($_POST['remove_multiple'])) $action['action'] = "remove";
1076 if(isset($_POST['new_profile'])) $action['action'] = "new_profile";
1077 if(isset($_POST['new_template'])) $action['action'] = "new_template";
1078 if(isset($_POST['new_script'])) $action['action'] = "new_script";
1079 if(isset($_POST['new_hook'])) $action['action'] = "new_hook";
1080 if(isset($_POST['new_variable'])) $action['action'] = "new_variable";
1081 if(isset($_POST['new_package'])) $action['action'] = "new_package";
1082 if(isset($_POST['new_partition'])) $action['action'] = "new_partition";
1084 if(isset($_POST['save_properties'])) $action['action'] = "saveOpsiProperties";
1085 if(isset($_POST['cancel_properties'])) $action['action'] = "cancel";
1087 if(isset($_POST['edit_continue'])) $action['action'] = "newClassNameSelected";
1088 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
1090 if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
1091 if(isset($_POST['CancelBranchName'])) $action['action'] = "cancel";
1092 if(isset($_POST['delete_branch_confirm'])) $action['action'] = "removeBranchConfirmed";
1093 if(isset($_GET['PerformBranch'])) $action['action'] = "PerformBranch";
1094 if(isset($_POST['UseBranchName'])) $action['action'] = "saveBranch";
1095 if(isset($_POST['faiGroupHandle_apply'])) $action['action'] = "editByGroup";
1096 if(isset($_GET['act']) && $_GET['act'] == "branch_branch") $action['action'] = "createBranch";
1097 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch") $action['action'] = "createFreeze";
1098 if(isset($_GET['act']) && $_GET['act'] == "remove_branch") $action['action'] = "removeBranch";
1100 foreach($_POST as $name => $value){
1101 if(preg_match("/^edit_([0-9]*)_([a-z_]*)_(x|y)/i", $name)){
1102 $id = preg_replace("/^edit_([0-9]*)_([a-z_]*)_(x|y)/i","\\1", $name);
1103 $tab = preg_replace("/^edit_([0-9]*)_([a-z_]*)_(x|y)/i","\\2", $name);
1105 $headpage = $this->getHeadpage();
1106 $entry = $headpage->entries[$id];
1108 if(in_array('FAKE_OC_FAI', $entry['objectClass'])){
1109 if(isset($headpage->entries[$id]['GROUPS'][$tab])){
1110 $data =$headpage->entries[$id]['GROUPS'][$tab];
1111 $type = $this->get_type($data);
1112 $str = management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
1113 if($str) return($str);
1114 }
1115 }else{
1116 $str = $this->editEntry('editEntry',array($entry['dn']));
1117 if($str) return($str);
1118 }
1119 break;
1120 }
1121 }
1122 return($action);
1123 }
1126 static function plInfo()
1127 {
1128 return (array(
1129 "plShortName" => _("FAI releases"),
1130 "plDescription" => _("FAI release management"),
1131 "plSelfModify" => FALSE,
1132 "plDepends" => array(),
1133 "plPriority" => 0,
1134 "plSection" => array("administration"),
1135 "plCategory" => array("fai"=> array("description" => _("FAI"),
1136 "objectClass" => "FAIclass")),
1137 "plProvidedAcls"=> array()));
1138 }
1139 }
1140 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1141 ?>