2017-05-07 13:38:31 +02:00
|
|
|
<?php
|
|
|
|
// Start session
|
|
|
|
ini_set("session.cookie_httponly", 1);
|
2017-07-16 11:03:28 +02:00
|
|
|
ini_set('session.gc_maxlifetime', $SESSION_LIFETIME);
|
|
|
|
|
2017-05-07 13:38:31 +02:00
|
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
|
|
|
|
strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == "https") {
|
|
|
|
ini_set("session.cookie_secure", 1);
|
|
|
|
$IS_HTTPS = true;
|
|
|
|
}
|
|
|
|
elseif (isset($_SERVER['HTTPS'])) {
|
|
|
|
ini_set("session.cookie_secure", 1);
|
|
|
|
$IS_HTTPS = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$IS_HTTPS = false;
|
|
|
|
}
|
2017-07-29 10:32:17 +02:00
|
|
|
// session_set_cookie_params($SESSION_LIFETIME, '/', '', $IS_HTTPS, true);
|
2017-05-07 13:38:31 +02:00
|
|
|
session_start();
|
2017-05-15 11:37:12 +02:00
|
|
|
if (!isset($_SESSION['CSRF']['TOKEN'])) {
|
|
|
|
$_SESSION['CSRF']['TOKEN'] = bin2hex(random_bytes(32));
|
2017-05-07 13:38:31 +02:00
|
|
|
}
|
|
|
|
|
2017-05-18 19:45:41 +02:00
|
|
|
// Set session UA
|
2017-05-07 13:38:31 +02:00
|
|
|
if (!isset($_SESSION['SESS_REMOTE_UA'])) {
|
|
|
|
$_SESSION['SESS_REMOTE_UA'] = $_SERVER['HTTP_USER_AGENT'];
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:09:50 +02:00
|
|
|
// Update session cookie
|
2017-07-29 10:32:17 +02:00
|
|
|
// setcookie(session_name() ,session_id(), time() + $SESSION_LIFETIME);
|
2017-07-26 23:09:50 +02:00
|
|
|
|
2017-05-07 13:38:31 +02:00
|
|
|
// Check session
|
|
|
|
function session_check() {
|
2017-05-18 19:45:41 +02:00
|
|
|
if (!isset($_SESSION['SESS_REMOTE_UA'])) {
|
2017-05-07 13:38:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($_SESSION['SESS_REMOTE_UA'] != $_SERVER['HTTP_USER_AGENT']) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-15 11:37:12 +02:00
|
|
|
if (!empty($_POST)) {
|
|
|
|
if ($_SESSION['CSRF']['TOKEN'] != $_POST['csrf_token']) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$_SESSION['CSRF']['TOKEN'] = bin2hex(random_bytes(32));
|
|
|
|
$_SESSION['CSRF']['TIME'] = time();
|
|
|
|
}
|
2017-05-07 13:38:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
2017-05-15 11:37:12 +02:00
|
|
|
|
2017-05-07 13:38:31 +02:00
|
|
|
if (isset($_SESSION['mailcow_cc_role']) && session_check() === false) {
|
2017-05-15 11:37:12 +02:00
|
|
|
$_SESSION['return'] = array(
|
|
|
|
'type' => 'warning',
|
|
|
|
'msg' => 'Form token invalid or timed out'
|
|
|
|
);
|
|
|
|
$_POST = array();
|
2017-10-21 10:07:06 +02:00
|
|
|
$_FILES = array();
|
2017-05-07 13:38:31 +02:00
|
|
|
}
|
2017-05-15 11:37:12 +02:00
|
|
|
|
|
|
|
// Handle logouts
|
|
|
|
if (isset($_POST["logout"])) {
|
|
|
|
if (isset($_SESSION["dual-login"])) {
|
|
|
|
$_SESSION["mailcow_cc_username"] = $_SESSION["dual-login"]["username"];
|
|
|
|
$_SESSION["mailcow_cc_role"] = $_SESSION["dual-login"]["role"];
|
|
|
|
unset($_SESSION["dual-login"]);
|
2017-11-03 20:37:24 +01:00
|
|
|
header("Location: /mailbox.php");
|
|
|
|
exit();
|
2017-05-15 11:37:12 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
session_regenerate_id(true);
|
|
|
|
session_unset();
|
|
|
|
session_destroy();
|
|
|
|
session_write_close();
|
|
|
|
header("Location: /");
|
|
|
|
}
|
2017-05-18 19:45:41 +02:00
|
|
|
}
|