2017-10-21 16:07:06 +08:00
|
|
|
<?php
|
|
|
|
function customize($_action, $_item, $_data = null) {
|
|
|
|
global $redis;
|
|
|
|
global $lang;
|
|
|
|
switch ($_action) {
|
|
|
|
case 'add':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'access_denied'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch ($_item) {
|
|
|
|
case 'main_logo':
|
|
|
|
if (in_array($_data['main_logo']['type'], array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/svg+xml'))) {
|
|
|
|
try {
|
|
|
|
if (file_exists($_data['main_logo']['tmp_name']) !== true) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'img_tmp_missing'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$image = new Imagick($_data['main_logo']['tmp_name']);
|
|
|
|
if ($image->valid() !== true) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'img_invalid'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$image->destroy();
|
|
|
|
}
|
|
|
|
catch (ImagickException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'img_invalid'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'invalid_mime_type'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$redis->Set('MAIN_LOGO', 'data:' . $_data['main_logo']['type'] . ';base64,' . base64_encode(file_get_contents($_data['main_logo']['tmp_name'])));
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'success',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'upload_success'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'access_denied'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch ($_item) {
|
|
|
|
case 'app_links':
|
|
|
|
$apps = (array)$_data['app'];
|
|
|
|
$links = (array)$_data['href'];
|
|
|
|
$out = array();
|
2017-12-09 20:17:15 +08:00
|
|
|
if (count($apps) == count($links)) {
|
2017-10-21 16:07:06 +08:00
|
|
|
for ($i = 0; $i < count($apps); $i++) {
|
|
|
|
$out[] = array($apps[$i] => $links[$i]);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$redis->set('APP_LINKS', json_encode($out));
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'success',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'app_links'
|
2017-12-09 20:17:15 +08:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'ui_texts':
|
2018-01-19 01:23:53 +08:00
|
|
|
$title_name = $_data['title_name'];
|
2017-12-09 20:17:15 +08:00
|
|
|
$main_name = $_data['main_name'];
|
|
|
|
$apps_name = $_data['apps_name'];
|
|
|
|
$help_text = $_data['help_text'];
|
|
|
|
try {
|
2018-01-19 01:23:53 +08:00
|
|
|
$redis->set('TITLE_NAME', htmlspecialchars($title_name));
|
2017-12-09 20:17:15 +08:00
|
|
|
$redis->set('MAIN_NAME', htmlspecialchars($main_name));
|
|
|
|
$redis->set('APPS_NAME', htmlspecialchars($apps_name));
|
|
|
|
$redis->set('HELP_TEXT', $help_text);
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-12-09 20:17:15 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-12-09 20:17:15 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-12-09 20:17:15 +08:00
|
|
|
'type' => 'success',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'ui_texts'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'access_denied'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch ($_item) {
|
|
|
|
case 'main_logo':
|
|
|
|
try {
|
|
|
|
if ($redis->del('MAIN_LOGO')) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'success',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'reset_main_logo'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'get':
|
|
|
|
switch ($_item) {
|
|
|
|
case 'app_links':
|
|
|
|
try {
|
|
|
|
$app_links = json_decode($redis->get('APP_LINKS'), true);
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return ($app_links) ? $app_links : false;
|
|
|
|
break;
|
|
|
|
case 'main_logo':
|
|
|
|
try {
|
|
|
|
return $redis->get('MAIN_LOGO');
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2017-12-09 20:17:15 +08:00
|
|
|
case 'ui_texts':
|
|
|
|
try {
|
2018-01-19 01:23:53 +08:00
|
|
|
$data['title_name'] = ($title_name = $redis->get('TITLE_NAME')) ? $title_name : 'mailcow UI';
|
2017-12-09 20:17:15 +08:00
|
|
|
$data['main_name'] = ($main_name = $redis->get('MAIN_NAME')) ? $main_name : 'mailcow UI';
|
|
|
|
$data['apps_name'] = ($apps_name = $redis->get('APPS_NAME')) ? $apps_name : 'mailcow Apps';
|
|
|
|
$data['help_text'] = ($help_text = $redis->get('HELP_TEXT')) ? $help_text : false;
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-12-09 20:17:15 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-12-09 20:17:15 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2017-10-21 16:07:06 +08:00
|
|
|
case 'main_logo_specs':
|
|
|
|
try {
|
|
|
|
$image = new Imagick();
|
|
|
|
$img_data = explode('base64,', customize('get', 'main_logo'));
|
|
|
|
if ($img_data[1]) {
|
|
|
|
$image->readImageBlob(base64_decode($img_data[1]));
|
|
|
|
}
|
|
|
|
return $image->identifyImage();
|
|
|
|
}
|
|
|
|
catch (ImagickException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2017-10-21 16:07:06 +08:00
|
|
|
'type' => 'danger',
|
2018-08-04 02:31:33 +08:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_item, $_data),
|
|
|
|
'msg' => 'imagick_exception'
|
2017-10-21 16:07:06 +08:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|