From 66e9833c911f5083d57cca57489ffb69a8e6a86d Mon Sep 17 00:00:00 2001 From: andryyy Date: Sun, 22 Jan 2017 16:41:45 +0100 Subject: [PATCH] More work on web UI --- data/web/add.php | 8 +- data/web/admin.php | 33 ++----- data/web/css/mailbox.css | 16 ++++ data/web/css/mailcow.css | 45 ++++++++++ data/web/css/tables.css | 79 +++++++++++++++++ data/web/delete.php | 8 +- data/web/edit.php | 16 ++-- data/web/inc/admin.inc.php | 146 +++++++++++++++++++++++++++++++ data/web/inc/functions.inc.php | 41 ++++++++- data/web/inc/header.inc.php | 152 +-------------------------------- data/web/inc/mailbox.inc.php | 24 +++++- data/web/lang/lang.en.php | 8 +- data/web/user.php | 51 ++++++----- 13 files changed, 401 insertions(+), 226 deletions(-) create mode 100644 data/web/css/mailbox.css create mode 100644 data/web/css/mailcow.css create mode 100644 data/web/css/tables.css create mode 100644 data/web/inc/admin.inc.php diff --git a/data/web/add.php b/data/web/add.php index 5d28d88b..45df8f4b 100644 --- a/data/web/add.php +++ b/data/web/add.php @@ -77,7 +77,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +

@@ -112,7 +112,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
@@ -167,7 +167,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
@@ -247,7 +247,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
diff --git a/data/web/admin.php b/data/web/admin.php index 1845bcb5..c6f78a89 100644 --- a/data/web/admin.php +++ b/data/web/admin.php @@ -13,25 +13,12 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
- prepare("SELECT `username` FROM `admin` - WHERE `superadmin`='1' and active='1'"); - $stmt->execute(); - $AdminData = $stmt->fetch(PDO::FETCH_ASSOC); - } - catch(PDOException $e) { - $_SESSION['return'] = array( - 'type' => 'danger', - 'msg' => 'MySQL: '.$e - ); - } - ?> - + +
- + a-z A-Z - _ .
@@ -124,18 +111,8 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
diff --git a/data/web/css/mailbox.css b/data/web/css/mailbox.css new file mode 100644 index 00000000..48fa5e39 --- /dev/null +++ b/data/web/css/mailbox.css @@ -0,0 +1,16 @@ +.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; +} \ No newline at end of file diff --git a/data/web/css/mailcow.css b/data/web/css/mailcow.css new file mode 100644 index 00000000..ee0b5cc6 --- /dev/null +++ b/data/web/css/mailcow.css @@ -0,0 +1,45 @@ +#maxmsgsize { min-width: 80px; } +#slider1 .slider-selection { + background: #FFD700; +} +#slider1 .slider-track-high { + background: #FF4500; +} +#slider1 .slider-track-low { + background: #66CD00; +} +.striped:nth-child(odd) { + background-color: #fff; +} +.striped:nth-child(even) { + background-color: #fafafa; + border:1px solid white; +} +.btn { + text-transform: none; +} +.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); + } +} +pre{white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word;} \ No newline at end of file diff --git a/data/web/css/tables.css b/data/web/css/tables.css new file mode 100644 index 00000000..651e1665 --- /dev/null +++ b/data/web/css/tables.css @@ -0,0 +1,79 @@ +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 } +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; +} +#data td, #no-data td { + vertical-align: middle; +} +.sort-table:hover { + border-bottom-color: #00B7DC !important; +} \ No newline at end of file diff --git a/data/web/delete.php b/data/web/delete.php index 86ac4764..5ba83e06 100644 --- a/data/web/delete.php +++ b/data/web/delete.php @@ -30,7 +30,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
@@ -49,7 +49,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm ">
- +
@@ -75,7 +75,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
@@ -118,7 +118,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
diff --git a/data/web/edit.php b/data/web/edit.php index d9f54b4f..ce54a2af 100644 --- a/data/web/edit.php +++ b/data/web/edit.php @@ -42,7 +42,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
@@ -191,7 +191,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
@@ -238,7 +238,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm if ($wl['object'] == $domain): ?> - + ">
- +
@@ -294,7 +294,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm - + ">
- +
@@ -359,7 +359,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
@@ -480,7 +480,7 @@ if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "adm
- +
diff --git a/data/web/inc/admin.inc.php b/data/web/inc/admin.inc.php new file mode 100644 index 00000000..d77d225d --- /dev/null +++ b/data/web/inc/admin.inc.php @@ -0,0 +1,146 @@ + '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)) + ); +} \ No newline at end of file diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php index cc19ffcf..4e591d2a 100644 --- a/data/web/inc/functions.inc.php +++ b/data/web/inc/functions.inc.php @@ -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) { diff --git a/data/web/inc/header.inc.php b/data/web/inc/header.inc.php index 43e1119c..e2d0c865 100644 --- a/data/web/inc/header.inc.php +++ b/data/web/inc/header.inc.php @@ -17,157 +17,11 @@ + + +' : null;?> - - - -