edit.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. ];
  66. $template = 'edit/domain-templates.twig';
  67. $result = true;
  68. }
  69. else {
  70. $mailbox_template = mailbox('get', 'mailbox_templates', $_GET["template"]);
  71. if ($mailbox_template){
  72. $template_data = [
  73. 'template' => $mailbox_template
  74. ];
  75. $template = 'edit/mailbox-templates.twig';
  76. $result = true;
  77. }
  78. }
  79. }
  80. elseif (isset($_GET['oauth2client']) &&
  81. is_numeric($_GET["oauth2client"]) &&
  82. !empty($_GET["oauth2client"])) {
  83. $oauth2client = $_GET["oauth2client"];
  84. $result = oauth2('details', 'client', $oauth2client);
  85. $template = 'edit/oauth2client.twig';
  86. $template_data = ['oauth2client' => $oauth2client];
  87. }
  88. elseif (isset($_GET['aliasdomain']) &&
  89. is_valid_domain_name(html_entity_decode(rawurldecode($_GET["aliasdomain"]))) &&
  90. !empty($_GET["aliasdomain"])) {
  91. $alias_domain = html_entity_decode(rawurldecode($_GET["aliasdomain"]));
  92. $result = mailbox('get', 'alias_domain_details', $alias_domain);
  93. $rl = ratelimit('get', 'domain', $alias_domain);
  94. $template = 'edit/aliasdomain.twig';
  95. $template_data = [
  96. 'alias_domain' => $alias_domain,
  97. 'rl' => $rl,
  98. 'domains' => mailbox('get', 'domains'),
  99. 'dkim' => dkim('details', $alias_domain),
  100. ];
  101. }
  102. elseif (isset($_GET['mailbox'])){
  103. if(filter_var(html_entity_decode(rawurldecode($_GET["mailbox"])), FILTER_VALIDATE_EMAIL) && !empty($_GET["mailbox"])) {
  104. // edit mailbox
  105. $mailbox = html_entity_decode(rawurldecode($_GET["mailbox"]));
  106. $result = mailbox('get', 'mailbox_details', $mailbox);
  107. $rl = ratelimit('get', 'mailbox', $mailbox);
  108. $pushover_data = pushover('get', $mailbox);
  109. $quarantine_notification = mailbox('get', 'quarantine_notification', $mailbox);
  110. $quarantine_category = mailbox('get', 'quarantine_category', $mailbox);
  111. $get_tls_policy = mailbox('get', 'tls_policy', $mailbox);
  112. $rlyhosts = relayhost('get');
  113. $template = 'edit/mailbox.twig';
  114. $template_data = [
  115. 'acl' => $_SESSION['acl'],
  116. 'mailbox' => $mailbox,
  117. 'rl' => $rl,
  118. 'pushover_data' => $pushover_data,
  119. 'quarantine_notification' => $quarantine_notification,
  120. 'quarantine_category' => $quarantine_category,
  121. 'get_tls_policy' => $get_tls_policy,
  122. 'rlyhosts' => $rlyhosts,
  123. 'sender_acl_handles' => mailbox('get', 'sender_acl_handles', $mailbox),
  124. 'user_acls' => acl('get', 'user', $mailbox),
  125. 'mailbox_details' => $result
  126. ];
  127. }
  128. }
  129. elseif (isset($_GET['relayhost']) && is_numeric($_GET["relayhost"]) && !empty($_GET["relayhost"])) {
  130. $relayhost = intval($_GET["relayhost"]);
  131. $result = relayhost('details', $relayhost);
  132. $template = 'edit/relayhost.twig';
  133. $template_data = ['relayhost' => $relayhost];
  134. }
  135. elseif (isset($_GET['transport']) && is_numeric($_GET["transport"]) && !empty($_GET["transport"])) {
  136. $transport = intval($_GET["transport"]);
  137. $result = transport('details', $transport);
  138. $template = 'edit/transport.twig';
  139. $template_data = ['transport' => $transport];
  140. }
  141. elseif (isset($_GET['resource']) && filter_var(html_entity_decode(rawurldecode($_GET["resource"])), FILTER_VALIDATE_EMAIL) && !empty($_GET["resource"])) {
  142. $resource = html_entity_decode(rawurldecode($_GET["resource"]));
  143. $result = mailbox('get', 'resource_details', $resource);
  144. $template = 'edit/resource.twig';
  145. }
  146. elseif (isset($_GET['bcc']) && !empty($_GET["bcc"])) {
  147. $bcc = intval($_GET["bcc"]);
  148. $result = bcc('details', $bcc);
  149. $template = 'edit/bcc.twig';
  150. $template_data = ['bcc' => $bcc];
  151. }
  152. elseif (isset($_GET['recipient_map']) &&
  153. !empty($_GET["recipient_map"]) &&
  154. $_SESSION['mailcow_cc_role'] == "admin") {
  155. $map = intval($_GET["recipient_map"]);
  156. $result = recipient_map('details', $map);
  157. if (substr($result['recipient_map_old'], 0, 1) == '@') {
  158. $result['recipient_map_old'] = substr($result['recipient_map_old'], 1);
  159. }
  160. $template = 'edit/recipient_map.twig';
  161. $template_data = ['map' => $map];
  162. }
  163. elseif (isset($_GET['tls_policy_map']) &&
  164. !empty($_GET["tls_policy_map"]) &&
  165. $_SESSION['mailcow_cc_role'] == "admin") {
  166. $map = intval($_GET["tls_policy_map"]);
  167. $result = tls_policy_maps('details', $map);
  168. $template = 'edit/tls_policy_map.twig';
  169. $template_data = [
  170. 'map' => $map,
  171. 'policy_options' => [
  172. 'none',
  173. 'may',
  174. 'encrypt',
  175. 'dane',
  176. 'dane-only',
  177. 'fingerprint',
  178. 'verify',
  179. 'secure',
  180. ],
  181. ];
  182. }
  183. }
  184. if ($_SESSION['mailcow_cc_role'] == "admin" || $_SESSION['mailcow_cc_role'] == "domainadmin" || $_SESSION['mailcow_cc_role'] == "user") {
  185. if (isset($_GET['syncjob']) &&
  186. is_numeric($_GET['syncjob'])) {
  187. $id = $_GET["syncjob"];
  188. $result = mailbox('get', 'syncjob_details', $id);
  189. $template = 'edit/syncjob.twig';
  190. }
  191. elseif (isset($_GET['filter']) &&
  192. is_numeric($_GET['filter'])) {
  193. $id = $_GET["filter"];
  194. $result = mailbox('get', 'filter_details', $id);
  195. $template = 'edit/filter.twig';
  196. }
  197. elseif (isset($_GET['app-passwd']) &&
  198. is_numeric($_GET['app-passwd'])) {
  199. $id = $_GET["app-passwd"];
  200. $result = app_passwd('details', $id);
  201. $template = 'edit/app-passwd.twig';
  202. }
  203. }
  204. }
  205. else {
  206. $template_data['access_denied'] = true;
  207. }
  208. $js_minifier->add('/web/js/site/edit.js');
  209. $js_minifier->add('/web/js/site/pwgen.js');
  210. $template_data['result'] = $result;
  211. $template_data['return_to'] = $_SESSION['return_to'];
  212. $template_data['lang_user'] = json_encode($lang['user']);
  213. $template_data['lang_datatables'] = json_encode($lang['datatables']);
  214. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';