Postfix Admin Setup Checker
Running software:
Error: Depends on: PHP v5+
\n";
$error += 1;
} elseif (version_compare(phpversion(), '7.0') < 0) {
$phpversion = 5;
print "- Recommended PHP version: >= 7.0, you have " . phpversion() . "; you should upgrade.
\n";
} else {
print "- PHP version " . phpversion() . " - Good
\n";
}
} else {
print "- DANGER Unable to check for PHP version. (missing function: phpversion())
\n";
$error++;
}
//
// Check for Apache version
//
if ($f_apache_get_version == 1) {
print "- " . apache_get_version() . "
\n";
} else {
# not running on Apache.
# However postfixadmin _is_ running, so obviously we are on a supported webserver ;-))
# No need to confuse the user with a warning.
}
print "
";
print "Checking environment:\n";
print "
\n";
//
// Check for Magic Quotes
//
if ($f_get_magic_quotes_gpc == 1) {
if (get_magic_quotes_gpc() == 0) {
print "- Magic Quotes: Disabled - OK
\n";
} else {
print "- Warning: Magic Quotes: ON (internal work around to disable is in place)
\n";
}
}
//
// Check for config.local.php
//
if ($file_local_config == 1) {
print "- Depends on: presence config.local.php - Found
\n";
} else {
print "- Warning: config.local.php - NOT FOUND
\n";
print "It's Recommended to store your own settings in config.local.php instead of editing config.inc.php
";
print "Create the file, and edit as appropriate (e.g. select database type etc)
";
}
//
// Check if there is support for at least 1 database
//
if (($f_mysql_connect == 0) and ($f_mysqli_connect == 0) and ($f_pg_connect == 0) and ($f_sqlite_open == 0)) {
print "- Error: There is no database support in your PHP setup
\n";
print "To install MySQL 3.23 or 4.0 support on FreeBSD:
\n";
print "% cd /usr/ports/databases/php{$phpversion}-mysql/\n";
print "% make clean install\n";
print " - or with portupgrade -\n";
print "% portinstall php{$phpversion}-mysql
\n";
if ($phpversion >= 5) {
print "To install MySQL 4.1 support on FreeBSD:
\n";
print "% cd /usr/ports/databases/php5-mysqli/\n";
print "% make clean install\n";
print " - or with portupgrade -\n";
print "% portinstall php5-mysqli
\n";
}
print "To install PostgreSQL support on FreeBSD:
\n";
print "% cd /usr/ports/databases/php{$phpversion}-pgsql/\n";
print "% make clean install\n";
print " - or with portupgrade -\n";
print "% portinstall php{$phpversion}-pgsql
\n";
$error += 1;
}
if ($f_mysqli_connect == 1) {
print "- Database - MySQL (mysqli_ functions) - Found\n";
if (Config::read_string('database_type') != 'mysqli') {
print "
(change the database_type to 'mysqli' in config.local.php if you want to use MySQL)\n";
}
print " ";
} else {
print "- Database - MySQL (mysqli_ functions) - Not found
";
}
if (Config::read_string('database_type') == 'mysql') {
print "- Warning: your configured database_type 'mysql' is deprecated; you must move to use 'mysqli' in your config.local.php.
\n";
$error++;
}
//
// PostgreSQL functions
//
if ($f_pg_connect == 1) {
print "- Database : PostgreSQL support (pg_ functions) - Found\n";
if (Config::read_string('database_type') != 'pgsql') {
print "
(change the database_type to 'pgsql' in config.local.php if you want to use PostgreSQL)\n";
}
print " ";
} else {
print "- Database - PostgreSQL (pg_ functions) - Not found
";
}
if ($f_sqlite_open == 1) {
print "- Database : SQLite support (SQLite3) - Found \n";
if (Config::read_string('database_type') != 'sqlite') {
print "
(change the database_type to 'sqlite' in config.local.php if you want to use SQLite)\n";
}
print " ";
} else {
print "- Database - SQLite (SQLite3) - Not found
";
}
//
// Database connection
//
list($link, $error_text) = db_connect_with_errors();
if (!empty($link) && $error_text == "") {
print "- Testing database connection (using {$CONF['database_type']}) - Success
";
} else {
print "- Error: Can't connect to database
\n";
print "Please check the \$CONF['database_*'] parameters in config.local.php.\n";
print "$error_text \n";
$error ++;
}
//
// Session functions
//
if ($f_session_start == 1) {
print "- Depends on: session - OK
\n";
} else {
print "- Error: Depends on: session - NOT FOUND
\n";
print "To install session support on FreeBSD:
\n";
print "% cd /usr/ports/www/php$phpversion-session/\n";
print "% make clean install\n";
print " - or with portupgrade -\n";
print "% portinstall php$phpversion-session
\n";
$error += 1;
}
//
// PCRE functions
//
if ($f_preg_match == 1) {
print "- Depends on: pcre - Found
\n";
} else {
print "- Error: Depends on: pcre - NOT FOUND
\n";
print "To install pcre support on FreeBSD:
\n";
print "% cd /usr/ports/devel/php$phpversion-pcre/\n";
print "% make clean install\n";
print " - or with portupgrade -\n";
print "% portinstall php$phpversion-pcre
\n";
$error += 1;
}
//
// Multibyte functions
//
if ($f_mb_encode_mimeheader == 1) {
print "- Depends on: multibyte string - Found
\n";
} else {
print "- Error: Depends on: multibyte string - NOT FOUND
\n";
print "To install multibyte string support, install php$phpversion-mbstring \n";
$error += 1;
}
//
// Imap functions
//
if ($f_imap_open == 1) {
print "- IMAP functions - Found
\n";
} else {
print "- Warning: May depend on: IMAP functions - Not Found
\n";
print "To install IMAP support, install php$phpversion-imap
\n";
print "Without IMAP support, you won't be able to create subfolders when creating mailboxes. \n";
}
//
// If PHP <7.0, require random_compat works. Currently we bundle it via the Phar extension.
//
if (version_compare(phpversion(), "7.0", '<')
&& !extension_loaded('Phar')
&& $CONF['configured']
&& $CONF['encrypt'] == 'php_crypt') {
print "- PHP before 7.0 requires 'Phar' extension support for secure random_int() function fallback";
print "
Either enable the 'Phar' extension, or install the random_compat library files from https://github.com/paragonie/random_compat and include/require them from functions.inc.php";
print "
PostfixAdmin has bundled lib/random_compat.phar but it's not usable on your installation due to the missing Phar extension. ";
$error += 1;
}
print "
";
if ($error != 0) {
print "Please fix the errors listed above.
";
} else {
print "Everything seems fine... attempting to create/update database structure
\n";
require_once(dirname(__FILE__) .'/upgrade.php');
$tUsername = '';
$setupMessage = '';
$lostpw_error = 0;
$setuppw = "";
if (isset($CONF['setup_password'])) {
$setuppw = $CONF['setup_password'];
}
if (safepost("form") == "setuppw") {
# "setup password" form submitted
if (safepost('setup_password') != safepost('setup_password2')) {
$setupMessage = "The two passwords differ!";
$lostpw_error = 1;
} else {
list($lostpw_error, $lostpw_result) = check_setup_password(safepost('setup_password'), 1);
$setupMessage = $lostpw_result;
$setuppw = "changed";
}
} elseif (safepost("form") == "createadmin") {
# "create admin" form submitted
list($pw_check_error, $pw_check_result) = check_setup_password(safepost('setup_password'));
if ($pw_check_result != 'pass_OK') {
$error += 1;
$setupMessage = $pw_check_result;
}
if ($error == 0 && $pw_check_result == 'pass_OK') {
// XXX need to ensure domains table includes an 'ALL' entry.
$table_domain = table_by_key('domain');
$r = db_query("SELECT * FROM $table_domain WHERE domain = 'ALL'");
if ($r['rows'] == 0) {
db_insert('domain', array('domain' => 'ALL', 'description' => '', 'transport' => '')); // all other fields should default through the schema.
}
$values = array(
'username' => safepost('username'),
'password' => safepost('password'),
'password2' => safepost('password2'),
'superadmin' => 1,
'domains' => array(),
'active' => 1,
);
list($error, $setupMessage, $errormsg) = create_admin($values);
if ($error != 0) {
$tUsername = htmlentities($values['username']);
} else {
$setupMessage .= "You are done with your basic setup. ";
$setupMessage .= "
You can now login to PostfixAdmin using the account you just created.";
}
}
}
if (($setuppw == "" || $setuppw == "changeme" || safeget("lostpw") == 1 || $lostpw_error != 0) /* && $_SERVER['REQUEST_METHOD'] != "POST" */) {
# show "create setup password" form?>
Since version 2.3 there is no requirement to delete setup.php
Check the config.inc.php file for any other settings that you may need to change.