TODO'; $tick = ' ✅ '; ?>

Configure and Setup Postfixadmin

This page helps you setup PostfixAdmin. For further help see the documentation.

Warning: connection not secure, switch to https if possible"; } ?>
  • config.local.php file"; } ?>

One you have logged in with the setup_password, this page will ...

  • run some simple hosting/environment checks which may help identify problems with your environment
  • create/update your database of choice,
  • allow you to list / add super user accounts

Login with setup_password

If you've forgotten your super-admin password, you can generate a new one using the Generate form and update your config.local.php

For a new installation, you must generate a 'setup_password' to go into your config.local.php file.

You can use the form below, or run something like the following in a shell - php -r 'echo password_hash("password", PASSWORD_DEFAULT);'

EOF; } if ($old_setup_password) { echo '

Your setup_password is in an obsolete format. As of PostfixAdmin 3.3 it needs regenerating.'; } if (!$authenticated || !$configSetupDone) { ?>

Generate setup_password

If you want to use the password you entered as setup password, edit config.inc.php or config.local.php and set

'; $result .= "
\$CONF['setup_password'] = '$hash';

After adding, refresh this page and log in using it.

"; } else { $form_error = 'has-error'; $errors['setup_password'] = implode(', ', $msgs); } } } ?>

Hosting Environment Check

Information
    "; foreach ($check['info'] as $msg) { echo "
  • {$tick} {$msg}
  • "; } echo "
"; } if (!empty($check['warn'])) { echo "

Warnings

    "; foreach ($check['warn'] as $msg) { echo "
  • ⚠ {$msg}
  • "; } echo "
"; } if (!empty($check['error'])) { echo "

Errors (MUST be fixed)

    "; foreach ($check['error'] as $msg) { echo "
  • ⛔{$msg}
  • "; } echo "
"; } $php_error_log = ini_get('error_log'); } else { if (!empty($check['error'])) { echo '

Hosting Environment errors found. Login to see details.

'; } if (!empty($check['warn'])) { echo '

Hosting Environment warnings found. Login to see details.

'; } } ?>

Database Update

getMessage()); } if ($db) { print "

Everything seems fine... attempting to create/update database structure

\n"; require_once(dirname(__FILE__) . '/upgrade.php'); } else { echo "

Could not connect to database to perform updates; check PHP error log.

"; } } else { echo "

Please login to see perform database update.

"; } ?>
"; # "create admin" form submitted, make sure the correct setup password was specified. // XXX need to ensure domains table includes an 'ALL' entry. $table_domain = table_by_key('domain'); $rows = db_query_all("SELECT * FROM $table_domain WHERE domain = 'ALL'"); if (empty($rows)) { // all other fields should default through the schema. db_insert('domain', array('domain' => 'ALL', 'description' => '', 'transport' => '')); } $values = array( 'username' => safepost('username'), 'password' => safepost('password'), 'password2' => safepost('password2'), 'superadmin' => 1, 'domains' => array(), 'active' => 1, ); list($error, $setupMessage, $errors) = create_admin($values); if ($error == 1) { $tUsername = htmlentities($values['username']); error_log("failed to add admin - " . json_encode([$error, $setupMessage, $errors])); echo "

Admin addition failed; check field error messages or server logs.

"; } else { // all good!. $setupMessage .= "

You are done with your basic setup. You can now login to PostfixAdmin using the account you just created.

"; } echo "
"; } $table_admin = table_by_key('admin'); $bool = db_get_boolean(true); $admins = db_query_all("SELECT * FROM $table_admin WHERE superadmin = '$bool' AND active = '$bool'"); if (!empty($admins)) { ?>

Super admins

The following 'super-admin' accounts have already been added to the database.

    {$row['username']}"; } ?>

Add Superadmin Account

{$errors[$key]}"; } function create_admin($values) { define('POSTFIXADMIN_SETUP', 1); # avoids instant redirect to login.php after creating the admin $handler = new AdminHandler(1, 'setup.php'); $formconf = $handler->webformConfig(); if (!$handler->init($values['username'])) { return array(1, "", $handler->errormsg); } if (!$handler->set($values)) { return array(1, "", $handler->errormsg); } if (!$handler->save()) { return array(1, "", $handler->errormsg); } return array( 0, $handler->infomsg['success'], array(), ); } /** * @return array like: ['info' => string[], 'warn' => string[], 'error' => string[] ] */ function do_software_environment_check() { $CONF = Config::getInstance()->getAll(); $warn = []; $error = []; $info = []; // // Check for availability functions // $f_phpversion = function_exists("phpversion"); $f_apache_get_version = function_exists("apache_get_version"); $m_pdo = extension_loaded("PDO"); $m_pdo_mysql = extension_loaded("pdo_mysql"); $m_pdo_pgsql = extension_loaded('pdo_pgsql'); $m_pdo_sqlite = extension_loaded("pdo_sqlite"); $f_session_start = function_exists("session_start"); $f_preg_match = function_exists("preg_match"); $f_mb_encode_mimeheader = function_exists("mb_encode_mimeheader"); $f_imap_open = function_exists("imap_open"); $file_local_config = realpath(__DIR__ . "/../config.local.php"); // Fall back to looking in /etc/postfixadmin for config.local.php (Debian etc) // this check might produce a false positive if someone has a legacy PostfixAdmin installation. if (!file_exists($file_local_config) && is_dir('/etc/postfixadmin')) { if (file_exists('/etc/postfixadmin/config.local.php')) { $file_local_config = '/etc/postfixadmin/config.local.php'; } } // Check for PHP version $phpversion = 'unknown-version'; if ($f_phpversion == 1) { if (version_compare(PHP_VERSION, '7.0.0', '<')) { $error[] = "Error: Depends on: PHP v7.0+. You must upgrade."; } else { $info[] = "PHP version - " . phpversion(); } } else { $error[] = "Unable to check for PHP version. (PHP_VERSION not found?)"; } // Check for Apache version if ($f_apache_get_version == 1) { $info[] = "Webserver - " . apache_get_version(); } $info[] = "Postfixadmin installed at - " . realpath(__DIR__); $error_log_file = ini_get('error_log'); if (file_exists($error_log_file) && is_writable($error_log_file)) { $info[] = "PHP Error log (error_log) is - $error_log_file"; } if (file_exists($error_log_file) && !is_writeable($error_log_file)) { $warn[] = "PHP Error log (error_log) is - $error_log_file, but is not writeable. Postfixadmin will be unable to log error(s)"; } if (file_exists($file_local_config)) { $info[] = "config.local.php file found : " . realpath($file_local_config); } else { $warn[] = "Warning: config.local.php - NOT FOUND - It's Recommended to store your own settings in config.local.php instead of editing config.inc.php"; } // Check if there is support for at least 1 database if (($m_pdo == 0) and ($m_pdo_mysql == 0) and ($m_pdo_sqlite == 0) and ($m_pdo_pgsql == 0)) { $error[] = "There is no database (PDO) support in your PHP setup, you MUST install a suitable PHP PDO extension (e.g. pdo_pgsql, pdo_mysql or pdo_sqlite)."; } if ($m_pdo_mysql == 1) { $info[] = "Database - MySQL support available"; } else { $info[] = "Database - MySQL (pdo_mysql) extension not found"; } // PostgreSQL functions if ($m_pdo_pgsql == 1) { $info[] = "Database - PostgreSQL support available "; } else { $warn[] = "Database - PostgreSQL (pdo_pgsql) extension not found"; } if ($m_pdo_sqlite == 1) { $info[] = "Database - SQLite support available"; if (Config::read_string('database_type') != 'sqlite') { $warn[] = "Change the database_type to 'sqlite' in config.local.php if you want to use SQLite"; } } else { $warn[] = "Database support - SQLite (pdo_sqlite) extension not found"; } if (empty($CONF['encrypt'])) { $error[] = 'Password hashing - $CONF["encrypt"] is empty. Please check your config.inc.php / config.local.php file.'; } else { $info[] = 'Password hashing - $CONF["encrypt"] = ' . $CONF['encrypt']; try { $output = pacrypt('foobar'); if ($output == 'foobar') { $warn[] = "You appear to be using a cleartext \$CONF['encrypt'] setting. This is insecure. You have been warned. Your users deserve better"; } $info[] = 'Password hashing - $CONF["encrypt"] - hash generation OK'; } catch (\Exception $e) { $error[] = "Password Hashing - attempted to use configured encrypt backend ({$CONF['encrypt']}) triggered an error: " . $e->getMessage(); if (is_writeable($error_log_file)) { $err = "Possibly helpful error_log messages - " . htmlspecialchars( implode("", array_slice(file($error_log_file), -4, 3) // last three lines, might fail miserably if error_log is large. ) ); $error[] = nl2br($err); } $error[] = "You will have problems logging into PostfixAdmin."; if (preg_match('/^dovecot:/', $CONF['encrypt'])) { $error[] = "Check out our Dovecot documentation at https://github.com/postfixadmin/postfixadmin/blob/master/DOCUMENTS/DOVECOT.txt, specifically around '3. Permissions'."; } } } $link = null; $error_text = null; $dsn = 'Could not generate'; try { $dsn = db_connection_string(); $info[] = "Database connection configured OK (using PDO $dsn)"; $link = db_connect(); $info[] = "Database connection - Connected OK"; } catch (Exception $e) { $error[] = "Database connection string : " . $dsn; $error[] = "Problem connecting to database, check database configuration (\$CONF['database_*'] entries in config.local.php)"; $error[] = $e->getMessage(); } // Session functions if ($f_session_start == 1) { $info[] = "Depends on: PHP session support - OK"; } else { $error[] = "Error: Depends on: PHP session support - NOT FOUND. (FreeBSD: portinstall php$phpversion-session ?)"; } // PCRE functions if ($f_preg_match == 1) { $info[] = "Depends on: PHP pcre support - OK"; } else { $error[] = "Error: Depends on: PHP pcre support - NOT FOUND. (FreeBSD: portinstall php$phpversion-pcre)"; } // Multibyte functions if ($f_mb_encode_mimeheader == 1) { $info[] = "Depends on: PHP mbstring support - OK"; } else { $error[] = "Error: Depends on: PHP mbstring support - NOT FOUND. (FreeBSD: portinstall php$phpversion-mbstring?)"; } // Imap functions if ($f_imap_open == 1) { $info[] = "Optional - PHP IMAP functions - OK"; } else { $warn[] = "Warning: Optional dependency 'imap' extension missing, without this you may not be able to automate creation of sub-folders for new mailboxes"; } return ['error' => $error, 'warn' => $warn, 'info' => $info]; }