diff --git a/functions.inc.php b/functions.inc.php index 39d20de7..2c9ce85d 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -737,9 +737,7 @@ function list_domains () // function admin_exist ($username) { - global $table_admin; - - $result = db_query ("SELECT 1 FROM $table_admin WHERE username='$username'"); + $result = db_query ("SELECT 1 FROM " . table_by_key ('admin') . " WHERE username='$username'"); if ($result['rows'] != 1) { return false; @@ -1236,65 +1234,87 @@ $DEBUG_TEXT = "\n "; - -// -// db_connect -// Action: Makes a connection to the database if it doesn't exist -// Call: db_connect () -// -function db_connect () +/** + * db_connect + * Action: Makes a connection to the database if it doesn't exist + * Call: db_connect () + * Optional parameter: $setup = TRUE, used by setup.php + * + * Return value: + * a) without $setup or $setup == 0 + * - $link - the database connection -OR- + * - call die() in case of connection problems + * b) with $setup == TRUE + * array($link, $error_text); + */ +function db_connect ($setup = 0) { global $CONF; global $DEBUG_TEXT; + if ($setup != 0) $DEBUG_TEXT = ''; + $error_text = ''; + $link = 0; if ($CONF['database_type'] == "mysql") { if (function_exists ("mysql_connect")) { - $link = @mysql_connect ($CONF['database_host'], $CONF['database_user'], $CONF['database_password']) or die ("
DEBUG INFORMATION:Running software: +
Checking for dependencies:\n"; +print "
% cp config.inc.php.sample config.inc.php\n"; $error =+ 1; } -print "\n"; // // Check if there is support for at least 1 database @@ -150,9 +151,8 @@ if (($f_mysql_connect == 0) and ($f_mysqli_connect == 0) and ($f_pg_connect == 0 // if ($f_mysql_connect == 1) { - print "- Depends on: MySQL 3.23, 4.0 - OK
Please fix the errors listed above.
"; +} +else { - print "Everything seems fine... you are ready to rock & roll!\n"; + print "Everything seems fine... you are ready to rock & roll!
\n"; + + $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text']; + $pAdminCreate_admin_password_text = ""; + $tUsername = ''; + $tMessage = ''; + + + if ($_SERVER['REQUEST_METHOD'] == "POST") + { + if (isset ($_POST['fUsername'])) $fUsername = escape_string ($_POST['fUsername']); + if (isset ($_POST['fPassword'])) $fPassword = escape_string ($_POST['fPassword']); + if (isset ($_POST['fPassword2'])) $fPassword2 = escape_string ($_POST['fPassword2']); + + list ($error, $tMessage, $pAdminCreate_admin_username_text, $pAdminCreate_admin_password_text) = create_admin($fUsername, $fPassword, $fPassword2, array('ALL'), TRUE); + if ($error != 0) { + if (isset ($_POST['fUsername'])) $tUsername = escape_string ($_POST['fUsername']); + } else { + print "$tMessage
"; + echo "You can now log in to Postfix Admin.
"; + } + } + + if ($_SERVER['REQUEST_METHOD'] == "GET" || $error != 0) + { + ?> + +