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'";
213 if ( isset( $defcfg[$k]['comment'] ) ) {
214 echo ' ' . $defcfg[$k]['comment'];
218 case SMOPT_TYPE_INTEGER
:
219 if ( isset( $HTTP_POST_VARS[$e] ) ) {
220 $v = intval( $HTTP_POST_VARS[$e] );
223 echo "<tr><td>$name</td><td>".
224 "<input size=10 name=\"adm_$n\" value=\"$v\">";
225 if ( isset( $defcfg[$k]['comment'] ) ) {
226 echo ' ' . $defcfg[$k]['comment'];
230 case SMOPT_TYPE_NUMLIST
:
231 if ( isset( $HTTP_POST_VARS[$e] ) ) {
232 $v = $HTTP_POST_VARS[$e];
235 echo "<tr><td>$name</td><td>";
236 echo "<select name=\"adm_$n\">";
237 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
238 echo "<option value=\"$kp\"";
242 echo ">$vp</option>";
245 if ( isset( $defcfg[$k]['comment'] ) ) {
246 echo ' ' . $defcfg[$k]['comment'];
250 case SMOPT_TYPE_STRLIST
:
251 if ( isset( $HTTP_POST_VARS[$e] ) ) {
252 $v = '"' . $HTTP_POST_VARS[$e] . '"';
255 echo "<tr><td>$name</td><td>".
256 "<select name=\"adm_$n\">";
257 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
258 echo "<option value=\"$kp\"";
259 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
262 echo ">$vp</option>";
265 if ( isset( $defcfg[$k]['comment'] ) ) {
266 echo ' ' . $defcfg[$k]['comment'];
271 case SMOPT_TYPE_TEXTAREA
:
272 if ( isset( $HTTP_POST_VARS[$e] ) ) {
273 $v = '"' . $HTTP_POST_VARS[$e] . '"';
274 $newcfg[$k] = str_replace( "\n", '', $v );
276 echo "<tr><td valign=top>$name</td><td>".
277 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
278 if ( isset( $defcfg[$k]['comment'] ) ) {
279 echo ' ' . $defcfg[$k]['comment'];
283 case SMOPT_TYPE_STRING
:
284 if ( isset( $HTTP_POST_VARS[$e] ) ) {
285 $v = '"' . $HTTP_POST_VARS[$e] . '"';
288 echo "<tr><td>$name</td><td>".
289 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
290 if ( isset( $defcfg[$k]['comment'] ) ) {
291 echo ' ' . $defcfg[$k]['comment'];
295 case SMOPT_TYPE_BOOLEAN
:
296 if ( isset( $HTTP_POST_VARS[$e] ) ) {
297 $v = $HTTP_POST_VARS[$e];
300 $v = strtoupper( $v );
302 if ( $v == 'TRUE' ) {
309 echo "<tr><td>$name</td><td>" .
310 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
311 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
312 if ( isset( $defcfg[$k]['comment'] ) ) {
313 echo ' ' . $defcfg[$k]['comment'];
318 echo "<tr><td>$name</td><td>" .
320 if ( isset( $defcfg[$k]['comment'] ) ) {
321 echo ' ' . $defcfg[$k]['comment'];
329 echo '<tr><th>' . _("Theme Name") .
330 '</th><th>' . _("Theme Path") .
332 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
333 $k1 = "\$theme[$i]['NAME']";
334 $e1 = "theme_name_$i";
335 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
336 $v1 = '"' . $HTTP_POST_VARS[$e1] . '"';
341 $k2 = "\$theme[$i]['PATH']";
342 $e2 = "theme_path_$i";
343 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
344 $v2 = '"' . $HTTP_POST_VARS[$e2] . '"';
349 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
350 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
352 "<td align=right><input name=\"$e1\" value=\"$name\" size=30></td>".
353 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
359 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" . _("Plugins") . '</th></tr>';
361 $fd = opendir( '../plugins/' );
362 $op_plugin = array();
363 while (false!==($file = readdir($fd))) {
364 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
365 if ( filetype( $file ) == 'dir' ) {
366 $op_plugin[] = $file;
374 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
375 $k = "\$plugins[$i]";
377 if ( isset( $HTTP_POST_VARS[$e] ) ) {
378 $v = '"' . $HTTP_POST_VARS[$e] . '"';
383 $name = substr( $v, 1, strlen( $v ) - 2 );
385 "<td align=right>$i.</td>".
386 "<td><select name=\"$e\">";
387 foreach ( $op_plugin as $op ) {
388 if ( $op == $name ) {
393 echo "<option$cs>$op</option>";
395 echo "</select></td>".
401 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
402 _("Change Settings") . "\" type=submit></th></tr>" ,
403 '</table></td></tr></table></form>';
406 Write the options to the file.
409 $fp = fopen( $cfgfile, 'w' );
410 fwrite( $fp, "<?PHP\n".
412 " * SquirrelMail Configuration File\n".
413 " * Created using the Administrator Plugin\n".
417 fwrite( $fp, 'GLOBAL ' );
419 foreach ( $newcfg as $k => $v ) {
420 if ( $k{0} == '$' ) {
421 if( $i = strpos( $k, '[' ) ) {
422 if( strpos( $k, '[0]' ) ) {
426 fwrite( $fp, substr( $k, 0, $i) );
437 fwrite( $fp, ";\n" );
439 foreach ( $newcfg as $k => $v ) {
440 if ( $k{0} == '$' ) {
441 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
442 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
443 $v = str_replace( 'array(', "array(\n\t", $v );
444 $v = str_replace( "',", "',\n\t", $v );
446 fwrite( $fp, "$k = $v;\n" );