blob: 4ced152ae73d577a2b7c71c38670e6e5213d9b04 [file] [log] [blame]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001<?php
Matthias Andreas Benkard4edeb9f2021-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 Benkardb4b5cc12021-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) {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020015 $message = htmlspecialchars($log['msg'], ENT_QUOTES);
16 $message = strtr($message, ["\n" => '', "\r" => '', "\t" => '<br>']);
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010017 $alerts[trim($log['type'], '"')][] = trim($message, '"');
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010018 }
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010019 $alert = array_filter(array_unique($alerts));
20 foreach($alert as $alert_type => $alert_msg) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010021 // html breaks from mysql alerts, replace ` with '
22 $alerts[$alert_type] = implode('<hr class="alert-hr">', str_replace("`", "'", $alert_msg));
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010023 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010024 unset($_SESSION['return']);
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010025}
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010026
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010027// map tfa details for twig
28$pending_tfa_authmechs = [];
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020029if (array_key_exists('pending_tfa_methods', $_SESSION)) {
30 foreach($_SESSION['pending_tfa_methods'] as $authdata){
31 $pending_tfa_authmechs[$authdata['authmech']] = false;
32 }
33 if (isset($pending_tfa_authmechs['webauthn'])) {
34 $pending_tfa_authmechs['webauthn'] = true;
35 }
36 if (!isset($pending_tfa_authmechs['webauthn'])
37 && isset($pending_tfa_authmechs['yubi_otp'])) {
38 $pending_tfa_authmechs['yubi_otp'] = true;
39 }
40 if (!isset($pending_tfa_authmechs['webauthn'])
41 && !isset($pending_tfa_authmechs['yubi_otp'])
42 && isset($pending_tfa_authmechs['totp'])) {
43 $pending_tfa_authmechs['totp'] = true;
44 }
45 if (isset($pending_tfa_authmechs['u2f'])) {
46 $pending_tfa_authmechs['u2f'] = true;
47 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010048}
49
50// globals
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010051$globalVariables = [
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010052 'mailcow_info' => array(
53 'version_tag' => $GLOBALS['MAILCOW_GIT_VERSION'],
54 'last_version_tag' => $GLOBALS['MAILCOW_LAST_GIT_VERSION'],
55 'git_owner' => $GLOBALS['MAILCOW_GIT_OWNER'],
56 'git_repo' => $GLOBALS['MAILCOW_GIT_REPO'],
57 'git_project_url' => $GLOBALS['MAILCOW_GIT_URL'],
58 'git_commit' => $GLOBALS['MAILCOW_GIT_COMMIT'],
59 'git_commit_date' => $GLOBALS['MAILCOW_GIT_COMMIT_DATE'],
60 'mailcow_branch' => $GLOBALS['MAILCOW_BRANCH'],
61 'updated_at' => $GLOBALS['MAILCOW_UPDATEDAT']
62 ),
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010063 'js_path' => '/cache/'.basename($JSPath),
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010064 'pending_tfa_methods' => @$_SESSION['pending_tfa_methods'],
65 'pending_tfa_authmechs' => $pending_tfa_authmechs,
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010066 'pending_mailcow_cc_username' => @$_SESSION['pending_mailcow_cc_username'],
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020067 'pending_tfa_setup' => !empty($_SESSION['pending_tfa_setup']),
68 'pending_pw_update_modal' => !empty($_SESSION['pending_pw_update']),
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010069 'lang_footer' => json_encode($lang['footer']),
70 'lang_acl' => json_encode($lang['acl']),
71 'lang_tfa' => json_encode($lang['tfa']),
72 'lang_fido2' => json_encode($lang['fido2']),
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020073 'lang_success' => json_encode($lang['success']),
74 'lang_danger' => json_encode($lang['danger']),
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010075 'docker_timeout' => $DOCKER_TIMEOUT,
76 'session_lifetime' => (int)$SESSION_LIFETIME,
77 'csrf_token' => $_SESSION['CSRF']['TOKEN'],
78 'pagination_size' => $PAGINATION_SIZE,
79 'log_pagination_size' => $LOG_PAGINATION_SIZE,
80 'alerts' => $alerts,
81 'totp_secret' => $tfa->createSecret(),
82];
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010083
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010084foreach ($globalVariables as $globalVariableName => $globalVariableValue) {
85 $twig->addGlobal($globalVariableName, $globalVariableValue);
86}
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010087
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010088if (is_array($template_data)) {
89 echo $twig->render($template, $template_data);
90}
91
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +020092if (isset($_SESSION['mailcow_cc_api'])) {
93 session_regenerate_id(true);
94 session_unset();
95 session_destroy();
96 session_write_close();
97 header("Location: /");
98}
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010099$stmt = null;
100$pdo = null;