Code

Updated setup step 8.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 3 Apr 2007 09:12:35 +0000 (09:12 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 3 Apr 2007 09:12:35 +0000 (09:12 +0000)
Saving of configuration files implemented.
Creates backups of old configurations now.
Warns the user if the current conf file is world readable.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5957 594d385d-05f5-0310-b6e9-bd551577e9d8

setup/class_setupStep8.inc
setup/setup_step8.tpl

index f7dc508ef081323da6ab72c3571f1f09ef3144c1..ac59df5b8e5c69b702ddc462693dc0de3763b55b 100644 (file)
 
 class setup_step_8 extends setup_step
 {
-  var $create_backup = TRUE;
-  var $gosa_conf_name = "/gosa.conf";
+  var $create_backup    = TRUE;
+  var $gosa_conf_name   = "/gosa.conf";
+  var $cfg_file_written = FALSE;
+  var $last_backup_name = "";
 
   function setup_step_8()
   {
     $this->s_title      = _("Configuration file");
-    $this->s_title_long = _("In this step the configuration file will be created.");
-    $this->s_info       = _("Saving configuration file");
+    $this->s_info       = _("In this step the configuration file will be created.");
+    $this->s_title_long = _("Saving configuration file");
+  }
+
+
+  function get_conf_data()
+  {
+    return("currently not implemented.");
   }
 
 
   function execute()
   {
 
+    
     /* Check if there is currently an active gosa.conf 
      */
     $exists = file_exists(CONFIG_DIR.$this->gosa_conf_name); 
@@ -47,25 +56,84 @@ class setup_step_8 extends setup_step
       $writeable = is_writeable(CONFIG_DIR);
     }
 
-    $smarty = get_smarty();
-  
+    /* Downlaod config */
+    if(isset($_POST['getconf'])){
+      header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+      header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+      header("Cache-Control: no-cache");
+      header("Pragma: no-cache");
+      header("Cache-Control: post-check=0, pre-check=0");
+      header("Content-type: text/plain");
+      header('Content-Disposition: attachment; filename="gosa.conf"');
+      echo $this->get_conf_data();
+      exit();
+    }
+   
+    
+    /* Try to save configuration */
+    $abort    = FALSE;
+    $err_msg  = "";
+    if(isset($_POST['saveconf'])){
+      if($exists && $this->create_backup){
+        if(!$this->create_backup()){
+          $abort = TRUE;
+          $err_msg = _("Could not create requested configuration file backup. Aborted writing config file. Please check folder permission and try again. Or use the manual method if this can not be fixed anyway.");
+        }
+      }
+    
+      if(!$abort){
+        
+        /* Try to create file handle */
+        $fp = @fopen(CONFIG_DIR.$this->gosa_conf_name, "w");
+    
+        if(!$fp){
+          $err_msg = sprintf(_("Can not create handle on file '%s', the configuration could not be written. Please check folder permission and try again. Or use the manual method if this can not be fixed anyway."),CONFIG_DIR.$this->gosa_conf_name);
+          $abort  =TRUE;
+        }else{
+
+          $data = $this->get_conf_data();
+          if(!fwrite($fp,strlen($data))){
+            $err_msg = sprintf(_("Can not write file '%s'. Please check folder permission and try again. Or use the manual method if this can not be fixed anyway."),CONFIG_DIR.$this->gosa_conf_name);
+            $abort  =TRUE;
+          }
+        }
+      }
+    } 
+
+
+    if($exists && $this->is_world_readable(CONFIG_DIR.$this->gosa_conf_name)){
+      $err_msg = _("Your configuration file is currently world readable. This is a big security issue. Please updated the file permissions as shown in the manual configuration part below.");
+    }
+
     $info= posix_getgrgid(posix_getgid());
-    $smarty->assign("webgroup", $info['name']);
 
+    $smarty = get_smarty();
+    $smarty->assign("save_requested", isset($_POST['saveconf']));
+    $smarty->assign("err_msg",$err_msg);
+    $smarty->assign("webgroup", $info['name']);
     $smarty->assign("gosa_conf_name" , $this->gosa_conf_name);
     $smarty->assign("create_backup" , $this->create_backup);
     $smarty->assign("CONFIG_DIR",CONFIG_DIR);
-  
-    $smarty->assign("msg_permissions",sprintf(_("The following file(s), folders(s) must be writeable for the web-user '%s'."),$info['name']));
     $smarty->assign("exists",$exists);
+    $smarty->assign("last_backup_name",$this->last_backup_name);
     $smarty->assign("writeable",$writeable);
     $smarty->assign("cv",$this->parent->captured_values);
+    $smarty->assign("msg_permissions",
+      sprintf(_("The following file(s), folders(s) must be writeable for the web-user '%s'."),$info['name']));
     return($smarty -> fetch (get_template_path("../setup/setup_step8.tpl")));
   }
 
 
+  /* check if given file is world readable */
+  function is_world_readable($file)
+  {
+    clearstatcache();
+    $p = fileperms($file);
+    $w_r = (decbin($p & 4) == TRUE);
+    return($w_r);
+  }
+
+
   /* Create a backup of the currently existing configuration file. 
    */
   function create_backup()
@@ -79,7 +147,13 @@ class setup_step_8 extends setup_step
         $dst = $dst_backup."-".$i;
         $i ++;
       }
-      return(rename($src,$dst));
+#      if(rename($src,$dst)){
+      if(copy($src,$dst)){
+        $this->last_backup_name = $dst;
+        return(TRUE);
+      }else{
+        return(FALSE);
+      }
     }else{
       return(FALSE);
     }
@@ -98,10 +172,12 @@ class setup_step_8 extends setup_step
       }
 
       /* Backup toggle */
-      if(isset($_POST['create_backup'])){
-        $this->create_backup = TRUE;
-      }else{
-        $this->create_backup = FALSE;
+      if(isset($_POST['create_backup_visible'])){
+        if(isset($_POST['create_backup'])){
+          $this->create_backup = TRUE;
+        }else{
+          $this->create_backup = FALSE;
+        }
       }
     }
   }
index 70cfee63ef1dc8431acc67896d818451abb9236c..bcde3ef39fd268c778a21eaa95555a25af401f12 100644 (file)
                {if $writeable}
                        {t}Write configuration file{/t}&nbsp;
                        <input type='submit' name='saveconf' value='{t}Save configuration{/t}'>
+
+                       {if $exists}
                        <br>
+                       <input type='hidden' name='create_backup_visible' value='1'>
                        <input {if $create_backup} checked {/if} type='checkbox' value='1' name='create_backup'>&nbsp;
                        {t}Create a backup from existing configuration file{/t}
+                       {/if}
+
+                       {if $err_msg != ""}
+                               <div style='color:red ; font-weight:bold '>{$err_msg}</div>
+                       {else}
+                               {if $save_requested}            
+                                       <div style='color:green ; font-weight:bold '>{t}Configuration succesfully written.{/t}</div>
+                               {/if}
+                       {/if}
+
+                       {if $last_backup_name}
+                               <br>
+                               <div style='padding-left:20px;'>{t}Last created backup{/t}: &nbsp;<i>{$last_backup_name}</i></div> 
+                       {/if}
                {else}          
                        <div style='font-weight: bold; color: red;'>{t}Can't write configuration file, please check permissions.{/t}</div>
                        <pre>