2017-03-02 18:23:23 +08:00
|
|
|
<?php
|
2017-05-07 19:38:31 +08:00
|
|
|
require_once 'inc/sessions.inc.php';
|
2017-03-02 18:23:23 +08:00
|
|
|
|
|
|
|
require_once 'inc/vars.inc.php';
|
|
|
|
if (file_exists('./inc/vars.local.inc.php')) {
|
|
|
|
include_once 'inc/vars.local.inc.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yubi OTP API
|
|
|
|
require_once 'inc/lib/Yubico.php';
|
|
|
|
|
2017-05-07 19:38:31 +08:00
|
|
|
// Autoload composer
|
2017-05-04 00:05:35 +08:00
|
|
|
require_once 'inc/lib/vendor/autoload.php';
|
2017-05-07 19:38:31 +08:00
|
|
|
|
|
|
|
// U2F API + T/HOTP API
|
|
|
|
$u2f = new u2flib_server\U2F('https://' . $_SERVER['HTTP_HOST']);
|
2017-05-04 00:05:35 +08:00
|
|
|
$tfa = new RobThree\Auth\TwoFactorAuth('mailcow UI');
|
2017-03-02 18:23:23 +08:00
|
|
|
|
2017-05-07 19:38:31 +08:00
|
|
|
// OWASP CSRF Protector
|
|
|
|
$csrfProtector = new csrfProtector;
|
|
|
|
class mailcowCsrfProtector extends csrfprotector {
|
|
|
|
public static function logCSRFattack() {
|
|
|
|
$_SESSION['return'] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'msg' => 'CSRF violation'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mailcowCsrfProtector::init();
|
|
|
|
|
2017-05-05 16:35:27 +08:00
|
|
|
// Redis
|
|
|
|
$redis = new Redis();
|
|
|
|
$redis->connect('redis-mailcow', 6379);
|
|
|
|
|
2017-03-02 18:23:23 +08:00
|
|
|
// PDO
|
2017-04-21 16:20:31 +08: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);
|
|
|
|
|
|
|
|
$dsn = $database_type . ":host=" . $database_host . ";dbname=" . $database_name;
|
2017-03-02 18:23:23 +08:00
|
|
|
$opt = [
|
|
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
2017-04-21 16:20:31 +08:00
|
|
|
PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '" . $offset . "'",
|
2017-03-02 18:23:23 +08:00
|
|
|
];
|
|
|
|
try {
|
|
|
|
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
|
|
|
?>
|
2017-04-21 16:20:31 +08:00
|
|
|
<center style='font-family: "Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;'>?? Connection failed, database may be in warm-up state, please try again later.<br /><br />The following error was reported:<br/> <?=$e->getMessage();?></center>
|
2017-03-02 18:23:23 +08:00
|
|
|
<?php
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$_SESSION['mailcow_locale'] = strtolower(trim($DEFAULT_LANG));
|
|
|
|
setcookie('language', $DEFAULT_LANG);
|
|
|
|
if (isset($_COOKIE['language'])) {
|
|
|
|
switch ($_COOKIE['language']) {
|
|
|
|
case "de":
|
|
|
|
$_SESSION['mailcow_locale'] = 'de';
|
|
|
|
setcookie('language', 'de');
|
|
|
|
break;
|
|
|
|
case "en":
|
|
|
|
$_SESSION['mailcow_locale'] = 'en';
|
|
|
|
setcookie('language', 'en');
|
|
|
|
break;
|
|
|
|
case "es":
|
|
|
|
$_SESSION['mailcow_locale'] = 'es';
|
|
|
|
setcookie('language', 'es');
|
|
|
|
break;
|
|
|
|
case "nl":
|
|
|
|
$_SESSION['mailcow_locale'] = 'nl';
|
|
|
|
setcookie('language', 'nl');
|
|
|
|
break;
|
|
|
|
case "pt":
|
|
|
|
$_SESSION['mailcow_locale'] = 'pt';
|
|
|
|
setcookie('language', 'pt');
|
|
|
|
break;
|
2017-03-22 17:46:24 +08:00
|
|
|
case "ru":
|
|
|
|
$_SESSION['mailcow_locale'] = 'ru';
|
|
|
|
setcookie('language', 'ru');
|
|
|
|
break;
|
2017-03-02 18:23:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($_GET['lang'])) {
|
|
|
|
switch ($_GET['lang']) {
|
|
|
|
case "de":
|
|
|
|
$_SESSION['mailcow_locale'] = 'de';
|
|
|
|
setcookie('language', 'de');
|
|
|
|
break;
|
|
|
|
case "en":
|
|
|
|
$_SESSION['mailcow_locale'] = 'en';
|
|
|
|
setcookie('language', 'en');
|
|
|
|
break;
|
|
|
|
case "es":
|
|
|
|
$_SESSION['mailcow_locale'] = 'es';
|
|
|
|
setcookie('language', 'es');
|
|
|
|
break;
|
|
|
|
case "nl":
|
|
|
|
$_SESSION['mailcow_locale'] = 'nl';
|
|
|
|
setcookie('language', 'nl');
|
|
|
|
break;
|
|
|
|
case "pt":
|
|
|
|
$_SESSION['mailcow_locale'] = 'pt';
|
|
|
|
setcookie('language', 'pt');
|
|
|
|
break;
|
2017-03-22 17:46:24 +08:00
|
|
|
case "ru":
|
|
|
|
$_SESSION['mailcow_locale'] = 'ru';
|
|
|
|
setcookie('language', 'ru');
|
|
|
|
break;
|
2017-03-02 18:23:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
require_once 'lang/lang.en.php';
|
|
|
|
include 'lang/lang.'.$_SESSION['mailcow_locale'].'.php';
|
|
|
|
require_once 'inc/functions.inc.php';
|
2017-04-21 16:20:31 +08:00
|
|
|
require_once 'inc/init_db.inc.php';
|
2017-03-02 18:23:23 +08:00
|
|
|
require_once 'inc/triggers.inc.php';
|
2017-04-21 16:20:31 +08:00
|
|
|
init_db_schema();
|