6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
14 function parseConfig( $cfg_file ) {
18 $cfg = file( $cfg_file );
23 for ($i=0;$i<$l;$i++
) {
24 $line = trim( $cfg[$i] );
26 for ($j=0;$j<$s;$j++
) {
29 if ( $line{$j} == '=' ) {
30 // Ok, we've got a right value, lets detect what type
32 } else if ( $line{$j} == ';' ) {
39 if( $line{$j} == ' ' ) {
47 if ( $line{$j} == ';' ) {
52 if ( $line{$j} == '\\' ) {
55 } else if ( $line{$j} == $delimiter && $modifier === FALSE ) {
57 $newcfg[$key] = $value . $delimiter;
66 if ( $line{$j} == ';' ) {
67 $newcfg{$key} = $value;
75 if ( $line{$j}.$line{$j+
1} == '*/' ) {
82 switch ( $line{$j} ) {
85 // Double quote string
86 $delimiter = $value = $line{$j};
93 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
95 $newcfg{$key} = 'TRUE';
98 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
99 $newcfg{$key} = 'FALSE';
103 // Number or function call
110 if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
111 // Skip untill next ;
114 } else if ( $line{$j}.$line{$j+
1} == '/*' ) {
117 } else if ( $line{$j} == '#' ||
$line{$j}.$line{$j+
1} == '//' ) {
118 // Delete till the end of the line
120 } else if ( $line{$j} == '$' ) {
121 // We must detect $key name
131 /* ---------------------- main -------------------------- */
134 require_once('../src/validate.php');
135 require_once('../functions/page_header.php');
136 require_once('../functions/imap.php');
137 require_once('../src/load_prefs.php');
138 require_once('../plugins/administrator/defines.php');
141 if ( $adm_id = fileowner('../config/config.php') ) {
142 $adm = posix_getpwuid( $adm_id );
143 if ( $username == $adm['name'] ) {
149 header("Location: ../../src/options.php") ;
153 displayPageHeader($color, 'None');
157 foreach ( $defcfg as $key => $def ) {
161 $cfgfile = '../config/config.php';
162 parseConfig( '../config/config_default.php' );
163 parseConfig( $cfgfile );
165 echo "<form action=$PHP_SELF method=post>" .
166 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
167 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
168 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
169 foreach ( $newcfg as $k => $v ) {
170 $l = strtolower( $v );
171 $type = SMOPT_TYPE_UNDEFINED
;
172 $n = substr( $k, 1 );
173 $n = str_replace( '[', '_', $n );
174 $n = str_replace( ']', '_', $n );
178 if ( isset( $defcfg[$k] ) ) {
179 $name = $defcfg[$k]['name'];
180 $type = $defcfg[$k]['type'];
181 $size = $defcfg[$k]['size'];
182 } else if ( $l == 'true' ) {
184 $type = SMOPT_TYPE_BOOLEAN
;
185 } else if ( $l == 'false' ) {
187 $type = SMOPT_TYPE_BOOLEAN
;
188 } else if ( $v{0} == "'" ) {
189 $type = SMOPT_TYPE_STRING
;
190 } else if ( $v{0} == '"' ) {
191 $type = SMOPT_TYPE_STRING
;
194 if ( substr( $k, 0, 7 ) == '$theme[' ) {
195 $type = SMOPT_TYPE_THEME
;
196 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
197 $type = SMOPT_TYPE_PLUGINS
;
201 case SMOPT_TYPE_PLUGINS
:
202 case SMOPT_TYPE_THEME
:
203 case SMOPT_TYPE_HIDDEN
:
205 case SMOPT_TYPE_TITLE
:
206 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>$name</th></tr>";
208 case SMOPT_TYPE_COMMENT
:
209 $v = substr( $v, 1, strlen( $v ) - 2 );
210 echo "<tr><td>$name</td><td>".
212 $newcfg[$k] = "'$v'";
214 case SMOPT_TYPE_INTEGER
:
215 if ( isset( $HTTP_POST_VARS[$e] ) ) {
216 $v = intval( $HTTP_POST_VARS[$e] );
219 echo "<tr><td>$name</td><td>".
220 "<input size=10 name=\"adm_$n\" value=\"$v\">";
222 case SMOPT_TYPE_NUMLIST
:
223 if ( isset( $HTTP_POST_VARS[$e] ) ) {
224 $v = $HTTP_POST_VARS[$e];
227 echo "<tr><td>$name</td><td>";
228 echo "<select name=\"adm_$n\">";
229 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
230 echo "<option value=\"$kp\"";
234 echo ">$vp</option>";
238 case SMOPT_TYPE_STRLIST
:
239 if ( isset( $HTTP_POST_VARS[$e] ) ) {
240 $v = '"' . $HTTP_POST_VARS[$e] . '"';
243 echo "<tr><td>$name</td><td>".
244 "<select name=\"adm_$n\">";
245 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
246 echo "<option value=\"$kp\"";
247 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
250 echo ">$vp</option>";
255 case SMOPT_TYPE_TEXTAREA
:
256 if ( isset( $HTTP_POST_VARS[$e] ) ) {
257 $v = '"' . $HTTP_POST_VARS[$e] . '"';
258 $newcfg[$k] = str_replace( "\n", '', $v );
260 echo "<tr><td valign=top>$name</td><td>".
261 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
263 case SMOPT_TYPE_STRING
:
264 if ( isset( $HTTP_POST_VARS[$e] ) ) {
265 $v = '"' . $HTTP_POST_VARS[$e] . '"';
268 echo "<tr><td>$name</td><td>".
269 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
271 case SMOPT_TYPE_BOOLEAN
:
272 if ( isset( $HTTP_POST_VARS[$e] ) ) {
273 $v = $HTTP_POST_VARS[$e];
276 $v = strtoupper( $v );
278 if ( $v == 'TRUE' ) {
285 echo "<tr><td>$name</td><td>" .
286 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
287 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
290 echo "<tr><td>$name</td><td>" .
293 if ( isset( $defcfg[$k]['comment'] ) ) {
294 echo ' ' . $defcfg[$k]['comment'];
298 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
299 _("Change Settings") . "\" type=submit></th></tr>" ,
300 '</table></td></tr></table></form>';
303 Write the options to the file.
306 $fp = fopen( $cfgfile, 'w' );
307 fwrite( $fp, "<?PHP\n".
309 " * SquirrelMail Configuration File\n".
310 " * Created using the Administrator Plugin\n".
314 fwrite( $fp, 'GLOBAL ' );
316 foreach ( $newcfg as $k => $v ) {
317 if ( $k{0} == '$' ) {
318 if( $i = strpos( $k, '[' ) ) {
319 if( strpos( $k, '[0]' ) ) {
323 fwrite( $fp, substr( $k, 0, $i) );
334 fwrite( $fp, ";\n" );
336 foreach ( $newcfg as $k => $v ) {
337 if ( $k{0} == '$' ) {
338 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
339 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
340 $v = str_replace( 'array(', "array(\n\t", $v );
341 $v = str_replace( "',", "',\n\t", $v );
343 fwrite( $fp, "$k = $v;\n" );