119 lines
3.6 KiB
PHP
119 lines
3.6 KiB
PHP
<?php
|
|
//
|
|
// OpenSMTPD Admin
|
|
// by Mischa Peters <mischa at high5 dot nl>
|
|
// Copyright (c) 2022 High5!
|
|
// License Info: LICENSE.TXT
|
|
//
|
|
// File: admin.php
|
|
//
|
|
// Template File: admin.tpl
|
|
//
|
|
//
|
|
// Template Variables:
|
|
//
|
|
// action
|
|
// message
|
|
// username
|
|
// domains
|
|
//
|
|
// POST / GET Variables:
|
|
//
|
|
// username
|
|
// password1
|
|
// password2
|
|
// domains
|
|
//
|
|
require_once '../functions.inc.php';
|
|
include '../languages/' . check_language() . '.lang';
|
|
|
|
$list_admins = list_admins();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|
$username = filter_input(INPUT_POST, 'username', FILTER_VALIDATE_EMAIL);
|
|
$password1 = filter_input(INPUT_POST, 'password1', FILTER_DEFAULT);
|
|
$password2 = filter_input(INPUT_POST, 'password2', FILTER_DEFAULT);
|
|
$ROLE = ADMIN_ROLE;
|
|
|
|
if (empty($username) || in_array($username, array_column($list_admins, 'username'))) {
|
|
$message = $LANG['AdminAdd_admin_username_error'];
|
|
}
|
|
|
|
if (empty($password1) || $password1 != $password2) {
|
|
$message = $LANG['AdminAdd_admin_password_error'];
|
|
}
|
|
|
|
if (empty($message)) {
|
|
$hashed = bcrypt($password1);
|
|
try {
|
|
$dbh = pdo_connect();
|
|
$sth = $dbh->prepare("INSERT INTO admin (username,password,role,created,modified) VALUES (?,?,?,NOW(),NOW())");
|
|
$sth->bindParam(1, $username, PDO::PARAM_STR);
|
|
$sth->bindParam(2, $hashed, PDO::PARAM_STR);
|
|
$sth->bindParam(3, $ROLE, PDO::PARAM_STR);
|
|
$sth->execute();
|
|
$message = $LANG['AdminAdd_admin_result_succes'] . " ($username)</br />Go to the <a href=\"/login.php\">LOGIN</a> page";
|
|
} catch(PDOException $e) {
|
|
$message = $LANG['AdminAdd_admin_result_error'] . " ($username)<br />$e";
|
|
}
|
|
}
|
|
|
|
}
|
|
@header("Expires: Wed, 29 Feb 1984 00:00:00 GMT");
|
|
@header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
|
@header("Cache-Control: no-store, no-cache, must-revalidate");
|
|
@header("Cache-Control: post-check=0, pre-check=0", false);
|
|
@header("Pragma: no-cache");
|
|
?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="stylesheet" href="../stylesheet.css">
|
|
<title>OpenSMTPD Admin - <?php echo $_SERVER['HTTP_HOST']; ?></title>
|
|
</head>
|
|
<body>
|
|
<div id="login_header">
|
|
<img id="login_header_logo" src="../images/postbox.png" />
|
|
<img id="login_header_logo" height="30px" src="../images/opensmtpdadmin.png" />
|
|
</div>
|
|
<div id="edit_form">
|
|
<form name="create_admin" method="post">
|
|
<table>
|
|
<tr>
|
|
<td colspan="2"><h3><?php echo $LANG['Role_admin_welcome'] . ' ' . ADMIN_ROLE; ?></h3></td>
|
|
</tr>
|
|
<tr>
|
|
<td><?php echo $LANG['AdminAdd_admin_username'] . ":"; ?></td>
|
|
<td><input class="flat" type="text" name="username" value="<?php echo $username ?? ''; ?>" /></td>
|
|
</tr>
|
|
<tr>
|
|
<td><?php echo $LANG['AdminAdd_admin_password1'] . ":"; ?></td>
|
|
<td><input class="flat" type="password" name="password1" /></td>
|
|
</tr>
|
|
<tr>
|
|
<td><?php echo $LANG['AdminAdd_admin_password2'] . ":"; ?></td>
|
|
<td><input class="flat" type="password" name="password2" /></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" class="hlp_center"><input class="button" type="submit" name="submit" value="<?php echo $LANG['AdminAdd_admin_button']; ?>" /></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2"> </td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2"><h3><?php echo $LANG['Role_admin_welcome'] . ' ' . ADMIN_ROLE; ?></h3></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" class="standout"><?php echo $message ?? ' '; ?></td>
|
|
</tr>
|
|
</table>
|
|
</form>
|
|
</div>
|
|
<?php echo $LANG['Role_admin_warning']; ?>
|
|
<div id="footer">
|
|
<a href="https://git.high5.nl/opensmtpdadmin/">OpenSMTPD Admin <?php echo VERSION; ?></a>
|
|
</div>
|
|
</body>
|
|
</html>
|