2017-03-02 12:23:23 +02:00
|
|
|
<?php
|
2017-09-17 14:39:10 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/vars.inc.php';
|
2017-09-16 13:33:27 +02:00
|
|
|
$default_autodiscover_config = $autodiscover_config;
|
2017-05-16 18:11:58 +02:00
|
|
|
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/inc/vars.local.inc.php')) {
|
|
|
|
include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/vars.local.inc.php';
|
2017-03-02 12:23:23 +02:00
|
|
|
}
|
2017-09-16 13:33:27 +02:00
|
|
|
$autodiscover_config = array_merge($default_autodiscover_config, $autodiscover_config);
|
2017-03-02 12:23:23 +02:00
|
|
|
|
2017-06-06 21:58:48 +02:00
|
|
|
header_remove("X-Powered-By");
|
|
|
|
|
2017-03-02 12:23:23 +02:00
|
|
|
// Yubi OTP API
|
2017-05-08 15:41:05 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/Yubico.php';
|
2017-03-02 12:23:23 +02:00
|
|
|
|
2017-05-07 13:38:31 +02:00
|
|
|
// Autoload composer
|
2017-05-08 15:41:05 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/vendor/autoload.php';
|
2017-05-07 13:38:31 +02:00
|
|
|
|
2017-11-03 21:37:24 +02:00
|
|
|
// Load Sieve
|
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/sieve/SieveParser.php';
|
|
|
|
|
2017-05-07 13:38:31 +02:00
|
|
|
// U2F API + T/HOTP API
|
|
|
|
$u2f = new u2flib_server\U2F('https://' . $_SERVER['HTTP_HOST']);
|
2017-05-26 23:02:04 +02:00
|
|
|
$tfa = new RobThree\Auth\TwoFactorAuth($OTP_LABEL);
|
2017-03-02 12:23:23 +02:00
|
|
|
|
2017-05-05 10:35:27 +02:00
|
|
|
// Redis
|
|
|
|
$redis = new Redis();
|
|
|
|
$redis->connect('redis-mailcow', 6379);
|
|
|
|
|
2017-03-02 12:23:23 +02:00
|
|
|
// PDO
|
2017-04-21 10:20:31 +02:00
|
|
|
// Calculate offset
|
|
|
|
$now = new DateTime();
|
|
|
|
$mins = $now->getOffset() / 60;
|
|
|
|
$sgn = ($mins < 0 ? -1 : 1);
|
|
|
|
$mins = abs($mins);
|
|
|
|
$hrs = floor($mins / 60);
|
|
|
|
$mins -= $hrs * 60;
|
|
|
|
$offset = sprintf('%+d:%02d', $hrs*$sgn, $mins);
|
|
|
|
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
$dsn = $database_type . ":unix_socket=" . $database_sock . ";dbname=" . $database_name;
|
2017-03-02 12:23:23 +02:00
|
|
|
$opt = [
|
2017-05-16 18:11:58 +02:00
|
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
2017-07-06 17:34:51 +02:00
|
|
|
PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '" . $offset . "', group_concat_max_len = 3423543543;",
|
2017-03-02 12:23:23 +02:00
|
|
|
];
|
|
|
|
try {
|
2017-05-16 18:11:58 +02:00
|
|
|
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
|
2017-03-02 12:23:23 +02:00
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
// Stop when SQL connection fails
|
2017-03-02 12:23:23 +02:00
|
|
|
?>
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
<center style='font-family:sans-serif;'>Connection to database failed.<br /><br />The following error was reported:<br/> <?=$e->getMessage();?></center>
|
2017-03-02 12:23:23 +02:00
|
|
|
<?php
|
|
|
|
exit;
|
|
|
|
}
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
// Stop when dockerapi is not available
|
|
|
|
if (fsockopen("tcp://dockerapi", 443, $errno, $errstr) === false) {
|
|
|
|
?>
|
|
|
|
<center style='font-family:sans-serif;'>Connection to dockerapi container failed.<br /><br />The following error was reported:<br/><?=$errno;?> - <?=$errstr;?></center>
|
|
|
|
<?php
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2018-08-13 23:20:40 +02:00
|
|
|
function pdo_exception_handler($e) {
|
2018-09-10 16:23:08 +02:00
|
|
|
print_r($e);
|
2018-08-13 23:20:40 +02:00
|
|
|
if ($e instanceof PDOException) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__),
|
|
|
|
'msg' => array('mysql_error', $e)
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__),
|
|
|
|
'msg' => array('mysql_error', 'unknown error')
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_exception_handler('pdo_exception_handler');
|
2017-03-02 12:23:23 +02:00
|
|
|
|
2018-08-05 22:31:53 +02:00
|
|
|
// TODO: Move function
|
|
|
|
function get_remote_ip($anonymize = null) {
|
|
|
|
global $ANONYMIZE_IPS;
|
|
|
|
if ($anonymize === null) {
|
|
|
|
$anonymize = $ANONYMIZE_IPS;
|
|
|
|
}
|
|
|
|
elseif ($anonymize !== true && $anonymize !== false) {
|
|
|
|
$anonymize = true;
|
|
|
|
}
|
2018-08-17 22:32:42 +02:00
|
|
|
$remote = $_SERVER['REMOTE_ADDR'];
|
2018-08-05 22:31:53 +02:00
|
|
|
if (filter_var($remote, FILTER_VALIDATE_IP) === false) {
|
|
|
|
return '0.0.0.0';
|
|
|
|
}
|
|
|
|
if ($anonymize) {
|
|
|
|
if (strlen(inet_pton($remote)) == 4) {
|
|
|
|
return inet_ntop(inet_pton($remote) & inet_pton("255.255.255.0"));
|
|
|
|
}
|
|
|
|
elseif (strlen(inet_pton($remote)) == 16) {
|
|
|
|
return inet_ntop(inet_pton($remote) & inet_pton('ffff:ffff:ffff:ffff:0000:0000:0000:0000'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $remote;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 14:17:15 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/sessions.inc.php';
|
|
|
|
|
2017-05-16 18:11:58 +02:00
|
|
|
// Set language
|
2018-01-02 13:30:45 +02:00
|
|
|
if (!isset($_SESSION['mailcow_locale']) && !isset($_COOKIE['mailcow_locale'])) {
|
2017-12-09 14:17:15 +02:00
|
|
|
if ($DETECT_LANGUAGE && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
|
|
|
$header_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
|
|
|
foreach ($AVAILABLE_LANGUAGES as $available_lang) {
|
|
|
|
if ($header_lang == $available_lang) {
|
|
|
|
$_SESSION['mailcow_locale'] = strtolower(trim($header_lang));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$_SESSION['mailcow_locale'] = strtolower(trim($DEFAULT_LANG));
|
|
|
|
}
|
2017-05-23 09:36:59 +02:00
|
|
|
}
|
2018-01-02 13:30:45 +02:00
|
|
|
if (isset($_COOKIE['mailcow_locale'])) {
|
|
|
|
$_SESSION['mailcow_locale'] = $_COOKIE['mailcow_locale'];
|
|
|
|
}
|
2017-05-16 18:11:58 +02:00
|
|
|
if (isset($_GET['lang']) && in_array($_GET['lang'], $AVAILABLE_LANGUAGES)) {
|
|
|
|
$_SESSION['mailcow_locale'] = $_GET['lang'];
|
2018-01-02 13:30:45 +02:00
|
|
|
setcookie("mailcow_locale", $_GET['lang'], time()+30758400); // one year
|
2017-05-16 18:11:58 +02:00
|
|
|
}
|
|
|
|
|
2017-05-08 15:41:05 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/lang/lang.en.php';
|
|
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/lang/lang.'.$_SESSION['mailcow_locale'].'.php';
|
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.inc.php';
|
2018-09-09 21:17:59 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.acl.inc.php';
|
2017-05-23 09:36:59 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.mailbox.inc.php';
|
2017-10-21 10:07:06 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.customize.inc.php';
|
2018-01-23 20:59:06 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.address_rewriting.inc.php';
|
2017-07-16 11:03:28 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.domain_admin.inc.php';
|
2018-10-11 11:59:23 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.admin.inc.php';
|
2018-02-08 21:13:36 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.quarantine.inc.php';
|
2017-05-23 09:36:59 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.policy.inc.php';
|
2017-05-26 23:02:04 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.dkim.inc.php';
|
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.fwdhost.inc.php';
|
2018-08-21 17:41:04 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.ratelimit.inc.php';
|
2017-07-22 20:39:54 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.relayhost.inc.php';
|
2018-06-23 23:50:22 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.rsettings.inc.php';
|
2018-10-04 14:38:12 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.tls_policy_maps.inc.php';
|
2017-06-29 10:29:56 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.fail2ban.inc.php';
|
2017-11-03 21:37:24 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.docker.inc.php';
|
2017-05-08 15:41:05 +02:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/init_db.inc.php';
|
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/triggers.inc.php';
|
2017-04-21 10:20:31 +02:00
|
|
|
init_db_schema();
|
2017-08-18 22:18:14 +02:00
|
|
|
if (isset($_SESSION['mailcow_cc_role'])) {
|
2018-09-09 21:17:59 +02:00
|
|
|
acl('to_session');
|
2017-10-01 20:34:37 +02:00
|
|
|
}
|
2017-12-09 14:17:15 +02:00
|
|
|
$UI_TEXTS = customize('get', 'ui_texts');
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
|