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
;
198 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
199 $type = SMOPT_TYPE_LDAP
;
203 case SMOPT_TYPE_LDAP
:
204 case SMOPT_TYPE_PLUGINS
:
205 case SMOPT_TYPE_THEME
:
206 case SMOPT_TYPE_HIDDEN
:
208 case SMOPT_TYPE_TITLE
:
209 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>$name</th></tr>";
211 case SMOPT_TYPE_COMMENT
:
212 $v = substr( $v, 1, strlen( $v ) - 2 );
213 echo "<tr><td>$name</td><td>".
215 $newcfg[$k] = "'$v'";
216 if ( isset( $defcfg[$k]['comment'] ) ) {
217 echo ' ' . $defcfg[$k]['comment'];
221 case SMOPT_TYPE_INTEGER
:
222 if ( isset( $HTTP_POST_VARS[$e] ) ) {
223 $v = intval( $HTTP_POST_VARS[$e] );
226 echo "<tr><td>$name</td><td>".
227 "<input size=10 name=\"adm_$n\" value=\"$v\">";
228 if ( isset( $defcfg[$k]['comment'] ) ) {
229 echo ' ' . $defcfg[$k]['comment'];
233 case SMOPT_TYPE_NUMLIST
:
234 if ( isset( $HTTP_POST_VARS[$e] ) ) {
235 $v = $HTTP_POST_VARS[$e];
238 echo "<tr><td>$name</td><td>";
239 echo "<select name=\"adm_$n\">";
240 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
241 echo "<option value=\"$kp\"";
245 echo ">$vp</option>";
248 if ( isset( $defcfg[$k]['comment'] ) ) {
249 echo ' ' . $defcfg[$k]['comment'];
253 case SMOPT_TYPE_STRLIST
:
254 if ( isset( $HTTP_POST_VARS[$e] ) ) {
255 $v = '"' . $HTTP_POST_VARS[$e] . '"';
258 echo "<tr><td>$name</td><td>".
259 "<select name=\"adm_$n\">";
260 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
261 echo "<option value=\"$kp\"";
262 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
265 echo ">$vp</option>";
268 if ( isset( $defcfg[$k]['comment'] ) ) {
269 echo ' ' . $defcfg[$k]['comment'];
274 case SMOPT_TYPE_TEXTAREA
:
275 if ( isset( $HTTP_POST_VARS[$e] ) ) {
276 $v = '"' . $HTTP_POST_VARS[$e] . '"';
277 $newcfg[$k] = str_replace( "\n", '', $v );
279 echo "<tr><td valign=top>$name</td><td>".
280 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
281 if ( isset( $defcfg[$k]['comment'] ) ) {
282 echo ' ' . $defcfg[$k]['comment'];
286 case SMOPT_TYPE_STRING
:
287 if ( isset( $HTTP_POST_VARS[$e] ) ) {
288 $v = '"' . $HTTP_POST_VARS[$e] . '"';
291 echo "<tr><td>$name</td><td>".
292 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
293 if ( isset( $defcfg[$k]['comment'] ) ) {
294 echo ' ' . $defcfg[$k]['comment'];
298 case SMOPT_TYPE_BOOLEAN
:
299 if ( isset( $HTTP_POST_VARS[$e] ) ) {
300 $v = $HTTP_POST_VARS[$e];
303 $v = strtoupper( $v );
305 if ( $v == 'TRUE' ) {
312 echo "<tr><td>$name</td><td>" .
313 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
314 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
315 if ( isset( $defcfg[$k]['comment'] ) ) {
316 echo ' ' . $defcfg[$k]['comment'];
321 echo "<tr><td>$name</td><td>" .
323 if ( isset( $defcfg[$k]['comment'] ) ) {
324 echo ' ' . $defcfg[$k]['comment'];
332 echo '<tr><th>' . _("Theme Name") .
333 '</th><th>' . _("Theme Path") .
335 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
336 $k1 = "\$theme[$i]['NAME']";
337 $e1 = "theme_name_$i";
338 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
339 $v1 = '"' . $HTTP_POST_VARS[$e1] . '"';
344 $k2 = "\$theme[$i]['PATH']";
345 $e2 = "theme_path_$i";
346 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
347 $v2 = '"' . $HTTP_POST_VARS[$e2] . '"';
352 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
353 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
355 "<td align=right><input name=\"$e1\" value=\"$name\" size=30></td>".
356 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
362 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" . _("Plugins") . '</th></tr>';
364 $fd = opendir( '../plugins/' );
365 $op_plugin = array();
366 while (false!==($file = readdir($fd))) {
367 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
368 if ( filetype( $file ) == 'dir' ) {
369 $op_plugin[] = $file;
377 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
378 $k = "\$plugins[$i]";
380 if ( isset( $HTTP_POST_VARS[$e] ) ) {
381 $v = '"' . $HTTP_POST_VARS[$e] . '"';
386 $name = substr( $v, 1, strlen( $v ) - 2 );
388 "<td align=right>$i.</td>".
389 "<td><select name=\"$e\">";
390 foreach ( $op_plugin as $op ) {
391 if ( $op == $name ) {
396 echo "<option$cs>$op</option>";
398 echo "</select></td>".
404 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
405 _("Change Settings") . "\" type=submit></th></tr>" ,
406 '</table></td></tr></table></form>';
409 Write the options to the file.
412 $fp = fopen( $cfgfile, 'w' );
413 fwrite( $fp, "<?PHP\n".
415 " * SquirrelMail Configuration File\n".
416 " * Created using the Administrator Plugin\n".
420 fwrite( $fp, 'GLOBAL ' );
422 foreach ( $newcfg as $k => $v ) {
423 if ( $k{0} == '$' ) {
424 if( $i = strpos( $k, '[' ) ) {
425 if( strpos( $k, '[0]' ) ) {
429 fwrite( $fp, substr( $k, 0, $i) );
440 fwrite( $fp, ";\n" );
442 foreach ( $newcfg as $k => $v ) {
443 if ( $k{0} == '$' ) {
444 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
445 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
446 $v = str_replace( 'array(', "array(\n\t", $v );
447 $v = str_replace( "',", "',\n\t", $v );
449 fwrite( $fp, "$k = $v;\n" );