functions.quota_notification.inc.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. function quota_notification($_action, $_data = null) {
  3. global $redis;
  4. $_data_log = $_data;
  5. if ($_SESSION['mailcow_cc_role'] != "admin") {
  6. $_SESSION['return'][] = array(
  7. 'type' => 'danger',
  8. 'log' => array(__FUNCTION__, $_action, $_data_log),
  9. 'msg' => 'access_denied'
  10. );
  11. return false;
  12. }
  13. switch ($_action) {
  14. case 'edit':
  15. $retention_size = $_data['retention_size'];
  16. if ($_data['release_format'] == 'attachment' || $_data['release_format'] == 'raw') {
  17. $release_format = $_data['release_format'];
  18. }
  19. else {
  20. $release_format = 'raw';
  21. }
  22. $subject = $_data['subject'];
  23. $sender = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $_data['sender']);
  24. if (filter_var($sender, FILTER_VALIDATE_EMAIL) === false) {
  25. $sender = '';
  26. }
  27. $html = $_data['html_tmpl'];
  28. try {
  29. $redis->Set('QW_SENDER', $sender);
  30. $redis->Set('QW_SUBJ', $subject);
  31. $redis->Set('QW_HTML', $html);
  32. }
  33. catch (RedisException $e) {
  34. $_SESSION['return'][] = array(
  35. 'type' => 'danger',
  36. 'log' => array(__FUNCTION__, $_action, $_data_log),
  37. 'msg' => array('redis_error', $e)
  38. );
  39. return false;
  40. }
  41. $_SESSION['return'][] = array(
  42. 'type' => 'success',
  43. 'log' => array(__FUNCTION__, $_action, $_data_log),
  44. 'msg' => 'saved_settings'
  45. );
  46. break;
  47. case 'get':
  48. try {
  49. $settings['subject'] = $redis->Get('QW_SUBJ');
  50. $settings['sender'] = $redis->Get('QW_SENDER');
  51. $settings['html_tmpl'] = htmlspecialchars($redis->Get('QW_HTML'));
  52. if (empty($settings['html_tmpl'])) {
  53. $settings['html_tmpl'] = htmlspecialchars(file_get_contents("/tpls/quota.tpl"));
  54. }
  55. }
  56. catch (RedisException $e) {
  57. $_SESSION['return'][] = array(
  58. 'type' => 'danger',
  59. 'log' => array(__FUNCTION__, $_action, $_data_log),
  60. 'msg' => array('redis_error', $e)
  61. );
  62. return false;
  63. }
  64. return $settings;
  65. break;
  66. }
  67. }
  68. function quota_notification_bcc($_action, $_data = null) {
  69. global $redis;
  70. $_data_log = $_data;
  71. if ($_SESSION['mailcow_cc_role'] != "admin" && $_SESSION['mailcow_cc_role'] != "domainadmin") {
  72. $_SESSION['return'][] = array(
  73. 'type' => 'danger',
  74. 'log' => array(__FUNCTION__, $_action, $_data_log),
  75. 'msg' => 'access_denied'
  76. );
  77. return false;
  78. }
  79. switch ($_action) {
  80. case 'edit':
  81. $domain = $_data['domain'];
  82. if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
  83. $_SESSION['return'][] = array(
  84. 'type' => 'danger',
  85. 'log' => array(__FUNCTION__, $_action, $_data_log),
  86. 'msg' => 'access_denied'
  87. );
  88. return false;
  89. }
  90. $active = intval($_data['active']);
  91. $bcc_rcpts = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['bcc_rcpt']));
  92. foreach ($bcc_rcpts as $i => &$rcpt) {
  93. $rcpt = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $rcpt);
  94. if (!empty($rcpt) && filter_var($rcpt, FILTER_VALIDATE_EMAIL) === false) {
  95. $_SESSION['return'][] = array(
  96. 'type' => 'danger',
  97. 'log' => array(__FUNCTION__, $_action, $_data_log),
  98. 'msg' => array('goto_invalid', htmlspecialchars($rcpt))
  99. );
  100. unset($bcc_rcpts[$i]);
  101. continue;
  102. }
  103. }
  104. $bcc_rcpts = array_unique($bcc_rcpts);
  105. $bcc_rcpts = array_filter($bcc_rcpts);
  106. if (empty($bcc_rcpts)) {
  107. $active = 0;
  108. }
  109. try {
  110. $redis->hSet('QW_BCC', $domain, json_encode(array('bcc_rcpts' => $bcc_rcpts, 'active' => $active)));
  111. }
  112. catch (RedisException $e) {
  113. $_SESSION['return'][] = array(
  114. 'type' => 'danger',
  115. 'log' => array(__FUNCTION__, $_action, $_data_log),
  116. 'msg' => array('redis_error', $e)
  117. );
  118. return false;
  119. }
  120. $_SESSION['return'][] = array(
  121. 'type' => 'success',
  122. 'log' => array(__FUNCTION__, $_action, $_data_log),
  123. 'msg' => 'saved_settings'
  124. );
  125. break;
  126. case 'get':
  127. $domain = $_data;
  128. if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
  129. $_SESSION['return'][] = array(
  130. 'type' => 'danger',
  131. 'log' => array(__FUNCTION__, $_action, $_data_log),
  132. 'msg' => 'access_denied'
  133. );
  134. return false;
  135. }
  136. try {
  137. return json_decode($redis->hGet('QW_BCC', $domain), true);
  138. }
  139. catch (RedisException $e) {
  140. $_SESSION['return'][] = array(
  141. 'type' => 'danger',
  142. 'log' => array(__FUNCTION__, $_action, $_data_log),
  143. 'msg' => array('redis_error', $e)
  144. );
  145. return false;
  146. }
  147. break;
  148. }
  149. }