edit.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. $domain_footer = mailbox('get', 'domain_wide_footer', $domain);
  49. $template = 'edit/domain.twig';
  50. $template_data = [
  51. 'acl' => $_SESSION['acl'],
  52. 'domain' => $domain,
  53. 'quota_notification_bcc' => $quota_notification_bcc,
  54. 'rl' => $rl,
  55. 'rlyhosts' => $rlyhosts,
  56. 'dkim' => dkim('details', $domain),
  57. 'domain_details' => $result,
  58. 'domain_footer' => $domain_footer,
  59. 'mailboxes' => mailbox('get', 'mailboxes', $_GET["domain"]),
  60. 'aliases' => mailbox('get', 'aliases', $_GET["domain"], 'address')
  61. ];
  62. }
  63. }
  64. elseif (isset($_GET['template'])){
  65. $domain_template = mailbox('get', 'domain_templates', $_GET['template']);
  66. if ($domain_template){
  67. $template_data = [
  68. 'template' => $domain_template,
  69. 'rl' => ['frame' => $domain_template['attributes']['rl_frame']],
  70. ];
  71. $template = 'edit/domain-templates.twig';
  72. $result = true;
  73. }
  74. else {
  75. $mailbox_template = mailbox('get', 'mailbox_templates', $_GET['template']);
  76. if ($mailbox_template){
  77. $template_data = [
  78. 'template' => $mailbox_template,
  79. 'rl' => ['frame' => $mailbox_template['attributes']['rl_frame']],
  80. ];
  81. $template = 'edit/mailbox-templates.twig';
  82. $result = true;
  83. }
  84. }
  85. }
  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. }
  108. 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. $iam_settings = identity_provider('get');
  120. $template = 'edit/mailbox.twig';
  121. $template_data = [
  122. 'acl' => $_SESSION['acl'],
  123. 'mailbox' => $mailbox,
  124. 'rl' => $rl,
  125. 'pushover_data' => $pushover_data,
  126. 'quarantine_notification' => $quarantine_notification,
  127. 'quarantine_category' => $quarantine_category,
  128. 'get_tls_policy' => $get_tls_policy,
  129. 'rlyhosts' => $rlyhosts,
  130. 'sender_acl_handles' => mailbox('get', 'sender_acl_handles', $mailbox),
  131. 'user_acls' => acl('get', 'user', $mailbox),
  132. 'mailbox_details' => $result,
  133. 'iam_settings' => $iam_settings,
  134. ];
  135. }
  136. }
  137. elseif (isset($_GET['relayhost']) && is_numeric($_GET["relayhost"]) && !empty($_GET["relayhost"])) {
  138. $relayhost = intval($_GET["relayhost"]);
  139. $result = relayhost('details', $relayhost);
  140. $template = 'edit/relayhost.twig';
  141. $template_data = ['relayhost' => $relayhost];
  142. }
  143. elseif (isset($_GET['transport']) && is_numeric($_GET["transport"]) && !empty($_GET["transport"])) {
  144. $transport = intval($_GET["transport"]);
  145. $result = transport('details', $transport);
  146. $template = 'edit/transport.twig';
  147. $template_data = ['transport' => $transport];
  148. }
  149. elseif (isset($_GET['resource']) && filter_var(html_entity_decode(rawurldecode($_GET["resource"])), FILTER_VALIDATE_EMAIL) && !empty($_GET["resource"])) {
  150. $resource = html_entity_decode(rawurldecode($_GET["resource"]));
  151. $result = mailbox('get', 'resource_details', $resource);
  152. $template = 'edit/resource.twig';
  153. }
  154. elseif (isset($_GET['bcc']) && !empty($_GET["bcc"])) {
  155. $bcc = intval($_GET["bcc"]);
  156. $result = bcc('details', $bcc);
  157. $template = 'edit/bcc.twig';
  158. $template_data = ['bcc' => $bcc];
  159. }
  160. elseif (isset($_GET['recipient_map']) &&
  161. !empty($_GET["recipient_map"]) &&
  162. $_SESSION['mailcow_cc_role'] == "admin") {
  163. $map = intval($_GET["recipient_map"]);
  164. $result = recipient_map('details', $map);
  165. if (substr($result['recipient_map_old'], 0, 1) == '@') {
  166. $result['recipient_map_old'] = substr($result['recipient_map_old'], 1);
  167. }
  168. $template = 'edit/recipient_map.twig';
  169. $template_data = ['map' => $map];
  170. }
  171. elseif (isset($_GET['tls_policy_map']) &&
  172. !empty($_GET["tls_policy_map"]) &&
  173. $_SESSION['mailcow_cc_role'] == "admin") {
  174. $map = intval($_GET["tls_policy_map"]);
  175. $result = tls_policy_maps('details', $map);
  176. $template = 'edit/tls_policy_map.twig';
  177. $template_data = [
  178. 'map' => $map,
  179. 'policy_options' => [
  180. 'none',
  181. 'may',
  182. 'encrypt',
  183. 'dane',
  184. 'dane-only',
  185. 'fingerprint',
  186. 'verify',
  187. 'secure',
  188. ],
  189. ];
  190. }
  191. }
  192. if ($_SESSION['mailcow_cc_role'] == "admin" || $_SESSION['mailcow_cc_role'] == "domainadmin" || $_SESSION['mailcow_cc_role'] == "user") {
  193. if (isset($_GET['syncjob']) &&
  194. is_numeric($_GET['syncjob'])) {
  195. $id = $_GET["syncjob"];
  196. $result = mailbox('get', 'syncjob_details', $id);
  197. $template = 'edit/syncjob.twig';
  198. }
  199. elseif (isset($_GET['filter']) &&
  200. is_numeric($_GET['filter'])) {
  201. $id = $_GET["filter"];
  202. $result = mailbox('get', 'filter_details', $id);
  203. $template = 'edit/filter.twig';
  204. }
  205. elseif (isset($_GET['app-passwd']) &&
  206. is_numeric($_GET['app-passwd'])) {
  207. $id = $_GET["app-passwd"];
  208. $result = app_passwd('details', $id);
  209. $template = 'edit/app-passwd.twig';
  210. }
  211. }
  212. }
  213. else {
  214. $template_data['access_denied'] = true;
  215. }
  216. $js_minifier->add('/web/js/site/edit.js');
  217. $js_minifier->add('/web/js/site/pwgen.js');
  218. $template_data['result'] = $result;
  219. $template_data['return_to'] = $_SESSION['return_to'];
  220. $template_data['lang_user'] = json_encode($lang['user']);
  221. $template_data['lang_admin'] = json_encode($lang['admin']);
  222. $template_data['lang_datatables'] = json_encode($lang['datatables']);
  223. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';