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