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