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 | }
|