edit.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
  3. $AuthUsers = array("admin", "domainadmin", "user");
  4. if (!isset($_SESSION['mailcow_cc_role']) OR !in_array($_SESSION['mailcow_cc_role'], $AuthUsers)) {
  5. header('Location: /');
  6. exit();
  7. }
  8. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
  9. $template = 'edit.twig';
  10. $template_data = [];
  11. $result = null;
  12. if (isset($_SESSION['mailcow_cc_role'])) {
  13. if ($_SESSION['mailcow_cc_role'] == "admin" || $_SESSION['mailcow_cc_role'] == "domainadmin") {
  14. if (isset($_GET["alias"]) &&
  15. !empty($_GET["alias"])) {
  16. $alias = html_entity_decode(rawurldecode($_GET["alias"]));
  17. $result = mailbox('get', 'alias_details', $alias);
  18. $template = 'edit/alias.twig';
  19. $template_data = [
  20. 'alias' => $alias,
  21. 'goto' => (preg_match('/^(null|ham|spam)@localhost$/i', $result['goto'])) ? null : $result['goto'],
  22. ];
  23. }
  24. elseif (isset($_GET['domainadmin'])) {
  25. $domain_admin = $_GET["domainadmin"];
  26. $result = domain_admin('details', $domain_admin);
  27. $template = 'edit/domainadmin.twig';
  28. $template_data = [
  29. 'domain_admin' => $domain_admin,
  30. 'da_acls' => acl('get', 'domainadmin', $domain_admin),
  31. ];
  32. }
  33. elseif (isset($_GET['admin'])) {
  34. $admin = $_GET["admin"];
  35. $result = admin('details', $admin);
  36. $template = 'edit/admin.twig';
  37. $template_data = ['admin' => $admin];
  38. }
  39. elseif (isset($_GET['domain'])) {
  40. if (is_valid_domain_name($_GET["domain"]) &&
  41. !empty($_GET["domain"])) {
  42. // edit domain
  43. $domain = $_GET["domain"];
  44. $result = mailbox('get', 'domain_details', $domain);
  45. $quota_notification_bcc = quota_notification_bcc('get', $domain);
  46. $rl = ratelimit('get', 'domain', $domain);
  47. $rlyhosts = relayhost('get');
  48. $template = 'edit/domain.twig';
  49. $template_data = [
  50. 'acl' => $_SESSION['acl'],
  51. 'domain' => $domain,
  52. 'quota_notification_bcc' => $quota_notification_bcc,
  53. 'rl' => $rl,
  54. 'rlyhosts' => $rlyhosts,
  55. 'dkim' => dkim('details', $domain),
  56. 'domain_details' => $result,
  57. ];
  58. }
  59. }
  60. elseif (isset($_GET['template'])){
  61. $domain_template = mailbox('get', 'domain_templates', $_GET['template']);
  62. if ($domain_template){
  63. $template_data = [
  64. 'template' => $domain_template,
  65. 'rl' => ['frame' => $domain_template['attributes']['rl_frame']],
  66. ];
  67. $template = 'edit/domain-templates.twig';
  68. $result = true;
  69. }
  70. else {
  71. $mailbox_template = mailbox('get', 'mailbox_templates', $_GET['template']);
  72. if ($mailbox_template){
  73. $template_data = [
  74. 'template' => $mailbox_template,
  75. 'rl' => ['frame' => $mailbox_template['attributes']['rl_frame']],
  76. ];
  77. $template = 'edit/mailbox-templates.twig';
  78. $result = true;
  79. }
  80. }
  81. }
  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. }
  104. 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. }
  130. }
  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. }
  207. else {
  208. $template_data['access_denied'] = true;
  209. }
  210. $js_minifier->add('/web/js/site/edit.js');
  211. $js_minifier->add('/web/js/site/pwgen.js');
  212. $template_data['result'] = $result;
  213. $template_data['return_to'] = $_SESSION['return_to'];
  214. $template_data['lang_user'] = json_encode($lang['user']);
  215. $template_data['lang_datatables'] = json_encode($lang['datatables']);
  216. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';