blob: 61d81dffa53839808302c4a355d8341c5a088209 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002logger();
3
4$hash = $js_minifier->getDataHash();
5$JSPath = '/tmp/' . $hash . '.js';
6if(!file_exists($JSPath)) {
7 $js_minifier->minify($JSPath);
8 cleanupJS($hash);
9}
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010010
11$alertbox_log_parser = alertbox_log_parser($_SESSION);
12$alerts = [];
13if (is_array($alertbox_log_parser)) {
14 foreach ($alertbox_log_parser as $log) {
15 $message = strtr($log['msg'], ["\n" => '', "\r" => '', "\t" => '<br>']);
16 $alerts[trim($log['type'], '"')][] = trim($message, '"');
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010017 }
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010018 $alert = array_filter(array_unique($alerts));
19 foreach($alert as $alert_type => $alert_msg) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010020 // html breaks from mysql alerts, replace ` with '
21 $alerts[$alert_type] = implode('<hr class="alert-hr">', str_replace("`", "'", $alert_msg));
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010022 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010023 unset($_SESSION['return']);
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010024}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010025
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010026// map tfa details for twig
27$pending_tfa_authmechs = [];
28foreach($_SESSION['pending_tfa_methods'] as $authdata){
29 $pending_tfa_authmechs[$authdata['authmech']] = false;
30}
31if (isset($pending_tfa_authmechs['webauthn'])) {
32 $pending_tfa_authmechs['webauthn'] = true;
33}
34if (!isset($pending_tfa_authmechs['webauthn'])
35 && isset($pending_tfa_authmechs['yubi_otp'])) {
36 $pending_tfa_authmechs['yubi_otp'] = true;
37}
38if (!isset($pending_tfa_authmechs['webauthn'])
39 && !isset($pending_tfa_authmechs['yubi_otp'])
40 && isset($pending_tfa_authmechs['totp'])) {
41 $pending_tfa_authmechs['totp'] = true;
42}
43if (isset($pending_tfa_authmechs['u2f'])) {
44 $pending_tfa_authmechs['u2f'] = true;
45}
46
47// globals
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010048$globalVariables = [
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010049 'mailcow_info' => array(
50 'version_tag' => $GLOBALS['MAILCOW_GIT_VERSION'],
51 'last_version_tag' => $GLOBALS['MAILCOW_LAST_GIT_VERSION'],
52 'git_owner' => $GLOBALS['MAILCOW_GIT_OWNER'],
53 'git_repo' => $GLOBALS['MAILCOW_GIT_REPO'],
54 'git_project_url' => $GLOBALS['MAILCOW_GIT_URL'],
55 'git_commit' => $GLOBALS['MAILCOW_GIT_COMMIT'],
56 'git_commit_date' => $GLOBALS['MAILCOW_GIT_COMMIT_DATE'],
57 'mailcow_branch' => $GLOBALS['MAILCOW_BRANCH'],
58 'updated_at' => $GLOBALS['MAILCOW_UPDATEDAT']
59 ),
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010060 'js_path' => '/cache/'.basename($JSPath),
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010061 'pending_tfa_methods' => @$_SESSION['pending_tfa_methods'],
62 'pending_tfa_authmechs' => $pending_tfa_authmechs,
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010063 'pending_mailcow_cc_username' => @$_SESSION['pending_mailcow_cc_username'],
64 'lang_footer' => json_encode($lang['footer']),
65 'lang_acl' => json_encode($lang['acl']),
66 'lang_tfa' => json_encode($lang['tfa']),
67 'lang_fido2' => json_encode($lang['fido2']),
68 'docker_timeout' => $DOCKER_TIMEOUT,
69 'session_lifetime' => (int)$SESSION_LIFETIME,
70 'csrf_token' => $_SESSION['CSRF']['TOKEN'],
71 'pagination_size' => $PAGINATION_SIZE,
72 'log_pagination_size' => $LOG_PAGINATION_SIZE,
73 'alerts' => $alerts,
74 'totp_secret' => $tfa->createSecret(),
75];
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010076
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010077foreach ($globalVariables as $globalVariableName => $globalVariableValue) {
78 $twig->addGlobal($globalVariableName, $globalVariableValue);
79}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010080
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010081if (is_array($template_data)) {
82 echo $twig->render($template, $template_data);
83}
84
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020085if (isset($_SESSION['mailcow_cc_api'])) {
86 session_regenerate_id(true);
87 session_unset();
88 session_destroy();
89 session_write_close();
90 header("Location: /");
91}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010092$stmt = null;
93$pdo = null;