| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | <?php |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2 | logger(); |
| 3 | |
| 4 | $hash = $js_minifier->getDataHash(); |
| 5 | $JSPath = '/tmp/' . $hash . '.js'; |
| 6 | if(!file_exists($JSPath)) { |
| 7 | $js_minifier->minify($JSPath); |
| 8 | cleanupJS($hash); |
| 9 | } |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 10 | |
| 11 | $alertbox_log_parser = alertbox_log_parser($_SESSION); |
| 12 | $alerts = []; |
| 13 | if (is_array($alertbox_log_parser)) { |
| 14 | foreach ($alertbox_log_parser as $log) { |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 15 | $message = htmlspecialchars($log['msg'], ENT_QUOTES); |
| 16 | $message = strtr($message, ["\n" => '', "\r" => '', "\t" => '<br>']); |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 17 | $alerts[trim($log['type'], '"')][] = trim($message, '"'); |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 18 | } |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 19 | $alert = array_filter(array_unique($alerts)); |
| 20 | foreach($alert as $alert_type => $alert_msg) { |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 21 | // html breaks from mysql alerts, replace ` with ' |
| 22 | $alerts[$alert_type] = implode('<hr class="alert-hr">', str_replace("`", "'", $alert_msg)); |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 23 | } |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 24 | unset($_SESSION['return']); |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 25 | } |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 26 | |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 27 | // map tfa details for twig |
| 28 | $pending_tfa_authmechs = []; |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 29 | if (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 Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | // globals |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 51 | $globalVariables = [ |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 52 | '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 Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 63 | 'js_path' => '/cache/'.basename($JSPath), |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 64 | 'pending_tfa_methods' => @$_SESSION['pending_tfa_methods'], |
| 65 | 'pending_tfa_authmechs' => $pending_tfa_authmechs, |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 66 | 'pending_mailcow_cc_username' => @$_SESSION['pending_mailcow_cc_username'], |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 67 | 'pending_tfa_setup' => !empty($_SESSION['pending_tfa_setup']), |
| 68 | 'pending_pw_update_modal' => !empty($_SESSION['pending_pw_update']), |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 69 | '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 Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 73 | 'lang_success' => json_encode($lang['success']), |
| 74 | 'lang_danger' => json_encode($lang['danger']), |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 75 | '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 Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 83 | |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 84 | foreach ($globalVariables as $globalVariableName => $globalVariableValue) { |
| 85 | $twig->addGlobal($globalVariableName, $globalVariableValue); |
| 86 | } |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 87 | |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 88 | if (is_array($template_data)) { |
| 89 | echo $twig->render($template, $template_data); |
| 90 | } |
| 91 | |
| Matthias Andreas Benkard | 8f91594 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 92 | if (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 Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 99 | $stmt = null; |
| 100 | $pdo = null; |