impl mailcow git support
This commit is contained in:
parent
385a7a5302
commit
4fd6bfddd6
23 changed files with 238 additions and 83 deletions
|
|
@ -9,25 +9,52 @@ function check_login($user, $pass, $app_passwd_data = false, $extra = null) {
|
|||
// Try validate admin
|
||||
if (!isset($role) || $role == "admin") {
|
||||
$result = admin_login($user, $pass);
|
||||
if ($result !== false) return $result;
|
||||
if ($result !== false){
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Try validate domain admin
|
||||
if (!isset($role) || $role == "domain_admin") {
|
||||
$result = domainadmin_login($user, $pass);
|
||||
if ($result !== false) return $result;
|
||||
if ($result !== false) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Try validate app password
|
||||
if (!isset($role) || $role == "app") {
|
||||
$result = apppass_login($user, $pass, $app_passwd_data);
|
||||
if ($result !== false) {
|
||||
if ($app_passwd_data['eas'] === true) {
|
||||
$service = 'EAS';
|
||||
} elseif ($app_passwd_data['dav'] === true) {
|
||||
$service = 'DAV';
|
||||
} else {
|
||||
$service = 'NONE';
|
||||
}
|
||||
$real_rip = ($_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['REMOTE_ADDR']);
|
||||
set_sasl_log($user, $real_rip, $service, $pass);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Try validate user
|
||||
if (!isset($role) || $role == "user") {
|
||||
$result = user_login($user, $pass);
|
||||
if ($result !== false) return $result;
|
||||
}
|
||||
|
||||
// Try validate app password
|
||||
if (!isset($role) || $role == "app") {
|
||||
$result = apppass_login($user, $pass, $app_passwd_data);
|
||||
if ($result !== false) return $result;
|
||||
if ($result !== false) {
|
||||
if ($app_passwd_data['eas'] === true) {
|
||||
$service = 'EAS';
|
||||
} elseif ($app_passwd_data['dav'] === true) {
|
||||
$service = 'DAV';
|
||||
} else {
|
||||
$service = 'MAILCOWUI';
|
||||
}
|
||||
$real_rip = ($_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['REMOTE_ADDR']);
|
||||
set_sasl_log($user, $real_rip, $service);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// skip log and only return false if it's an internal request
|
||||
|
|
@ -415,21 +442,7 @@ function apppass_login($user, $pass, $app_passwd_data, $extra = null){
|
|||
|
||||
// verify password
|
||||
if (verify_hash($row['password'], $pass) !== false) {
|
||||
if ($is_internal){
|
||||
$remote_addr = $extra['remote_addr'];
|
||||
} else {
|
||||
$remote_addr = ($_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
|
||||
$service = strtoupper($is_app_passwd);
|
||||
$stmt = $pdo->prepare("REPLACE INTO sasl_log (`service`, `app_password`, `username`, `real_rip`) VALUES (:service, :app_id, :username, :remote_addr)");
|
||||
$stmt->execute(array(
|
||||
':service' => $service,
|
||||
':app_id' => $row['app_passwd_id'],
|
||||
':username' => $user,
|
||||
':remote_addr' => $remote_addr
|
||||
));
|
||||
|
||||
$_SESSION['app_passwd_id'] = $row['app_passwd_id'];
|
||||
unset($_SESSION['ldelay']);
|
||||
return "user";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -350,6 +350,34 @@ function last_login($action, $username, $sasl_limit_days = 7, $ui_offset = 1) {
|
|||
}
|
||||
|
||||
}
|
||||
function set_sasl_log($username, $real_rip, $service){
|
||||
global $pdo;
|
||||
|
||||
try {
|
||||
if (!empty($_SESSION['app_passwd_id'])) {
|
||||
$app_password = $_SESSION['app_passwd_id'];
|
||||
} else {
|
||||
$app_password = 0;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare('REPLACE INTO `sasl_log` (`username`, `real_rip`, `service`, `app_password`) VALUES (:username, :real_rip, :service, :app_password)');
|
||||
$stmt->execute(array(
|
||||
':username' => $username,
|
||||
':real_rip' => $real_rip,
|
||||
':service' => $service,
|
||||
':app_password' => $app_password
|
||||
));
|
||||
} catch (PDOException $e) {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'danger',
|
||||
'log' => array(__FUNCTION__, $_data_log),
|
||||
'msg' => array('mysql_error', $e)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
function flush_memcached() {
|
||||
try {
|
||||
$m = new Memcached();
|
||||
|
|
|
|||
|
|
@ -681,7 +681,7 @@ jQuery(function($){
|
|||
$(this).html('<div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div> ');
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'inc/ajax/transport_check.php',
|
||||
url: '/inc/ajax/transport_check.php',
|
||||
dataType: 'text',
|
||||
data: $('#test_transport_form').serialize(),
|
||||
complete: function (data) {
|
||||
|
|
|
|||
|
|
@ -90,13 +90,7 @@ jQuery(function($){
|
|||
console.log('error reading last logins');
|
||||
},
|
||||
success: function (data) {
|
||||
$('.last-ui-login').html('');
|
||||
$('.last-sasl-login').html('');
|
||||
if (data.ui.time) {
|
||||
$('.last-ui-login').html('<i class="bi bi-person-fill"></i> ' + lang.last_ui_login + ': ' + unix_time_format(data.ui.time));
|
||||
} else {
|
||||
$('.last-ui-login').text(lang.no_last_login);
|
||||
}
|
||||
if (data.sasl) {
|
||||
$('.last-sasl-login').append('<ul class="list-group">');
|
||||
$.each(data.sasl, function (i, item) {
|
||||
|
|
|
|||
|
|
@ -238,7 +238,9 @@
|
|||
"iam_username_field": "Username Feld",
|
||||
"iam_binddn": "Bind DN",
|
||||
"iam_use_ssl": "Benutze SSL",
|
||||
"iam_use_tls": "Benutze TLS",
|
||||
"iam_use_ssl_info": "Wenn SSL aktiviert ist und der Port auf 389 gesetzt wurde, wird dieser automatisch auf 636 geändert.",
|
||||
"iam_use_tls": "Benutze StartTLS",
|
||||
"iam_use_tls_info": "Wenn TLS aktiviert wird, muss der Standardport deines LDAP-Servers (389) verwendet werden. SSL-Ports können dabei nicht verwendet werden.",
|
||||
"iam_version": "Version",
|
||||
"ignore_ssl_error": "Ignoriere SSL Fehler",
|
||||
"import": "Importieren",
|
||||
|
|
@ -1333,7 +1335,7 @@
|
|||
"tag_in_subfolder": "In Unterordner",
|
||||
"tag_in_subject": "In Betreff",
|
||||
"text": "Text",
|
||||
"tfa_info": "Zwei-Faktor-Authentifizierung hilft dabei, Ihr Konto zu schützen. Wenn Sie sie aktivieren, benötigen Sie möglicherweise App-Passwörter, um sich bei Apps oder Diensten anzumelden, die die Zwei-Faktor-Authentifizierung nicht unterstützen (z.B. Mailclients).",
|
||||
"tfa_info": "Zwei-Faktor-Authentifizierung hilft dabei, Ihr Konto zu schützen. Wenn Sie sie aktivieren, benötigen Sie App-Passwörter, um sich bei Apps oder Diensten anzumelden, die die Zwei-Faktor-Authentifizierung nicht unterstützen (z.B. Mailclients).",
|
||||
"title": "Title",
|
||||
"tls_enforce_in": "TLS eingehend erzwingen",
|
||||
"tls_enforce_out": "TLS ausgehend erzwingen",
|
||||
|
|
|
|||
|
|
@ -245,7 +245,9 @@
|
|||
"iam_username_field": "Username Field",
|
||||
"iam_binddn": "Bind DN",
|
||||
"iam_use_ssl": "Use SSL",
|
||||
"iam_use_tls": "Use TLS",
|
||||
"iam_use_ssl_info": "If enabling SSL, and port is set to 389, it will be automatically overridden to use 636.",
|
||||
"iam_use_tls": "Use StartTLS",
|
||||
"iam_use_tls_info": "If enabling TLS, you must use the default port for your LDAP server (389). SSL ports cannot be used.",
|
||||
"iam_version": "Version",
|
||||
"ignore_ssl_error": "Ignore SSL Errors",
|
||||
"import": "Import",
|
||||
|
|
@ -1355,7 +1357,7 @@
|
|||
"tag_in_subfolder": "In subfolder",
|
||||
"tag_in_subject": "In subject",
|
||||
"text": "Text",
|
||||
"tfa_info": "Two-factor authentication helps protect your account. If you enable it, you may need app passwords to log in to apps or services that don't support two-factor authentication (e.g. Mailclients).",
|
||||
"tfa_info": "Two-factor authentication helps protect your account. If you enable it, you need app passwords to log in to apps or services that don't support two-factor authentication (e.g. Mailclients).",
|
||||
"title": "Title",
|
||||
"tls_enforce_in": "Enforce TLS incoming",
|
||||
"tls_enforce_out": "Enforce TLS outgoing",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/triggers.user.inc.php';
|
||||
|
||||
if (isset($_SESSION['mailcow_cc_role']) && $_SESSION['mailcow_cc_role'] == 'admin') {
|
||||
header('Location: /admin/dashboard');
|
||||
|
|
|
|||
|
|
@ -392,11 +392,11 @@
|
|||
<input type="hidden" name="authsource" value="ldap">
|
||||
<div class="row mb-2">
|
||||
<div class="col-md-3 d-flex align-items-center justify-content-md-end">
|
||||
<i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill m-2 ms-0" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_host_info }}"></i>
|
||||
<i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill mx-2 ms-0" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_host_info }}"></i>
|
||||
<label class="control-label" for="iam_ldap_host">{{ lang.admin.iam_host }}:</label>
|
||||
</div>
|
||||
<div class="col-12 col-md-9 col-lg-4 d-flex">
|
||||
<input type="text" class="form-control" id="iam_ldap_host" name="host" value="{{ iam_settings.host }}" required>
|
||||
<input type="text" class="form-control" id="iam_ldap_host" name="host" value="{{ iam_settings.host }}" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-2">
|
||||
|
|
@ -409,21 +409,37 @@
|
|||
</div>
|
||||
<div class="row mb-2">
|
||||
<div class="col-md-3 d-flex align-items-center justify-content-md-end">
|
||||
<i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill mx-2 ms-0" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_use_ssl_info }}"></i>
|
||||
<label class="control-label">{{ lang.admin.iam_use_ssl }}</label>
|
||||
</div>
|
||||
<div class="col-12 col-md-9">
|
||||
<div class="col-12 col-md-9 d-flex align-items-center">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="use_ssl" value="1" {% if iam_settings.use_ssl == 1 %}checked{% endif %}>
|
||||
<input class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="use_ssl"
|
||||
name="use_ssl"
|
||||
value="1"
|
||||
onchange="if(this.checked) document.getElementById('use_tls').checked = false"
|
||||
{% if iam_settings.use_ssl == 1 %}checked{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-2">
|
||||
<div class="col-md-3 d-flex align-items-center justify-content-md-end">
|
||||
<i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill mx-2 ms-0" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_use_tls_info }}"></i>
|
||||
<label class="control-label">{{ lang.admin.iam_use_tls }}</label>
|
||||
</div>
|
||||
<div class="col-12 col-md-9">
|
||||
<div class="col-12 col-md-9 d-flex align-items-center">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="use_tls" value="1" {% if iam_settings.use_tls == 1 %}checked{% endif %}>
|
||||
<input class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="use_tls"
|
||||
name="use_tls"
|
||||
value="1"
|
||||
onchange="if(this.checked) document.getElementById('use_ssl').checked = false"
|
||||
{% if iam_settings.use_tls == 1 %}checked{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="ms-auto col-xl-3 col-lg-5 col-md-12 col-12 d-flex flex-column well flex-grow-1">
|
||||
<div class="ms-auto col-xl-3 col-lg-5 col-md-12 col-12 d-flex flex-column well flex-grow-1" id="recent-logins">
|
||||
<legend class="d-flex">
|
||||
<span>{{ lang.user.recent_successful_connections }}</span>
|
||||
<div id="spinner-last-login" class="ms-auto my-auto spinner-border spinner-border-sm d-none" role="status">
|
||||
|
|
@ -192,7 +192,6 @@
|
|||
</div>
|
||||
</legend>
|
||||
<hr>
|
||||
<h6 class="last-ui-login"></h6>
|
||||
<div class="d-flex">
|
||||
<span class="clear-last-logins mt-auto mb-2">
|
||||
{{ lang.user.clear_recent_successful_connections }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue