Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | <?php |
Matthias Andreas Benkard | b382b10 | 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 | 12a5735 | 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) { |
| 15 | $message = strtr($log['msg'], ["\n" => '', "\r" => '', "\t" => '<br>']); |
| 16 | $alerts[trim($log['type'], '"')][] = trim($message, '"'); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 17 | } |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 18 | $alert = array_filter(array_unique($alerts)); |
| 19 | foreach($alert as $alert_type => $alert_msg) { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 20 | // html breaks from mysql alerts, replace ` with ' |
| 21 | $alerts[$alert_type] = implode('<hr class="alert-hr">', str_replace("`", "'", $alert_msg)); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 22 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 23 | unset($_SESSION['return']); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 24 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 25 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 26 | // map tfa details for twig |
| 27 | $pending_tfa_authmechs = []; |
| 28 | foreach($_SESSION['pending_tfa_methods'] as $authdata){ |
| 29 | $pending_tfa_authmechs[$authdata['authmech']] = false; |
| 30 | } |
| 31 | if (isset($pending_tfa_authmechs['webauthn'])) { |
| 32 | $pending_tfa_authmechs['webauthn'] = true; |
| 33 | } |
| 34 | if (!isset($pending_tfa_authmechs['webauthn']) |
| 35 | && isset($pending_tfa_authmechs['yubi_otp'])) { |
| 36 | $pending_tfa_authmechs['yubi_otp'] = true; |
| 37 | } |
| 38 | if (!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 | } |
| 43 | if (isset($pending_tfa_authmechs['u2f'])) { |
| 44 | $pending_tfa_authmechs['u2f'] = true; |
| 45 | } |
| 46 | |
| 47 | // globals |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 48 | $globalVariables = [ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 49 | '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 Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 60 | 'js_path' => '/cache/'.basename($JSPath), |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 61 | 'pending_tfa_methods' => @$_SESSION['pending_tfa_methods'], |
| 62 | 'pending_tfa_authmechs' => $pending_tfa_authmechs, |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 63 | '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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 76 | |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 77 | foreach ($globalVariables as $globalVariableName => $globalVariableValue) { |
| 78 | $twig->addGlobal($globalVariableName, $globalVariableValue); |
| 79 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 80 | |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 81 | if (is_array($template_data)) { |
| 82 | echo $twig->render($template, $template_data); |
| 83 | } |
| 84 | |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 85 | if (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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 92 | $stmt = null; |
| 93 | $pdo = null; |