added script to add the ADMIN_ROLE admin
This commit is contained in:
parent
050fa4a19a
commit
f9c77d55a9
|
@ -0,0 +1,8 @@
|
|||
AuthUserFile /usr/local/www/mailadmin.high5.net/admin/.htpasswd
|
||||
AuthGroupFile /dev/null
|
||||
AuthName "Postfix Admin"
|
||||
AuthType Basic
|
||||
|
||||
<limit GET POST>
|
||||
require valid-user
|
||||
</limit>
|
|
@ -0,0 +1,118 @@
|
|||
<?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>
|
|
@ -146,9 +146,9 @@ $LANG['AdminAdd_domain_domain'] = 'Domain';
|
|||
$LANG['AdminAdd_domain_domain_text_error'] = '<span class="error_msg">The domain already exists.</span>';
|
||||
$LANG['AdminAdd_domain_description'] = 'Description';
|
||||
$LANG['AdminAdd_domain_aliases'] = 'Aliases';
|
||||
$LANG['AdminAdd_domain_aliases_text'] = '-1 = disable | 0 = unlimited';
|
||||
$LANG['AdminAdd_domain_aliases_text'] = '0 = unlimited';
|
||||
$LANG['AdminAdd_domain_mailboxes'] = 'Mailboxes';
|
||||
$LANG['AdminAdd_domain_mailboxes_text'] = '-1 = disable | 0 = unlimited';
|
||||
$LANG['AdminAdd_domain_mailboxes_text'] = '0 = unlimited';
|
||||
$LANG['AdminAdd_domain_button'] = 'Add Domain';
|
||||
$LANG['AdminAdd_domain_result_error'] = '<span class="error_msg">Unable to add domain.</span>';
|
||||
$LANG['AdminAdd_domain_result_succes'] = 'Domain has been added.';
|
||||
|
@ -157,9 +157,9 @@ $LANG['AdminEdit_domain_welcome'] = 'Edit a domain';
|
|||
$LANG['AdminEdit_domain_domain'] = 'Domain';
|
||||
$LANG['AdminEdit_domain_description'] = 'Description';
|
||||
$LANG['AdminEdit_domain_aliases'] = 'Aliases';
|
||||
$LANG['AdminEdit_domain_aliases_text'] = '-1 = disable | 0 = unlimited';
|
||||
$LANG['AdminEdit_domain_aliases_text'] = '0 = unlimited';
|
||||
$LANG['AdminEdit_domain_mailboxes'] = 'Mailboxes';
|
||||
$LANG['AdminEdit_domain_mailboxes_text'] = '-1 = disable | 0 = unlimited';
|
||||
$LANG['AdminEdit_domain_mailboxes_text'] = '0 = unlimited';
|
||||
$LANG['AdminEdit_domain_button'] = 'Edit Domain';
|
||||
$LANG['AdminEdit_domain_result_error'] = '<span class="error_msg">Unable to modify domain.</span>';
|
||||
|
||||
|
@ -184,6 +184,9 @@ $LANG['AdminEdit_admin_button'] = 'Edit Admin';
|
|||
$LANG['AdminEdit_admin_result_error'] = '<span class="error_msg">Unable to modify admin.</span>';
|
||||
$LANG['AdminEdit_admin_result_succes'] = 'Admin has been modified.';
|
||||
|
||||
$LANG['Role_admin_welcome'] = 'Add a new ';
|
||||
$LANG['Role_admin_warning'] = '<h3>Make sure you remove or protect this file when you are done.</h3>';
|
||||
|
||||
$LANG['UsersLogin_welcome'] = 'Mailbox users login to change your password and aliases';
|
||||
$LANG['UsersLogin_username'] = 'Login (email)';
|
||||
$LANG['UsersLogin_password'] = 'Password';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div id="footer">
|
||||
<a href="https://git.high5.nl/opensmtpdadmin/">OpenSMTPD Admin <?php echo VERSION ?></a>
|
||||
<a href="https://git.high5.nl/opensmtpdadmin/">OpenSMTPD Admin <?php echo VERSION; ?></a>
|
||||
<?php
|
||||
if (SHOW_FOOTER == "YES" && FOOTER_LINK) {
|
||||
echo " | ";
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
<li><a target="_top" href="admin.php"><?php echo $LANG['Menu_add_admin']; ?></a></li>
|
||||
<?php } else {?>
|
||||
<li><a target="_top" href="sendmail.php"><?php echo $LANG['Menu_sendmail']; ?></a></li>
|
||||
<?php } ?>
|
||||
<li><a target="_top" href="password.php"><?php echo $LANG['Menu_password']; ?></a></li>
|
||||
<?php } ?>
|
||||
<li><a target="_top" href="add-alias.php<?php if (isset($domain)) echo '?domain=' . $domain; ?>"><?php echo $LANG['Menu_add_alias']; ?></a></li>
|
||||
<li><a target="_top" href="add-mailbox.php<?php if (isset($domain)) echo '?domain=' . $domain; ?>"><?php echo $LANG['Menu_add_mailbox']; ?></a></li>
|
||||
<li><a target="_top" href="viewlog.php"><?php echo $LANG['Menu_viewlog']; ?></a></li>
|
||||
|
|
Loading…
Reference in New Issue