footer.inc.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if (array_key_exists('pending_tfa_methods', $_SESSION)) {
  27. foreach($_SESSION['pending_tfa_methods'] as $authdata){
  28. $pending_tfa_authmechs[$authdata['authmech']] = false;
  29. }
  30. if (isset($pending_tfa_authmechs['webauthn'])) {
  31. $pending_tfa_authmechs['webauthn'] = true;
  32. }
  33. if (!isset($pending_tfa_authmechs['webauthn'])
  34. && isset($pending_tfa_authmechs['yubi_otp'])) {
  35. $pending_tfa_authmechs['yubi_otp'] = true;
  36. }
  37. if (!isset($pending_tfa_authmechs['webauthn'])
  38. && !isset($pending_tfa_authmechs['yubi_otp'])
  39. && isset($pending_tfa_authmechs['totp'])) {
  40. $pending_tfa_authmechs['totp'] = true;
  41. }
  42. if (isset($pending_tfa_authmechs['u2f'])) {
  43. $pending_tfa_authmechs['u2f'] = true;
  44. }
  45. }
  46. // globals
  47. $globalVariables = [
  48. 'mailcow_info' => array(
  49. 'version_tag' => $GLOBALS['MAILCOW_GIT_VERSION'],
  50. 'last_version_tag' => $GLOBALS['MAILCOW_LAST_GIT_VERSION'],
  51. 'git_owner' => $GLOBALS['MAILCOW_GIT_OWNER'],
  52. 'git_repo' => $GLOBALS['MAILCOW_GIT_REPO'],
  53. 'git_project_url' => $GLOBALS['MAILCOW_GIT_URL'],
  54. 'git_commit' => $GLOBALS['MAILCOW_GIT_COMMIT'],
  55. 'git_commit_date' => $GLOBALS['MAILCOW_GIT_COMMIT_DATE'],
  56. 'mailcow_branch' => $GLOBALS['MAILCOW_BRANCH'],
  57. 'updated_at' => $GLOBALS['MAILCOW_UPDATEDAT']
  58. ),
  59. 'js_path' => '/cache/'.basename($JSPath),
  60. 'pending_tfa_methods' => @$_SESSION['pending_tfa_methods'],
  61. 'pending_tfa_authmechs' => $pending_tfa_authmechs,
  62. 'pending_mailcow_cc_username' => @$_SESSION['pending_mailcow_cc_username'],
  63. 'lang_footer' => json_encode($lang['footer']),
  64. 'lang_acl' => json_encode($lang['acl']),
  65. 'lang_tfa' => json_encode($lang['tfa']),
  66. 'lang_fido2' => json_encode($lang['fido2']),
  67. 'lang_success' => json_encode($lang['success']),
  68. 'lang_danger' => json_encode($lang['danger']),
  69. 'docker_timeout' => $DOCKER_TIMEOUT,
  70. 'session_lifetime' => (int)$SESSION_LIFETIME,
  71. 'csrf_token' => $_SESSION['CSRF']['TOKEN'],
  72. 'pagination_size' => $PAGINATION_SIZE,
  73. 'log_pagination_size' => $LOG_PAGINATION_SIZE,
  74. 'alerts' => $alerts,
  75. 'totp_secret' => $tfa->createSecret(),
  76. ];
  77. foreach ($globalVariables as $globalVariableName => $globalVariableValue) {
  78. $twig->addGlobal($globalVariableName, $globalVariableValue);
  79. }
  80. if (is_array($template_data)) {
  81. echo $twig->render($template, $template_data);
  82. }
  83. if (isset($_SESSION['mailcow_cc_api'])) {
  84. session_regenerate_id(true);
  85. session_unset();
  86. session_destroy();
  87. session_write_close();
  88. header("Location: /");
  89. }
  90. $stmt = null;
  91. $pdo = null;