Source for file options.php
Documentation is available at options.php
* Administrator Plugin - Options Page
* This script creates separate page, that allows to review and modify
* SquirrelMail configuration file.
* @version $Id: options.php 14840 2020-01-07 07:42:38Z pdontthink $
* @copyright (c) 1999-2020 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @subpackage administrator
/** This is the administrator_options page */
define('PAGE_NAME', 'administrator_options');
* @param string $cfg_file
function parseConfig( $cfg_file ) {
$cfg =
file( $cfg_file );
$line =
trim( $cfg[$i] );
if ( $line{$j} ==
'=' ) {
// Ok, we've got a right value, lets detect what type
} else if ( $line{$j} ==
';' ) {
if ( $line{$j} ==
' ' ) {
if ( $line{$j} ==
';' ) {
if ( $line{$j} ==
'\\' ) {
} else if ( $line{$j} ==
$delimiter &&
$modifier ===
FALSE ) {
$newcfg[$key] =
$value .
$delimiter;
if ( $line{$j} ==
';' ) {
$line{$j}.
$line{$j+
1} ==
'*/' ) {
$delimiter =
$value =
$line{$j};
// Number or function call
if ( $line{$j} ==
'$' ) {
// We must detect $key name
} else if ( $s <
$j +
2 ) {
} else if ( $line{$j}.
$line{$j+
1} ==
'/*' ) {
} else if ( $line{$j} ==
'#' ||
$line{$j}.
$line{$j+
1} ==
'//' ) {
// Delete till the end of the line
* Change paths containing SM_PATH to admin-friendly paths
* relative to the config dir, i.e.:
* SM_PATH . 'images/logo.gif' --> ../images/logo.gif
* '/absolute/path/logo.gif' --> /absolute/path/logo.gif
* 'http://whatever/' --> http://whatever
* Note removal of quotes in returned value
* @param string $old_path path that has to be converted
* @return string new path
function change_to_rel_path($old_path) {
$new_path =
str_replace("SM_PATH . '", "../", $old_path);
* Change relative path (relative to config dir) to
* internal SM_PATH, i.e.:
* ../images/logo.gif --> SM_PATH . 'images/logo.gif'
* images/logo.gif --> SM_PATH . 'config/images/logo.gif'
* /absolute/path/logo.gif --> '/absolute/path/logo.gif'
* C:/absolute/win/path --> 'C:/absolute/win/path'
* http://whatever/ --> 'http://whatever'
* @param string $old_path path that has to be converted
* @return string new path
function change_to_sm_path($old_path) {
if ( $old_path ===
'' ||
$old_path ==
"''" ) {
} elseif ( preg_match("/^(\/|http)/", $old_path) ||
substr($old_path,1,2) ==
':/' ) {
return "'" .
$old_path .
"'";
} elseif ( preg_match("/^(\$|SM_PATH)/", $old_path) ) {
$rel_path =
explode("../", $old_path);
if ( count($rel_path) >
2 ) {
// Since we're relative to the config dir,
// more than 1 ../ puts us OUTSIDE the SM tree.
// get full path to config.php, then pop the filename
foreach ( $rel_path as $subdir ) {
foreach ($abs_path as $subdir) {
$new_path .=
$subdir .
'/';
$new_path =
"'$new_path'";
} elseif ( count($rel_path) >
1 ) {
// we're within the SM tree, prepend SM_PATH
$new_path =
str_replace('../',"SM_PATH . '", $old_path .
"'");
// Last, if it's a relative path without a .. prefix,
// we're somewhere within the config dir, so prepend
$new_path =
"SM_PATH . 'config/" .
$old_path .
"'";
/* ---------------------- main -------------------------- */
/* SquirrelMail required files. */
require_once(SM_PATH .
'include/validate.php');
require_once(SM_PATH .
'plugins/administrator/defines.php');
require_once(SM_PATH .
'plugins/administrator/auth.php');
global $data_dir, $username;
foreach ( $defcfg as $key =>
$def ) {
$cfgfile =
SM_PATH .
'config/config.php';
parseConfig( SM_PATH .
'config/config_default.php' );
// backward compatibility for IMAP/SMTP TLS
if ($newcfg['$use_imap_tls'] ===
'TRUE')
$newcfg['$use_imap_tls'] =
'1';
if ($newcfg['$use_smtp_tls'] ===
'TRUE')
$newcfg['$use_smtp_tls'] =
'1';
$colapse =
array( 'Titles' =>
'off',
'Group1' =>
getPref($data_dir, $username, 'adm_Group1', 'off' ),
'Group2' =>
getPref($data_dir, $username, 'adm_Group2', 'on' ),
'Group3' =>
getPref($data_dir, $username, 'adm_Group3', 'on' ),
'Group4' =>
getPref($data_dir, $username, 'adm_Group4', 'on' ),
'Group5' =>
getPref($data_dir, $username, 'adm_Group5', 'on' ),
'Group6' =>
getPref($data_dir, $username, 'adm_Group6', 'on' ),
'Group7' =>
getPref($data_dir, $username, 'adm_Group7', 'on' ),
'Group8' =>
getPref($data_dir, $username, 'adm_Group8', 'on' ),
'Group9' =>
getPref($data_dir, $username, 'adm_Group9', 'on' ),
'Group10' =>
getPref($data_dir, $username, 'adm_Group10', 'on' ) );
/* look in $_GET array for 'switch' */
if ( $colapse[$switch] ==
'on' ) {
$colapse[$switch] =
'off';
$colapse[$switch] =
'on';
setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
echo
'<form action="options.php" method="post" name="options">' .
'<center><table width="95%" bgcolor="'.
$color[5].
'"><tr><td>'.
'<table width="100%" cellspacing="0" bgcolor="'.
$color[4].
'">'.
'<tr bgcolor="'.
$color[5].
'"><th colspan="2">'.
_("Configuration Administrator").
'</th></tr>'.
'<tr bgcolor="'.
$color[5].
'"><td colspan="2" align="center"><small>'.
_("Note: it is recommended that you configure your system using conf.pl, and not this plugin. conf.pl contains additional information regarding the purpose of variables and appropriate values, as well as additional verification steps.").
_("Run or consult conf.pl should you run into difficulty with your configuration.").
$act_grp =
'Titles'; /* Active group */
foreach ( $newcfg as $k =>
$v ) {
if ( isset
( $defcfg[$k] ) ) {
$name =
$defcfg[$k]['name'];
$type =
$defcfg[$k]['type'];
if ( isset
( $defcfg[$k]['size'] ) ) {
$size =
$defcfg[$k]['size'];
} else if ( $l ==
'true' ) {
} else if ( $l ==
'false' ) {
} else if ( $v{0} ==
"'" ) {
} else if ( $v{0} ==
'"' ) {
if ( substr( $k, 0, 7 ) ==
'$theme[' ) {
} else if ( substr( $k, 0, 9 ) ==
'$plugins[' ) {
} else if ( substr( $k, 0, 13 ) ==
'$ldap_server[' ) {
echo
"<tr><td>$name</td><td><b>" .
if ( $colapse[$k] ==
'on' ) {
echo
'<tr bgcolor="'.
$color[0].
'"><th colspan="2">'.
"<a href=\"options.php?switch=$k\" style=\"text-decoration:none\">".
'<b>'.
$sw.
'</b></a> '.
$name.
'</th></tr>';
echo
"<tr><td>$name</td><td>".
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
/* look for variable $e in POST, fill into $v */
echo
"<tr><td>$name</td><td>".
"<input size=\"10\" name=\"adm_$n\" value=\"$v\" />";
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
echo
"<tr><td>$name</td><td>";
echo
"<select name=\"adm_$n\">";
foreach ( $defcfg[$k]['posvals'] as $kp =>
$vp ) {
echo
"<option value=\"$kp\"";
echo
' selected="selected"';
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
echo
"<tr><td>$name</td><td>".
"<select name=\"adm_$n\">";
foreach ( $defcfg[$k]['posvals'] as $kp =>
$vp ) {
echo
"<option value=\"$kp\"";
echo
' selected="selected"';
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
echo
"<tr><td valign=\"top\">$name</td><td>".
"<textarea cols=\"$size\" rows=\"4\" name=\"adm_$n\">" .
substr( $v, 1, strlen( $v ) -
2 ) .
"</textarea>";
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
if ( $v ==
'""' && isset
( $defcfg[$k]['default'] ) ) {
$v =
"'" .
$defcfg[$k]['default'] .
"'";
echo
"<tr><td>$name</td><td>".
"<input size=\"$size\" name=\"adm_$n\" value=\"" .
substr( $v, 1, strlen( $v ) -
2 ) .
'" />';
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
$ct =
' checked="checked"';
$cf =
' checked="checked"';
echo
"<tr><td>$name</td><td>" .
"<input$ct type=\"radio\" name=\"adm_$n\" value=\"TRUE\" />" .
_("Yes") .
"<input$cf type=\"radio\" name=\"adm_$n\" value=\"FALSE\" />" .
_("No");
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
$v =
change_to_sm_path($new_v);
if ( $v ==
"''" && isset
( $defcfg[$k]['default'] ) ) {
$v =
change_to_sm_path($defcfg[$k]['default']);
echo
"<tr><td>$name</td><td>".
"<input size=\"$size\" name=\"adm_$n\" value=\"" .
change_to_rel_path($v) .
'" />';
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
echo
"<tr><td>$name</td><td>" .
if ( isset
( $defcfg[$k]['comment'] ) ) {
echo
' ' .
$defcfg[$k]['comment'];
/* Special Themes Block */
if ( $colapse['Group7'] ==
'off' ) {
echo
'<tr><th>' .
_("Theme Name") .
'</th><th>' .
_("Theme Path") .
while ( isset
( $newcfg["\$theme[$i]['NAME']"] ) ) {
$k1 =
"\$theme[$i]['NAME']";
$k2 =
"\$theme[$i]['PATH']";
$v2 =
change_to_sm_path($v2);
$path =
change_to_rel_path($v2);
"<td align=\"right\">$i. <input name=\"$e1\" value=\"$name\" size=\"30\" /></td>".
"<td><input name=\"$e2\" value=\"$path\" size=\"40\" /></td>".
/* Special Plugins Block */
if ( $colapse['Group8'] ==
'on' ) {
echo
'<tr bgcolor="'.
$color[0].
'"><th colspan="2">'.
'<a href="options.php?switch=Group8" style="text-decoration:none"><b>'.
$sw.
'</b></a> '.
_("Plugins").
'</th></tr>';
if ( $colapse['Group8'] ==
'off' ) {
while (false !==
($file =
readdir($fd))) {
if ($file !=
'.' &&
$file !=
'..' &&
$file !=
'CVS' &&
is_dir($plugpath .
$file) ) {
/* Lets get the plugins that are active */
foreach ( $op_plugin as $plg ) {
foreach ( $plugins as $plg ) {
while ( isset
( $newcfg["\$plugins[$i]"] ) ) {
while ( isset
( $newcfg["\$plugins[$i]"] ) ) {
echo
'<tr><td colspan="2"><input type="hidden" name="plg" value="on" /><center><table>';
foreach ( $op_plugin as $plg ) {
$sw =
' checked="checked"';
echo
"<a href=\"../$plg/README\" target=\"_blank\">$plg</a>";
"<td><input$sw type=\"checkbox\" name=\"plgs_$plg\" /></td>".
echo
'</table></center></td></tr>';
echo
'<tr><td colspan="2" align="center">'.
sprintf(_("Plugin directory could not be found: %s"), $plugpath).
echo
'<tr bgcolor="'.
$color[5].
'"><th colspan="2"><input value="'.
_("Change Settings").
'" type="submit" /><br />'.
'<a href="'.
SM_PATH.
'src/configtest.php" target="_blank">'.
_("Test Configuration").
"</a></th></tr>\n".
'</table></td></tr></table></center></form>';
Write the options to the file.
// $cfgfile = '/tmp/config.php';
if ( $fp =
@fopen( $cfgfile, 'w' ) ) {
" * SquirrelMail Configuration File\n".
" * Created using the Administrator Plugin\n".
foreach ( $newcfg as $k =>
$v ) {
if ( $k{0} ==
'$' &&
$v <>
'' ||
is_int($v)) {
if ( substr( $k, 1, 11 ) ==
'ldap_server' ) {
// add local config support
fwrite( $fp, "@include SM_PATH . 'config/config_local.php';\n" );
echo
'<br /><p align="center"><big>'.
_("Config file can't be opened. Please check config.php.").
Documentation generated on Mon, 13 Jan 2020 04:25:07 +0100 by phpDocumentor 1.4.3