Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 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 | }
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 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 | }
|
| 110 | try {
|
| 111 | $redis->hSet('QW_BCC', $domain, json_encode(array('bcc_rcpts' => $bcc_rcpts, 'active' => $active)));
|
| 112 | }
|
| 113 | catch (RedisException $e) {
|
| 114 | $_SESSION['return'][] = array(
|
| 115 | 'type' => 'danger',
|
| 116 | 'log' => array(__FUNCTION__, $_action, $_data_log),
|
| 117 | 'msg' => array('redis_error', $e)
|
| 118 | );
|
| 119 | return false;
|
| 120 | }
|
| 121 | $_SESSION['return'][] = array(
|
| 122 | 'type' => 'success',
|
| 123 | 'log' => array(__FUNCTION__, $_action, $_data_log),
|
| 124 | 'msg' => 'saved_settings'
|
| 125 | );
|
| 126 | break;
|
| 127 | case 'get':
|
| 128 | $domain = $_data;
|
| 129 | if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
|
| 130 | $_SESSION['return'][] = array(
|
| 131 | 'type' => 'danger',
|
| 132 | 'log' => array(__FUNCTION__, $_action, $_data_log),
|
| 133 | 'msg' => 'access_denied'
|
| 134 | );
|
| 135 | return false;
|
| 136 | }
|
| 137 | try {
|
| 138 | return json_decode($redis->hGet('QW_BCC', $domain), true);
|
| 139 | }
|
| 140 | catch (RedisException $e) {
|
| 141 | $_SESSION['return'][] = array(
|
| 142 | 'type' => 'danger',
|
| 143 | 'log' => array(__FUNCTION__, $_action, $_data_log),
|
| 144 | 'msg' => array('redis_error', $e)
|
| 145 | );
|
| 146 | return false;
|
| 147 | }
|
| 148 | break;
|
| 149 | }
|
| 150 | }
|