X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=plugins%2Fadministrator%2Foptions.php;h=f9f06adda65a06addea32f87db61eb2681e39316;hb=66eee195afb7bff6d87637e50b1744183575c9ce;hp=f1b5f6eec5abe1a5acea3690412270bdc3905c16;hpb=a55bb20745b11201a20908015bc299857769734e;p=squirrelmail.git diff --git a/plugins/administrator/options.php b/plugins/administrator/options.php index f1b5f6ee..f9f06add 100644 --- a/plugins/administrator/options.php +++ b/plugins/administrator/options.php @@ -16,71 +16,133 @@ 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 ); - $c = trim( $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; + $mode = ''; + $l = count( $cfg ); + $modifier = FALSE; + + for ($i=0;$i<$l;$i++) { + $line = trim( $cfg[$i] ); + $s = strlen( $line ); + for ($j=0;$j<$s;$j++) { + switch ( $mode ) { + case '=': + if ( $line{$j} == '=' ) { + // Ok, we've got a right value, lets detect what type + $mode = 'D'; + } else if ( $line{$j} == ';' ) { + // hu! end of command + $key = $mode = ''; + } + break; + case 'K': + // Key detect + if( $line{$j} == ' ' ) { + $mode = '='; } else { - $l = ''; + $key .= $line{$j}; } - } else { - if( $l{0}.$l{1} == '/*' ) { - $l = ''; - $cm = TRUE; - } else if ( $k = strpos( $l, '/*' ) ) { - $l = substr( $l, 0, $k ); - $cm = TRUE; + break; + case ';': + // Skip until next ; + if ( $line{$j} == ';' ) { + $mode = ''; + } + break; + case 'S': + if ( $line{$j} == '\\' ) { + $value .= $line{$j}; + $modifier = TRUE; + } else if ( $line{$j} == $delimiter && $modifier === FALSE ) { + // End of string; + $newcfg[$key] = $value . $delimiter; + $key = $value = ''; + $mode = ';'; + } else { + $value .= $line{$j}; + $modifier = FALSE; + } + break; + case 'N': + if ( $line{$j} == ';' ) { + $newcfg{$key} = $value; + $key = $mode = ''; + } else { + $value .= $line{$j}; + } + break; + case 'C': + // Comments + if ( $s > $j + 1 && + $line{$j}.$line{$j+1} == '*/' ) { + $mode = ''; + $j++; + } + break; + case 'D': + // Delimiter detect + switch ( $line{$j} ) { + case '"': + case "'": + // Double quote string + $delimiter = $value = $line{$j}; + $mode = 'S'; + break; + case ' ': + // Nothing yet + break; + default: + if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) { + // Boolean TRUE + $newcfg{$key} = 'TRUE'; + $key = ''; + $mode = ';'; + } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) { + $newcfg{$key} = 'FALSE'; + $key = ''; + $mode = ';'; + } else { + // Number or function call + $mode = 'N'; + $value = $line{$j}; + } + } + break; + default: + if ( $line{$j} == '$' ) { + // We must detect $key name + $mode = 'K'; + $key = '$'; + } else if ( $s < $j + 2 ) { + } else if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) { + // Skip untill next ; + $mode = ';'; + $j += 6; + } else if ( $line{$j}.$line{$j+1} == '/*' ) { + $mode = 'C'; + $j++; + } else if ( $line{$j} == '#' || $line{$j}.$line{$j+1} == '//' ) { + // Delete till the end of the line + $j = $s; } - } - - 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'); require_once('../functions/imap.php'); require_once('../src/load_prefs.php'); require_once('../plugins/administrator/defines.php'); +require_once('../plugins/administrator/auth.php'); -$auth = FALSE; -if ( $adm_id = fileowner('../config/config.php') ) { - $adm = posix_getpwuid( $adm_id ); - if ( $username == $adm['name'] ) { - $auth = TRUE; - } -} +GLOBAL $data_dir, $username; -if ( !auth ) { +if ( !adm_check_user() ) { header("Location: ../../src/options.php") ; exit; } @@ -97,10 +159,34 @@ $cfgfile = '../config/config.php'; parseConfig( '../config/config_default.php' ); parseConfig( $cfgfile ); -echo "