footer.inc.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. 'lang_success' => json_encode($lang['success']),
  66. 'lang_danger' => json_encode($lang['danger']),
  67. 'docker_timeout' => $DOCKER_TIMEOUT,
  68. 'session_lifetime' => (int)$SESSION_LIFETIME,
  69. 'csrf_token' => $_SESSION['CSRF']['TOKEN'],
  70. 'pagination_size' => $PAGINATION_SIZE,
  71. 'log_pagination_size' => $LOG_PAGINATION_SIZE,
  72. 'alerts' => $alerts,
  73. 'totp_secret' => $tfa->createSecret(),
  74. ];
  75. foreach ($globalVariables as $globalVariableName => $globalVariableValue) {
  76. $twig->addGlobal($globalVariableName, $globalVariableValue);
  77. }
  78. if (is_array($template_data)) {
  79. echo $twig->render($template, $template_data);
  80. }
  81. if (isset($_SESSION['mailcow_cc_api'])) {
  82. session_regenerate_id(true);
  83. session_unset();
  84. session_destroy();
  85. session_write_close();
  86. header("Location: /");
  87. }
  88. $stmt = null;
  89. $pdo = null;