From bbec2384b83a688d50f1135a202611df4b9fd681 Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 9 Jul 2010 09:27:02 +0000 Subject: [PATCH] Updated FAIhooks -Added encoding verification. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18973 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../fai/admin/fai/class_faiHookEntry.inc | 48 +++++++++++++++++++ gosa-plugins/fai/admin/fai/faiHookEntry.tpl | 11 ++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc b/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc index 5bfdf5823..501ffaa54 100644 --- a/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc +++ b/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc @@ -20,6 +20,12 @@ class faiHookEntry extends plugin var $status = "new"; var $parent = NULL; var $FAIstate = ""; + + // Encoding validation + var $enc_before_edit = ""; + var $enc_after_edit = ""; + var $write_protect = FALSE; + function faiHookEntry (&$config, $dn= NULL,$object=false) { @@ -45,6 +51,15 @@ class faiHookEntry extends plugin $this->orig_cn = false; } } + + // Keep an eye on dangerous encodings, we may break scripts while editing. + $this->mb_extension = function_exists("mb_detect_encoding"); + if($this->mb_extension){ + $this->enc_before_edit = mb_detect_encoding($this->FAIscript); + if($this->enc_before_edit != "ASCII"){ + $this->write_protect = TRUE; + } + } } @@ -66,9 +81,21 @@ class faiHookEntry extends plugin }else{ $str = file_get_contents($_FILES['ImportFile']['tmp_name']); $this->FAIscript = $str; + + // Check encoding again + if($this->mb_extension){ + $this->enc_before_edit = mb_detect_encoding($this->FAIscript); + if($this->enc_before_edit != "ASCII"){ + $this->write_protect = TRUE; + } + } } } + // Assign encoding related variables. + $smarty->assign("write_protect",$this->write_protect); + + /* File download requested */ if(isset($_POST['download'])){ send_binary_content($this->FAIscript,$this->cn.".FAIhook"); @@ -114,6 +141,10 @@ class faiHookEntry extends plugin { if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/^freeze/", $this->FAIstate)){ foreach($this->attributes as $attrs){ + + // Do not update the hook content, here, we'll do this a few lines below. + if($attrs == 'FAIscript') continue; + if($this->acl_is_writeable($attrs)){ if(isset($_POST[$attrs])){ $this->$attrs = get_post($attrs); @@ -122,6 +153,16 @@ class faiHookEntry extends plugin } } } + + // Get FAIscript changes + if(isset($_POST['FAIscript']) && + $this->acl_is_writeable('FAIscript') && + !$this->write_protect){ + + // Check encoding again. + $this->FAIscript = get_post('FAIscript'); + $this->enc_after_edit = mb_detect_encoding($this->FAIscript); + } } } @@ -131,6 +172,13 @@ class faiHookEntry extends plugin /* Call common method to give check the hook */ $message= plugin::check(); + if($this->mb_extension && !$this->write_protect && $this->enc_after_edit !== $this->enc_before_edit ){ + $msg = sprintf(_("The script encodig has changed from '%s' to '%s'. Do you really want to save?"), + "".$this->enc_before_edit."","".$this->enc_after_edit.""); + $message[] = $msg; + $this->enc_before_edit = $this->enc_after_edit; + } + if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn && $this->parent->SubObjects[$this->cn]['status'] != 'delete'){ $message[]= msgPool::duplicated(_("Name")); diff --git a/gosa-plugins/fai/admin/fai/faiHookEntry.tpl b/gosa-plugins/fai/admin/fai/faiHookEntry.tpl index 591598ede..98c99dda0 100644 --- a/gosa-plugins/fai/admin/fai/faiHookEntry.tpl +++ b/gosa-plugins/fai/admin/fai/faiHookEntry.tpl @@ -43,8 +43,17 @@

+ +{if $write_protect} + {t}This FAI script is write protected, due to its encoding. Editing may break it!{/t} +
+ +{/if} + + {render acl=$FAIscriptACL} - + {/render}
-- 2.30.2