Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | <?php
|
| 2 | function customize($_action, $_item, $_data = null) {
|
| 3 | global $redis;
|
| 4 | global $lang;
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 5 |
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 6 | switch ($_action) {
|
| 7 | case 'add':
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 8 | // disable functionality when demo mode is enabled
|
| 9 | if ($GLOBALS["DEMO_MODE"]) {
|
| 10 | $_SESSION['return'][] = array(
|
| 11 | 'type' => 'danger',
|
| 12 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 13 | 'msg' => 'demo_mode_enabled'
|
| 14 | );
|
| 15 | return false;
|
| 16 | }
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 17 | if ($_SESSION['mailcow_cc_role'] != "admin") {
|
| 18 | $_SESSION['return'][] = array(
|
| 19 | 'type' => 'danger',
|
| 20 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 21 | 'msg' => 'access_denied'
|
| 22 | );
|
| 23 | return false;
|
| 24 | }
|
| 25 | switch ($_item) {
|
| 26 | case 'main_logo':
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 27 | case 'main_logo_dark':
|
| 28 | if (in_array($_data[$_item]['type'], array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/svg+xml'))) {
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 29 | try {
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 30 | if (file_exists($_data[$_item]['tmp_name']) !== true) {
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 31 | $_SESSION['return'][] = array(
|
| 32 | 'type' => 'danger',
|
| 33 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 34 | 'msg' => 'img_tmp_missing'
|
| 35 | );
|
| 36 | return false;
|
| 37 | }
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 38 | $image = new Imagick($_data[$_item]['tmp_name']);
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 39 | if ($image->valid() !== true) {
|
| 40 | $_SESSION['return'][] = array(
|
| 41 | 'type' => 'danger',
|
| 42 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 43 | 'msg' => 'img_invalid'
|
| 44 | );
|
| 45 | return false;
|
| 46 | }
|
| 47 | $image->destroy();
|
| 48 | }
|
| 49 | catch (ImagickException $e) {
|
| 50 | $_SESSION['return'][] = array(
|
| 51 | 'type' => 'danger',
|
| 52 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 53 | 'msg' => 'img_invalid'
|
| 54 | );
|
| 55 | return false;
|
| 56 | }
|
| 57 | }
|
| 58 | else {
|
| 59 | $_SESSION['return'][] = array(
|
| 60 | 'type' => 'danger',
|
| 61 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 62 | 'msg' => 'invalid_mime_type'
|
| 63 | );
|
| 64 | return false;
|
| 65 | }
|
| 66 | try {
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 67 | $redis->Set(strtoupper($_item), 'data:' . $_data[$_item]['type'] . ';base64,' . base64_encode(file_get_contents($_data[$_item]['tmp_name'])));
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 68 | }
|
| 69 | catch (RedisException $e) {
|
| 70 | $_SESSION['return'][] = array(
|
| 71 | 'type' => 'danger',
|
| 72 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 73 | 'msg' => array('redis_error', $e)
|
| 74 | );
|
| 75 | return false;
|
| 76 | }
|
| 77 | $_SESSION['return'][] = array(
|
| 78 | 'type' => 'success',
|
| 79 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 80 | 'msg' => 'upload_success'
|
| 81 | );
|
| 82 | break;
|
| 83 | }
|
| 84 | break;
|
| 85 | case 'edit':
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 86 | // disable functionality when demo mode is enabled
|
| 87 | if ($GLOBALS["DEMO_MODE"]) {
|
| 88 | $_SESSION['return'][] = array(
|
| 89 | 'type' => 'danger',
|
| 90 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 91 | 'msg' => 'demo_mode_enabled'
|
| 92 | );
|
| 93 | return false;
|
| 94 | }
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 95 | if ($_SESSION['mailcow_cc_role'] != "admin") {
|
| 96 | $_SESSION['return'][] = array(
|
| 97 | 'type' => 'danger',
|
| 98 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 99 | 'msg' => 'access_denied'
|
| 100 | );
|
| 101 | return false;
|
| 102 | }
|
| 103 | switch ($_item) {
|
| 104 | case 'app_links':
|
| 105 | $apps = (array)$_data['app'];
|
| 106 | $links = (array)$_data['href'];
|
| 107 | $out = array();
|
| 108 | if (count($apps) == count($links)) {
|
| 109 | for ($i = 0; $i < count($apps); $i++) {
|
| 110 | $out[] = array($apps[$i] => $links[$i]);
|
| 111 | }
|
| 112 | try {
|
| 113 | $redis->set('APP_LINKS', json_encode($out));
|
| 114 | }
|
| 115 | catch (RedisException $e) {
|
| 116 | $_SESSION['return'][] = array(
|
| 117 | 'type' => 'danger',
|
| 118 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 119 | 'msg' => array('redis_error', $e)
|
| 120 | );
|
| 121 | return false;
|
| 122 | }
|
| 123 | }
|
| 124 | $_SESSION['return'][] = array(
|
| 125 | 'type' => 'success',
|
| 126 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 127 | 'msg' => 'app_links'
|
| 128 | );
|
| 129 | break;
|
| 130 | case 'ui_texts':
|
| 131 | $title_name = $_data['title_name'];
|
| 132 | $main_name = $_data['main_name'];
|
| 133 | $apps_name = $_data['apps_name'];
|
| 134 | $help_text = $_data['help_text'];
|
| 135 | $ui_footer = $_data['ui_footer'];
|
| 136 | $ui_announcement_text = $_data['ui_announcement_text'];
|
| 137 | $ui_announcement_type = (in_array($_data['ui_announcement_type'], array('info', 'warning', 'danger'))) ? $_data['ui_announcement_type'] : false;
|
| 138 | $ui_announcement_active = (!empty($_data['ui_announcement_active']) ? 1 : 0);
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 139 |
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 140 | try {
|
| 141 | $redis->set('TITLE_NAME', htmlspecialchars($title_name));
|
| 142 | $redis->set('MAIN_NAME', htmlspecialchars($main_name));
|
| 143 | $redis->set('APPS_NAME', htmlspecialchars($apps_name));
|
| 144 | $redis->set('HELP_TEXT', $help_text);
|
| 145 | $redis->set('UI_FOOTER', $ui_footer);
|
| 146 | $redis->set('UI_ANNOUNCEMENT_TEXT', $ui_announcement_text);
|
| 147 | $redis->set('UI_ANNOUNCEMENT_TYPE', $ui_announcement_type);
|
| 148 | $redis->set('UI_ANNOUNCEMENT_ACTIVE', $ui_announcement_active);
|
| 149 | }
|
| 150 | catch (RedisException $e) {
|
| 151 | $_SESSION['return'][] = array(
|
| 152 | 'type' => 'danger',
|
| 153 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 154 | 'msg' => array('redis_error', $e)
|
| 155 | );
|
| 156 | return false;
|
| 157 | }
|
| 158 | $_SESSION['return'][] = array(
|
| 159 | 'type' => 'success',
|
| 160 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 161 | 'msg' => 'ui_texts'
|
| 162 | );
|
| 163 | break;
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 164 | case 'ip_check':
|
| 165 | $ip_check = ($_data['ip_check_opt_in'] == "1") ? 1 : 0;
|
| 166 | try {
|
| 167 | $redis->set('IP_CHECK', $ip_check);
|
| 168 | }
|
| 169 | catch (RedisException $e) {
|
| 170 | $_SESSION['return'][] = array(
|
| 171 | 'type' => 'danger',
|
| 172 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 173 | 'msg' => array('redis_error', $e)
|
| 174 | );
|
| 175 | return false;
|
| 176 | }
|
| 177 | $_SESSION['return'][] = array(
|
| 178 | 'type' => 'success',
|
| 179 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 180 | 'msg' => 'ip_check_opt_in_modified'
|
| 181 | );
|
| 182 | break;
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 183 | }
|
| 184 | break;
|
| 185 | case 'delete':
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 186 | // disable functionality when demo mode is enabled
|
| 187 | if ($GLOBALS["DEMO_MODE"]) {
|
| 188 | $_SESSION['return'][] = array(
|
| 189 | 'type' => 'danger',
|
| 190 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 191 | 'msg' => 'demo_mode_enabled'
|
| 192 | );
|
| 193 | return false;
|
| 194 | }
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 195 | if ($_SESSION['mailcow_cc_role'] != "admin") {
|
| 196 | $_SESSION['return'][] = array(
|
| 197 | 'type' => 'danger',
|
| 198 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 199 | 'msg' => 'access_denied'
|
| 200 | );
|
| 201 | return false;
|
| 202 | }
|
| 203 | switch ($_item) {
|
| 204 | case 'main_logo':
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 205 | case 'main_logo_dark':
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 206 | try {
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 207 | if ($redis->del(strtoupper($_item))) {
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 208 | $_SESSION['return'][] = array(
|
| 209 | 'type' => 'success',
|
| 210 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 211 | 'msg' => 'reset_main_logo'
|
| 212 | );
|
| 213 | return true;
|
| 214 | }
|
| 215 | }
|
| 216 | catch (RedisException $e) {
|
| 217 | $_SESSION['return'][] = array(
|
| 218 | 'type' => 'danger',
|
| 219 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 220 | 'msg' => array('redis_error', $e)
|
| 221 | );
|
| 222 | return false;
|
| 223 | }
|
| 224 | break;
|
| 225 | }
|
| 226 | break;
|
| 227 | case 'get':
|
| 228 | switch ($_item) {
|
| 229 | case 'app_links':
|
| 230 | try {
|
| 231 | $app_links = json_decode($redis->get('APP_LINKS'), true);
|
| 232 | }
|
| 233 | catch (RedisException $e) {
|
| 234 | $_SESSION['return'][] = array(
|
| 235 | 'type' => 'danger',
|
| 236 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 237 | 'msg' => array('redis_error', $e)
|
| 238 | );
|
| 239 | return false;
|
| 240 | }
|
| 241 | return ($app_links) ? $app_links : false;
|
| 242 | break;
|
| 243 | case 'main_logo':
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 244 | case 'main_logo_dark':
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 245 | try {
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 246 | return $redis->get(strtoupper($_item));
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 247 | }
|
| 248 | catch (RedisException $e) {
|
| 249 | $_SESSION['return'][] = array(
|
| 250 | 'type' => 'danger',
|
| 251 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 252 | 'msg' => array('redis_error', $e)
|
| 253 | );
|
| 254 | return false;
|
| 255 | }
|
| 256 | break;
|
| 257 | case 'ui_texts':
|
| 258 | try {
|
| 259 | $data['title_name'] = ($title_name = $redis->get('TITLE_NAME')) ? $title_name : 'mailcow UI';
|
| 260 | $data['main_name'] = ($main_name = $redis->get('MAIN_NAME')) ? $main_name : 'mailcow UI';
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 261 | $data['apps_name'] = ($apps_name = $redis->get('APPS_NAME')) ? $apps_name : $lang['header']['apps'];
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 262 | $data['help_text'] = ($help_text = $redis->get('HELP_TEXT')) ? $help_text : false;
|
| 263 | if (!empty($redis->get('UI_IMPRESS'))) {
|
| 264 | $redis->set('UI_FOOTER', $redis->get('UI_IMPRESS'));
|
| 265 | $redis->del('UI_IMPRESS');
|
| 266 | }
|
| 267 | $data['ui_footer'] = ($ui_footer = $redis->get('UI_FOOTER')) ? $ui_footer : false;
|
| 268 | $data['ui_announcement_text'] = ($ui_announcement_text = $redis->get('UI_ANNOUNCEMENT_TEXT')) ? $ui_announcement_text : false;
|
| 269 | $data['ui_announcement_type'] = ($ui_announcement_type = $redis->get('UI_ANNOUNCEMENT_TYPE')) ? $ui_announcement_type : false;
|
| 270 | $data['ui_announcement_active'] = ($redis->get('UI_ANNOUNCEMENT_ACTIVE') == 1) ? 1 : 0;
|
| 271 | return $data;
|
| 272 | }
|
| 273 | catch (RedisException $e) {
|
| 274 | $_SESSION['return'][] = array(
|
| 275 | 'type' => 'danger',
|
| 276 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 277 | 'msg' => array('redis_error', $e)
|
| 278 | );
|
| 279 | return false;
|
| 280 | }
|
| 281 | break;
|
| 282 | case 'main_logo_specs':
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 283 | case 'main_logo_dark_specs':
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 284 | try {
|
| 285 | $image = new Imagick();
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 286 | if($_item == 'main_logo_specs') {
|
| 287 | $img_data = explode('base64,', customize('get', 'main_logo'));
|
| 288 | } else {
|
| 289 | $img_data = explode('base64,', customize('get', 'main_logo_dark'));
|
| 290 | }
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 291 | if ($img_data[1]) {
|
| 292 | $image->readImageBlob(base64_decode($img_data[1]));
|
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 293 | return $image->identifyImage();
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 294 | }
|
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 295 | return false;
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 296 | }
|
| 297 | catch (ImagickException $e) {
|
| 298 | $_SESSION['return'][] = array(
|
| 299 | 'type' => 'danger',
|
| 300 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 301 | 'msg' => 'imagick_exception'
|
| 302 | );
|
| 303 | return false;
|
| 304 | }
|
| 305 | break;
|
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 306 | case 'ip_check':
|
| 307 | try {
|
| 308 | $ip_check = ($ip_check = $redis->get('IP_CHECK')) ? $ip_check : 0;
|
| 309 | return $ip_check;
|
| 310 | }
|
| 311 | catch (RedisException $e) {
|
| 312 | $_SESSION['return'][] = array(
|
| 313 | 'type' => 'danger',
|
| 314 | 'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
| 315 | 'msg' => array('redis_error', $e)
|
| 316 | );
|
| 317 | return false;
|
| 318 | }
|
| 319 | break;
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 320 | }
|
| 321 | break;
|
| 322 | }
|
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 323 | }
|