2017-07-16 17:03:28 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function domain_admin($_action, $_data = null) {
|
|
|
|
global $pdo;
|
|
|
|
global $lang;
|
2018-08-04 02:31:33 +08:00
|
|
|
$_data_log = $_data;
|
|
|
|
!isset($_data_log['password']) ?: $_data_log['password'] = '*';
|
|
|
|
!isset($_data_log['password2']) ?: $_data_log['password2'] = '*';
|
2017-07-16 17:03:28 +08:00
|
|
|
switch ($_action) {
|
|
|
|
case 'add':
|
|
|
|
$username = strtolower(trim($_data['username']));
|
|
|
|
$password = $_data['password'];
|
|
|
|
$password2 = $_data['password2'];
|
|
|
|
$domains = (array)$_data['domains'];
|
|
|
|
$active = intval($_data['active']);
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (empty($domains)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'domain_invalid'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!ctype_alnum(str_replace(array('_', '.', '-'), '', $username)) || empty ($username)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'username_invalid'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
|
|
|
|
$stmt = $pdo->prepare("SELECT `username` FROM `mailbox`
|
|
|
|
WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(':username' => $username));
|
|
|
|
$num_results[] = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
|
|
|
|
|
|
$stmt = $pdo->prepare("SELECT `username` FROM `admin`
|
|
|
|
WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(':username' => $username));
|
|
|
|
$num_results[] = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
|
|
|
|
|
|
$stmt = $pdo->prepare("SELECT `username` FROM `domain_admins`
|
|
|
|
WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(':username' => $username));
|
|
|
|
$num_results[] = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
|
|
|
2017-07-16 17:03:28 +08:00
|
|
|
foreach ($num_results as $num_results_each) {
|
|
|
|
if ($num_results_each != 0) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('object_exists', htmlspecialchars($username))
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($password) && !empty($password2)) {
|
|
|
|
if (!preg_match('/' . $GLOBALS['PASSWD_REGEP'] . '/', $password)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'password_complexity'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($password != $password2) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'password_mismatch'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$password_hashed = hash_password($password);
|
|
|
|
foreach ($domains as $domain) {
|
|
|
|
if (!is_valid_domain_name($domain)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'domain_invalid'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)
|
|
|
|
VALUES (:username, :domain, :created, :active)");
|
2017-07-16 17:03:28 +08:00
|
|
|
$stmt->execute(array(
|
|
|
|
':username' => $username,
|
2018-09-10 03:17:59 +08:00
|
|
|
':domain' => $domain,
|
|
|
|
':created' => date('Y-m-d H:i:s'),
|
2017-07-16 17:03:28 +08:00
|
|
|
':active' => $active
|
|
|
|
));
|
|
|
|
}
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("INSERT INTO `admin` (`username`, `password`, `superadmin`, `active`)
|
|
|
|
VALUES (:username, :password_hashed, '0', :active)");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':username' => $username,
|
|
|
|
':password_hashed' => $password_hashed,
|
|
|
|
':active' => $active
|
|
|
|
));
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
else {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'password_empty'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("INSERT INTO `da_acl` (`username`) VALUES (:username)");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':username' => $username
|
|
|
|
));
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'success',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('domain_admin_added', htmlspecialchars($username))
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin" && $_SESSION['mailcow_cc_role'] != "domainadmin") {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Administrator
|
|
|
|
if ($_SESSION['mailcow_cc_role'] == "admin") {
|
|
|
|
if (!is_array($_data['username'])) {
|
|
|
|
$usernames = array();
|
|
|
|
$usernames[] = $_data['username'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$usernames = $_data['username'];
|
|
|
|
}
|
|
|
|
foreach ($usernames as $username) {
|
|
|
|
$is_now = domain_admin('details', $username);
|
|
|
|
$domains = (isset($_data['domains'])) ? (array)$_data['domains'] : null;
|
|
|
|
if (!empty($is_now)) {
|
|
|
|
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int'];
|
|
|
|
$domains = (!empty($domains)) ? $domains : $is_now['selected_domains'];
|
|
|
|
$username_new = (!empty($_data['username_new'])) ? $_data['username_new'] : $is_now['username'];
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
2018-08-14 05:20:40 +08:00
|
|
|
continue;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
$password = $_data['password'];
|
|
|
|
$password2 = $_data['password2'];
|
|
|
|
if (!empty($domains)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
foreach ($domains as $i => &$domain) {
|
2017-07-16 17:03:28 +08:00
|
|
|
if (!is_valid_domain_name($domain)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
2018-08-14 05:20:40 +08:00
|
|
|
'msg' => array('domain_invalid', htmlspecialchars($domain))
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
2018-08-14 05:20:40 +08:00
|
|
|
unset($domains[$i]);
|
|
|
|
continue;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ctype_alnum(str_replace(array('_', '.', '-'), '', $username_new))) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
2018-08-14 05:20:40 +08:00
|
|
|
'msg' => array('username_invalid', $username_new)
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
2018-08-14 05:20:40 +08:00
|
|
|
continue;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
if ($username_new != $username) {
|
|
|
|
if (!empty(domain_admin('details', $username_new)['username'])) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
2018-08-14 05:20:40 +08:00
|
|
|
'msg' => array('username_invalid', $username_new)
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
2018-08-14 05:20:40 +08:00
|
|
|
continue;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("DELETE FROM `domain_admins` WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':username' => $username,
|
|
|
|
));
|
2017-07-16 17:03:28 +08:00
|
|
|
if (!empty($domains)) {
|
|
|
|
foreach ($domains as $domain) {
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)
|
|
|
|
VALUES (:username_new, :domain, :created, :active)");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':username_new' => $username_new,
|
|
|
|
':domain' => $domain,
|
|
|
|
':created' => date('Y-m-d H:i:s'),
|
|
|
|
':active' => $active
|
|
|
|
));
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($password) && !empty($password2)) {
|
|
|
|
if (!preg_match('/' . $GLOBALS['PASSWD_REGEP'] . '/', $password)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'password_complexity'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
2018-08-14 05:20:40 +08:00
|
|
|
continue;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
if ($password != $password2) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'password_mismatch'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
2018-08-14 05:20:40 +08:00
|
|
|
continue;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
$password_hashed = hash_password($password);
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("UPDATE `admin` SET `username` = :username_new, `active` = :active, `password` = :password_hashed WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':password_hashed' => $password_hashed,
|
|
|
|
':username_new' => $username_new,
|
|
|
|
':username' => $username,
|
|
|
|
':active' => $active
|
|
|
|
));
|
|
|
|
if (isset($_data['disable_tfa'])) {
|
|
|
|
$stmt = $pdo->prepare("UPDATE `tfa` SET `active` = '0' WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(':username' => $username));
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
2018-09-10 03:17:59 +08:00
|
|
|
else {
|
|
|
|
$stmt = $pdo->prepare("UPDATE `tfa` SET `username` = :username_new WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(':username_new' => $username_new, ':username' => $username));
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("UPDATE `admin` SET `username` = :username_new, `active` = :active WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':username_new' => $username_new,
|
|
|
|
':username' => $username,
|
|
|
|
':active' => $active
|
|
|
|
));
|
|
|
|
if (isset($_data['disable_tfa'])) {
|
|
|
|
$stmt = $pdo->prepare("UPDATE `tfa` SET `active` = '0' WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(':username' => $username));
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
2018-09-10 03:17:59 +08:00
|
|
|
else {
|
|
|
|
$stmt = $pdo->prepare("UPDATE `tfa` SET `username` = :username_new WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(':username_new' => $username_new, ':username' => $username));
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'success',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('domain_admin_modified', htmlspecialchars($username))
|
|
|
|
);
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
return true;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
// Domain administrator
|
|
|
|
// Can only edit itself
|
|
|
|
elseif ($_SESSION['mailcow_cc_role'] == "domainadmin") {
|
|
|
|
$username = $_SESSION['mailcow_cc_username'];
|
|
|
|
$password_old = $_data['user_old_pass'];
|
|
|
|
$password_new = $_data['user_new_pass'];
|
|
|
|
$password_new2 = $_data['user_new_pass2'];
|
|
|
|
|
|
|
|
$stmt = $pdo->prepare("SELECT `password` FROM `admin`
|
|
|
|
WHERE `username` = :user");
|
|
|
|
$stmt->execute(array(':user' => $username));
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
2018-08-14 05:20:40 +08:00
|
|
|
|
2018-07-12 06:24:23 +08:00
|
|
|
if (!verify_hash($row['password'], $password_old)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($password_new2) && !empty($password_new)) {
|
|
|
|
if ($password_new2 != $password_new) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'password_mismatch'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!preg_match('/' . $GLOBALS['PASSWD_REGEP'] . '/', $password_new)) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'password_complexity'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$password_hashed = hash_password($password_new);
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("UPDATE `admin` SET `password` = :password_hashed WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':password_hashed' => $password_hashed,
|
|
|
|
':username' => $username
|
|
|
|
));
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'success',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('domain_admin_modified', htmlspecialchars($username))
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$usernames = (array)$_data['username'];
|
|
|
|
foreach ($usernames as $username) {
|
|
|
|
if (!ctype_alnum(str_replace(array('_', '.', '-'), '', $username))) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
2018-08-14 05:20:40 +08:00
|
|
|
'msg' => array('username_invalid', $username)
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
2018-08-14 05:20:40 +08:00
|
|
|
continue;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
2018-09-10 03:17:59 +08:00
|
|
|
$stmt = $pdo->prepare("DELETE FROM `domain_admins` WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':username' => $username,
|
|
|
|
));
|
|
|
|
$stmt = $pdo->prepare("DELETE FROM `admin` WHERE `username` = :username");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':username' => $username,
|
|
|
|
));
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'success',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('domain_admin_removed', htmlspecialchars($username))
|
|
|
|
);
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'get':
|
|
|
|
$domainadmins = array();
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-07-16 17:03:28 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2017-07-16 17:03:28 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
|
|
|
|
$stmt = $pdo->query("SELECT DISTINCT
|
|
|
|
`username`
|
|
|
|
FROM `domain_admins`
|
|
|
|
WHERE `username` IN (
|
|
|
|
SELECT `username` FROM `admin`
|
|
|
|
WHERE `superadmin`!='1'
|
|
|
|
)");
|
|
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
while ($row = array_shift($rows)) {
|
|
|
|
$domainadmins[] = $row['username'];
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
|
2017-07-16 17:03:28 +08:00
|
|
|
return $domainadmins;
|
|
|
|
break;
|
|
|
|
case 'details':
|
|
|
|
$domainadmindata = array();
|
|
|
|
|
|
|
|
if ($_SESSION['mailcow_cc_role'] == "domainadmin" && $_data != $_SESSION['mailcow_cc_username']) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
elseif ($_SESSION['mailcow_cc_role'] != "admin" || !isset($_data)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ctype_alnum(str_replace(array('_', '.', '-'), '', $_data))) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
|
|
|
|
$stmt = $pdo->prepare("SELECT
|
|
|
|
`tfa`.`active` AS `tfa_active_int`,
|
|
|
|
CASE `tfa`.`active` WHEN 1 THEN '".$lang['mailbox']['yes']."' ELSE '".$lang['mailbox']['no']."' END AS `tfa_active`,
|
|
|
|
`domain_admins`.`username`,
|
|
|
|
`domain_admins`.`created`,
|
|
|
|
`domain_admins`.`active` AS `active_int`,
|
|
|
|
CASE `domain_admins`.`active` WHEN 1 THEN '".$lang['mailbox']['yes']."' ELSE '".$lang['mailbox']['no']."' END AS `active`
|
|
|
|
FROM `domain_admins`
|
|
|
|
LEFT OUTER JOIN `tfa` ON `tfa`.`username`=`domain_admins`.`username`
|
|
|
|
WHERE `domain_admins`.`username`= :domain_admin");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':domain_admin' => $_data
|
|
|
|
));
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (empty($row)) {
|
|
|
|
return false;
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
$domainadmindata['username'] = $row['username'];
|
|
|
|
$domainadmindata['tfa_active'] = $row['tfa_active'];
|
|
|
|
$domainadmindata['active'] = $row['active'];
|
|
|
|
$domainadmindata['tfa_active_int'] = $row['tfa_active_int'];
|
|
|
|
$domainadmindata['active_int'] = $row['active_int'];
|
|
|
|
$domainadmindata['modified'] = $row['created'];
|
|
|
|
// GET SELECTED
|
|
|
|
$stmt = $pdo->prepare("SELECT `domain` FROM `domain`
|
|
|
|
WHERE `domain` IN (
|
|
|
|
SELECT `domain` FROM `domain_admins`
|
|
|
|
WHERE `username`= :domain_admin)");
|
|
|
|
$stmt->execute(array(':domain_admin' => $_data));
|
|
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
while($row = array_shift($rows)) {
|
|
|
|
$domainadmindata['selected_domains'][] = $row['domain'];
|
2017-07-16 17:03:28 +08:00
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
// GET UNSELECTED
|
|
|
|
$stmt = $pdo->prepare("SELECT `domain` FROM `domain`
|
|
|
|
WHERE `domain` NOT IN (
|
|
|
|
SELECT `domain` FROM `domain_admins`
|
|
|
|
WHERE `username`= :domain_admin)");
|
|
|
|
$stmt->execute(array(':domain_admin' => $_data));
|
|
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
while($row = array_shift($rows)) {
|
|
|
|
$domainadmindata['unselected_domains'][] = $row['domain'];
|
|
|
|
}
|
|
|
|
if (!isset($domainadmindata['unselected_domains'])) {
|
|
|
|
$domainadmindata['unselected_domains'] = "";
|
|
|
|
}
|
|
|
|
|
2017-07-16 17:03:28 +08:00
|
|
|
return $domainadmindata;
|
|
|
|
break;
|
|
|
|
}
|
2018-07-12 06:24:23 +08:00
|
|
|
}
|