From fa27c7c8b7622e66175d27797414d699132e9abe Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 13 Aug 2019 09:00:21 +0100 Subject: [PATCH] reindent/reformat --- public/setup.php | 754 ++++++++++++++++++++++++----------------------- 1 file changed, 379 insertions(+), 375 deletions(-) diff --git a/public/setup.php b/public/setup.php index a7e2c42c..508c3001 100644 --- a/public/setup.php +++ b/public/setup.php @@ -17,7 +17,7 @@ define('POSTFIXADMIN', 1); # by defining it here, common.php will not start a session. -require_once(dirname(__FILE__).'/common.php'); # make sure correct common.php is used. +require_once(dirname(__FILE__) . '/common.php'); # make sure correct common.php is used. $CONF['show_header_text'] = 'NO'; $CONF['theme_logo'] = 'images/logo-default.png'; @@ -26,427 +26,429 @@ require(dirname(__FILE__) . '/../templates/header.php'); ?>
-

Postfix Admin Setup Checker

- -

Running software: -

"; -print "

Checking environment:\n"; -print "

"; if ($error != 0) { - $tUsername = htmlentities($values['username']); + print "

Please fix the errors listed above.

"; } else { - $setupMessage .= "

You are done with your basic setup. "; - $setupMessage .= "

You can now login to PostfixAdmin using the account you just created."; - } - } - } + print "

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

\n"; + require_once(dirname(__FILE__) . '/upgrade.php'); - if (($setuppw == "" || $setuppw == "changeme" || safeget("lostpw") == 1 || $lostpw_error != 0) /* && $_SERVER['REQUEST_METHOD'] != "POST" */) { - # show "create setup password" form?> - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - -

Change setup password

Warning: connection not secure, switch to https if possible

-
-
+ $tUsername = ''; + $setupMessage = ''; + $lostpw_error = 0; - - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Create superadmin account

Warning: connection not secure, switch to https if possible

Lost password?
-
-
+ $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'); + $rows = db_query_all("SELECT * FROM $table_domain WHERE domain = 'ALL'"); + if (empty($rows)) { + 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?> + +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + +

Change setup password

Warning: connection not secure, switch to https if possible

+
+
+ + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Create superadmin account

Warning: connection not secure, switch to https if possible

Lost password?
+
+
+ +

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.

- +
{$errors[$key]}"; } -function generate_setup_password_salt() { +function generate_setup_password_salt() +{ $salt = time() . '*' . $_SERVER['REMOTE_ADDR'] . '*' . mt_rand(0, 60000); $salt = md5($salt); return $salt; } -function encrypt_setup_password($password, $salt) { +function encrypt_setup_password($password, $salt) +{ return $salt . ':' . sha1($salt . ':' . $password); } @@ -457,7 +459,8 @@ function encrypt_setup_password($password, $salt) { 'message => text ) */ -function check_setup_password($password, $lostpw_mode = 0) { +function check_setup_password($password, $lostpw_mode = 0) +{ global $CONF; $error = 1; # be pessimistic @@ -492,7 +495,8 @@ function check_setup_password($password, $lostpw_mode = 0) { return array($error, $result); } -function create_admin($values) { +function create_admin($values) +{ DEFINE('POSTFIXADMIN_SETUP', 1); # avoids instant redirect to login.php after creating the admin $handler = new AdminHandler(1, 'setup.php');