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;
76 $line{$j}.$line{$j+
1} == '*/' ) {
83 switch ( $line{$j} ) {
86 // Double quote string
87 $delimiter = $value = $line{$j};
94 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
96 $newcfg{$key} = 'TRUE';
99 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
100 $newcfg{$key} = 'FALSE';
104 // Number or function call
111 if ( $line{$j} == '$' ) {
112 // We must detect $key name
115 } else if ( $s < $j +
2 ) {
116 } else if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
117 // Skip untill next ;
120 } else if ( $line{$j}.$line{$j+
1} == '/*' ) {
123 } else if ( $line{$j} == '#' ||
$line{$j}.$line{$j+
1} == '//' ) {
124 // Delete till the end of the line
133 /* ---------------------- main -------------------------- */
135 define('SM_PATH','../../');
137 /* SquirrelMail required files. */
138 require_once(SM_PATH
. 'include/validate.php');
139 require_once(SM_PATH
. 'functions/page_header.php');
140 require_once(SM_PATH
. 'functions/imap.php');
141 require_once(SM_PATH
. 'include/load_prefs.php');
142 require_once(SM_PATH
. 'plugins/administrator/defines.php');
143 require_once(SM_PATH
. 'plugins/administrator/auth.php');
145 GLOBAL $data_dir, $username;
147 if ( !adm_check_user() ) {
148 header("Location: ../../src/options.php") ;
152 displayPageHeader($color, 'None');
156 foreach ( $defcfg as $key => $def ) {
160 $cfgfile = '../config/config.php';
161 parseConfig( '../config/config_default.php' );
162 parseConfig( $cfgfile );
164 $colapse = array( 'Titles' => 'off',
165 'Group1' => getPref($data_dir, $username, 'adm_Group1', 'off' ),
166 'Group2' => getPref($data_dir, $username, 'adm_Group2', 'on' ),
167 'Group3' => getPref($data_dir, $username, 'adm_Group3', 'on' ),
168 'Group4' => getPref($data_dir, $username, 'adm_Group4', 'on' ),
169 'Group5' => getPref($data_dir, $username, 'adm_Group5', 'on' ),
170 'Group6' => getPref($data_dir, $username, 'adm_Group6', 'on' ),
171 'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
172 'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ) );
174 if ( isset( $switch ) ) {
176 if ( $colapse[$switch] == 'on' ) {
177 $colapse[$switch] = 'off';
179 $colapse[$switch] = 'on';
181 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
185 echo "<form action=options.php method=post name=options>" .
186 "<center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
187 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
188 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
190 $act_grp = 'Titles'; /* Active group */
192 foreach ( $newcfg as $k => $v ) {
193 $l = strtolower( $v );
194 $type = SMOPT_TYPE_UNDEFINED
;
195 $n = substr( $k, 1 );
196 $n = str_replace( '[', '_', $n );
197 $n = str_replace( ']', '_', $n );
201 if ( isset( $defcfg[$k] ) ) {
202 $name = $defcfg[$k]['name'];
203 $type = $defcfg[$k]['type'];
204 if ( isset( $defcfg[$k]['size'] ) ) {
205 $size = $defcfg[$k]['size'];
209 } else if ( $l == 'true' ) {
211 $type = SMOPT_TYPE_BOOLEAN
;
212 } else if ( $l == 'false' ) {
214 $type = SMOPT_TYPE_BOOLEAN
;
215 } else if ( $v{0} == "'" ) {
216 $type = SMOPT_TYPE_STRING
;
217 } else if ( $v{0} == '"' ) {
218 $type = SMOPT_TYPE_STRING
;
221 if ( substr( $k, 0, 7 ) == '$theme[' ) {
222 $type = SMOPT_TYPE_THEME
;
223 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
224 $type = SMOPT_TYPE_PLUGINS
;
225 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
226 $type = SMOPT_TYPE_LDAP
;
229 if( $type == SMOPT_TYPE_TITLE ||
$colapse[$act_grp] == 'off' ) {
232 case SMOPT_TYPE_LDAP
:
233 case SMOPT_TYPE_PLUGINS
:
234 case SMOPT_TYPE_THEME
:
235 case SMOPT_TYPE_HIDDEN
:
237 case SMOPT_TYPE_EXTERNAL
:
238 echo "<tr><td>$name</td><td><b>" .
239 $defcfg[$k]['value'] .
242 case SMOPT_TYPE_TITLE
:
243 if ( $colapse[$k] == 'on' ) {
248 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
249 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
253 case SMOPT_TYPE_COMMENT
:
254 $v = substr( $v, 1, strlen( $v ) - 2 );
255 echo "<tr><td>$name</td><td>".
257 $newcfg[$k] = "'$v'";
258 if ( isset( $defcfg[$k]['comment'] ) ) {
259 echo ' ' . $defcfg[$k]['comment'];
263 case SMOPT_TYPE_INTEGER
:
264 if ( isset( $HTTP_POST_VARS[$e] ) ) {
265 $v = intval( $HTTP_POST_VARS[$e] );
268 echo "<tr><td>$name</td><td>".
269 "<input size=10 name=\"adm_$n\" value=\"$v\">";
270 if ( isset( $defcfg[$k]['comment'] ) ) {
271 echo ' ' . $defcfg[$k]['comment'];
275 case SMOPT_TYPE_NUMLIST
:
276 if ( isset( $HTTP_POST_VARS[$e] ) ) {
277 $v = $HTTP_POST_VARS[$e];
280 echo "<tr><td>$name</td><td>";
281 echo "<select name=\"adm_$n\">";
282 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
283 echo "<option value=\"$kp\"";
287 echo ">$vp</option>";
290 if ( isset( $defcfg[$k]['comment'] ) ) {
291 echo ' ' . $defcfg[$k]['comment'];
295 case SMOPT_TYPE_STRLIST
:
296 if ( isset( $HTTP_POST_VARS[$e] ) ) {
297 $v = '"' . $HTTP_POST_VARS[$e] . '"';
300 echo "<tr><td>$name</td><td>".
301 "<select name=\"adm_$n\">";
302 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
303 echo "<option value=\"$kp\"";
304 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
307 echo ">$vp</option>";
310 if ( isset( $defcfg[$k]['comment'] ) ) {
311 echo ' ' . $defcfg[$k]['comment'];
316 case SMOPT_TYPE_TEXTAREA
:
317 if ( isset( $HTTP_POST_VARS[$e] ) ) {
318 $v = '"' . $HTTP_POST_VARS[$e] . '"';
319 $newcfg[$k] = str_replace( "\n", '', $v );
321 echo "<tr><td valign=top>$name</td><td>".
322 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
323 if ( isset( $defcfg[$k]['comment'] ) ) {
324 echo ' ' . $defcfg[$k]['comment'];
328 case SMOPT_TYPE_STRING
:
329 if ( isset( $HTTP_POST_VARS[$e] ) ) {
330 $v = '"' . $HTTP_POST_VARS[$e] . '"';
333 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
334 $v = "'" . $defcfg[$k]['default'] . "'";
337 echo "<tr><td>$name</td><td>".
338 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
339 if ( isset( $defcfg[$k]['comment'] ) ) {
340 echo ' ' . $defcfg[$k]['comment'];
344 case SMOPT_TYPE_BOOLEAN
:
345 if ( isset( $HTTP_POST_VARS[$e] ) ) {
346 $v = $HTTP_POST_VARS[$e];
349 $v = strtoupper( $v );
351 if ( $v == 'TRUE' ) {
358 echo "<tr><td>$name</td><td>" .
359 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
360 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
361 if ( isset( $defcfg[$k]['comment'] ) ) {
362 echo ' ' . $defcfg[$k]['comment'];
367 echo "<tr><td>$name</td><td>" .
369 if ( isset( $defcfg[$k]['comment'] ) ) {
370 echo ' ' . $defcfg[$k]['comment'];
378 /* Special Themes Block */
379 if ( $colapse['Group7'] == 'off' ) {
381 echo '<tr><th>' . _("Theme Name") .
382 '</th><th>' . _("Theme Path") .
384 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
385 $k1 = "\$theme[$i]['NAME']";
386 $e1 = "theme_name_$i";
387 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
388 $v1 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
389 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
394 $k2 = "\$theme[$i]['PATH']";
395 $e2 = "theme_path_$i";
396 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
397 $v2 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e2] ) . '"';
398 $v2 = '"' . str_replace( '"', '\"', $v2 ) . '"';
403 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
404 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
406 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
407 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
414 /* Special Plugins Block */
415 if ( $colapse['Group8'] == 'on' ) {
420 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
421 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
422 _("Plugins") . '</th></tr>';
424 if( $colapse['Group8'] == 'off' ) {
426 $fd = opendir( '../plugins/' );
427 $op_plugin = array();
429 while (false!==($file = readdir($fd))) {
430 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
431 if ( filetype( $file ) == 'dir' ) {
432 $op_plugin[] = $file;
440 /* Lets get the plugins that are active */
442 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
443 foreach ( $op_plugin as $plg ) {
444 if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
445 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
450 foreach ( $plugins as $plg ) {
451 $k = "\$plugins[$i]";
452 $newcfg[$k] = "'$plg'";
455 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
456 $k = "\$plugins[$i]";
462 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
463 $k = "\$plugins[$i]";
465 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
469 echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
470 foreach ( $op_plugin as $plg ) {
471 if ( in_array( $plg, $plugins ) ) {
477 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
480 echo '</td></tr></table>';
483 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
484 _("Change Settings") . "\" type=submit></th></tr>" ,
485 '</table></td></tr></table></form>';
488 Write the options to the file.
491 if( $fp = @fopen
( $cfgfile, 'w' ) ) {
492 fwrite( $fp, "<?PHP\n".
494 " * SquirrelMail Configuration File\n".
495 " * Created using the Administrator Plugin\n".
498 foreach ( $newcfg as $k => $v ) {
499 if ( $k{0} == '$' && $v <> '' ) {
500 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
501 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
502 $v = str_replace( 'array(', "array(\n\t", $v );
503 $v = str_replace( "',", "',\n\t", $v );
505 fwrite( $fp, "$k = $v;\n" );
511 echo '<font size=+1><br>'.
512 _("Config file can't be opened. Please check config.php.").