6 * Copyright (c) 1999-2003 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
132 /* Change paths containing SM_PATH to admin-friendly paths
133 relative to the config dir, i.e.:
134 '' --> <empty string>
135 SM_PATH . 'images/logo.gif' --> ../images/logo.gif
136 '/absolute/path/logo.gif' --> /absolute/path/logo.gif
137 'http://whatever/' --> http://whatever
138 Note removal of quotes in returned value
140 function change_to_rel_path($old_path) {
141 $new_path = str_replace("SM_PATH . '", "../", $old_path);
142 $new_path = str_replace("../config/","", $new_path);
143 $new_path = str_replace("'","", $new_path);
147 /* Change relative path (relative to config dir) to
148 internal SM_PATH, i.e.:
150 ../images/logo.gif --> SM_PATH . 'images/logo.gif'
151 images/logo.gif --> SM_PATH . 'config/images/logo.gif'
152 /absolute/path/logo.gif --> '/absolute/path/logo.gif'
153 http://whatever/ --> 'http://whatever'
155 function change_to_sm_path($old_path) {
156 if ( $old_path === '' ||
$old_path == "''" ) {
158 } elseif ( preg_match("/^(\/|http)/", $old_path) ) {
159 return "'" . $old_path . "'";
160 } elseif ( preg_match("/^(\$|SM_PATH)/", $old_path) ) {
165 $rel_path = explode("../", $old_path);
166 if ( count($rel_path) > 2 ) {
167 // Since we're relative to the config dir,
168 // more than 1 ../ puts us OUTSIDE the SM tree.
169 // get full path to config.php, then pop the filename
170 $abs_path = explode('/', realpath (SM_PATH
. 'config/config.php'));
171 array_pop ($abs_path);
172 foreach ( $rel_path as $subdir ) {
173 if ( $subdir === '' ) {
174 array_pop ($abs_path);
176 array_push($abs_path, $subdir);
179 foreach ($abs_path as $subdir) {
180 $new_path .= $subdir . '/';
182 $new_path = "'$new_path'";
183 } elseif ( count($rel_path) > 1 ) {
184 // we're within the SM tree, prepend SM_PATH
185 $new_path = str_replace('../',"SM_PATH . '", $old_path . "'");
187 // Last, if it's a relative path without a .. prefix,
188 // we're somewhere within the config dir, so prepend
189 // SM_PATH . 'config/
190 $new_path = "SM_PATH . 'config/" . $old_path . "'";
196 /* ---------------------- main -------------------------- */
198 define('SM_PATH','../../');
200 /* SquirrelMail required files. */
201 require_once(SM_PATH
. 'include/validate.php');
202 require_once(SM_PATH
. 'functions/page_header.php');
203 require_once(SM_PATH
. 'functions/imap.php');
204 require_once(SM_PATH
. 'include/load_prefs.php');
205 require_once(SM_PATH
. 'plugins/administrator/defines.php');
206 require_once(SM_PATH
. 'plugins/administrator/auth.php');
208 GLOBAL $data_dir, $username;
210 if ( !adm_check_user() ) {
211 header('Location: ' . SM_PATH
. 'src/options.php') ;
215 displayPageHeader($color, 'None');
219 foreach ( $defcfg as $key => $def ) {
223 $cfgfile = SM_PATH
. 'config/config.php';
224 parseConfig( SM_PATH
. 'config/config_default.php' );
225 parseConfig( $cfgfile );
227 $colapse = array( 'Titles' => 'off',
228 'Group1' => getPref($data_dir, $username, 'adm_Group1', 'off' ),
229 'Group2' => getPref($data_dir, $username, 'adm_Group2', 'on' ),
230 'Group3' => getPref($data_dir, $username, 'adm_Group3', 'on' ),
231 'Group4' => getPref($data_dir, $username, 'adm_Group4', 'on' ),
232 'Group5' => getPref($data_dir, $username, 'adm_Group5', 'on' ),
233 'Group6' => getPref($data_dir, $username, 'adm_Group6', 'on' ),
234 'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
235 'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ) );
237 if ( isset( $_GET['switch'] ) ) {
238 $switch = $_GET['switch'];
239 if ( $colapse[$switch] == 'on' ) {
240 $colapse[$switch] = 'off';
242 $colapse[$switch] = 'on';
244 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
247 echo "<form action=options.php method=post name=options>" .
248 "<center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
249 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
250 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
252 $act_grp = 'Titles'; /* Active group */
254 foreach ( $newcfg as $k => $v ) {
255 $l = strtolower( $v );
256 $type = SMOPT_TYPE_UNDEFINED
;
257 $n = substr( $k, 1 );
258 $n = str_replace( '[', '_', $n );
259 $n = str_replace( ']', '_', $n );
263 if ( isset( $defcfg[$k] ) ) {
264 $name = $defcfg[$k]['name'];
265 $type = $defcfg[$k]['type'];
266 if ( isset( $defcfg[$k]['size'] ) ) {
267 $size = $defcfg[$k]['size'];
271 } else if ( $l == 'true' ) {
273 $type = SMOPT_TYPE_BOOLEAN
;
274 } else if ( $l == 'false' ) {
276 $type = SMOPT_TYPE_BOOLEAN
;
277 } else if ( $v{0} == "'" ) {
278 $type = SMOPT_TYPE_STRING
;
279 } else if ( $v{0} == '"' ) {
280 $type = SMOPT_TYPE_STRING
;
283 if ( substr( $k, 0, 7 ) == '$theme[' ) {
284 $type = SMOPT_TYPE_THEME
;
285 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
286 $type = SMOPT_TYPE_PLUGINS
;
287 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
288 $type = SMOPT_TYPE_LDAP
;
291 if( $type == SMOPT_TYPE_TITLE ||
$colapse[$act_grp] == 'off' ) {
294 case SMOPT_TYPE_LDAP
:
295 case SMOPT_TYPE_PLUGINS
:
296 case SMOPT_TYPE_THEME
:
297 case SMOPT_TYPE_HIDDEN
:
299 case SMOPT_TYPE_EXTERNAL
:
300 echo "<tr><td>$name</td><td><b>" .
301 $defcfg[$k]['value'] .
304 case SMOPT_TYPE_TITLE
:
305 if ( $colapse[$k] == 'on' ) {
310 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
311 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
315 case SMOPT_TYPE_COMMENT
:
316 $v = substr( $v, 1, strlen( $v ) - 2 );
317 echo "<tr><td>$name</td><td>".
319 $newcfg[$k] = "'$v'";
320 if ( isset( $defcfg[$k]['comment'] ) ) {
321 echo ' ' . $defcfg[$k]['comment'];
325 case SMOPT_TYPE_INTEGER
:
326 if ( isset( $HTTP_POST_VARS[$e] ) ) {
327 $v = intval( $HTTP_POST_VARS[$e] );
330 echo "<tr><td>$name</td><td>".
331 "<input size=10 name=\"adm_$n\" value=\"$v\">";
332 if ( isset( $defcfg[$k]['comment'] ) ) {
333 echo ' ' . $defcfg[$k]['comment'];
337 case SMOPT_TYPE_NUMLIST
:
338 if ( isset( $HTTP_POST_VARS[$e] ) ) {
339 $v = $HTTP_POST_VARS[$e];
342 echo "<tr><td>$name</td><td>";
343 echo "<select name=\"adm_$n\">";
344 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
345 echo "<option value=\"$kp\"";
349 echo ">$vp</option>";
352 if ( isset( $defcfg[$k]['comment'] ) ) {
353 echo ' ' . $defcfg[$k]['comment'];
357 case SMOPT_TYPE_STRLIST
:
358 if ( isset( $HTTP_POST_VARS[$e] ) ) {
359 $v = '"' . $HTTP_POST_VARS[$e] . '"';
362 echo "<tr><td>$name</td><td>".
363 "<select name=\"adm_$n\">";
364 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
365 echo "<option value=\"$kp\"";
366 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
369 echo ">$vp</option>";
372 if ( isset( $defcfg[$k]['comment'] ) ) {
373 echo ' ' . $defcfg[$k]['comment'];
378 case SMOPT_TYPE_TEXTAREA
:
379 if ( isset( $HTTP_POST_VARS[$e] ) ) {
380 $v = '"' . $HTTP_POST_VARS[$e] . '"';
381 $newcfg[$k] = str_replace( "\n", '', $v );
383 echo "<tr><td valign=top>$name</td><td>".
384 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
385 if ( isset( $defcfg[$k]['comment'] ) ) {
386 echo ' ' . $defcfg[$k]['comment'];
390 case SMOPT_TYPE_STRING
:
391 if ( isset( $HTTP_POST_VARS[$e] ) ) {
392 $v = '"' . $HTTP_POST_VARS[$e] . '"';
395 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
396 $v = "'" . $defcfg[$k]['default'] . "'";
399 echo "<tr><td>$name</td><td>".
400 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
401 if ( isset( $defcfg[$k]['comment'] ) ) {
402 echo ' ' . $defcfg[$k]['comment'];
406 case SMOPT_TYPE_BOOLEAN
:
407 if ( isset( $HTTP_POST_VARS[$e] ) ) {
408 $v = $HTTP_POST_VARS[$e];
411 $v = strtoupper( $v );
413 if ( $v == 'TRUE' ) {
420 echo "<tr><td>$name</td><td>" .
421 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
422 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
423 if ( isset( $defcfg[$k]['comment'] ) ) {
424 echo ' ' . $defcfg[$k]['comment'];
428 case SMOPT_TYPE_PATH
:
429 if ( isset( $HTTP_POST_VARS[$e] ) ) {
430 $v = change_to_sm_path($HTTP_POST_VARS[$e]);
433 if ( $v == "''" && isset( $defcfg[$k]['default'] ) ) {
434 $v = change_to_sm_path($defcfg[$k]['default']);
437 echo "<tr><td>$name</td><td>".
438 "<input size=\"$size\" name=\"adm_$n\" value=\"" . change_to_rel_path($v) . "\">";
439 if ( isset( $defcfg[$k]['comment'] ) ) {
440 echo ' ' . $defcfg[$k]['comment'];
445 echo "<tr><td>$name</td><td>" .
447 if ( isset( $defcfg[$k]['comment'] ) ) {
448 echo ' ' . $defcfg[$k]['comment'];
455 /* Special Themes Block */
456 if ( $colapse['Group7'] == 'off' ) {
458 echo '<tr><th>' . _("Theme Name") .
459 '</th><th>' . _("Theme Path") .
461 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
462 $k1 = "\$theme[$i]['NAME']";
463 $e1 = "theme_name_$i";
464 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
465 $v1 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
466 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
471 $k2 = "\$theme[$i]['PATH']";
472 $e2 = "theme_path_$i";
473 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
474 $v2 = change_to_sm_path($HTTP_POST_VARS[$e2]);
479 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
480 $path = change_to_rel_path($v2);
482 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
483 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
490 /* Special Plugins Block */
491 if ( $colapse['Group8'] == 'on' ) {
496 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
497 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
498 _("Plugins") . '</th></tr>';
500 if( $colapse['Group8'] == 'off' ) {
502 $fd = opendir( '../plugins/' );
503 $op_plugin = array();
505 while (false!==($file = readdir($fd))) {
506 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
507 if ( filetype( $file ) == 'dir' ) {
508 $op_plugin[] = $file;
516 /* Lets get the plugins that are active */
518 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
519 foreach ( $op_plugin as $plg ) {
520 if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
521 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
526 foreach ( $plugins as $plg ) {
527 $k = "\$plugins[$i]";
528 $newcfg[$k] = "'$plg'";
531 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
532 $k = "\$plugins[$i]";
538 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
539 $k = "\$plugins[$i]";
541 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
545 echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
546 foreach ( $op_plugin as $plg ) {
547 if ( in_array( $plg, $plugins ) ) {
553 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
556 echo '</td></tr></table>';
559 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
560 _("Change Settings") . "\" type=submit></th></tr>" ,
561 '</table></td></tr></table></form>';
564 Write the options to the file.
567 if( $fp = @fopen
( $cfgfile, 'w' ) ) {
568 fwrite( $fp, "<?PHP\n".
570 " * SquirrelMail Configuration File\n".
571 " * Created using the Administrator Plugin\n".
574 foreach ( $newcfg as $k => $v ) {
575 if ( $k{0} == '$' && $v <> '' ) {
576 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
577 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
578 $v = str_replace( 'array(', "array(\n\t", $v );
579 $v = str_replace( "',", "',\n\t", $v );
581 fwrite( $fp, "$k = $v;\n" );
587 echo '<font size=+1><br>'.
588 _("Config file can't be opened. Please check config.php.").