admin.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
  3. if (!isset($_SESSION['mailcow_cc_role']) || $_SESSION['mailcow_cc_role'] != "admin") {
  4. header('Location: /');
  5. exit();
  6. }
  7. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
  8. $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
  9. $tfa_data = get_tfa();
  10. $fido2_data = fido2(array("action" => "get_friendly_names"));
  11. $js_minifier->add('/web/js/site/admin.js');
  12. $js_minifier->add('/web/js/presets/rspamd.js');
  13. $js_minifier->add('/web/js/site/pwgen.js');
  14. // all domains
  15. $domains = mailbox('get', 'domains');
  16. $all_domains = array_merge($domains, mailbox('get', 'alias_domains'));
  17. // mailboxes
  18. $mailboxes = [];
  19. foreach ($all_domains as $domain) {
  20. foreach (mailbox('get', 'mailboxes', $domain) as $mailbox) {
  21. $mailboxes[] = $mailbox;
  22. }
  23. }
  24. $mailboxes = array_filter($mailboxes);
  25. // DKIM domains
  26. $dkim_domains = [];
  27. $dkim_domains_with_keys = [];
  28. foreach($domains as $domain) {
  29. $dkim_domains[$domain] = ['dkim' => null, 'alias_domains' => []];
  30. if (!empty($dkim = dkim('details', $domain))) {
  31. $dkim_domains_with_keys[] = $domain;
  32. if ($GLOBALS['SHOW_DKIM_PRIV_KEYS'] !== true) {
  33. $dkim['privkey'] = base64_encode('Please set $SHOW_DKIM_PRIV_KEYS to true to show DKIM private keys.');
  34. }
  35. $dkim_domains[$domain]['dkim'] = $dkim;
  36. }
  37. // get alias domains
  38. foreach (mailbox('get', 'alias_domains', $domain) as $alias_domain) {
  39. $dkim_domains[$domain]['alias_domains'][$alias_domain] = ['dkim' => null];
  40. if (!empty($dkim = dkim('details', $alias_domain))) {
  41. $dkim_domains_with_keys[] = $alias_domain;
  42. if ($GLOBALS['SHOW_DKIM_PRIV_KEYS'] !== true) {
  43. $dkim['privkey'] = base64_encode('Please set $SHOW_DKIM_PRIV_KEYS to true to show DKIM private keys.');
  44. }
  45. $dkim_domains[$domain]['alias_domains'][$alias_domain]['dkim'] = $dkim;
  46. }
  47. }
  48. }
  49. $dkim_blind_domains = [];
  50. foreach(dkim('blind') as $blind) {
  51. $dkim_blind_domains[$blind] = ['dkim' => null];
  52. if (!empty($dkim = dkim('details', $blind))) {
  53. $dkim_domains_with_keys[] = $blind;
  54. if ($GLOBALS['SHOW_DKIM_PRIV_KEYS'] !== true) {
  55. $dkim['privkey'] = base64_encode('Please set $SHOW_DKIM_PRIV_KEYS to true to show DKIM private keys.');
  56. }
  57. $dkim_blind_domains[$blind]['dkim'] = $dkim;
  58. }
  59. }
  60. // rsettings
  61. $rsettings = array_map(function ($rsetting){
  62. $rsetting['details'] = rsettings('details', $rsetting['id']);
  63. return $rsetting;
  64. }, rsettings('get'));
  65. // rspamd regex maps
  66. $rspamd_regex_maps = [];
  67. foreach ($RSPAMD_MAPS['regex'] as $rspamd_regex_desc => $rspamd_regex_map) {
  68. $rspamd_regex_maps[$rspamd_regex_desc] = [
  69. 'map' => $rspamd_regex_map,
  70. 'data' => file_get_contents('/rspamd_custom_maps/' . $rspamd_regex_map)
  71. ];
  72. }
  73. // cors settings
  74. $cors_settings = cors('get');
  75. $cors_settings['allowed_origins'] = str_replace(", ", "\n", $cors_settings['allowed_origins']);
  76. $cors_settings['allowed_methods'] = explode(", ", $cors_settings['allowed_methods']);
  77. $f2b_data = fail2ban('get');
  78. $template = 'admin.twig';
  79. $template_data = [
  80. 'tfa_data' => $tfa_data,
  81. 'tfa_id' => @$_SESSION['tfa_id'],
  82. 'fido2_cid' => @$_SESSION['fido2_cid'],
  83. 'fido2_data' => $fido2_data,
  84. 'api' => [
  85. 'ro' => admin_api('ro', 'get'),
  86. 'rw' => admin_api('rw', 'get'),
  87. ],
  88. 'dkim_domains' => $dkim_domains,
  89. 'dkim_domains_with_keys' => $dkim_domains_with_keys,
  90. 'dkim_blind_domains' => $dkim_blind_domains,
  91. 'domains' => $domains,
  92. 'all_domains' => $all_domains,
  93. 'mailboxes' => $mailboxes,
  94. 'f2b_data' => $f2b_data,
  95. 'f2b_banlist_url' => getBaseUrl() . "/api/v1/get/fail2ban/banlist/" . $f2b_data['banlist_id'],
  96. 'q_data' => quarantine('settings'),
  97. 'qn_data' => quota_notification('get'),
  98. 'pw_reset_data' => reset_password('get_notification'),
  99. 'rsettings_map' => file_get_contents('http://nginx:8081/settings.php'),
  100. 'rsettings' => $rsettings,
  101. 'rspamd_regex_maps' => $rspamd_regex_maps,
  102. 'logo_specs' => customize('get', 'main_logo_specs'),
  103. 'logo_dark_specs' => customize('get', 'main_logo_dark_specs'),
  104. 'ip_check' => customize('get', 'ip_check'),
  105. 'password_complexity' => password_complexity('get'),
  106. 'show_rspamd_global_filters' => @$_SESSION['show_rspamd_global_filters'],
  107. 'cors_settings' => $cors_settings,
  108. 'is_https' => isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on',
  109. 'lang_admin' => json_encode($lang['admin']),
  110. 'lang_datatables' => json_encode($lang['datatables'])
  111. ];
  112. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';