This commit allows the administrator plugin to parse ldap information
authorphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 28 Jan 2002 14:23:08 +0000 (14:23 +0000)
committerphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 28 Jan 2002 14:23:08 +0000 (14:23 +0000)
(not yet to edit it).

Left to go:
* Themes Edit.
* LDAP Edit.
* Data to default (if empty strings or whatever).

Independent mode. For now it is only possible to enter this plugin if
config.php exists, chmod 660, owned by administrator and group = php user.

It should be interesting to hook at login and look for configuration. If
no configuration is found then switch to the plugin to create a deafult one
and start to input data.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2255 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/administrator/options.php

index a5500f7b899049f615ce0a60bd0e1c81deccd4e2..93370f64b1f96d463b006cb1a633930657a4fa5e 100644 (file)
  * $Id$
  */
 
+function parseConfig( $cfg_file ) {
+
+    global $newcfg;
+
+    $cfg = file( $cfg_file );
+    $cm = FALSE;
+    $j = count( $cfg );
+
+    for ( $i=0; $i < $j; $i++ ) {
+        $l = '';
+        $first_char = $cfg[$i]{0};
+        do {
+            // Remove comments
+            $c = trim( $cfg[$i] );
+            $c = preg_replace( '/\/\*.*\*\//', '', $c );
+            $c = preg_replace( '/#.*$/', '', $c );
+            $c = preg_replace( '/\/\/.*$/', '', $c );
+            $l .= $c;
+            $i++;
+        } while( $first_char == '$' && substr( $c, -1 ) <> ';' && $i < $j );
+        $i--;
+        if ( $l <> '' ) {
+            if ( $cm ) {
+                if( substr( $l, -2 ) == '*/' ) {
+                    $l = '';
+                    $cm = FALSE;
+                } else if( $k = strpos( $l, '*/' ) ) {
+                    $l = substr( $l, $k );
+                    $cm = FALSE;
+                } else {
+                    $l = '';
+                }
+            } else {
+                if( $l{0}.$l{1} == '/*' ) {
+                    $l = '';
+                    $cm = TRUE;
+                } else if ( $k = strpos( $l, '/*' ) ) {
+                    $l = substr( $l, 0, $k );
+                    $cm = TRUE;
+                }
+            }
+    
+            if ( $k = strpos( $l, '=' ) ) {
+                $key = trim( substr( $l, 0, $k - 1 ) );
+                $val = str_replace( ';', '', trim( substr( $l, $k + 1 ) ) );
+                $newcfg[$key] = $val;
+            }
+        }
+
+    }
+
+}
+/* ---------------------- main -------------------------- */
 chdir('..');
 require_once('../src/validate.php');
 require_once('../functions/page_header.php');
@@ -33,86 +86,15 @@ if ( !auth ) {
 
 displayPageHeader($color, 'None');
 
-$cfgfile = '../config/config.php';
-$cfg_defaultfile = '../config/config_default.php';
-$cfg = file( $cfg_defaultfile );
-$newcfg = $dfncfg = array( );
-$cm = FALSE;
+$newcfg = array( );
 
 foreach ( $defcfg as $key => $def ) {
     $newcfg[$key] = '';
 }
 
-foreach ( $cfg as $l ) {
-    // Remove inline /* */ Blocks
-    $l = preg_replace( '/\/\*.*\*\//', '', $l );
-    $l = preg_replace( '/#.*$/', '', $l );
-    $l = preg_replace( '/\/\/.*$/', '', $l );
-    $v = $s = trim( $l );
-    if ( $cm ) {
-        if( substr( $v, -2 ) == '*/' ) {
-            $v = '';
-            $cm = FALSE;
-        } else if( $i = strpos( $v, '*/' ) ) {
-            $v = substr( $v, $i );
-            $cm = FALSE;
-        } else {
-            $v = '';
-        }
-    } else {
-        if( $v{0}.$v{1} == '/*' ) {
-            $v = '';
-            $cm = TRUE;
-        } else if ( $i = strpos( $v, '/*' ) ) {
-            $v = substr( $v, 0, $i );
-            $cm = TRUE;
-        }
-    }
-
-    if ( $i = strpos( $v, '=' ) ) {
-        $key = trim( substr( $v, 0, $i - 1 ) );
-        $val = str_replace( ';', '', trim( substr( $v, $i + 1 ) ) );
-        $newcfg[$key] = $val;
-        $dfncfg[$key] = $val;
-    }
-
-}
-
-$cfg = file( $cfgfile );
-
-$cm = FALSE;
-foreach ( $cfg as $l ) {
-    $l = preg_replace( '/\/\*.*\*\//', '', $l );
-    $l = preg_replace( '/#.*$/', '', $l );
-    $l = preg_replace( '/\/\/.*$/', '', $l );
-    $v = $s = trim( $l );
-    if ( $cm ) {
-        if( substr( $v, -2 ) == '*/' ) {
-            $v = '';
-            $cm = FALSE;
-        } else if( $i = strpos( $v, '*/' ) ) {
-            $v = substr( $v, $i );
-            $cm = FALSE;
-        } else {
-            $v = '';
-        }
-    } else {
-        if( $v{0}.$v{1} == '/*' ) {
-            $v = '';
-            $cm = TRUE;
-        } else if ( $i = strpos( $v, '/*' ) ) {
-            $v = substr( $v, 0, $i );
-            $cm = TRUE;
-        }
-    }
-
-    if ( $i = strpos( $v, '=' ) ) {
-        $key = trim( substr( $v, 0, $i - 1 ) );
-        $val = str_replace( ';', '', trim( substr( $v, $i + 1 ) ) );
-        $newcfg[$key] = $val;
-    }
-
-}
+$cfgfile = '../config/config.php';
+parseConfig( '../config/config_default.php' );
+parseConfig( $cfgfile );
 
 echo "<form action=$PHP_SELF method=post>" .
     "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
@@ -267,4 +249,4 @@ foreach ( $newcfg as $k => $v ) {
 }
 fwrite( $fp, '?>' );
 fclose( $fp );
-?>
+?>
\ No newline at end of file