@ -1,8 +1,9 @@
<! DOCTYPE html >
< ? php
$PALANG = [];
require_once ( 'common.php' );
?>
< html lang = " " >
< html lang = " en ">
< head >
< meta charset = " utf-8 " >
< meta http - equiv = " X-UA-Compatible " content = " IE=edge " >
@ -88,12 +89,12 @@ $tick = ' ✅ ';
< div class = " container " >
< div class = " row " >
< h1 class = " h1 " > Configure and Setup Postfixadmin </ h1 >
< p > This page helps you setup PostfixAdmin . For further help see < a
href = " https://github.com/postfixadmin/postfixadmin/tree/master/DOCUMENTS " > the documentation </ a >.</ p >
href = " https://github.com/postfixadmin/postfixadmin/tree/master/DOCUMENTS " > the documentation </ a >.
</ p >
< ? php
@ -102,7 +103,6 @@ $tick = ' ✅ ';
} ?>
< div class = " col-12 " >
< ul >
< li >
< ? php
@ -112,16 +112,16 @@ $tick = ' ✅ ';
} else {
echo $todo . " You need to have a setup_password hash configured in a <code>config.local.php</code> file " ;
}
?>
?>
</ li >
< li >
< ? php
if ( $authenticated ) {
echo $tick . " You are logged in with the setup_password, some environment and hosting checks are displayed below. " ;
} else {
echo $todo . " You need to authenticate using the setup_password before you can perform some environment and hosting checks. " ;
}
?>
if ( $authenticated ) {
echo $tick . " You are logged in with the setup_password, some environment and hosting checks are displayed below. " ;
} else {
echo $todo . " You need to authenticate using the setup_password before you can perform some environment and hosting checks. " ;
}
?>
</ li >
</ ul >
@ -136,14 +136,10 @@ if ($authenticated) {
</ ul >
< ? php } ?>
</ div >
</ div >
< ? php
if ( $configSetupDone && ! $authenticated ) { ?>
< ? php if ( $configSetupDone && ! $authenticated ) { ?>
< div class = " row " >
< div class = " col-12 " >
< h2 class = " h2 " > Login with setup_password </ h2 >
@ -188,43 +184,43 @@ if ($authenticated) {
EOF ;
}
if ( $old_setup_password ) {
echo '<p class="text-danger"><strong>Your setup_password is in an obsolete format. As of PostfixAdmin 3.3 it needs regenerating.</strong>' ;
}
if ( $old_setup_password ) {
echo '<p class="text-danger"><strong>Your setup_password is in an obsolete format. As of PostfixAdmin 3.3 it needs regenerating.</strong>' ;
}
if ( ! $authenticated || ! $configSetupDone ) { ?>
if ( ! $authenticated || ! $configSetupDone ) { ?>
< h2 > Generate setup_password </ h2 >
< ? php
$form_error = '' ;
$result = '' ;
$form_error = '' ;
$result = '' ;
if ( safepost ( 'form' ) === " setuppw " ) {
$errors = [];
if ( safepost ( 'form' ) === " setuppw " ) {
$errors = [];
# "setup password" form submitted
if ( safepost ( 'setup_password' , 'abc' ) != safepost ( 'setup_password2' )) {
$errors [ 'setup_password' ] = " The two passwords differ! " ;
$form_error = 'has-error' ;
} else {
$msgs = validate_password ( safepost ( 'setup_password' ));
# "setup password" form submitted
if ( safepost ( 'setup_password' , 'abc' ) != safepost ( 'setup_password2' )) {
$errors [ 'setup_password' ] = " The two passwords differ! " ;
$form_error = 'has-error' ;
} else {
$msgs = validate_password ( safepost ( 'setup_password' ));
if ( empty ( $msgs )) {
// form has been submitted; both fields filled in, so generate a new setup password.
$hash = password_hash ( safepost ( 'setup_password' ), PASSWORD_DEFAULT );
if ( empty ( $msgs )) {
// form has been submitted; both fields filled in, so generate a new setup password.
$hash = password_hash ( safepost ( 'setup_password' ), PASSWORD_DEFAULT );
$result = '<p>If you want to use the password you entered as setup password, edit config.inc.php or config.local.php and set</p>' ;
$result .= " <pre> \$ CONF['setup_password'] = ' $hash ';</pre><p>After adding, refresh this page and log in using it.</p> " ;
} else {
$form_error = 'has-error' ;
$errors [ 'setup_password' ] = implode ( ', ' , $msgs );
}
}
}
$result = '<p>If you want to use the password you entered as setup password, edit config.inc.php or config.local.php and set</p>' ;
$result .= " <pre> \$ CONF['setup_password'] = ' $hash ';</pre><p>After adding, refresh this page and log in using it.</p> " ;
} else {
$form_error = 'has-error' ;
$errors [ 'setup_password' ] = implode ( ', ' , $msgs );
}
}
}
?>
?>
< form name = " setuppw " method = " post " class = " form-horizontal " action = " setup.php " >
< input type = " hidden " name = " form " value = " setuppw " />
@ -259,65 +255,61 @@ if (!$authenticated || !$configSetupDone) { ?>
< div class = " form-group " >
< div class = " col-sm-offset-4 col-sm-4 " >
< button class = " btn btn-primary " type = " submit " name = " submit " value = " setuppw " > Generate
setup_password
hash
< button class = " btn btn-primary " type = " submit " name = " submit " value = " setuppw " >
Generate setup_password hash
</ button >
</ div >
</ div >
</ form >
< ? = $result ?>
< ? php
} // end if(!$authenticated)?>
} // end if(!$authenticated)?>
</ div >
</ div >
< div class = " row " >
< div clas = " col-12 " >
< div class = " col-12 " >
< h2 class = " h2 " > Hosting Environment Check </ h2 >
< ? php
$check = do_software_environment_check ();
$check = do_software_environment_check ();
if ( $authenticated ) {
if ( ! empty ( $check [ 'info' ])) {
echo " <h3>Information</h3><ul> " ;
foreach ( $check [ 'info' ] as $msg ) {
echo " <li> { $tick } { $msg } </li> " ;
}
echo " </ul> " ;
}
if ( $authenticated ) {
if ( ! empty ( $check [ 'info' ])) {
echo " <h3>Information</h3><ul> " ;
foreach ( $check [ 'info' ] as $msg ) {
echo " <li> { $tick } { $msg } </li> " ;
}
echo " </ul> " ;
}
if ( ! empty ( $check [ 'warn' ])) {
echo " <h3>Warnings</h3><ul> " ;
foreach ( $check [ 'warn' ] as $msg ) {
echo " <li class='text-warning'>⚠ { $msg } </li> " ;
}
echo " </ul> " ;
}
if ( ! empty ( $check [ 'error' ])) {
echo " <h3>Errors (MUST be fixed)</h3><ul> " ;
foreach ( $check [ 'error' ] as $msg ) {
echo " <li class='text-danger'>⛔ { $msg } </li> " ;
}
echo " </ul> " ;
}
if ( ! empty ( $check [ 'warn' ])) {
echo " <h3>Warnings</h3><ul> " ;
foreach ( $check [ 'warn' ] as $msg ) {
echo " <li class='text-warning'>⚠ { $msg } </li> " ;
}
echo " </ul> " ;
}
if ( ! empty ( $check [ 'error' ])) {
echo " <h3>Errors (MUST be fixed)</h3><ul> " ;
foreach ( $check [ 'error' ] as $msg ) {
echo " <li class='text-danger'>⛔ { $msg } </li> " ;
}
echo " </ul> " ;
}
$php_error_log = ini_get ( 'error_log' );
} else {
if ( ! empty ( $check [ 'error' ])) {
echo '<h3 class="text-danger">Hosting Environment errors found. Login to see details.</h3>' ;
}
$php_error_log = ini_get ( 'error_log' );
} else {
if ( ! empty ( $check [ 'error' ])) {
echo '<h3 class="text-danger">Hosting Environment errors found. Login to see details.</h3>' ;
}
if ( ! empty ( $check [ 'warn' ])) {
echo '<h3 class="text-warning">Hosting Environment warnings found. Login to see details.</h3>' ;
}
}
if ( ! empty ( $check [ 'warn' ])) {
echo '<h3 class="text-warning">Hosting Environment warnings found. Login to see details.</h3>' ;
}
}
?>
?>
</ div >
</ div >
@ -327,40 +319,42 @@ if ($authenticated) {
< h2 class = " h2 " > Database Update </ h2 >
< ? php
$db = false ;
try {
$db = db_connect ();
} catch ( \Exception $e ) {
echo " <p class='h3 text-danger'>Something went wrong while trying to connect to the database. A message should be logged - check PHP's error_log ( " . ini_get ( 'error_log' ) . ')</p>' ;
error_log ( " Couldn't perform PostfixAdmin database update - failed to connect to db? " . $e -> getMessage () . " Trace: " . $e -> getTraceAsString ());
}
$db = false ;
try {
$db = db_connect ();
} catch ( \Exception $e ) {
echo " <p class='h3 text-danger'>Something went wrong while trying to connect to the database. A message should be logged - check PHP's error_log ( " . ini_get ( 'error_log' ) . ')</p>' ;
error_log ( " Couldn't perform PostfixAdmin database update - failed to connect to db? " . $e -> getMessage () . " Trace: " . $e -> getTraceAsString ());
}
if ( $db ) {
echo " <p>Everything seems fine... attempting to create/update database structure</p> \n " ;
try {
require_once ( dirname ( __FILE__ ) . '/upgrade.php' );
} catch ( \Exception $e ) {
if ( $authenticated ) {
echo " <p class='h3 text-danger'>Exception message: { $e -> getMessage () } - check logs!</p> " ;
}
echo " <p class='h3 text-danger'>Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log ( " . ini_get ( 'error_log' ) . ')</p>' ;
error_log ( " Couldn't perform PostfixAdmin database update via upgrade.php - " . $e -> getMessage () . " Trace: " . $e -> getTraceAsString ());
}
} else {
echo " <h3 class='h3 text-danger'>Could not connect to database to perform updates; check PHP error log.</h3> " ;
}
?>
if ( $db ) {
echo " <p>Everything seems fine... attempting to create/update database structure</p> \n " ;
try {
require_once ( dirname ( __FILE__ ) . '/upgrade.php' );
} catch ( \Exception $e ) {
if ( $authenticated ) {
echo " <p class='h3 text-danger'>Exception message: { $e -> getMessage () } - check logs!</p> " ;
}
echo " <p class='h3 text-danger'>Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log ( " . ini_get ( 'error_log' ) . ')</p>' ;
error_log ( " Couldn't perform PostfixAdmin database update via upgrade.php - " . $e -> getMessage () . " Trace: " . $e -> getTraceAsString ());
}
} else {
echo " <h3 class='h3 text-danger'>Could not connect to database to perform updates; check PHP error log.</h3> " ;
}
?>
</ div >
</ div >
< ? php
if ( $authenticated ) {
$setupMessage = '' ;
if ( safepost ( " submit " ) === " createadmin " ) {
echo " <div class=row><div class='col-12'> " ;
$setupMessage = '' ;
if ( safepost ( " submit " ) === " createadmin " ) {
?>
< div class = 'row' >
< div class = 'col-12' >
< ? php
# "create admin" form submitted, make sure the correct setup password was specified.
// XXX need to ensure domains table includes an 'ALL' entry.
@ -391,122 +385,119 @@ if ($db) {
$setupMessage .= " <p>You are done with your basic setup. <b>You can now <a href='login.php'>login to PostfixAdmin</a> using the account you just created.</b></p> " ;
}
echo " </div> " ;
}
echo " </div></div> " ;
}
$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 ' " );
$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 )) { ?>
if ( ! empty ( $admins )) { ?>
< div class = " row " >
< div class = " col-12 " >
< div class = " row " >
< div class = " col-12 " >
< h2 class = " h2 " > Super admins </ h2 >
< p > The following 'super-admin' accounts have already been added to the database .</ p >
< ul >
< ? php
foreach ( $admins as $row ) {
echo " <li> { $row [ 'username' ] } </li> " ;
}
?>
</ ul >
< h2 class = " h2 " > Super admins </ h2 >
< p > The following 'super-admin' accounts have already been added to the database .</ p >
< ul >
< ? php
foreach ( $admins as $row ) {
echo " <li> { $row [ 'username' ] } </li> " ;
}
?>
</ ul >
</ div >
</ div >
</ div >
< ? php } ?>
< div class = " row " >
< div class = " col-12 " >
< h2 > Add Superadmin Account </ h2 >
< form name = " create_admin " class = " form-horizontal " method = " post " >
< div class = " form-group " >
< label for = " setup_password " class = " col-sm-4 control-label " > Setup password </ label >
< div class = " col-sm-4 " >
< input class = " form-control " type = " password " required = " required "
name = " setup_password "
minlength = 5
value = " " />
< ? php } ?>
< div class = " row " >
< div class = " col-12 " >
< h2 > Add Superadmin Account </ h2 >
< form name = " create_admin " class = " form-horizontal " method = " post " >
< div class = " form-group " >
< label for = " setup_password " class = " col-sm-4 control-label " > Setup password </ label >
< div class = " col-sm-4 " >
< input class = " form-control " type = " password " required = " required "
name = " setup_password "
minlength = 5
value = " " />
</ div >
</ div >
</ div >
< div class = " form-group " >
< label for = " username " class = " col-sm-4 control-label " >< ? = $PALANG [ 'admin' ] ?> </label>
< div class = " col-sm-4 " >
< input class = " form-control " type = " text " required = " required " name = " username "
minlength = 5
id = " username "
value = " " />
< div class = " form-group " >
< label for = " username " class = " col-sm-4 control-label " >< ? = $PALANG [ 'admin' ] ?> </label>
< div class = " col-sm-4 " >
< input class = " form-control " type = " text " required = " required " name = " username "
minlength = 5
id = " username "
value = " " />
< ? = _error_field ( $errors , 'username' ); ?>
< ? = _error_field ( $errors , 'username' ); ?>
</ div >
</ div >
</ div >
< div class = " form-group " >
< label for = " password " class = " col-sm-4 control-label " >< ? = $PALANG [ 'password' ] ?> </label>
< div class = " col-sm-4 " >
< input class = " form-control " type = " password " required = required
name = " password " minlength = 5
id = " password " autocomplete = " new-password "
value = " " />
< ? = _error_field ( $errors , 'password' ); ?>
< div class = " form-group " >
< label for = " password " class = " col-sm-4 control-label " >< ? = $PALANG [ 'password' ] ?> </label>
< div class = " col-sm-4 " >
< input class = " form-control " type = " password " required = required
name = " password " minlength = 5
id = " password " autocomplete = " new-password "
value = " " />
< ? = _error_field ( $errors , 'password' ); ?>
</ div >
</ div >
</ div >
< div class = " form-group " >
< label for = " password2 "
class = " col-sm-4 control-label " >< ? = $PALANG [ 'password_again' ] ?> </label>
< div class = " col-sm-4 " >
< input class = " form-control " type = " password " required = required
name = " password2 " minlength = 5
id = " password2 " autocomplete = " new-password "
value = " " />
< div class = " form-group " >
< label for = " password2 "
class = " col-sm-4 control-label " >< ? = $PALANG [ 'password_again' ] ?> </label>
< div class = " col-sm-4 " >
< input class = " form-control " type = " password " required = required
name = " password2 " minlength = 5
id = " password2 " autocomplete = " new-password "
value = " " />
< ? = _error_field ( $errors , 'password2' ); ?>
< ? = _error_field ( $errors , 'password2' ); ?>
</ div >
</ div >
</ div >
< div class = " form-group " >
< div class = " col-sm-offset-4 col-sm-4 " >
< button class = " btn btn-primary " type = " submit " name = " submit "
value = " createadmin " >< ? = $PALANG [ 'pAdminCreate_admin_button' ] ?>
</ button >
< div class = " form-group " >
< div class = " col-sm-offset-4 col-sm-4 " >
< button class = " btn btn-primary " type = " submit " name = " submit "
value = " createadmin " >< ? = $PALANG [ 'pAdminCreate_admin_button' ] ?>
</ button >
</ div >
</ div >
</ div >
</ form >
</ form >
</ div >
</ div >
</ div >
< div class = " row " >
< div class = " col-12 " >
< p class = " text-success " >< ? = $setupMessage ?> </p>
< div class = " row " >
< div class = " col-12 " >
< p class = " text-success " >< ? = $setupMessage ?> </p>
</ div >
</ div >
</ div >
< ? php
}
?>
</ div >
< footer class = " footer mt-5 bg-dark " >
< div class = " container text-center " >
< a target = " _blank " rel = " noopener " href = " https://github.com/postfixadmin/postfixadmin/blob/master/DOCUMENTS/ " > Documentation </ a >
//
< a target = " _blank " rel = " noopener "
href = " https://github.com/postfixadmin/postfixadmin/ " > Postfix Admin </ a >
</ div >
</ footer >
< ? php
}
?>
</ div >
< footer class = " footer mt-5 bg-dark " >
< div class = " container text-center " >
< a target = " _blank " rel = " noopener "
href = " https://github.com/postfixadmin/postfixadmin/blob/master/DOCUMENTS/ " > Documentation </ a >
//
< a target = " _blank " rel = " noopener "
href = " https://github.com/postfixadmin/postfixadmin/ " > Postfix Admin </ a >
</ div >
</ footer >
</ body >
</ html >
@ -665,10 +656,10 @@ function do_software_environment_check()
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.
)
);
implode ( " " ,
array_slice ( file ( $error_log_file ), - 4 , 3 ) // last three lines, might fail miserably if error_log is large.
)
);
$error [] = nl2br ( $err );
}