blob: ebddb7b91b46aff1b32bc5f29531ed22122865d2 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
3
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01004if (!isset($_SESSION['mailcow_cc_role']) || $_SESSION['mailcow_cc_role'] != "admin") {
5 header('Location: /');
6 exit();
7}
8
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01009require_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 Benkardb382b102021-01-02 15:32:21 +010013
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010014$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 Benkard12a57352021-12-28 18:02:04 +010017
18// all domains
19$domains = mailbox('get', 'domains');
20$all_domains = array_merge($domains, mailbox('get', 'alias_domains'));
21
22// mailboxes
23$mailboxes = [];
24foreach ($all_domains as $domain) {
25 foreach (mailbox('get', 'mailboxes', $domain) as $mailbox) {
26 $mailboxes[] = $mailbox;
27 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010028}
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010029$mailboxes = array_filter($mailboxes);
30
31// DKIM domains
32$dkim_domains = [];
33$dkim_domains_with_keys = [];
34foreach($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 = [];
57foreach(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 Benkarda515bc62023-11-18 16:44:25 +010067
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010068// 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 = [];
76foreach ($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 Benkarda515bc62023-11-18 16:44:25 +010082
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +010083// 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 Benkard12a57352021-12-28 18:02:04 +010087
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010088$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 Benkard12a57352021-12-28 18:02:04 +010094 '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 Benkardd1f5b682023-11-18 13:18:30 +0100111 'logo_dark_specs' => customize('get', 'main_logo_dark_specs'),
112 'ip_check' => customize('get', 'ip_check'),
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100113 'password_complexity' => password_complexity('get'),
114 'show_rspamd_global_filters' => @$_SESSION['show_rspamd_global_filters'],
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +0100115 'cors_settings' => $cors_settings,
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100116 'lang_admin' => json_encode($lang['admin']),
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100117 'lang_datatables' => json_encode($lang['datatables'])
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100118];
119
120require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';