X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Ffai%2Fclass_faiManagement.inc;h=95907126a9116dcce95cde4b0b851afc83e7e1ed;hb=56815fbe62493b4d07232b73631c31c4ff92d396;hp=a55f831e346a52e68844650d1fa33fb59381e3f0;hpb=237a82732d922e00d762df84970f1ced6fa9bdc9;p=gosa.git diff --git a/plugins/admin/fai/class_faiManagement.inc b/plugins/admin/fai/class_faiManagement.inc index a55f831e3..95907126a 100644 --- a/plugins/admin/fai/class_faiManagement.inc +++ b/plugins/admin/fai/class_faiManagement.inc @@ -33,22 +33,19 @@ class faiManagement extends plugin var $plDescription = "Fully Automatic Installation - management"; /* CLI vars */ - var $cli_summary = "Handling of FAI entries"; + var $cli_summary = "Handling of FAI entries"; var $cli_description = "This plugin represents a management tool\n which allows us to manage all needed attributes for fully automatic installations (FAI)"; var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); /* Headpage attributes */ - var $departments= array(); - var $deptabs= NULL; var $lock_type = ""; // should be branch/freeze var $lock_name = ""; var $lock_dn = ""; /* attribute list for save action */ - var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin, none, - // because this is only an overview over all objects already defined in FAI. - var $objectclasses = array(); // ObjectClasses which the attributes are related to + var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin + var $objectclasses= array(); // ObjectClasses which the attributes are related to var $dialog = array(); // This object contains every dialog we have currently opened var $objects = array(); // This array contains all available objects shown in divlist @@ -57,154 +54,84 @@ class faiManagement extends plugin var $dispNewBranch= false; var $dispNewFreeze= false; + var $DivListFai; + /* construction/reconstruction - * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last - * selected department and filter options - * If it is not defined already we create a new fresh faifilter. */ function faiManagement ($config, $ui) { - $this->ui = $ui; - - /* Set current dn to "", */ + /* Set defaults */ $this->dn = ""; - - /* Assign config */ - $this->config = $config; - - /* Get global filter config */ - if (!is_global("faifilter")){ - $base = get_base_from_people($ui->dn); - $faifilter= array("base" => $base, - "regex" => "*","branch" => "main"); - $faifilter['ShowProfiles'] = true; - $faifilter['ShowTemplates'] = true; - $faifilter['ShowScripts'] = true; - $faifilter['ShowHooks'] = true; - $faifilter['ShowVariables'] = true; - $faifilter['ShowPackages'] = true; - $faifilter['ShowPartitions']=true; - register_global("faifilter", $faifilter); - } + $this->config = $config; + $this->ui = $ui; + + /* Creat dialog object */ + $this->DivListFai = new divListFai($this->config,$this); } function execute() { + /* Call parent execute */ + plugin::execute(); - /* Call parent execute */ - plugin::execute(); - - $display = ""; + /* Initialise vars and smarty */ $smarty = get_smarty(); $smarty->assign("BranchName",""); + + $display = ""; $s_action = ""; $s_entry = ""; - /* filter management - * Filter will be changed if POST['regex'] or $_GET['search'] isset - * New Filter will be stored in session and is used to generate list contents - */ - $faifilter = $_SESSION['faifilter']; - if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){ - $faifilter['branch'] = $_POST['select_branch']; - } + /* If an entry was locked, these vars will be stored in a session to allow direct edit */ + $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/"); - /* Filter is posted by apply button - * Check every single chkbox - */ - if(isset($_POST['regex'])){ - $faifilter['regex'] = $_POST['regex']."*"; - foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){ - if(isset($_POST[$attrs])){ - $faifilter[$attrs] = true; - }else{ - $faifilter[$attrs] = false; - } - } - } + /**************** + Handle posts + ****************/ /* Check ImageButton posts * Create new tab ich new_xx is posted */ - foreach($_POST as $key => $val){ - if(preg_match("/remove_branch/",$key)){ - $s_action = "remove_branch"; - }elseif(preg_match("/branch_branch/",$key)){ - $s_action = "branch_branch"; - }elseif(preg_match("/freeze_branch/",$key)){ - $s_action = "freeze_branch"; - }elseif(preg_match("/create_partition/i",$key)){ - $s_action = "new_partition"; - }elseif(preg_match("/create_script/i",$key)){ - $s_action = "new_script"; - }elseif(preg_match("/create_hook/i",$key)){ - $s_action = "new_hook"; - }elseif(preg_match("/create_variable/i",$key)){ - $s_action = "new_variable"; - }elseif(preg_match("/create_template/i",$key)){ - $s_action = "new_template"; - }elseif(preg_match("/create_package/i",$key)){ - $s_action = "new_package"; - }elseif(preg_match("/create_profile/i",$key)){ - $s_action = "new_profile"; - }elseif(preg_match("/edit_continue/",$key)){ - $s_action = "select_class_name_finished"; - }elseif(preg_match("/^entry_edit_.*/",$key)){ - $s_entry = preg_replace("/^entry_edit_/","",$key); + $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch", + "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition", + "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook", + "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template", + "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile", + "/edit_continue/"=>"select_class_name_finished"); + + foreach($_POST as $name => $value){ + foreach($posts as $reg => $act ){ + if(preg_match($reg,$name)){ + $s_action = $act; + } + } + if(preg_match("/^entry_edit_.*/",$name)){ + $s_entry = preg_replace("/^entry_edit_/","",$name); $s_entry = preg_replace("/_.*$/","",$s_entry); $s_action = "edit"; - }elseif(preg_match("/^entry_delete_.*/",$key)){ - $s_entry = preg_replace("/^entry_delete_/","",$key); + }elseif(preg_match("/^entry_delete_.*/",$name)){ + $s_entry = preg_replace("/^entry_delete_/","",$name); $s_entry = preg_replace("/_.*$/","",$s_entry); $s_action = "delete"; - }elseif(preg_match("/dep_back.*/i",$key)){ - $faifilter['branch'] = "main"; - $s_action="back"; - }elseif(preg_match("/dep_home.*/i",$key)){ - $faifilter['branch'] = "main"; - $s_action="home"; - }elseif(preg_match("/dep_root.*/i",$key)){ - $faifilter['branch'] = "main"; - $s_action="root"; } - } - if($s_action=="root"){ - $faifilter['base']=($this->config->current['BASE']); - } - - if($s_action=="home"){ - $faifilter['base']=(preg_replace("/^[^,]+,/","",$this->ui->dn)); - $faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base'])); - } - - if($s_action=="back"){ - $base_back = preg_replace("/^[^,]+,/","",$faifilter['base']); - $base_back = convert_department_dn($base_back); - - if(isset($this->config->departments[trim($base_back)])){ - $faifilter['base']= $this->config->departments[trim($base_back)]; - }else{ - $faifilter['base']= $this->config->departments["/"]; - } - } - - if(isset($_GET['act'])&&($_GET['act']=="dep_open")){ - $s_action="open"; - $s_entry = base64_decode($_GET['dep_id']); - $faifilter['base']= $this->config->departments[trim($s_entry)]; - } - if(isset($_GET['edit_entry'])){ $s_entry = $_GET['edit_entry']; $s_action = "edit"; } + + if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){ + $this->dispNewBranch = false; + $this->dispNewFreeze = false; + } + + + /**************** + Delete confirme dialog + ****************/ - /* Confirm dialog - * Delte object - */ if ($s_action=="delete"){ /* Get 'dn' from posted termlinst */ @@ -212,7 +139,7 @@ class faiManagement extends plugin /* Load permissions for selected 'dn' and check if we're allowed to remove this 'dn' */ - $acl= get_permissions ($this->dn, $this->ui->subtreeACL); + $acl= get_permissions ($this->dn, $this->ui->subtreeACL); $this->acl= get_module_permission($acl, "FAIclass", $this->dn); if (chkacl($this->acl, "delete") == ""){ @@ -233,12 +160,21 @@ class faiManagement extends plugin } } + + /**************** + Delete aborted + ****************/ + /* Delete canceled? */ if (isset($_POST['delete_cancel'])){ del_lock ($this->dn); } + /**************** + Delete confirmed + ****************/ + /* Deltetion was confirmed, so delete this entry */ if (isset($_POST['delete_terminal_confirm'])){ @@ -248,21 +184,17 @@ class faiManagement extends plugin if (chkacl($this->acl, "delete") == ""){ /* Find out more about the object type */ - $ldap = $this->config->get_ldap_link(); - $ldap->cat($this->dn); + $ldap = $this->config->get_ldap_link(); + $ldap->cat($this->dn, array('objectClass')); $attrs = $ldap->fetch(); - - $type = $this->get_type($attrs); - - $this->dialog= new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn); + $type = $this->get_type($attrs); + $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn); $this->dialog->set_acl(array($this->acl)); $this->dialog->by_object[$type[1]]->remove_from_parent (); unset ($this->dialog); gosa_log ("FAI class '".$this->dn."' has been removed"); $this->dialog= NULL; - - /* Terminal list has changed, reload it. */ } else { /* Normally this shouldn't be reached, send some extra @@ -276,22 +208,28 @@ class faiManagement extends plugin del_lock ($this->dn); } - /* Edit Entry */ - if($s_action == "edit"){ - $entry = $this->objects[$s_entry]; - $a_setup = ($this->get_type($entry)); - + /**************** + Edit entry + ****************/ + + if(($s_action == "edit") && (!isset($this->dialog->config))){ + $entry = $this->objects[$s_entry]; + $a_setup = $this->get_type($entry); $this->dn = $entry['dn']; + /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */ if (($user= get_lock($this->dn)) != ""){ return(gen_locked_message ($user, $this->dn)); } add_lock ($this->dn, $this->ui->dn); - $this->dialog= new $a_setup[0]($this->config, - $this->config->data['TABS'][$a_setup[2]],$this->dn); - $this->is_dialog = true; + $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn); + $this->is_dialog = true; + + if($entry['FAIstate'] == "freeze"){ + $this->dialog->set_acl(array("*none*")) ; + } $_SESSION['objectinfo'] = $this->dn; } @@ -300,88 +238,34 @@ class faiManagement extends plugin 09.01.2006 */ - /* Create new branch */ - if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){ - - /* Check branch name */ - $name = $_POST['BranchName']; - $is_ok = true; - - $smarty->assign("BranchName",$name); - $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base']; - - /* Check used characters */ - if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){ - print_red(_("Specified branch name is invalid.")); - $is_ok = false; - } - - /* Check if this name is already in use */ - if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){ - print_red(_("This name is already in use.")); - $is_ok = false; - } - - if($is_ok){ - /* Create it know */ - $ldap = $this->config->get_ldap_link(); - - $baseToUse = $base; - if($_SESSION['faifilter']['branch']!="main"){ - $baseToUse = $_SESSION['faifilter']['branch']; - } - - $ldap->cd($this->config->current['BASE']); - $ldap->create_missing_trees($baseToUse); - $ldap->cd ("ou=".$name.",".$baseToUse); - $ldap->recursive_remove(); - - $ldap->cd ($this->config->current['BASE']); - $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"branch",true); - - /* Postcreate */ - - /* Assign possible attributes */ - $this->lock_type = "branch"; - $this->lock_name = $name; - $this->lock_dn = $baseToUse; - $this->postcreate(); - $this->dispNewBranch = false; - } - } - - /* Abort creating new branch */ - if(isset($_POST['CancelBranchName'])){ - $this->dispNewBranch = false; - $this->dispNewFreeze = false; - } - - /* Open dialog to insert new branch name */ - if(($s_action == "branch_branch")||($this->dispNewBranch)){ - $this->dispNewBranch=true; - $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base']; - $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); - return($display); - } + /**************** + Remove branch + ****************/ - /* Remove branch */ + /* Remove branch + */ if($s_action == "remove_branch"){ - $base= $faifilter['branch']; + $base= $this->DivListFai->selectedBranch; + /* Load permissions for selected 'dn' and check if we're allowed to remove this 'dn' */ - $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL); - $this->acl= get_module_permission($acl, "fai", $base); + $acl= get_permissions ($this->DivListFai->selectedBase, $this->ui->subtreeACL); + $this->acl= get_module_permission($acl, "FAIclass", $base); if (chkacl($this->acl, "delete") == ""){ - $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $faifilter['branch'])); + $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch)); return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE))); } else { - print_red (_("You are not allowed to delete this user!")); + print_red (_("You are not allowed to delete this release!")); } } - /* Delete this entry */ + + /**************** + Remove branch confirmed + ****************/ + if(isset($_POST['delete_branch_confirm'])){ - $bb = $faifilter['branch']; + $bb = $this->DivListFai->selectedBranch; if(!isset($ldap)){ $ldap = $this->config->get_ldap_link(); } @@ -389,166 +273,205 @@ class faiManagement extends plugin $br = $this->getBranches(); if(isset($br[$bb])){ - $name = $br[$bb]; - $ldap->cd($bb); $ldap->recursive_remove(); - $faifilter['branch'] = "main"; + $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb)); + $ldap->recursive_remove(); + $this->DivListFai->selectedBranch = "main"; /* Post remove */ - -// $this->lock_type is set from this->reload $this->lock_name = $name; $this->lock_dn = $bb; - $this->postremove(); } } - if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){ + /**************** + Create a new branch "insert Name" + ****************/ + + if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){ + $_SESSION['LASTPOST'] = $_POST; + + if($this->dispNewBranch){ + $type = "branch"; + }else{ + $type = "freeze"; + } + /* Check branch name */ $name = $_POST['BranchName']; $is_ok = true; - $smarty->assign("BranchName",$name); + $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase; - $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base']; - /* Check used characters */ if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){ - print_red(_("Specified branch name is invalid.")); + if($type == "branch"){ + print_red(_("Specified branch name is invalid.")); + }else{ + print_red(_("Specified freeze name is invalid.")); + } $is_ok = false; } - + /* Check if this name is already in use */ - if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){ + if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){ print_red(_("This name is already in use.")); $is_ok = false; } - + if($is_ok){ - /* Create it know */ - $ldap = $this->config->get_ldap_link(); + $_SESSION['LASTPOST']['base'] = $base; + $_SESSION['LASTPOST']['type'] = $type; + $smarty->assign("iframe", true); + $smarty->assign("plugID", $_GET['plug']); + $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); + return($display); + } + } - $baseToUse = $base; - if($_SESSION['faifilter']['branch']!="main"){ - $baseToUse = $_SESSION['faifilter']['branch']; - } - - $ldap->cd ("ou=".$name.",".$baseToUse); - $ldap->recursive_remove(); - - $ldap->cd ($this->config->current['BASE']); - $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"freeze",true); - - $this->dispNewFreeze = false; - - /* Postcreate */ - - /* Assign possible attributes */ - $this->lock_type = "branch"; - $this->lock_name = $name; - $this->lock_dn = "ou=".$name.",".$baseToUse; - $this->postcreate(); + + /**************** + Create a new branch + ****************/ + + if(isset($_GET['PerformBranch'])){ + /* Create it know */ + $this->dispNewBranch = false; + $this->dispNewFreeze = false; + $base = $_SESSION['LASTPOST']['base']; + $_POST = $_SESSION['LASTPOST']; + $name = $_POST['BranchName']; + + $type = $_SESSION['LASTPOST']['type']; + $ldap = $this->config->get_ldap_link(); + + $baseToUse = $base; + if($this->DivListFai->selectedBranch != "main" ){ + $baseToUse = $this->DivListFai->selectedBranch; } + + $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); + $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; + + /* Print header to have styles included */ + echo "".$smarty->fetch(get_template_path('headers.tpl')); + echo "
"; + + /* Duplicate applications + */ + $ldap->cd ($appdst); + $ldap->recursive_remove(); + $ldap->cd ($this->config->current['BASE']); + $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$type,true); + + /* Duplicate fai objects + */ + $ldap->cd ("ou=".$name.",".$baseToUse); + $ldap->recursive_remove(); + $ldap->cd ($this->config->current['BASE']); + $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$type,true); + + echo ""; + + /* Print footer to have valid html */ + echo "