blob: 09db796d343756528b9bd00afc259cc7c2d5a380 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001<?php
2require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
3$AuthUsers = array("admin", "domainadmin", "user");
4if (!isset($_SESSION['mailcow_cc_role']) OR !in_array($_SESSION['mailcow_cc_role'], $AuthUsers)) {
5 header('Location: /');
6 exit();
7}
8require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
9
10$template = 'edit.twig';
11$template_data = [];
12$result = null;
13if (isset($_SESSION['mailcow_cc_role'])) {
14 if ($_SESSION['mailcow_cc_role'] == "admin" || $_SESSION['mailcow_cc_role'] == "domainadmin") {
15 if (isset($_GET["alias"]) &&
16 !empty($_GET["alias"])) {
17 $alias = html_entity_decode(rawurldecode($_GET["alias"]));
18 $result = mailbox('get', 'alias_details', $alias);
19
20 $template = 'edit/alias.twig';
21 $template_data = [
22 'alias' => $alias,
23 'goto' => (preg_match('/^(null|ham|spam)@localhost$/i', $result['goto'])) ? null : $result['goto'],
24 ];
25 }
26 elseif (isset($_GET['domainadmin'])) {
27 $domain_admin = $_GET["domainadmin"];
28 $result = domain_admin('details', $domain_admin);
29 $template = 'edit/domainadmin.twig';
30 $template_data = [
31 'domain_admin' => $domain_admin,
32 'da_acls' => acl('get', 'domainadmin', $domain_admin),
33 ];
34 }
35 elseif (isset($_GET['admin'])) {
36 $admin = $_GET["admin"];
37 $result = admin('details', $admin);
38 $template = 'edit/admin.twig';
39 $template_data = ['admin' => $admin];
40 }
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010041 elseif (isset($_GET['domain'])) {
42 if (is_valid_domain_name($_GET["domain"]) &&
43 !empty($_GET["domain"])) {
44 // edit domain
45 $domain = $_GET["domain"];
46 $result = mailbox('get', 'domain_details', $domain);
47 $quota_notification_bcc = quota_notification_bcc('get', $domain);
48 $rl = ratelimit('get', 'domain', $domain);
49 $rlyhosts = relayhost('get');
50 $template = 'edit/domain.twig';
51 $template_data = [
52 'acl' => $_SESSION['acl'],
53 'domain' => $domain,
54 'quota_notification_bcc' => $quota_notification_bcc,
55 'rl' => $rl,
56 'rlyhosts' => $rlyhosts,
57 'dkim' => dkim('details', $domain),
58 'domain_details' => $result,
59 ];
60 }
61 }
62 elseif (isset($_GET["template"])){
63 $domain_template = mailbox('get', 'domain_templates', $_GET["template"]);
64 if ($domain_template){
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010065 $template_data = [
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010066 'template' => $domain_template
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010067 ];
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010068 $template = 'edit/domain-templates.twig';
69 $result = true;
70 }
71 else {
72 $mailbox_template = mailbox('get', 'mailbox_templates', $_GET["template"]);
73 if ($mailbox_template){
74 $template_data = [
75 'template' => $mailbox_template
76 ];
77 $template = 'edit/mailbox-templates.twig';
78 $result = true;
79 }
80 }
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010081 }
82 elseif (isset($_GET['oauth2client']) &&
83 is_numeric($_GET["oauth2client"]) &&
84 !empty($_GET["oauth2client"])) {
85 $oauth2client = $_GET["oauth2client"];
86 $result = oauth2('details', 'client', $oauth2client);
87 $template = 'edit/oauth2client.twig';
88 $template_data = ['oauth2client' => $oauth2client];
89 }
90 elseif (isset($_GET['aliasdomain']) &&
91 is_valid_domain_name(html_entity_decode(rawurldecode($_GET["aliasdomain"]))) &&
92 !empty($_GET["aliasdomain"])) {
93 $alias_domain = html_entity_decode(rawurldecode($_GET["aliasdomain"]));
94 $result = mailbox('get', 'alias_domain_details', $alias_domain);
95 $rl = ratelimit('get', 'domain', $alias_domain);
96 $template = 'edit/aliasdomain.twig';
97 $template_data = [
98 'alias_domain' => $alias_domain,
99 'rl' => $rl,
100 'domains' => mailbox('get', 'domains'),
101 'dkim' => dkim('details', $alias_domain),
102 ];
103 }
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100104 elseif (isset($_GET['mailbox'])){
105 if(filter_var(html_entity_decode(rawurldecode($_GET["mailbox"])), FILTER_VALIDATE_EMAIL) && !empty($_GET["mailbox"])) {
106 // edit mailbox
107 $mailbox = html_entity_decode(rawurldecode($_GET["mailbox"]));
108 $result = mailbox('get', 'mailbox_details', $mailbox);
109 $rl = ratelimit('get', 'mailbox', $mailbox);
110 $pushover_data = pushover('get', $mailbox);
111 $quarantine_notification = mailbox('get', 'quarantine_notification', $mailbox);
112 $quarantine_category = mailbox('get', 'quarantine_category', $mailbox);
113 $get_tls_policy = mailbox('get', 'tls_policy', $mailbox);
114 $rlyhosts = relayhost('get');
115 $template = 'edit/mailbox.twig';
116 $template_data = [
117 'acl' => $_SESSION['acl'],
118 'mailbox' => $mailbox,
119 'rl' => $rl,
120 'pushover_data' => $pushover_data,
121 'quarantine_notification' => $quarantine_notification,
122 'quarantine_category' => $quarantine_category,
123 'get_tls_policy' => $get_tls_policy,
124 'rlyhosts' => $rlyhosts,
125 'sender_acl_handles' => mailbox('get', 'sender_acl_handles', $mailbox),
126 'user_acls' => acl('get', 'user', $mailbox),
127 'mailbox_details' => $result
128 ];
129 }
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100130 }
131 elseif (isset($_GET['relayhost']) && is_numeric($_GET["relayhost"]) && !empty($_GET["relayhost"])) {
132 $relayhost = intval($_GET["relayhost"]);
133 $result = relayhost('details', $relayhost);
134 $template = 'edit/relayhost.twig';
135 $template_data = ['relayhost' => $relayhost];
136 }
137 elseif (isset($_GET['transport']) && is_numeric($_GET["transport"]) && !empty($_GET["transport"])) {
138 $transport = intval($_GET["transport"]);
139 $result = transport('details', $transport);
140 $template = 'edit/transport.twig';
141 $template_data = ['transport' => $transport];
142 }
143 elseif (isset($_GET['resource']) && filter_var(html_entity_decode(rawurldecode($_GET["resource"])), FILTER_VALIDATE_EMAIL) && !empty($_GET["resource"])) {
144 $resource = html_entity_decode(rawurldecode($_GET["resource"]));
145 $result = mailbox('get', 'resource_details', $resource);
146 $template = 'edit/resource.twig';
147 }
148 elseif (isset($_GET['bcc']) && !empty($_GET["bcc"])) {
149 $bcc = intval($_GET["bcc"]);
150 $result = bcc('details', $bcc);
151 $template = 'edit/bcc.twig';
152 $template_data = ['bcc' => $bcc];
153 }
154 elseif (isset($_GET['recipient_map']) &&
155 !empty($_GET["recipient_map"]) &&
156 $_SESSION['mailcow_cc_role'] == "admin") {
157 $map = intval($_GET["recipient_map"]);
158 $result = recipient_map('details', $map);
159 if (substr($result['recipient_map_old'], 0, 1) == '@') {
160 $result['recipient_map_old'] = substr($result['recipient_map_old'], 1);
161 }
162 $template = 'edit/recipient_map.twig';
163 $template_data = ['map' => $map];
164 }
165 elseif (isset($_GET['tls_policy_map']) &&
166 !empty($_GET["tls_policy_map"]) &&
167 $_SESSION['mailcow_cc_role'] == "admin") {
168 $map = intval($_GET["tls_policy_map"]);
169 $result = tls_policy_maps('details', $map);
170 $template = 'edit/tls_policy_map.twig';
171 $template_data = [
172 'map' => $map,
173 'policy_options' => [
174 'none',
175 'may',
176 'encrypt',
177 'dane',
178 'dane-only',
179 'fingerprint',
180 'verify',
181 'secure',
182 ],
183 ];
184 }
185 }
186 if ($_SESSION['mailcow_cc_role'] == "admin" || $_SESSION['mailcow_cc_role'] == "domainadmin" || $_SESSION['mailcow_cc_role'] == "user") {
187 if (isset($_GET['syncjob']) &&
188 is_numeric($_GET['syncjob'])) {
189 $id = $_GET["syncjob"];
190 $result = mailbox('get', 'syncjob_details', $id);
191 $template = 'edit/syncjob.twig';
192 }
193 elseif (isset($_GET['filter']) &&
194 is_numeric($_GET['filter'])) {
195 $id = $_GET["filter"];
196 $result = mailbox('get', 'filter_details', $id);
197 $template = 'edit/filter.twig';
198 }
199 elseif (isset($_GET['app-passwd']) &&
200 is_numeric($_GET['app-passwd'])) {
201 $id = $_GET["app-passwd"];
202 $result = app_passwd('details', $id);
203 $template = 'edit/app-passwd.twig';
204 }
205 }
206}
207else {
208 $template_data['access_denied'] = true;
209}
210
211$js_minifier->add('/web/js/site/edit.js');
212$js_minifier->add('/web/js/site/pwgen.js');
213
214$template_data['result'] = $result;
215$template_data['return_to'] = $_SESSION['return_to'];
216$template_data['lang_user'] = json_encode($lang['user']);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100217$template_data['lang_datatables'] = json_encode($lang['datatables']);
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100218
219require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';