summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7e3fbe7)
raw | patch | inline | side by side (parent: 7e3fbe7)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 9 Jul 2010 09:27:02 +0000 (09:27 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 9 Jul 2010 09:27:02 +0000 (09:27 +0000) |
-Added encoding verification.
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18973 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18973 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-plugins/fai/admin/fai/class_faiHookEntry.inc | patch | blob | history | |
gosa-plugins/fai/admin/fai/faiHookEntry.tpl | patch | blob | history |
diff --git a/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc b/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc
index 5bfdf5823d6ec248b67b111d6b83a93bc21ae104..501ffaa54e8d669ec5eea5ee44478b64c73a7178 100644 (file)
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)
{
$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;
+ }
+ }
}
}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");
{
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);
}
}
}
+
+ // 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);
+ }
}
}
/* 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?"),
+ "<i>".$this->enc_before_edit."</i>","<i>".$this->enc_after_edit."</i>");
+ $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 591598ede0cc97e37970572f774f1fe484eff025..98c99dda0a6a4187630a47ca7ce96d269635b3b7 100644 (file)
<hr>
<h3><LABEL for="FAIscript">{t}Script{/t}</LABEL>
</h3>
+
+{if $write_protect}
+ {t}This FAI script is write protected, due to its encoding. Editing may break it!{/t}
+ <br>
+ <button type='submit' name='editAnyway'>{t}Edit anyway{/t}</button>
+{/if}
+
+
{render acl=$FAIscriptACL}
- <textarea name="FAIscript" style="width:100%;height:300px;" id="FAIscript" rows=20 cols=120>{$FAIscript}</textarea>
+ <textarea {if $write_protect} disabled {/if} {if !$write_protect} name="FAIscript" {/if}
+ style="width:100%;height:300px;" id="FAIscript" rows=20 cols=120>{$FAIscript}</textarea>
{/render}
<br>
<div>