change table name to role, fix list-admin

This commit is contained in:
mischa 2022-09-05 20:24:35 +00:00
parent 4db75ba328
commit 080e0cc016
23 changed files with 91 additions and 91 deletions

View File

@ -10,6 +10,7 @@ Database needed to use SQL with OpenSMTPD
CREATE TABLE `admin` (
`username` varchar(255) NOT NULL DEFAULT '',
`password` varchar(255) NOT NULL DEFAULT '',
`role` varchar(32) DEFAULT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`username`),

View File

@ -26,12 +26,10 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
$ROLE = check_role();
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
$list_admins = list_admins();
} else {
$list_domains = list_domains($SESSID_USERNAME);
}
@ -71,7 +69,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$sth->bindParam(2, $goto, PDO::PARAM_STR);
$sth->bindParam(3, $domain, PDO::PARAM_STR);
$sth->execute();
logging($admin, $domain, $LANG['Logging_alias_add'], "$from -> $goto");
logging($SESSID_USERNAME, $domain, $LANG['Logging_alias_add'], "$from -> $goto");
$message = $LANG['Add_alias_result_succes'] . "<br />($from -> $goto)</br />";
$address = '';
$goto = '';

View File

@ -28,12 +28,10 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
$ROLE = check_role();
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
$list_admins = list_admins();
} else {
$list_domains = list_domains($SESSID_USERNAME);
}
@ -90,7 +88,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$sth->bindParam(4, $maildir, PDO::PARAM_STR);
$sth->bindParam(5, $domain, PDO::PARAM_STR);
$sth->execute();
logging($admin, $domain, $LANG['Logging_mailbox_add'], "$from");
logging($SESSID_USERNAME, $domain, $LANG['Logging_mailbox_add'], "$from");
$message = $LANG['Add_mailbox_result_succes'] . "<br />($from)";
$username = '';
$name = '';

View File

@ -28,9 +28,9 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$ROLE = check_role();
if ($PERMISSIONS != ADMIN_RIGHTS) {
if ($ROLE != ADMIN_ROLE) {
header("Location: list-domain.php");
die();;
}

View File

@ -22,9 +22,9 @@ include './languages/' . check_language() . '.lang';
date_default_timezone_set('Europe/Amsterdam');
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$ROLE = check_role();
if ($PERMISSIONS != ADMIN_RIGHTS) {
if ($ROLE != ADMIN_ROLE) {
header("Location: list-domain.php");
die();;
}

View File

@ -23,6 +23,9 @@ define('DB_NAME', '');
define('ALIASES', '10');
define('MAILBOXES', '10');
// Mail Admin Administrator tag
define('ADMIN_RIGHTS', 'ADMINISTRATOR');
// Expose virtual mail construct 'vmail' to admins.
define('ALIAS_CONTROL', 'NO');

View File

@ -25,7 +25,6 @@ include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$list_domains = list_domains($SESSID_USERNAME);
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$table = filter_input(INPUT_GET, 'table', FILTER_DEFAULT);
@ -44,7 +43,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($sth->rowCount() != 1) {
throw new RuntimeException('alias');
}
logging($admin, $domain, $LANG['Logging_alias_delete'], $delete);
logging($SESSID_USERNAME, $domain, $LANG['Logging_alias_delete'], $delete);
header("Location: list-virtual.php?domain=$domain");
} catch (RuntimeException $e) {
@ -67,7 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($sth->rowCount() != 1) {
throw new RuntimeException('mailbox');
}
logging($admin, $domain, $LANG['Logging_mailbox_delete'], $delete);
logging($SESSID_USERNAME, $domain, $LANG['Logging_mailbox_delete'], $delete);
$sth = $dbh->prepare("DELETE FROM vacation WHERE email=? AND domain=?");
$sth->bindParam(1, $delete, PDO::PARAM_STR);

View File

@ -29,9 +29,9 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$ROLE = check_role();
if ($PERMISSIONS != ADMIN_RIGHTS) {
if ($ROLE != ADMIN_ROLE) {
header("Location: list-domain.php");
die();
}

View File

@ -24,10 +24,9 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
$ROLE = check_role();
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
$list_admins = list_admins();
} else {
@ -87,7 +86,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$sth->bindParam(2, $address, PDO::PARAM_STR);
$sth->bindParam(3, $domain, PDO::PARAM_STR);
$sth->execute();
logging($admin, $domain, $LANG['Logging_alias_edit'], "$address -> $goto");
logging($SESSID_USERNAME, $domain, $LANG['Logging_alias_edit'], "$address -> $goto");
header("Location: list-virtual.php?domain=$domain");
} catch(PDOException $e) {
$message = $LANG['Edit_alias_result_error'];

View File

@ -26,10 +26,9 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
$ROLE = check_role();
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
$list_admins = list_admins();
} else {
@ -93,7 +92,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$sth->bindParam(2, $username, PDO::PARAM_STR);
$sth->bindParam(3, $domain, PDO::PARAM_STR);
$sth->execute();
logging($admin, $domain, $LANG['Logging_mailbox_edit'], $username);
logging($SESSID_USERNAME, $domain, $LANG['Logging_mailbox_edit'], $username);
header("Location: list-virtual.php?domain=$domain");
} catch(PDOException $e) {
$message = $LANG['Edit_mailbox_result_error'];

View File

@ -43,9 +43,14 @@ function check_session($session = "sessid") {
return $_SESSION[$session]['username'];
}
function check_permissions($session = "sessid") {
if (!empty($_SESSION[$session]['rights'])) {
return $_SESSION[$session]['rights'];
//
// check_role
// Action: Check which role is assighed
// Call: check_role()
//
function check_role($session = "sessid") {
if (!empty($_SESSION[$session]['role'])) {
return $_SESSION[$session]['role'];
}
}

View File

@ -20,10 +20,14 @@ $LANG['Login_login_users'] = 'Users click here to login to the user section.';
$LANG['Menu_list_domain'] = 'List Domains';
$LANG['Menu_list_virtual'] = 'List Virtuals';
$LANG['Menu_add_alias'] = 'Add Alias';
$LANG['Menu_add_mailbox'] = 'Add Mailbox';
$LANG['Menu_list_admin'] = 'List Admins';
$LANG['Menu_backup'] = 'Backup';
$LANG['Menu_add_domain'] = 'Add Domain';
$LANG['Menu_add_admin'] = 'Add Admin';
$LANG['Menu_sendmail'] = 'Send Email';
$LANG['Menu_password'] = 'Password';
$LANG['Menu_add_alias'] = 'Add Alias';
$LANG['Menu_add_mailbox'] = 'Add Mailbox';
$LANG['Menu_viewlog'] = 'View Log';
$LANG['Menu_logout'] = 'Logout';
@ -131,37 +135,11 @@ $LANG['Sendmail_button'] = 'Send Message';
$LANG['Sendmail_result_error'] = '<span class="error_msg">Unable to send message.</span>';
$LANG['Sendmail_result_succes'] = 'The mailbox has been created.';
$LANG['AdminMenu_list_domain'] = 'List Domains';
$LANG['AdminMenu_list_admin'] = 'List Admins';
$LANG['AdminMenu_viewlog'] = 'View Log';
$LANG['AdminMenu_backup'] = 'Backup';
$LANG['AdminMenu_create_domain_admins'] = 'Domain Admins';
$LANG['AdminMenu_create_domain'] = 'Add Domain';
$LANG['AdminMenu_create_admin'] = 'Add Admin';
$LANG['AdminMenu_create_alias'] = 'Add Alias';
$LANG['AdminMenu_create_mailbox'] = 'Add Mailbox';
$LANG['AdminList_admin_domain'] = 'Domain';
$LANG['AdminList_admin_username'] = 'Admin';
$LANG['AdminList_admin_count'] = 'Domains';
$LANG['AdminList_admin_modified'] = 'Last Modified';
$LANG['AdminList_domain_domain'] = 'Domain';
$LANG['AdminList_domain_description'] = 'Description';
$LANG['AdminList_domain_aliases'] = 'Aliases';
$LANG['AdminList_domain_mailboxes'] = 'Mailboxes';
$LANG['AdminList_domain_modified'] = 'Last Modified';
$LANG['AdminList_virtual_button'] = 'Go';
$LANG['AdminList_virtual_welcome'] = 'Overview for ';
$LANG['AdminList_virtual_alias_alias_count'] = 'Aliases';
$LANG['AdminList_virtual_alias_mailbox_count'] = 'Mailboxes';
$LANG['AdminList_virtual_alias_address'] = 'From';
$LANG['AdminList_virtual_alias_goto'] = 'To';
$LANG['AdminList_virtual_alias_modified'] = 'Last Modified';
$LANG['AdminList_virtual_mailbox_username'] = 'Email';
$LANG['AdminList_virtual_mailbox_name'] = 'Name';
$LANG['AdminList_virtual_mailbox_modified'] = 'Last Modified';
$LANG['AdminList_admin_active'] = 'Active';
$LANG['AdminAdd_domain_welcome'] = 'Add a new domain';
$LANG['AdminAdd_domain_domain'] = 'Domain';

View File

@ -21,18 +21,17 @@ require './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
$ROLE = check_role();
$list_admins = array();
if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_admins = list_admins();
}
}
include './templates/header.tpl';
include './templates/menu.tpl';
include './templates/admin_list-admin.tpl';
include './templates/list-admin.tpl';
include './templates/footer.tpl';
?>

View File

@ -21,11 +21,11 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$ROLE = check_role();
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$username = filter_input(INPUT_GET, 'username', FILTER_VALIDATE_EMAIL);
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_admins = list_admins();
if (empty($username)) {
$list_domains = list_domains();

View File

@ -23,9 +23,9 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$ROLE = check_role();
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
} else {
$list_domains = list_domains($SESSID_USERNAME);

View File

@ -28,7 +28,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (!empty($username) && !empty($password)) {
$dbh = pdo_connect();
$sth = $dbh->prepare("SELECT password,rights FROM admin WHERE username=?");
$sth = $dbh->prepare("SELECT password,role FROM admin WHERE username=?");
$sth->bindParam(1, $username, PDO::PARAM_STR);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
@ -45,7 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (empty($message)) {
session_start();
$_SESSION['sessid']['username'] = $username;
$_SESSION['sessid']['rights'] = $row['rights'];
$_SESSION['sessid']['role'] = $row['role'];
header("Location: list-domain.php");
exit;
}

View File

@ -23,10 +23,10 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
$ROLE = check_role();
$SESSID_USERNAME = $SESSID_USERNAME ?? ADMIN_EMAIL;
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
$list_admins = list_admins();
} else {

View File

@ -22,9 +22,9 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$ROLE = check_role();
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
} else {
$list_domains = list_domains($SESSID_USERNAME);

View File

@ -26,10 +26,10 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
$ROLE = check_role();
$SESSID_USERNAME = $SESSID_USERNAME ?? ADMIN_EMAIL;
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
$list_admins = list_admins();
} else {

22
templates/list-admin.tpl Normal file
View File

@ -0,0 +1,22 @@
<?php
if (count($list_admins) > 0) {
echo "<table id=\"admin_table\">";
echo "<tr class=\"header\">";
echo "<td>" . $LANG['AdminList_admin_username'] . "</td>";
echo "<td>" . $LANG['AdminList_admin_count'] . "</td>";
echo "<td>" . $LANG['List_modified'] . "</td>";
echo "<td colspan=\"2\">&nbsp;</td>";
echo "</tr>";
foreach ($list_admins as $row) {
echo "<tr class=\"hilightoff\" onMouseOver=\"className='hilighton';\" onMouseOut=\"className='hilightoff';\">";
echo "<td><a href=\"list-domain.php?username=" . $row['username'] . "\">" . $row['username'] . "</a></td>";
echo "<td>" . $row['domain_count'] . "</td>";
echo "<td>" . $row['modified'] . "</td>";
echo "<td><a href=\"edit-admin.php?username=" . $row['username'] . "\">" . $LANG['edit'] . "</a></td>";
echo "<td><a href=\"delete.php?table=admin&where=username&delete=" . $row['username'] . "\" onclick=\"return confirm ('" . $LANG['confirm'] . $LANG['AdminList_admin_username'] . ": " . $row['username'] . "')\">" . $LANG['del'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>

View File

@ -1,5 +1,5 @@
<div id="overview">
<?php if ($PERMISSIONS == ADMIN_RIGHTS) { ?>
<?php if ($ROLE == ADMIN_ROLE) { ?>
<form name="list_domain" method="get">
<select name="username" onChange="this.form.submit()";>
<?php
@ -27,7 +27,7 @@ if (count($list_domains) > 0) {
echo "<td>" . $LANG['List_domain_aliases'] . "</td>";
echo "<td>" . $LANG['List_domain_mailboxes'] . "</td>";
echo "<td>" . $LANG['List_modified'] . "</td>";
if ($PERMISSIONS == ADMIN_RIGHTS) echo "<td colspan=\"2\">&nbsp;</td>";
if ($ROLE == ADMIN_ROLE) echo "<td colspan=\"2\">&nbsp;</td>";
echo "</tr>";
foreach ($list_domains as $row) {
if ($row['aliases'] == 0) $row['aliases'] = $LANG['List_domain_unlimited'];
@ -38,8 +38,8 @@ if (count($list_domains) > 0) {
echo "<td>" . $row['alias_count'] . " / " . $row['aliases'] . "</td>";
echo "<td>" . $row['mailbox_count'] . " / " . $row['mailboxes'] . "</td>";
echo "<td>" . $row['modified'] . "</td>";
if ($PERMISSIONS == ADMIN_RIGHTS) echo "<td><a href=\"domain.php?action=edit&domain=" . $row['domain'] . "\">" . $LANG['edit'] . "</a></td>";
if ($PERMISSIONS == ADMIN_RIGHTS) echo "<td><a href=\"delete.php?table=domain&domain=" . $row['domain'] . "\" onclick=\"return confirm ('" . $LANG['confirm_domain'] . $LANG['List_domain_domain'] . ": " . $row['domain'] . "')\">" . $LANG['del'] . "</a></td>";
if ($ROLE == ADMIN_ROLE) echo "<td><a href=\"domain.php?action=edit&domain=" . $row['domain'] . "\">" . $LANG['edit'] . "</a></td>";
if ($ROLE == ADMIN_ROLE) echo "<td><a href=\"delete.php?table=domain&domain=" . $row['domain'] . "\" onclick=\"return confirm ('" . $LANG['confirm_domain'] . $LANG['List_domain_domain'] . ": " . $row['domain'] . "')\">" . $LANG['del'] . "</a></td>";
echo " </tr>";
}
echo "</table>";

View File

@ -3,16 +3,15 @@
<li><a target="_top" href="list-domain.php"><?php echo $LANG['Menu_list_domain']; ?></a></li>
<li><a target="_top" href="list-virtual.php"><?php echo $LANG['Menu_list_virtual']; ?></a></li>
<?php if ($PERMISSIONS == ADMIN_RIGHTS) { ?>
<li><a target="_top" href="list-admin.php"><?php echo $LANG['AdminMenu_list_admin']; ?></a></li>
<li><a target="_top" href="backup.php"><?php echo $LANG['AdminMenu_backup']; ?></a></li>
<li><a target="_top" href="domain.php"><?php echo $LANG['AdminMenu_create_domain']; ?></a></li>
<li><a target="_top" href="admin.php"><?php echo $LANG['AdminMenu_create_admin']; ?></a></li>
<?php if ($ROLE == ADMIN_ROLE) { ?>
<li><a target="_top" href="list-admin.php"><?php echo $LANG['Menu_list_admin']; ?></a></li>
<li><a target="_top" href="backup.php"><?php echo $LANG['Menu_backup']; ?></a></li>
<li><a target="_top" href="domain.php"><?php echo $LANG['Menu_add_domain']; ?></a></li>
<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>
<li><a target="_top" href="password.php"><?php echo $LANG['Menu_password']; ?></a></li>
<?php } ?>
<li><a target="_top" href="password.php"><?php echo $LANG['Menu_password']; ?></a></li>
<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>

View File

@ -21,10 +21,10 @@ require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$PERMISSIONS = check_permissions();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
$ROLE = check_role();
$SESSID_USERNAME = $SESSID_USERNAME ?? ADMIN_EMAIL;
if ($PERMISSIONS == ADMIN_RIGHTS) {
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
$list_admins = list_admins();
} else {