Code

Completed lvm partition changes
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiScriptEntry.inc
index 0321329209825ddaac037fff565a47c70348d085..a0ba363c99bb006685447226502687eefeee6e2c 100644 (file)
@@ -2,11 +2,6 @@
 
 class faiScriptEntry 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;
   var $attributes   = array("cn","description","FAIpriority","FAIscript");
@@ -25,7 +20,7 @@ class faiScriptEntry extends plugin
   
   function faiScriptEntry (&$config, $dn= NULL,$object=false)
   {
-    plugin::plugin ($config, $dn);
+    plugin::plugin ($config, NULL);
     if($dn != "new"){
       $this->orig_cn= $object['cn'];
       $this->dn=$object['dn'];
@@ -33,11 +28,6 @@ class faiScriptEntry extends plugin
         $oname = $name;
         $this->$oname=$value;
       }
-
-      if(isset($this->attrs['FAIstate'][0])){
-        $this->FAIstate = $this->attrs['FAIstate'][0];
-      }
-
     }else{
       if(is_array($object)&&count($object)){
         $this->orig_cn= $object['cn'];
@@ -56,38 +46,45 @@ class faiScriptEntry extends plugin
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     /* Fill templating stuff */
     $smarty     = get_smarty();
+    $smarty->assign("freeze", preg_match("/freeze/i",$this->FAIstate));
     $display = "";
   
     if(isset($_POST['ImportUpload']) && $this->acl_is_writeable("FAIscript")){
       if(($_FILES['ImportFile']['error']!=0)){
-        print_red(_("Please select a valid file."));
+        msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG);
       }else
       if(($_FILES['ImportFile']['size']==0)){
-        print_red(_("Selected file is empty."));
+        msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG);
       }else{
         $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
         $this->FAIscript = $str;
       }
     }
   
+     /* Magic quotes GPC, escapes every ' " \, to solve some security risks
+     * If we post the escaped strings they will be escaped again
+     */
     foreach($this->attributes as $attrs){
       if(get_magic_quotes_gpc()){
-       $smarty->assign($attrs,stripslashes($this->$attrs));
+        $smarty->assign($attrs,(stripslashes($this->$attrs)));
       }else{
-       $smarty->assign($attrs,($this->$attrs));
-      } 
+        $smarty->assign($attrs,($this->$attrs));
+      }
     }
 
-     /* Create download button*/
+    /* File download requested */
+    if(isset($_POST['download'])){
+      send_binary_content(stripslashes($this->FAIscript),$this->cn.".FAIscript");
+    }
+
+    /* Create download button*/
     if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
-      $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
-        <input type='button' value='"._("Download")."'>
-        </a>");
+      $smarty->assign("DownMe", image('images/save.png','download',_("Download")));
     }else{
       $smarty->assign("DownMe","");
     }
@@ -98,19 +95,16 @@ class faiScriptEntry extends plugin
 
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translated){
-      $acl = $this->getacl($name);
-      if($this->FAIstate == "freezed"){
-        $acl = preg_replace("/w/","",$acl);
-      }
+      $acl = $this->getacl($name,preg_match("/freeze/i",$this->FAIstate));
       $smarty->assign($name."ACL",$acl);
     }
 
-    $smarty->assign("FAIprioritys",$FAIprioritys);
     if(get_magic_quotes_gpc()){
       $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
     }else{
       $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
     }
+    $smarty->assign("FAIprioritys",$FAIprioritys);
     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
     return($display);
   }
@@ -118,7 +112,7 @@ class faiScriptEntry extends plugin
   /* Save data to object */
   function save_object()
   {
-    if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
+    if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/freeze/", $this->FAIstate)){
       foreach($this->attributes as $attrs){
         if($this->acl_is_writeable($attrs)){
           if(isset($_POST[$attrs])){
@@ -138,15 +132,20 @@ class faiScriptEntry extends plugin
     $message= plugin::check();
   
     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
-      $message[] =_("There is already a script with the given name.");
+      $message[] = msgPool::duplicated(_("Name"));
     }
 
-    if(empty($this->cn)){
-      $message[] = _("Please enter a name.");
+    $c = trim($this->cn);
+    if($c == ""){
+      $message[] = msgPool::required(_("Name"));
+    }
+    if(preg_match("/[^a-z0-9_\-]/i",$c)){
+      $message[] = msgPool::invalid(_("Name"),$c,"/[a-z0-9_\-]/i");
     }
 
-    if(empty($this->FAIscript)){
-      $message[]=_("Please enter a script.");
+    $s = trim($this->FAIscript);
+    if($s == ""){
+      $message[]= msgPool::required(_("Script"));
     }
 
     return ($message);