blob: d59482208adea6757364f674be11fe5d6514001b [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2function customize($_action, $_item, $_data = null) {
3 global $redis;
4 global $lang;
5 switch ($_action) {
6 case 'add':
7 if ($_SESSION['mailcow_cc_role'] != "admin") {
8 $_SESSION['return'][] = array(
9 'type' => 'danger',
10 'log' => array(__FUNCTION__, $_action, $_item, $_data),
11 'msg' => 'access_denied'
12 );
13 return false;
14 }
15 switch ($_item) {
16 case 'main_logo':
17 if (in_array($_data['main_logo']['type'], array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/svg+xml'))) {
18 try {
19 if (file_exists($_data['main_logo']['tmp_name']) !== true) {
20 $_SESSION['return'][] = array(
21 'type' => 'danger',
22 'log' => array(__FUNCTION__, $_action, $_item, $_data),
23 'msg' => 'img_tmp_missing'
24 );
25 return false;
26 }
27 $image = new Imagick($_data['main_logo']['tmp_name']);
28 if ($image->valid() !== true) {
29 $_SESSION['return'][] = array(
30 'type' => 'danger',
31 'log' => array(__FUNCTION__, $_action, $_item, $_data),
32 'msg' => 'img_invalid'
33 );
34 return false;
35 }
36 $image->destroy();
37 }
38 catch (ImagickException $e) {
39 $_SESSION['return'][] = array(
40 'type' => 'danger',
41 'log' => array(__FUNCTION__, $_action, $_item, $_data),
42 'msg' => 'img_invalid'
43 );
44 return false;
45 }
46 }
47 else {
48 $_SESSION['return'][] = array(
49 'type' => 'danger',
50 'log' => array(__FUNCTION__, $_action, $_item, $_data),
51 'msg' => 'invalid_mime_type'
52 );
53 return false;
54 }
55 try {
56 $redis->Set('MAIN_LOGO', 'data:' . $_data['main_logo']['type'] . ';base64,' . base64_encode(file_get_contents($_data['main_logo']['tmp_name'])));
57 }
58 catch (RedisException $e) {
59 $_SESSION['return'][] = array(
60 'type' => 'danger',
61 'log' => array(__FUNCTION__, $_action, $_item, $_data),
62 'msg' => array('redis_error', $e)
63 );
64 return false;
65 }
66 $_SESSION['return'][] = array(
67 'type' => 'success',
68 'log' => array(__FUNCTION__, $_action, $_item, $_data),
69 'msg' => 'upload_success'
70 );
71 break;
72 }
73 break;
74 case 'edit':
75 if ($_SESSION['mailcow_cc_role'] != "admin") {
76 $_SESSION['return'][] = array(
77 'type' => 'danger',
78 'log' => array(__FUNCTION__, $_action, $_item, $_data),
79 'msg' => 'access_denied'
80 );
81 return false;
82 }
83 switch ($_item) {
84 case 'app_links':
85 $apps = (array)$_data['app'];
86 $links = (array)$_data['href'];
87 $out = array();
88 if (count($apps) == count($links)) {
89 for ($i = 0; $i < count($apps); $i++) {
90 $out[] = array($apps[$i] => $links[$i]);
91 }
92 try {
93 $redis->set('APP_LINKS', json_encode($out));
94 }
95 catch (RedisException $e) {
96 $_SESSION['return'][] = array(
97 'type' => 'danger',
98 'log' => array(__FUNCTION__, $_action, $_item, $_data),
99 'msg' => array('redis_error', $e)
100 );
101 return false;
102 }
103 }
104 $_SESSION['return'][] = array(
105 'type' => 'success',
106 'log' => array(__FUNCTION__, $_action, $_item, $_data),
107 'msg' => 'app_links'
108 );
109 break;
110 case 'ui_texts':
111 $title_name = $_data['title_name'];
112 $main_name = $_data['main_name'];
113 $apps_name = $_data['apps_name'];
114 $help_text = $_data['help_text'];
115 $ui_footer = $_data['ui_footer'];
116 $ui_announcement_text = $_data['ui_announcement_text'];
117 $ui_announcement_type = (in_array($_data['ui_announcement_type'], array('info', 'warning', 'danger'))) ? $_data['ui_announcement_type'] : false;
118 $ui_announcement_active = (!empty($_data['ui_announcement_active']) ? 1 : 0);
119 try {
120 $redis->set('TITLE_NAME', htmlspecialchars($title_name));
121 $redis->set('MAIN_NAME', htmlspecialchars($main_name));
122 $redis->set('APPS_NAME', htmlspecialchars($apps_name));
123 $redis->set('HELP_TEXT', $help_text);
124 $redis->set('UI_FOOTER', $ui_footer);
125 $redis->set('UI_ANNOUNCEMENT_TEXT', $ui_announcement_text);
126 $redis->set('UI_ANNOUNCEMENT_TYPE', $ui_announcement_type);
127 $redis->set('UI_ANNOUNCEMENT_ACTIVE', $ui_announcement_active);
128 }
129 catch (RedisException $e) {
130 $_SESSION['return'][] = array(
131 'type' => 'danger',
132 'log' => array(__FUNCTION__, $_action, $_item, $_data),
133 'msg' => array('redis_error', $e)
134 );
135 return false;
136 }
137 $_SESSION['return'][] = array(
138 'type' => 'success',
139 'log' => array(__FUNCTION__, $_action, $_item, $_data),
140 'msg' => 'ui_texts'
141 );
142 break;
143 }
144 break;
145 case 'delete':
146 if ($_SESSION['mailcow_cc_role'] != "admin") {
147 $_SESSION['return'][] = array(
148 'type' => 'danger',
149 'log' => array(__FUNCTION__, $_action, $_item, $_data),
150 'msg' => 'access_denied'
151 );
152 return false;
153 }
154 switch ($_item) {
155 case 'main_logo':
156 try {
157 if ($redis->del('MAIN_LOGO')) {
158 $_SESSION['return'][] = array(
159 'type' => 'success',
160 'log' => array(__FUNCTION__, $_action, $_item, $_data),
161 'msg' => 'reset_main_logo'
162 );
163 return true;
164 }
165 }
166 catch (RedisException $e) {
167 $_SESSION['return'][] = array(
168 'type' => 'danger',
169 'log' => array(__FUNCTION__, $_action, $_item, $_data),
170 'msg' => array('redis_error', $e)
171 );
172 return false;
173 }
174 break;
175 }
176 break;
177 case 'get':
178 switch ($_item) {
179 case 'app_links':
180 try {
181 $app_links = json_decode($redis->get('APP_LINKS'), true);
182 }
183 catch (RedisException $e) {
184 $_SESSION['return'][] = array(
185 'type' => 'danger',
186 'log' => array(__FUNCTION__, $_action, $_item, $_data),
187 'msg' => array('redis_error', $e)
188 );
189 return false;
190 }
191 return ($app_links) ? $app_links : false;
192 break;
193 case 'main_logo':
194 try {
195 return $redis->get('MAIN_LOGO');
196 }
197 catch (RedisException $e) {
198 $_SESSION['return'][] = array(
199 'type' => 'danger',
200 'log' => array(__FUNCTION__, $_action, $_item, $_data),
201 'msg' => array('redis_error', $e)
202 );
203 return false;
204 }
205 break;
206 case 'ui_texts':
207 try {
208 $data['title_name'] = ($title_name = $redis->get('TITLE_NAME')) ? $title_name : 'mailcow UI';
209 $data['main_name'] = ($main_name = $redis->get('MAIN_NAME')) ? $main_name : 'mailcow UI';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200210 $data['apps_name'] = ($apps_name = $redis->get('APPS_NAME')) ? $apps_name : $lang['header']['apps'];
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100211 $data['help_text'] = ($help_text = $redis->get('HELP_TEXT')) ? $help_text : false;
212 if (!empty($redis->get('UI_IMPRESS'))) {
213 $redis->set('UI_FOOTER', $redis->get('UI_IMPRESS'));
214 $redis->del('UI_IMPRESS');
215 }
216 $data['ui_footer'] = ($ui_footer = $redis->get('UI_FOOTER')) ? $ui_footer : false;
217 $data['ui_announcement_text'] = ($ui_announcement_text = $redis->get('UI_ANNOUNCEMENT_TEXT')) ? $ui_announcement_text : false;
218 $data['ui_announcement_type'] = ($ui_announcement_type = $redis->get('UI_ANNOUNCEMENT_TYPE')) ? $ui_announcement_type : false;
219 $data['ui_announcement_active'] = ($redis->get('UI_ANNOUNCEMENT_ACTIVE') == 1) ? 1 : 0;
220 return $data;
221 }
222 catch (RedisException $e) {
223 $_SESSION['return'][] = array(
224 'type' => 'danger',
225 'log' => array(__FUNCTION__, $_action, $_item, $_data),
226 'msg' => array('redis_error', $e)
227 );
228 return false;
229 }
230 break;
231 case 'main_logo_specs':
232 try {
233 $image = new Imagick();
234 $img_data = explode('base64,', customize('get', 'main_logo'));
235 if ($img_data[1]) {
236 $image->readImageBlob(base64_decode($img_data[1]));
237 }
238 return $image->identifyImage();
239 }
240 catch (ImagickException $e) {
241 $_SESSION['return'][] = array(
242 'type' => 'danger',
243 'log' => array(__FUNCTION__, $_action, $_item, $_data),
244 'msg' => 'imagick_exception'
245 );
246 return false;
247 }
248 break;
249 }
250 break;
251 }
252}