2
0

footer.inc.php 3.0 KB

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