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) { |
| 20 | $alerts[$alert_type] = implode('<hr class="alert-hr">', $alert_msg); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 21 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 22 | unset($_SESSION['return']); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 23 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 24 | |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 25 | $globalVariables = [ |
| 26 | 'js_path' => '/cache/'.basename($JSPath), |
| 27 | 'pending_tfa_method' => @$_SESSION['pending_tfa_method'], |
| 28 | 'pending_mailcow_cc_username' => @$_SESSION['pending_mailcow_cc_username'], |
| 29 | 'lang_footer' => json_encode($lang['footer']), |
| 30 | 'lang_acl' => json_encode($lang['acl']), |
| 31 | 'lang_tfa' => json_encode($lang['tfa']), |
| 32 | 'lang_fido2' => json_encode($lang['fido2']), |
| 33 | 'docker_timeout' => $DOCKER_TIMEOUT, |
| 34 | 'session_lifetime' => (int)$SESSION_LIFETIME, |
| 35 | 'csrf_token' => $_SESSION['CSRF']['TOKEN'], |
| 36 | 'pagination_size' => $PAGINATION_SIZE, |
| 37 | 'log_pagination_size' => $LOG_PAGINATION_SIZE, |
| 38 | 'alerts' => $alerts, |
| 39 | 'totp_secret' => $tfa->createSecret(), |
| 40 | ]; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 41 | |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 42 | foreach ($globalVariables as $globalVariableName => $globalVariableValue) { |
| 43 | $twig->addGlobal($globalVariableName, $globalVariableValue); |
| 44 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 45 | |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 46 | if (is_array($template_data)) { |
| 47 | echo $twig->render($template, $template_data); |
| 48 | } |
| 49 | |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 50 | if (isset($_SESSION['mailcow_cc_api'])) { |
| 51 | session_regenerate_id(true); |
| 52 | session_unset(); |
| 53 | session_destroy(); |
| 54 | session_write_close(); |
| 55 | header("Location: /"); |
| 56 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 57 | $stmt = null; |
| 58 | $pdo = null; |