blob: 93a6c22b4a0c70bfce0b9223d9c6819e40c25992 [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 Benkard12a57352021-12-28 18:02:04 +010067// rsettings
68$rsettings = array_map(function ($rsetting){
69 $rsetting['details'] = rsettings('details', $rsetting['id']);
70 return $rsetting;
71}, rsettings('get'));
72
73// rspamd regex maps
74$rspamd_regex_maps = [];
75foreach ($RSPAMD_MAPS['regex'] as $rspamd_regex_desc => $rspamd_regex_map) {
76 $rspamd_regex_maps[$rspamd_regex_desc] = [
77 'map' => $rspamd_regex_map,
78 'data' => file_get_contents('/rspamd_custom_maps/' . $rspamd_regex_map)
79 ];
80}
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +010081// cors settings
82$cors_settings = cors('get');
83$cors_settings['allowed_origins'] = str_replace(", ", "\n", $cors_settings['allowed_origins']);
84$cors_settings['allowed_methods'] = explode(", ", $cors_settings['allowed_methods']);
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010085
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010086$template = 'admin.twig';
87$template_data = [
88 'tfa_data' => $tfa_data,
89 'tfa_id' => @$_SESSION['tfa_id'],
90 'fido2_cid' => @$_SESSION['fido2_cid'],
91 'fido2_data' => $fido2_data,
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010092 'api' => [
93 'ro' => admin_api('ro', 'get'),
94 'rw' => admin_api('rw', 'get'),
95 ],
96 'dkim_domains' => $dkim_domains,
97 'dkim_domains_with_keys' => $dkim_domains_with_keys,
98 'dkim_blind_domains' => $dkim_blind_domains,
99 'domains' => $domains,
100 'all_domains' => $all_domains,
101 'mailboxes' => $mailboxes,
102 'f2b_data' => fail2ban('get'),
103 'q_data' => quarantine('settings'),
104 'qn_data' => quota_notification('get'),
105 'rsettings_map' => file_get_contents('http://nginx:8081/settings.php'),
106 'rsettings' => $rsettings,
107 'rspamd_regex_maps' => $rspamd_regex_maps,
108 'logo_specs' => customize('get', 'main_logo_specs'),
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +0100109 'logo_dark_specs' => customize('get', 'main_logo_dark_specs'),
110 'ip_check' => customize('get', 'ip_check'),
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100111 'password_complexity' => password_complexity('get'),
112 'show_rspamd_global_filters' => @$_SESSION['show_rspamd_global_filters'],
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +0100113 'cors_settings' => $cors_settings,
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100114 'lang_admin' => json_encode($lang['admin']),
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100115 'lang_datatables' => json_encode($lang['datatables'])
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100116];
117
118require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';