X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-plugins%2Ffai%2Fadmin%2Ffai%2Fclass_faiScript.inc;h=17cd0734488bedbef6dd95be8b76c0051bbcdc44;hb=ff3ef83f8dcb54659807a39f8513486b5c0badb0;hp=87592976cbb1f4d5212bd86a45a44b165b872604;hpb=9bbfb86b625d4bfb02a97b95075c5ef7f3f196cd;p=gosa.git
diff --git a/gosa-plugins/fai/admin/fai/class_faiScript.inc b/gosa-plugins/fai/admin/fai/class_faiScript.inc
index 87592976c..17cd07344 100644
--- a/gosa-plugins/fai/admin/fai/class_faiScript.inc
+++ b/gosa-plugins/fai/admin/fai/class_faiScript.inc
@@ -2,11 +2,6 @@
class faiScript extends plugin
{
- /* CLI vars */
- var $cli_summary = "Manage server basic objects";
- var $cli_description = "Some longer text\nfor help";
- var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
/* attribute list for save action */
var $ignore_account = TRUE;
@@ -35,7 +30,7 @@ class faiScript extends plugin
var $is_dialog = false; // specifies which buttons will be shown to save or abort
var $SubObjects = array(); // All leafobjects of this object
- var $FAIstate = "";
+ var $FAIstate = "branch";
var $sort_by = "name";
var $sort_order = "up";
@@ -52,42 +47,29 @@ class faiScript extends plugin
* First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
*/
if($dn != "new"){
-
$this->dn =$dn;
- /* Get FAIstate
- */
- if(isset($this->attrs['FAIstate'][0])){
- $this->FAIstate = $this->attrs['FAIstate'][0];
- }
-
/* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
*/
- $ldap = $this->config->get_ldap_link();
- $ldap->cd ($this->dn);
-
- $attrs_to_search = $this->subAttributes;
- $attrs_to_search[] = "FAIstate";
- $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search);
+ $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+ foreach($res as $obj){
- while($object = $ldap->fetch()){
+ /* Skip not relevant objects */
+ if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
- /* Skip objects, that are tagged as removed */
- if(isset($object['FAIstate'][0])){
- if(preg_match("/removed$/",$object['FAIstate'][0])){
- continue;
- }
- }
-
- /* Set status for save management */
$objects = array();
$objects['status'] = "FreshLoaded";
- $objects['dn'] = $object['dn'];
+ $objects['dn'] = $obj['dn'];
$objects = $this->get_object_attributes($objects,$this->subAttributes);
$this->SubObjects[$objects['cn']] = $objects;
}
-
}
+
+ $this->is_new = FALSE;
+ if($this->dn == "new"){
+ $this->is_new =TRUE;
+ }
+
$this->ui = get_userinfo();
}
@@ -106,7 +88,7 @@ class faiScript extends plugin
/* Check if we must decode some attributes */
if(in_array_ics($attrs,$this->sub64coded)){
- $var = base64_decode($var);
+ $var = postDecode($var);
}
/* check if this is a binary entry */
@@ -126,9 +108,9 @@ class faiScript extends plugin
/* Return a valid dn to fetch acls. Because 'new' will not work. */
function acl_base_for_current_object($dn)
{
- if($dn == "new"){
+ if($dn == "new" || $dn == ""){
if($this->dn == "new"){
- $dn= "cn=dummy,".session::get('CurrentMainBase');
+ $dn= $this->parent->parent->acl_base;
}else{
$dn = $this->dn;
}
@@ -152,8 +134,9 @@ class faiScript extends plugin
$display= "";
/* Add new sub object */
- if(isset($_POST['AddSubObject'])){
+ if(isset($_POST['AddSubObject']) && !preg_match("/freeze/i",$this->FAIstate)){
$this->dialog= new $this->subClassName($this->config,"new");
+ $this->dialog->FAIstate = $this->FAIstate;
$this->dialog->set_acl_base($this->acl_base);
$this->dialog->set_acl_category("fai");
$this->dialog->parent = &$this;
@@ -161,41 +144,40 @@ class faiScript extends plugin
}
if($this->dn != "new"){
- session::set('objectinfo',$this->dn);
+ set_object_info($this->dn);
}
- /* File download requested */
- if(isset($_GET['getFAIscript'])){
- if(isset($this->SubObjects[$_GET['getFAIscript']])){
- $obj = $this->SubObjects[$_GET['getFAIscript']];
- $obj = $this->get_object_attributes($obj,$this->sub_Load_Later);
- send_binary_content($obj['FAIscript'],$obj['cn'].".FAIscript");
- }
- }
-
/* Handle posts */
$s_action = $s_entry = "";
foreach($_POST as $name => $value){
+ if(preg_match("/^download_/",$name)){
+ $s_entry = postDecode(preg_replace("/^download_/","",$name));
+ $obj = $this->SubObjects[$s_entry];
+ $obj = $this->get_object_attributes($obj,$this->sub_Load_Later);
+ send_binary_content(stripslashes($obj['FAIscript']),$obj['cn'].".FAIscript");
+ break;
+ }
+
/* Edit script posted */
if(preg_match("/^editscript_/",$name)){
$s_action = "edit";
$s_entry = preg_replace("/^editscript_/","",$name);
- $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
+ $s_entry = postDecode(preg_replace("/_.*/","",$s_entry));
break;
}
/* Delete script requested */
- if(preg_match("/^deletescript_/",$name)){
+ if(preg_match("/^deletescript_/",$name) && !preg_match("/freeze/i",$this->FAIstate)){
$s_action = "remove";
$s_entry = preg_replace("/^deletescript_/","",$name);
- $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
+ $s_entry = postDecode(preg_replace("/_.*/","",$s_entry));
break;
}
}
if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
- $s_entry = $_GET['id'];
+ $s_entry = postDecode($_GET['id']);
if(isset($this->SubObjects[$s_entry])){
$s_action = "edit";
}
@@ -211,11 +193,12 @@ class faiScript extends plugin
/* Create new dialog and set acl attributes */
$this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
+ $this->dialog->FAIstate = $this->FAIstate;
$this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn']));
$this->dialog->set_acl_category("fai");
/* Assign some additional dialog informations like headline and parent */
- session::set('objectinfo',$obj['dn']);
+ set_object_info($obj['dn']);
$this->dialog->parent = &$this;
$this->is_dialog=true;
}
@@ -242,7 +225,7 @@ class faiScript extends plugin
$msgs = $this->dialog->check();
if(count($msgs)>0){
foreach($msgs as $msg){
- print_red($msg);
+ msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
}
}else{
@@ -327,9 +310,9 @@ class faiScript extends plugin
$plug = $_GET['plug'];
if($this->sort_order == "up"){
- $dir = "";
+ $dir = image('images/lists/sort-up.png');
}else{
- $dir = "";
+ $dir = image('images/lists/sort-down.png');
}
if($this->sort_by == "name"){
@@ -340,7 +323,7 @@ class faiScript extends plugin
$sort_prio = $dir;
}
- $divlist->SetHeader(array( array("string"=>""._("Name").$sort_name.""),
+ $divlist->SetHeader(array( array("string"=>""._("Name")."".$sort_name),
array("string"=>"".$sort_prio._("Priority")."",
"attach"=>"style='width:100px;'"),
array("string"=>_("Download"),
@@ -356,12 +339,12 @@ class faiScript extends plugin
$act = "";
/* Hide delete icon if this object is freezed */
- if($this->FAIstate == "freeze"){
- $act .= "";
+ if(preg_match("/freeze/", $this->FAIstate)){
+ $act .= image('images/lists/edit.png', 'editscript_%s',msgPool::editButton());
}else{
- $act .= "";
+ $act .= image('images/lists/edit.png', 'editscript_%s',msgPool::editButton());
if(preg_match("/d/",$acl)){
- $act .="";
+ $act .= image('images/lists/trash.png', 'deletescript_%s',msgPool::delButton());
}
}
@@ -370,24 +353,21 @@ class faiScript extends plugin
if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){
$down = "";
}else{
- $down = "
-
- ";
+ $down = image('images/save.png', 'download_'.postEncode($key));
}
/* Check if we are allowed to view this object */
$s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","cn") ;
if(preg_match("/r/",$s_acl)){
- $divlist->AddEntry(array( array("string"=>"".$name['name'].""),
+ $divlist->AddEntry(array( array("string"=>"".$name['name'].""),
array("string"=>$name['FAIpriority'] , "attach" => "style='width:100px;'"),
array("string"=>$down , "attach" => "style='width:100px;'"),
- array("string"=>str_replace("%s",base64_encode($key),$act),
+ array("string"=>str_replace("%s",postEncode($key),$act),
"attach"=>"style='border-right: 0px;width:100px;text-align:right;'")));
}
}
$smarty->assign("Entry_divlist",$divlist->DrawList());
-
/* Magic quotes GPC, escapes every ' " \, to solve some security risks
* If we post the escaped strings they will be escaped again
*/
@@ -413,32 +393,34 @@ class faiScript extends plugin
return($display);
}
+
/* Generate listbox friendly SubObject list
*/
function getList($use_dns=false){
$a_return=array();
foreach($this->SubObjects as $obj){
if($obj['status'] != "delete"){
+
+ $cn = stripslashes($obj['cn']);
+ $desc = "";
+
+ if((isset($obj['description']))&&(!empty($obj['description']))){
+ $desc = " [".stripslashes($obj['description'])."]";
+ }
+
if($use_dns){
- if((isset($obj['description']))&&(!empty($obj['description']))){
- $a_return[$obj['cn']]['name']= $obj['cn']." [".stripslashes($obj['description'])."]";
- }else{
- $a_return[$obj['cn']]['name']= $obj['cn'];
- }
+ $a_return[$obj['cn']]['name']= $cn.$desc;
$a_return[$obj['cn']]['dn']= $obj['dn'];
$a_return[$obj['cn']]['FAIpriority']= $obj['FAIpriority'];
}else{
- if((isset($obj['description']))&&(!empty($obj['description']))){
- $a_return[$obj['cn']]= $obj['cn']." [".stripslashes($obj['description'])."]";
- }else{
- $a_return[$obj['cn']]= $obj['cn'];
- }
+ $a_return[$obj['cn']] = $cn.$desc;
}
}
}
return($a_return);
}
+
/* Delete me, and all my subtrees
*/
function remove_from_parent()
@@ -446,21 +428,13 @@ class faiScript extends plugin
if($this->acl_is_removeable()){
$ldap = $this->config->get_ldap_link();
$ldap->cd ($this->dn);
- $faifilter = session::get('faifilter');
- $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
- if($faifilter['branch'] == "main"){
- $use_dn = $this->dn;
- }
-
+ $release = $this->parent->parent->fai_release;
+ $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
-
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
-
+
foreach($this->SubObjects as $name => $obj){
- $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
- if($faifilter['branch'] == "main"){
- $use_dn = $obj['dn'];
- }
+ $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $obj['dn']);
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
}
$this->handle_post_events("remove");
@@ -472,13 +446,8 @@ class faiScript extends plugin
*/
function save_object()
{
- if((isset($_POST['FAIscript_posted'])) && ($this->FAIstate != "freeze")){
+ if((isset($_POST['FAIscript_posted'])) && !preg_match("/freeze/", $this->FAIstate)){
plugin::save_object();
- foreach($this->attributes as $attrs){
- if(isset($_POST[$attrs])){
- $this->$attrs = $_POST[$attrs];
- }
- }
}
/* Get sort order */
@@ -501,6 +470,17 @@ class faiScript extends plugin
/* Call common method to give check the hook */
$message= plugin::check();
+ /* Ensure that we do not overwrite an allready existing entry
+ */
+ if($this->is_new){
+ $release = $this->parent->parent->fai_release;
+ $new_dn= 'cn='.$this->cn.",".get_ou('faiScriptRDN').get_ou('faiBaseRDN').$release;
+ $res = faiManagement::check_class_name("FAIscript",$this->cn,$new_dn);
+ if(isset($res[$this->cn])){
+ $message[] = msgPool::duplicated(_("Name"));
+ }
+ }
+
return ($message);
}
@@ -513,7 +493,6 @@ class faiScript extends plugin
$ldap = $this->config->get_ldap_link();
FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
- show_ldap_error($ldap->get_error(), sprintf(_("Creating of FAI/script with dn '%s' failed."),$this->dn));
if($this->initially_was_account){
new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
@@ -549,14 +528,14 @@ class faiScript extends plugin
foreach($Objects as $name => $obj){
foreach($this->sub64coded as $codeIt){
- $obj[$codeIt]=base64_encode(stripslashes($obj[$codeIt]));
+ $obj[$codeIt]=postEncode(stripslashes($obj[$codeIt]));
}
$tmp = array();
$attributes = array_merge($this->sub_Load_Later,$this->subAttributes);
foreach($attributes as $attrs){
-
- if(empty($obj[$attrs])){
+ if(!isset($obj[$attrs])) continue;
+ if($obj[$attrs] == ""){
$obj[$attrs] = array();
}
if(!is_array($obj[$attrs])){
@@ -604,32 +583,48 @@ class faiScript extends plugin
/* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
*/
- $ldap = $this->config->get_ldap_link();
- $ldap->cd ($source['dn']);
-
- $attrs_to_search = $this->subAttributes;
- $attrs_to_search[] = "FAIstate";
- $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search);
+ $res = FAI::get_all_objects_for_given_base($source['dn'],"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+ foreach($res as $obj){
- while($object = $ldap->fetch()){
+ /* Skip not relevant objects */
+ if(!preg_match("/".preg_quote($source['dn'], '/')."$/i",$obj['dn'])) continue;
- /* Skip objects, that are tagged as removed */
- if(isset($object['FAIstate'][0])){
- if(preg_match("/removed$/",$object['FAIstate'][0])){
- continue;
- }
- }
-
- /* Set status for save management */
$objects = array();
$objects['status'] = "edited";
- $objects['dn'] = $object['dn'];
+ $objects['dn'] = $obj['dn'];
$objects = $this->get_object_attributes($objects,$this->subAttributes);
$objects = $this->get_object_attributes($objects,$this->sub_Load_Later);
-
$this->SubObjects[$objects['cn']] = $objects;
}
}
+
+
+ /*! \brief Used for copy & paste.
+ Returns a HTML input mask, which allows to change the cn of this entry.
+ @param Array Array containing current status && a HTML template.
+ */
+ function getCopyDialog()
+ {
+ $vars = array("cn");
+ $smarty = get_smarty();
+ $smarty->assign("cn", htmlentities($this->cn));
+ $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
+ $ret = array();
+ $ret['string'] = $str;
+ $ret['status'] = "";
+ return($ret);
+ }
+
+
+ /*! \brief Used for copy & paste.
+ Some entries must be renamed to avaoid duplicate entries.
+ */
+ function saveCopyDialog()
+ {
+ if(isset($_POST['cn'])){
+ $this->cn = get_post('cn');
+ }
+ }
/* Return plugin informations for acl handling */