blob: 8061441b84f0d244094abab9ef973c9e015df8eb [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');
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +010050 $domain_footer = mailbox('get', 'domain_wide_footer', $domain);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010051 $template = 'edit/domain.twig';
52 $template_data = [
53 'acl' => $_SESSION['acl'],
54 'domain' => $domain,
55 'quota_notification_bcc' => $quota_notification_bcc,
56 'rl' => $rl,
57 'rlyhosts' => $rlyhosts,
58 'dkim' => dkim('details', $domain),
59 'domain_details' => $result,
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +010060 'domain_footer' => $domain_footer,
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010061 ];
62 }
63 }
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +010064 elseif (isset($_GET['template'])){
65 $domain_template = mailbox('get', 'domain_templates', $_GET['template']);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010066 if ($domain_template){
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010067 $template_data = [
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +010068 'template' => $domain_template,
69 'rl' => ['frame' => $domain_template['attributes']['rl_frame']],
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010070 ];
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010071 $template = 'edit/domain-templates.twig';
72 $result = true;
73 }
74 else {
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +010075 $mailbox_template = mailbox('get', 'mailbox_templates', $_GET['template']);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010076 if ($mailbox_template){
77 $template_data = [
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +010078 'template' => $mailbox_template,
79 'rl' => ['frame' => $mailbox_template['attributes']['rl_frame']],
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010080 ];
81 $template = 'edit/mailbox-templates.twig';
82 $result = true;
83 }
84 }
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010085 }
86 elseif (isset($_GET['oauth2client']) &&
87 is_numeric($_GET["oauth2client"]) &&
88 !empty($_GET["oauth2client"])) {
89 $oauth2client = $_GET["oauth2client"];
90 $result = oauth2('details', 'client', $oauth2client);
91 $template = 'edit/oauth2client.twig';
92 $template_data = ['oauth2client' => $oauth2client];
93 }
94 elseif (isset($_GET['aliasdomain']) &&
95 is_valid_domain_name(html_entity_decode(rawurldecode($_GET["aliasdomain"]))) &&
96 !empty($_GET["aliasdomain"])) {
97 $alias_domain = html_entity_decode(rawurldecode($_GET["aliasdomain"]));
98 $result = mailbox('get', 'alias_domain_details', $alias_domain);
99 $rl = ratelimit('get', 'domain', $alias_domain);
100 $template = 'edit/aliasdomain.twig';
101 $template_data = [
102 'alias_domain' => $alias_domain,
103 'rl' => $rl,
104 'domains' => mailbox('get', 'domains'),
105 'dkim' => dkim('details', $alias_domain),
106 ];
107 }
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100108 elseif (isset($_GET['mailbox'])){
109 if(filter_var(html_entity_decode(rawurldecode($_GET["mailbox"])), FILTER_VALIDATE_EMAIL) && !empty($_GET["mailbox"])) {
110 // edit mailbox
111 $mailbox = html_entity_decode(rawurldecode($_GET["mailbox"]));
112 $result = mailbox('get', 'mailbox_details', $mailbox);
113 $rl = ratelimit('get', 'mailbox', $mailbox);
114 $pushover_data = pushover('get', $mailbox);
115 $quarantine_notification = mailbox('get', 'quarantine_notification', $mailbox);
116 $quarantine_category = mailbox('get', 'quarantine_category', $mailbox);
117 $get_tls_policy = mailbox('get', 'tls_policy', $mailbox);
118 $rlyhosts = relayhost('get');
119 $template = 'edit/mailbox.twig';
120 $template_data = [
121 'acl' => $_SESSION['acl'],
122 'mailbox' => $mailbox,
123 'rl' => $rl,
124 'pushover_data' => $pushover_data,
125 'quarantine_notification' => $quarantine_notification,
126 'quarantine_category' => $quarantine_category,
127 'get_tls_policy' => $get_tls_policy,
128 'rlyhosts' => $rlyhosts,
129 'sender_acl_handles' => mailbox('get', 'sender_acl_handles', $mailbox),
130 'user_acls' => acl('get', 'user', $mailbox),
131 'mailbox_details' => $result
132 ];
133 }
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100134 }
135 elseif (isset($_GET['relayhost']) && is_numeric($_GET["relayhost"]) && !empty($_GET["relayhost"])) {
136 $relayhost = intval($_GET["relayhost"]);
137 $result = relayhost('details', $relayhost);
138 $template = 'edit/relayhost.twig';
139 $template_data = ['relayhost' => $relayhost];
140 }
141 elseif (isset($_GET['transport']) && is_numeric($_GET["transport"]) && !empty($_GET["transport"])) {
142 $transport = intval($_GET["transport"]);
143 $result = transport('details', $transport);
144 $template = 'edit/transport.twig';
145 $template_data = ['transport' => $transport];
146 }
147 elseif (isset($_GET['resource']) && filter_var(html_entity_decode(rawurldecode($_GET["resource"])), FILTER_VALIDATE_EMAIL) && !empty($_GET["resource"])) {
148 $resource = html_entity_decode(rawurldecode($_GET["resource"]));
149 $result = mailbox('get', 'resource_details', $resource);
150 $template = 'edit/resource.twig';
151 }
152 elseif (isset($_GET['bcc']) && !empty($_GET["bcc"])) {
153 $bcc = intval($_GET["bcc"]);
154 $result = bcc('details', $bcc);
155 $template = 'edit/bcc.twig';
156 $template_data = ['bcc' => $bcc];
157 }
158 elseif (isset($_GET['recipient_map']) &&
159 !empty($_GET["recipient_map"]) &&
160 $_SESSION['mailcow_cc_role'] == "admin") {
161 $map = intval($_GET["recipient_map"]);
162 $result = recipient_map('details', $map);
163 if (substr($result['recipient_map_old'], 0, 1) == '@') {
164 $result['recipient_map_old'] = substr($result['recipient_map_old'], 1);
165 }
166 $template = 'edit/recipient_map.twig';
167 $template_data = ['map' => $map];
168 }
169 elseif (isset($_GET['tls_policy_map']) &&
170 !empty($_GET["tls_policy_map"]) &&
171 $_SESSION['mailcow_cc_role'] == "admin") {
172 $map = intval($_GET["tls_policy_map"]);
173 $result = tls_policy_maps('details', $map);
174 $template = 'edit/tls_policy_map.twig';
175 $template_data = [
176 'map' => $map,
177 'policy_options' => [
178 'none',
179 'may',
180 'encrypt',
181 'dane',
182 'dane-only',
183 'fingerprint',
184 'verify',
185 'secure',
186 ],
187 ];
188 }
189 }
190 if ($_SESSION['mailcow_cc_role'] == "admin" || $_SESSION['mailcow_cc_role'] == "domainadmin" || $_SESSION['mailcow_cc_role'] == "user") {
191 if (isset($_GET['syncjob']) &&
192 is_numeric($_GET['syncjob'])) {
193 $id = $_GET["syncjob"];
194 $result = mailbox('get', 'syncjob_details', $id);
195 $template = 'edit/syncjob.twig';
196 }
197 elseif (isset($_GET['filter']) &&
198 is_numeric($_GET['filter'])) {
199 $id = $_GET["filter"];
200 $result = mailbox('get', 'filter_details', $id);
201 $template = 'edit/filter.twig';
202 }
203 elseif (isset($_GET['app-passwd']) &&
204 is_numeric($_GET['app-passwd'])) {
205 $id = $_GET["app-passwd"];
206 $result = app_passwd('details', $id);
207 $template = 'edit/app-passwd.twig';
208 }
209 }
210}
211else {
212 $template_data['access_denied'] = true;
213}
214
215$js_minifier->add('/web/js/site/edit.js');
216$js_minifier->add('/web/js/site/pwgen.js');
217
218$template_data['result'] = $result;
219$template_data['return_to'] = $_SESSION['return_to'];
220$template_data['lang_user'] = json_encode($lang['user']);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100221$template_data['lang_datatables'] = json_encode($lang['datatables']);
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100222
223require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';