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>",
251 "<tr bgcolor=\"$color[5]\"><td colspan=2i align=\"center\">";
253 <small
>Note
: it is recommended that you configure your system using conf
.pl
, and not this plugin
.
254 conf
.pl contains additional information regarding the purpose of variables
and
255 appropriate values
, as well
as additional verification steps
.<br
/>
256 Run
or consult conf
.pl should you run into difficulty with your configuration
.</small
>
260 $act_grp = 'Titles'; /* Active group */
262 foreach ( $newcfg as $k => $v ) {
263 $l = strtolower( $v );
264 $type = SMOPT_TYPE_UNDEFINED
;
265 $n = substr( $k, 1 );
266 $n = str_replace( '[', '_', $n );
267 $n = str_replace( ']', '_', $n );
271 if ( isset( $defcfg[$k] ) ) {
272 $name = $defcfg[$k]['name'];
273 $type = $defcfg[$k]['type'];
274 if ( isset( $defcfg[$k]['size'] ) ) {
275 $size = $defcfg[$k]['size'];
279 } else if ( $l == 'true' ) {
281 $type = SMOPT_TYPE_BOOLEAN
;
282 } else if ( $l == 'false' ) {
284 $type = SMOPT_TYPE_BOOLEAN
;
285 } else if ( $v{0} == "'" ) {
286 $type = SMOPT_TYPE_STRING
;
287 } else if ( $v{0} == '"' ) {
288 $type = SMOPT_TYPE_STRING
;
291 if ( substr( $k, 0, 7 ) == '$theme[' ) {
292 $type = SMOPT_TYPE_THEME
;
293 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
294 $type = SMOPT_TYPE_PLUGINS
;
295 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
296 $type = SMOPT_TYPE_LDAP
;
299 if( $type == SMOPT_TYPE_TITLE ||
$colapse[$act_grp] == 'off' ) {
302 case SMOPT_TYPE_LDAP
:
303 case SMOPT_TYPE_PLUGINS
:
304 case SMOPT_TYPE_THEME
:
305 case SMOPT_TYPE_HIDDEN
:
307 case SMOPT_TYPE_EXTERNAL
:
308 echo "<tr><td>$name</td><td><b>" .
309 $defcfg[$k]['value'] .
312 case SMOPT_TYPE_TITLE
:
313 if ( $colapse[$k] == 'on' ) {
318 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
319 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
323 case SMOPT_TYPE_COMMENT
:
324 $v = substr( $v, 1, strlen( $v ) - 2 );
325 echo "<tr><td>$name</td><td>".
327 $newcfg[$k] = "'$v'";
328 if ( isset( $defcfg[$k]['comment'] ) ) {
329 echo ' ' . $defcfg[$k]['comment'];
333 case SMOPT_TYPE_INTEGER
:
334 if ( isset( $HTTP_POST_VARS[$e] ) ) {
335 $v = intval( $HTTP_POST_VARS[$e] );
338 echo "<tr><td>$name</td><td>".
339 "<input size=10 name=\"adm_$n\" value=\"$v\">";
340 if ( isset( $defcfg[$k]['comment'] ) ) {
341 echo ' ' . $defcfg[$k]['comment'];
345 case SMOPT_TYPE_NUMLIST
:
346 if ( isset( $HTTP_POST_VARS[$e] ) ) {
347 $v = $HTTP_POST_VARS[$e];
350 echo "<tr><td>$name</td><td>";
351 echo "<select name=\"adm_$n\">";
352 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
353 echo "<option value=\"$kp\"";
357 echo ">$vp</option>";
360 if ( isset( $defcfg[$k]['comment'] ) ) {
361 echo ' ' . $defcfg[$k]['comment'];
365 case SMOPT_TYPE_STRLIST
:
366 if ( isset( $HTTP_POST_VARS[$e] ) ) {
367 $v = '"' . $HTTP_POST_VARS[$e] . '"';
370 echo "<tr><td>$name</td><td>".
371 "<select name=\"adm_$n\">";
372 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
373 echo "<option value=\"$kp\"";
374 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
377 echo ">$vp</option>";
380 if ( isset( $defcfg[$k]['comment'] ) ) {
381 echo ' ' . $defcfg[$k]['comment'];
386 case SMOPT_TYPE_TEXTAREA
:
387 if ( isset( $HTTP_POST_VARS[$e] ) ) {
388 $v = '"' . $HTTP_POST_VARS[$e] . '"';
389 $newcfg[$k] = str_replace( "\n", '', $v );
391 echo "<tr><td valign=top>$name</td><td>".
392 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
393 if ( isset( $defcfg[$k]['comment'] ) ) {
394 echo ' ' . $defcfg[$k]['comment'];
398 case SMOPT_TYPE_STRING
:
399 if ( isset( $HTTP_POST_VARS[$e] ) ) {
400 $v = '"' . $HTTP_POST_VARS[$e] . '"';
403 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
404 $v = "'" . $defcfg[$k]['default'] . "'";
407 echo "<tr><td>$name</td><td>".
408 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
409 if ( isset( $defcfg[$k]['comment'] ) ) {
410 echo ' ' . $defcfg[$k]['comment'];
414 case SMOPT_TYPE_BOOLEAN
:
415 if ( isset( $HTTP_POST_VARS[$e] ) ) {
416 $v = $HTTP_POST_VARS[$e];
419 $v = strtoupper( $v );
421 if ( $v == 'TRUE' ) {
428 echo "<tr><td>$name</td><td>" .
429 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
430 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
431 if ( isset( $defcfg[$k]['comment'] ) ) {
432 echo ' ' . $defcfg[$k]['comment'];
436 case SMOPT_TYPE_PATH
:
437 if ( isset( $HTTP_POST_VARS[$e] ) ) {
438 $v = change_to_sm_path($HTTP_POST_VARS[$e]);
441 if ( $v == "''" && isset( $defcfg[$k]['default'] ) ) {
442 $v = change_to_sm_path($defcfg[$k]['default']);
445 echo "<tr><td>$name</td><td>".
446 "<input size=\"$size\" name=\"adm_$n\" value=\"" . change_to_rel_path($v) . "\">";
447 if ( isset( $defcfg[$k]['comment'] ) ) {
448 echo ' ' . $defcfg[$k]['comment'];
453 echo "<tr><td>$name</td><td>" .
455 if ( isset( $defcfg[$k]['comment'] ) ) {
456 echo ' ' . $defcfg[$k]['comment'];
463 /* Special Themes Block */
464 if ( $colapse['Group7'] == 'off' ) {
466 echo '<tr><th>' . _("Theme Name") .
467 '</th><th>' . _("Theme Path") .
469 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
470 $k1 = "\$theme[$i]['NAME']";
471 $e1 = "theme_name_$i";
472 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
473 $v1 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
474 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
479 $k2 = "\$theme[$i]['PATH']";
480 $e2 = "theme_path_$i";
481 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
482 $v2 = change_to_sm_path($HTTP_POST_VARS[$e2]);
487 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
488 $path = change_to_rel_path($v2);
490 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
491 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
498 /* Special Plugins Block */
499 if ( $colapse['Group8'] == 'on' ) {
504 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
505 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
506 _("Plugins") . '</th></tr>';
508 if( $colapse['Group8'] == 'off' ) {
510 $plugpath = SM_PATH
. 'plugins/';
511 if ( file_exists($plugpath) ) {
512 $fd = opendir( $plugpath );
513 $op_plugin = array();
515 while (false !== ($file = readdir($fd))) {
516 if ($file != '.' && $file != '..' && $file != 'CVS' && is_dir($plugpath . $file) ) {
517 $op_plugin[] = $file;
524 /* Lets get the plugins that are active */
526 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
527 foreach ( $op_plugin as $plg ) {
528 if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
529 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
534 foreach ( $plugins as $plg ) {
535 $k = "\$plugins[$i]";
536 $newcfg[$k] = "'$plg'";
539 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
540 $k = "\$plugins[$i]";
546 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
547 $k = "\$plugins[$i]";
549 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
553 echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
554 foreach ( $op_plugin as $plg ) {
555 if ( in_array( $plg, $plugins ) ) {
561 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
564 echo '</td></tr></table></td></tr>';
566 echo '<tr><td colspan=2 align="center">Plugin directory could not be found: ' . $plugpath . "</td></tr>\n";
569 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
570 _("Change Settings") . "\" type=submit></th></tr>" ,
571 '</table></td></tr></table></form>';
574 Write the options to the file.
577 if( $fp = @fopen
( $cfgfile, 'w' ) ) {
578 fwrite( $fp, "<?PHP\n".
580 " * SquirrelMail Configuration File\n".
581 " * Created using the Administrator Plugin\n".
584 foreach ( $newcfg as $k => $v ) {
585 if ( $k{0} == '$' && $v <> '' ) {
586 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
587 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
588 $v = str_replace( 'array(', "array(\n\t", $v );
589 $v = str_replace( "',", "',\n\t", $v );
591 fwrite( $fp, "$k = $v;\n" );
597 echo '<font size=+1><br>'.
598 _("Config file can't be opened. Please check config.php.").