Happy New Year
[squirrelmail.git] / plugins / administrator / options.php
index 1c35dc432c4f2c529f2e64a27bddbae6b2418b56..82f1b8ea77d6ce5488753441633d9a74e8bbd4f0 100644 (file)
@@ -7,13 +7,15 @@
  * SquirrelMail configuration file.
  *
  * @author Philippe Mingo
- * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @copyright 1999-2020 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
  * @subpackage administrator
  */
 
+define('PAGE_NAME', 'administrator_options');
+
 /**
  * parse the config file
  *
@@ -170,6 +172,7 @@ function change_to_rel_path($old_path) {
  *     empty_string            --> ''
  *     ../images/logo.gif      --> SM_PATH . 'images/logo.gif'
  *     images/logo.gif         --> SM_PATH . 'config/images/logo.gif'
+ *     C:/absolute/win/path    --> 'C:/absolute/win/path'
  *     /absolute/path/logo.gif --> '/absolute/path/logo.gif'
  *     http://whatever/        --> 'http://whatever'
  *
@@ -180,7 +183,8 @@ function change_to_rel_path($old_path) {
 function change_to_sm_path($old_path) {
     if ( $old_path === '' || $old_path == "''" ) {
         return "''";
-    } elseif ( preg_match("/^(\/|http)/", $old_path) ) {
+    } elseif ( preg_match("/^(\/|http)/", $old_path) ||
+        substr($old_path,1,2) == ':/' ) {
         return "'" . $old_path . "'";
     } elseif ( preg_match("/^(\$|SM_PATH)/", $old_path) ) {
         return $old_path;
@@ -219,15 +223,12 @@ function change_to_sm_path($old_path) {
 
 
 /* ---------------------- main -------------------------- */
-
-/** @ignore */
-define('SM_PATH','../../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/imap.php');
-require_once(SM_PATH . 'plugins/administrator/defines.php');
-require_once(SM_PATH . 'plugins/administrator/auth.php');
+/** main SquirrelMail include */
+require('../../include/init.php');
+/* configuration definitions */
+include_once(SM_PATH . 'plugins/administrator/defines.php');
+/* additional functions */
+include_once(SM_PATH . 'plugins/administrator/auth.php');
 
 global $data_dir, $username;
 
@@ -236,7 +237,7 @@ if ( !adm_check_user() ) {
     exit;
 }
 
-displayPageHeader($color, 'None');
+displayPageHeader($color);
 
 $newcfg = array( );
 
@@ -321,7 +322,7 @@ foreach ( $newcfg as $k => $v ) {
     } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
         $type = SMOPT_TYPE_LDAP;
     } else if ( substr( $k, 0, 9 ) == '$fontsets' ||
-       substr( $k, 0, 13 ) == '$aTemplateSet' ) {
+                substr( $k, 0, 13 ) == '$aTemplateSet' ) {
         $type = SMOPT_TYPE_CUSTOM;
     }
 
@@ -416,11 +417,13 @@ foreach ( $newcfg as $k => $v ) {
 
         case SMOPT_TYPE_TEXTAREA:
             if (  sqgetGlobalVar($e, $new_v, SQ_POST) ) {
-                $v = '"' . $new_v . '"';
+                $v = '"' . addslashes($new_v) . '"';
                 $newcfg[$k] = str_replace( "\n", '', $v );
             }
-            echo "<tr><td valign=\"top\">$name</td><td>".
-                 "<textarea cols=\"$size\" rows=\"4\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
+            echo "<tr><td valign=\"top\">$name</td><td>"
+                ."<textarea cols=\"$size\" rows=\"4\" name=\"adm_$n\">" 
+                .sm_encode_html_special_chars(stripslashes(substr( $v, 1, strlen( $v ) - 2 )))
+                ."</textarea>";
             if ( isset( $defcfg[$k]['comment'] ) ) {
                 echo ' &nbsp; ' . $defcfg[$k]['comment'];
             }
@@ -428,15 +431,17 @@ foreach ( $newcfg as $k => $v ) {
             break;
         case SMOPT_TYPE_STRING:
             if (  sqgetGlobalVar($e, $new_v, SQ_POST) ) {
-                $v = '"' . $new_v . '"';
+                $v = '"' . addslashes($new_v) . '"';
                 $newcfg[$k] = $v;
             }
             if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
                 $v = "'" . $defcfg[$k]['default'] . "'";
                 $newcfg[$k] = $v;
             }
-            echo "<tr><td>$name</td><td>".
-                 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . '" />';
+            echo "<tr><td>$name</td><td>"
+                ."<input size=\"$size\" name=\"adm_$n\" value=\""
+                .sm_encode_html_special_chars(stripslashes(substr( $v, 1, strlen( $v ) - 2 )))
+                .'" />';
             if ( isset( $defcfg[$k]['comment'] ) ) {
                 echo ' &nbsp; ' . $defcfg[$k]['comment'];
             }
@@ -615,14 +620,15 @@ echo '<tr bgcolor="'.$color[5].'"><th colspan="2"><input value="'.
     Write the options to the file.
 */
 
+// Test/debug
+// $cfgfile = '/tmp/config.php';
 if ( $fp = @fopen( $cfgfile, 'w' ) ) {
     fwrite( $fp, "<?php\n".
     "/**\n".
     " * SquirrelMail Configuration File\n".
     " * Created using the Administrator Plugin\n".
     " */\n".
-    "\n".
-    "global \$version;\n" );
+    "\n" );
 
     foreach ( $newcfg as $k => $v ) {
         if ( $k{0} == '$' && $v <> '' || is_int($v)) {
@@ -635,8 +641,6 @@ if ( $fp = @fopen( $cfgfile, 'w' ) ) {
             fwrite( $fp, "$k = $v;\n" );
         }
     }
-    // add local config support
-    fwrite( $fp, "@include SM_PATH . 'config/config_local.php';\n" );
     // close php
     fwrite( $fp, '?>' );
     fclose( $fp );
@@ -645,5 +649,6 @@ if ( $fp = @fopen( $cfgfile, 'w' ) ) {
          _("Config file can't be opened. Please check config.php.").
          '</big></p>';
 }
+
 ?>
-</body></html>
\ No newline at end of file
+</body></html>