More work on web UI
This commit is contained in:
146
data/web/inc/admin.inc.php
Normal file
146
data/web/inc/admin.inc.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
function get_admin_details() {
|
||||
// No parameter to be given, only one admin should exist
|
||||
global $pdo;
|
||||
global $lang;
|
||||
$data = array();
|
||||
if ($_SESSION['mailcow_cc_role'] != 'admin') {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => sprintf($lang['danger']['access_denied'])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$stmt = $pdo->prepare("SELECT `username`, `modified`, `created` FROM `admin`WHERE `superadmin`='1' AND active='1'");
|
||||
$stmt->execute();
|
||||
$data = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => 'MySQL: '.$e
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
function edit_admin($postarray) {
|
||||
global $lang;
|
||||
global $pdo;
|
||||
$username = $postarray['username'];
|
||||
$password = $postarray['password'];
|
||||
$password2 = $postarray['password2'];
|
||||
isset($postarray['active']) ? $active = '1' : $active = '0';
|
||||
|
||||
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => sprintf($lang['danger']['access_denied'])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isset($postarray['domain'])) {
|
||||
foreach ($postarray['domain'] as $domain) {
|
||||
if (!is_valid_domain_name($domain)) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => sprintf($lang['danger']['domain_invalid'])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctype_alnum(str_replace(array('_', '.', '-'), '', $username))) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => sprintf($lang['danger']['username_invalid'])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM `domain_admins` WHERE `username` = :username");
|
||||
$stmt->execute(array(
|
||||
':username' => $username,
|
||||
));
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => 'MySQL: '.$e
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isset($postarray['domain'])) {
|
||||
foreach ($postarray['domain'] as $domain) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)
|
||||
VALUES (:username, :domain, :created, :active)");
|
||||
$stmt->execute(array(
|
||||
':username' => $username,
|
||||
':domain' => $domain,
|
||||
':created' => date('Y-m-d H:i:s'),
|
||||
':active' => $active
|
||||
));
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => 'MySQL: '.$e
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($password) && !empty($password2)) {
|
||||
if ($password != $password2) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => sprintf($lang['danger']['password_mismatch'])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
$password_hashed = hash_password($password);
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE `admin` SET `modified` = :modified, `active` = :active, `password` = :password_hashed WHERE `username` = :username");
|
||||
$stmt->execute(array(
|
||||
':password_hashed' => $password_hashed,
|
||||
':username' => $username,
|
||||
':modified' => date('Y-m-d H:i:s'),
|
||||
':active' => $active
|
||||
));
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => 'MySQL: '.$e
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE `admin` SET `modified` = :modified, `active` = :active WHERE `username` = :username");
|
||||
$stmt->execute(array(
|
||||
':username' => $username,
|
||||
':modified' => date('Y-m-d H:i:s'),
|
||||
':active' => $active
|
||||
));
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => 'MySQL: '.$e
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'success',
|
||||
'msg' => sprintf($lang['success']['domain_admin_modified'], htmlspecialchars($username))
|
||||
);
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
require_once 'dkim.inc.php';
|
||||
require_once 'mailbox.inc.php';
|
||||
require_once 'domainadmin.inc.php';
|
||||
require_once 'admin.inc.php';
|
||||
function hash_password($password) {
|
||||
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
|
||||
return "{SSHA256}".base64_encode(hash('sha256', $password . $salt_str, true) . $salt_str);
|
||||
@@ -433,11 +434,11 @@ function set_time_limited_aliases($postarray) {
|
||||
'msg' => sprintf($lang['success']['mailbox_modified'], htmlspecialchars($username))
|
||||
);
|
||||
break;
|
||||
case "extend":
|
||||
case "extendall":
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE `spamalias` SET `validity` = (`validity` + 3600)
|
||||
WHERE `goto` = :username
|
||||
AND `validity` >= :validity");
|
||||
$stmt = $pdo->prepare("UPDATE `spamalias` SET `validity` = (`validity` + 3600) WHERE
|
||||
`goto` = :username AND
|
||||
`validity` >= :validity");
|
||||
$stmt->execute(array(
|
||||
':username' => $username,
|
||||
':validity' => time(),
|
||||
@@ -455,6 +456,38 @@ function set_time_limited_aliases($postarray) {
|
||||
'msg' => sprintf($lang['success']['mailbox_modified'], htmlspecialchars($username))
|
||||
);
|
||||
break;
|
||||
case "extend":
|
||||
if (empty($postarray['item']) || !filter_var($postarray['item'], FILTER_VALIDATE_EMAIL)) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => sprintf($lang['danger']['access_denied'])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
$item = $postarray['item'];
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE `spamalias` SET `validity` = (`validity` + 3600) WHERE
|
||||
`goto` = :username AND
|
||||
`address` = :item AND
|
||||
`validity` >= :validity");
|
||||
$stmt->execute(array(
|
||||
':username' => $username,
|
||||
':item' => $item,
|
||||
':validity' => time(),
|
||||
));
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'danger',
|
||||
'msg' => 'MySQL: '.$e
|
||||
);
|
||||
return false;
|
||||
}
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'success',
|
||||
'msg' => sprintf($lang['success']['mailbox_modified'], htmlspecialchars($username))
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
function get_time_limited_aliases($username = null) {
|
||||
|
@@ -17,157 +17,11 @@
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap3/bootstrap-switch.min.css">
|
||||
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,700&subset=latin,latin-ext">
|
||||
<link rel="stylesheet" href="/inc/languages.min.css">
|
||||
<link rel="stylesheet" href="/css/mailcow.css">
|
||||
<link rel="stylesheet" href="/css/tables.css">
|
||||
<?=(preg_match("/mailbox.php/i", $_SERVER['REQUEST_URI'])) ? '<link rel="stylesheet" href="/css/mailbox.css">' : null;?>
|
||||
<link rel="shortcut icon" href="/favicon.png" type="image/png">
|
||||
<link rel="icon" href="/favicon.png" type="image/png">
|
||||
<style>
|
||||
#maxmsgsize { min-width: 80px; }
|
||||
ul[id*="sortable"] { word-wrap: break-word; list-style-type: none; float: left; padding: 0 15px 0 0; width: 48%; cursor:move}
|
||||
ul[id$="sortable-active"] li {cursor:move; }
|
||||
ul[id$="sortable-inactive"] li {cursor:move }
|
||||
.list-heading { cursor:default !important}
|
||||
.ui-state-disabled { cursor:no-drop; color:#ccc; }
|
||||
.ui-state-highlight {background: #F5F5F5 !important; height: 41px !important; cursor:move }
|
||||
#slider1 .slider-selection {
|
||||
background: #FFD700;
|
||||
}
|
||||
#slider1 .slider-track-high {
|
||||
background: #FF4500;
|
||||
}
|
||||
#slider1 .slider-track-low {
|
||||
background: #66CD00;
|
||||
}
|
||||
table[data-sortable] {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
table[data-sortable] th {
|
||||
vertical-align: bottom;
|
||||
font-weight: bold;
|
||||
}
|
||||
table[data-sortable] th, table[data-sortable] td {
|
||||
text-align: left;
|
||||
padding: 10px;
|
||||
}
|
||||
table[data-sortable] th:not([data-sortable="false"]) {
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
-o-user-select: none;
|
||||
user-select: none;
|
||||
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
||||
-webkit-touch-callout: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
table[data-sortable] th:after {
|
||||
content: "";
|
||||
visibility: hidden;
|
||||
display: inline-block;
|
||||
vertical-align: inherit;
|
||||
height: 0;
|
||||
width: 0;
|
||||
border-width: 5px;
|
||||
border-style: solid;
|
||||
border-color: transparent;
|
||||
margin-right: 1px;
|
||||
margin-left: 10px;
|
||||
float: right;
|
||||
}
|
||||
table[data-sortable] th[data-sortable="false"]:after {
|
||||
display: none;
|
||||
}
|
||||
table[data-sortable] th[data-sorted="true"]:after {
|
||||
visibility: visible;
|
||||
}
|
||||
table[data-sortable] th[data-sorted-direction="descending"]:after {
|
||||
border-top-color: inherit;
|
||||
margin-top: 8px;
|
||||
}
|
||||
table[data-sortable] th[data-sorted-direction="ascending"]:after {
|
||||
border-bottom-color: inherit;
|
||||
margin-top: 3px;
|
||||
}
|
||||
table[data-sortable].sortable-theme-bootstrap thead th {
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
}
|
||||
table[data-sortable].sortable-theme-bootstrap th[data-sorted="true"] {
|
||||
color: #3a87ad;
|
||||
background: #d9edf7;
|
||||
border-bottom-color: #bce8f1;
|
||||
}
|
||||
table[data-sortable].sortable-theme-bootstrap th[data-sorted="true"][data-sorted-direction="descending"]:after {
|
||||
border-top-color: #3a87ad;
|
||||
}
|
||||
table[data-sortable].sortable-theme-bootstrap th[data-sorted="true"][data-sorted-direction="ascending"]:after {
|
||||
border-bottom-color: #3a87ad;
|
||||
}
|
||||
table[data-sortable].sortable-theme-bootstrap.sortable-theme-bootstrap-striped tbody > tr:nth-child(odd) > td {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.btn {
|
||||
text-transform: none;
|
||||
}
|
||||
#data td, #no-data td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
.sort-table:hover {
|
||||
border-bottom-color: #00B7DC !important;
|
||||
}
|
||||
.striped:nth-child(odd) {
|
||||
background-color: #fff;
|
||||
}
|
||||
.striped:nth-child(even) {
|
||||
background-color: #fafafa;
|
||||
border:1px solid white;
|
||||
}
|
||||
.glyphicon-spin {
|
||||
-webkit-animation: spin 1000ms infinite linear;
|
||||
animation: spin 1000ms infinite linear;
|
||||
}
|
||||
@-webkit-keyframes spin {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(359deg);
|
||||
transform: rotate(359deg);
|
||||
}
|
||||
}
|
||||
@keyframes spin {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(359deg);
|
||||
transform: rotate(359deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
if (preg_match("/mailbox.php/i", $_SERVER['REQUEST_URI'])):
|
||||
?>
|
||||
<style>
|
||||
.panel-heading div {
|
||||
margin-top: -18px;
|
||||
font-size: 15px;
|
||||
}
|
||||
.panel-heading div span {
|
||||
margin-left:5px;
|
||||
}
|
||||
.panel-body {
|
||||
display: none;
|
||||
}
|
||||
.clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
.progress {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</head>
|
||||
<body style="padding-top:70px">
|
||||
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
|
||||
|
@@ -671,9 +671,14 @@ function mailbox_edit_alias_domain($postarray) {
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE `alias_domain` SET `alias_domain` = :alias_domain, `active` = :active WHERE `alias_domain` = :alias_domain_now");
|
||||
$stmt = $pdo->prepare("UPDATE `alias_domain` SET
|
||||
`alias_domain` = :alias_domain,
|
||||
`active` = :active,
|
||||
`modified` = :modified,
|
||||
WHERE `alias_domain` = :alias_domain_now");
|
||||
$stmt->execute(array(
|
||||
':alias_domain' => $alias_domain,
|
||||
':modified' => date('Y-m-d H:i:s'),
|
||||
':alias_domain_now' => $alias_domain_now,
|
||||
':active' => $active
|
||||
));
|
||||
@@ -747,11 +752,16 @@ function mailbox_edit_alias($postarray) {
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE `alias` SET `goto` = :goto, `active`= :active WHERE `address` = :address");
|
||||
$stmt = $pdo->prepare("UPDATE `alias` SET
|
||||
`goto` = :goto,
|
||||
`active`= :active,
|
||||
`modified` = :modified,
|
||||
WHERE `address` = :address");
|
||||
$stmt->execute(array(
|
||||
':goto' => $goto,
|
||||
':active' => $active,
|
||||
':address' => $address
|
||||
':address' => $address,
|
||||
':modified' => date('Y-m-d H:i:s'),
|
||||
));
|
||||
$_SESSION['return'] = array(
|
||||
'type' => 'success',
|
||||
@@ -903,6 +913,7 @@ function mailbox_edit_domain($postarray) {
|
||||
`active` = :active,
|
||||
`quota` = :quota,
|
||||
`maxquota` = :maxquota,
|
||||
`modified` = :modified,
|
||||
`mailboxes` = :mailboxes,
|
||||
`aliases` = :aliases,
|
||||
`description` = :description
|
||||
@@ -913,6 +924,7 @@ function mailbox_edit_domain($postarray) {
|
||||
':active' => $active,
|
||||
':quota' => $quota,
|
||||
':maxquota' => $maxquota,
|
||||
':modified' => date('Y-m-d H:i:s'),
|
||||
':mailboxes' => $mailboxes,
|
||||
':aliases' => $aliases,
|
||||
':modified' => date('Y-m-d H:i:s'),
|
||||
@@ -1856,9 +1868,13 @@ function mailbox_delete_mailbox($postarray) {
|
||||
unset($goto_exploded[$key]);
|
||||
}
|
||||
$gotos_rebuild = implode(',', $goto_exploded);
|
||||
$stmt = $pdo->prepare("UPDATE `alias` SET `goto` = :goto WHERE `address` = :address");
|
||||
$stmt = $pdo->prepare("UPDATE `alias` SET
|
||||
`goto` = :goto,
|
||||
`modified` = :modified,
|
||||
WHERE `address` = :address");
|
||||
$stmt->execute(array(
|
||||
':goto' => $gotos_rebuild,
|
||||
':modified' => date('Y-m-d H:i:s'),
|
||||
':address' => $gotos['address']
|
||||
));
|
||||
}
|
||||
|
Reference in New Issue
Block a user