footer.inc.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. logger();
  3. $hash = $js_minifier->getDataHash();
  4. $JSPath = '/tmp/' . $hash . '.js';
  5. if(!file_exists($JSPath)) {
  6. $js_minifier->minify($JSPath);
  7. cleanupJS($hash);
  8. }
  9. $alertbox_log_parser = alertbox_log_parser($_SESSION);
  10. $alerts = [];
  11. if (is_array($alertbox_log_parser)) {
  12. foreach ($alertbox_log_parser as $log) {
  13. $message = htmlspecialchars($log['msg'], ENT_QUOTES);
  14. $message = strtr($message, ["\n" => '', "\r" => '', "\t" => '<br>']);
  15. $alerts[trim($log['type'], '"')][] = trim($message, '"');
  16. }
  17. $alert = array_filter(array_unique($alerts));
  18. foreach($alert as $alert_type => $alert_msg) {
  19. // html breaks from mysql alerts, replace ` with '
  20. $alerts[$alert_type] = implode('<hr class="alert-hr">', str_replace("`", "'", $alert_msg));
  21. }
  22. unset($_SESSION['return']);
  23. }
  24. // map tfa details for twig
  25. $pending_tfa_authmechs = [];
  26. foreach($_SESSION['pending_tfa_methods'] as $authdata){
  27. $pending_tfa_authmechs[$authdata['authmech']] = false;
  28. }
  29. if (isset($pending_tfa_authmechs['webauthn'])) {
  30. $pending_tfa_authmechs['webauthn'] = true;
  31. }
  32. if (!isset($pending_tfa_authmechs['webauthn'])
  33. && isset($pending_tfa_authmechs['yubi_otp'])) {
  34. $pending_tfa_authmechs['yubi_otp'] = true;
  35. }
  36. if (!isset($pending_tfa_authmechs['webauthn'])
  37. && !isset($pending_tfa_authmechs['yubi_otp'])
  38. && isset($pending_tfa_authmechs['totp'])) {
  39. $pending_tfa_authmechs['totp'] = true;
  40. }
  41. if (isset($pending_tfa_authmechs['u2f'])) {
  42. $pending_tfa_authmechs['u2f'] = true;
  43. }
  44. // globals
  45. $globalVariables = [
  46. 'mailcow_info' => array(
  47. 'version_tag' => $GLOBALS['MAILCOW_GIT_VERSION'],
  48. 'last_version_tag' => $GLOBALS['MAILCOW_LAST_GIT_VERSION'],
  49. 'git_owner' => $GLOBALS['MAILCOW_GIT_OWNER'],
  50. 'git_repo' => $GLOBALS['MAILCOW_GIT_REPO'],
  51. 'git_project_url' => $GLOBALS['MAILCOW_GIT_URL'],
  52. 'git_commit' => $GLOBALS['MAILCOW_GIT_COMMIT'],
  53. 'git_commit_date' => $GLOBALS['MAILCOW_GIT_COMMIT_DATE'],
  54. 'mailcow_branch' => $GLOBALS['MAILCOW_BRANCH'],
  55. 'updated_at' => $GLOBALS['MAILCOW_UPDATEDAT']
  56. ),
  57. 'js_path' => '/cache/'.basename($JSPath),
  58. 'pending_tfa_methods' => @$_SESSION['pending_tfa_methods'],
  59. 'pending_tfa_authmechs' => $pending_tfa_authmechs,
  60. 'pending_mailcow_cc_username' => @$_SESSION['pending_mailcow_cc_username'],
  61. 'lang_footer' => json_encode($lang['footer']),
  62. 'lang_acl' => json_encode($lang['acl']),
  63. 'lang_tfa' => json_encode($lang['tfa']),
  64. 'lang_fido2' => json_encode($lang['fido2']),
  65. 'docker_timeout' => $DOCKER_TIMEOUT,
  66. 'session_lifetime' => (int)$SESSION_LIFETIME,
  67. 'csrf_token' => $_SESSION['CSRF']['TOKEN'],
  68. 'pagination_size' => $PAGINATION_SIZE,
  69. 'log_pagination_size' => $LOG_PAGINATION_SIZE,
  70. 'alerts' => $alerts,
  71. 'totp_secret' => $tfa->createSecret(),
  72. ];
  73. foreach ($globalVariables as $globalVariableName => $globalVariableValue) {
  74. $twig->addGlobal($globalVariableName, $globalVariableValue);
  75. }
  76. if (is_array($template_data)) {
  77. echo $twig->render($template, $template_data);
  78. }
  79. if (isset($_SESSION['mailcow_cc_api'])) {
  80. session_regenerate_id(true);
  81. session_unset();
  82. session_destroy();
  83. session_write_close();
  84. header("Location: /");
  85. }
  86. $stmt = null;
  87. $pdo = null;