* Remove useless code.
This commit is contained in:
+1
-181
@@ -157,7 +157,7 @@ class instance extends control
|
||||
/* Request CNE to adjust memory size. */
|
||||
if(!$this->instance->updateMemorySize($instance, $memoryKb * 1024))
|
||||
{
|
||||
$this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,184 +534,4 @@ class instance extends control
|
||||
$url = '/adminer?' . http_build_query($dbAuth);
|
||||
$this->send(array('result' => 'success', 'message' => '', 'data' => array('url' => $url)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整实例内存大小。
|
||||
* Adjust instance memory size by ajax.
|
||||
*
|
||||
* @param int $instanceID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxAdjustMemory($instanceID)
|
||||
{
|
||||
if(!commonModel::hasPriv('instance', 'manage')) $this->loadModel('common')->deny('instance', 'manage', false);
|
||||
$postData = fixer::input('post')->get();
|
||||
|
||||
/* Check free memory size is enough or not. */
|
||||
$clusterResource = $this->cne->cneMetrics();
|
||||
$freeMemory = intval($clusterResource->metrics->memory->allocatable * 0.9); // Remain 10% memory for system.
|
||||
if($postData->memory_kb * 1024 > $freeMemory) $this->send(array('result' => 'fail', 'message' => $this->lang->instance->errors->notEnoughResource));
|
||||
|
||||
/* Request CNE to adjust memory size. */
|
||||
$instance = $this->instance->getByID($instanceID);
|
||||
if(!$this->instance->updateMemorySize($instance, $postData->memory_kb * 1024))
|
||||
{
|
||||
$this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
}
|
||||
|
||||
$this->send(array('result' => 'success', 'message' => ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新自定义配置。
|
||||
* Update custom settings by ajax. For example: env variables.
|
||||
*
|
||||
* @param int $instanceID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxUpdateCustom($instanceID)
|
||||
{
|
||||
$instance = $this->instance->getByID($instanceID);
|
||||
if(!$instance) $this->send(array('result' => 'fail', 'message' => $this->lang->instance->instanceNotExists));
|
||||
|
||||
$postData = fixer::input('post')->get();
|
||||
|
||||
$settings = new stdclass;
|
||||
$settings->force_restart = true;
|
||||
$settings->settings_map = new stdclass;
|
||||
$settings->settings_map->custom = $postData;
|
||||
|
||||
if($this->cne->updateConfig($instance, $settings))
|
||||
{
|
||||
$this->action->create('instance', $instanceID, 'updatecustom', '', json_encode($settings));
|
||||
$this->send(array('result' => 'success', 'message' => ''));
|
||||
}
|
||||
|
||||
$this->send(array('result' => 'fail', 'message' => $this->lang->instance->errors->setEnvFailed));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实例信息。
|
||||
* Get instance info for q tool in console.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function apiDetail(int $id)
|
||||
{
|
||||
if(!$this->checkCneToken())
|
||||
{
|
||||
helper::setStatus(401);
|
||||
return print(json_encode(array('code' => 401, 'message' => 'Invalid token.')));
|
||||
}
|
||||
|
||||
if(empty($id)) return print(json_encode(array('code' => 401, 'message' => 'Invalid id.')));
|
||||
|
||||
$instance = $this->instance->getByID($id);
|
||||
if(empty($instance)) return print(json_encode(array('code' => 404, 'message' => 'Not found.', 'data' => array())));
|
||||
|
||||
$instance->space = $instance->spaceData && isset($instance->spaceData->k8space) ? $instance->spaceData->k8space : '';
|
||||
unset($instance->desc);
|
||||
unset($instance->spaceData);
|
||||
|
||||
return print(json_encode(array('code' => 200, 'message' => 'success', 'data' => $instance)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实例列表。
|
||||
* Get instances list by account through api for q tool.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function apiBrowse()
|
||||
{
|
||||
if(!$this->checkCneToken())
|
||||
{
|
||||
helper::setStatus(401);
|
||||
return print(json_encode(array('code' => 401, 'message' => 'Invalid token.')));
|
||||
}
|
||||
|
||||
$requestBody = json_decode(file_get_contents("php://input"));
|
||||
$account = zget($requestBody, 'account', '');
|
||||
if(empty($account)) return print(json_encode(array('code' => 700, 'message' => 'Account is required.', 'data' => new stdclass)));
|
||||
|
||||
$recPerPage = zget($requestBody, 'perPage', 20);
|
||||
$pageID = zget($requestBody, 'page', 1);
|
||||
|
||||
$this->app->loadClass('pager', true);
|
||||
$pager = pager::init(0, $recPerPage, $pageID);
|
||||
|
||||
$instanceList = $this->instance->getByAccount($account, $pager);
|
||||
|
||||
$result = new stdclass;
|
||||
$result->list = $instanceList;
|
||||
$result->page = $pageID;
|
||||
$result->perPage = $recPerPage;
|
||||
$result->pageTotal = $pager->pageTotal;
|
||||
$result->total = $pager->recTotal;
|
||||
|
||||
return print(json_encode(array('code' => 200, 'message' => 'success', 'data' => $result)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过API安装应用。
|
||||
* Install app by api for q tool.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function apiInstall()
|
||||
{
|
||||
if(!$this->checkCneToken())
|
||||
{
|
||||
helper::setStatus(401);
|
||||
return print(json_encode(array('code' => 401, 'message' => 'Invalid token.')));
|
||||
}
|
||||
|
||||
$requestBody = json_decode(file_get_contents("php://input"));
|
||||
$chart = zget($requestBody , 'chart', '');
|
||||
if(empty($chart)) return print(json_encode(array('code' => 701, 'message' => 'Param chart is required.')));
|
||||
|
||||
$user = null;
|
||||
$account = zget($requestBody, 'account', '');
|
||||
if($account) $user = $this->loadModel('user')->getById($account);
|
||||
if(empty($user)) $user = $this->loadModel('company')->getAdmin();
|
||||
if(empty($user)) return print(json_encode(array('code' => 703, 'message' => 'No user.')));
|
||||
|
||||
$this->app->user = $user;
|
||||
|
||||
$name = zget($requestBody , 'name', '');
|
||||
$channel = zget($requestBody , 'channel', 'stable');
|
||||
$k8name = zget($requestBody , 'k8name', '');
|
||||
if($k8name && $this->instance->k8nameExists($k8name)) return print(json_encode(array('code' => 706, 'message' => $k8name . ' has been used, please change it and try again.')));
|
||||
|
||||
$thirdDomain = zget($requestBody , 'domain', '');
|
||||
if($this->instance->domainExists($thirdDomain)) return print(json_encode(array('code' => 705, 'message' => $thirdDomain . ' has been used, please change it and try again.')));
|
||||
|
||||
$cloudApp = $this->store->getAppInfoByChart($chart, $channel, false);
|
||||
if(empty($cloudApp)) return print(json_encode(array('code' => 702, 'message' => 'App not found.')));
|
||||
|
||||
$result = $this->instance->apiInstall($cloudApp, $thirdDomain, $name, $k8name, $channel);
|
||||
|
||||
if($result) return print(json_encode(array('code' => 200, 'message' => 'success', 'data' => new stdclass)));
|
||||
|
||||
return print(json_encode(array('code' => 704, 'message' => 'Fail to install app.', 'data' => new stdclass)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查CNE token。
|
||||
* Check CNE token.
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function checkCneToken()
|
||||
{
|
||||
$token = zget($_SERVER, 'HTTP_TOKEN');
|
||||
return $token == $this->config->CNE->api->token;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,502 +0,0 @@
|
||||
$(function()
|
||||
{
|
||||
$('#memBtn').on('click', function(event)
|
||||
{
|
||||
bootbox.confirm(instanceNotices.adjustMemory, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.adjusting + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'ajaxAdjustMemory', 'id=' + id, 'json');
|
||||
var adjustData = {memory_kb: $('select[name=memory_kb]').val()};
|
||||
$.post(url, adjustData).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
window.parent.$.apps.open(createLink('instance', 'view', 'id=' + id), 'space');
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
$('#ldapBtn').on('click', function(event)
|
||||
{
|
||||
bootbox.confirm(instanceNotices.switchLDAP, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.switching + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'ajaxSwitchLDAP', 'id=' + id, 'json');
|
||||
var postData = {enableLDAP: $("[name='enableLDAP[]']:checked").length > 0};
|
||||
$.post(url, postData).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
window.parent.location.reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#smtpBtn').on('click', function(event)
|
||||
{
|
||||
bootbox.confirm(instanceNotices.switchSMTP, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.switching + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'ajaxSwitchSMTP', 'id=' + id, 'json');
|
||||
var postData = {enableSMTP: $("[name='enableSMTP[]']:checked").length > 0};
|
||||
$.post(url, postData).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
window.parent.location.reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#customBtn').on('click', function(event)
|
||||
{
|
||||
var errors = '';
|
||||
$("#customForm").find("input[type=text]").each(function(index, item)
|
||||
{
|
||||
if($(item).val().trim().length == 0)
|
||||
{
|
||||
errors += $(item).attr('placeholder') + instanceNotices.required + '<br/>';
|
||||
}
|
||||
});
|
||||
if(errors.length > 0)
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.error,
|
||||
message: errors,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
bootbox.confirm(instanceNotices.confirmCustom, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.setting + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'ajaxUpdateCustom', 'id=' + id, 'json');
|
||||
var formData = $('#customForm').serializeArray();
|
||||
var customData = {};
|
||||
formData.forEach(function(item, index){
|
||||
customData[item.name] = item.value;
|
||||
});
|
||||
|
||||
$.post(url, customData).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
window.parent.location.reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
$('.btn-uninstall').on('click', function(event)
|
||||
{
|
||||
bootbox.confirm(instanceNotices.confirmUninstall, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.uninstalling + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'ajaxUninstall', 'id=' + id, 'json');
|
||||
$.post(url).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
window.parent.$.apps.open(createLink('space', 'browse'), 'space');
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.btn-start').on('click', function(event)
|
||||
{
|
||||
bootbox.confirm(instanceNotices.confirmStart, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.starting + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'ajaxStart', 'id=' + id, 'json');
|
||||
$.post(url).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
window.location.reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.btn-stop').on('click', function(event)
|
||||
{
|
||||
bootbox.confirm(instanceNotices.confirmStop, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.stopping + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'ajaxStop', 'id=' + id, 'json');
|
||||
$.post(url).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
window.location.reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.btn-backup').on('click', function(event)
|
||||
{
|
||||
$('#confirmRestore').modal('hide');
|
||||
bootbox.confirm(instanceNotices.confirmBackup, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.backuping + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'ajaxBackup', 'id=' + id, 'json');
|
||||
$.post(url).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.success,
|
||||
message: res.message,
|
||||
callback: function(){window.location.reload();}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.btn-restore').click(function()
|
||||
{
|
||||
let backupName = $(this).attr('backup-name');
|
||||
let instanceID = $(this).attr('instance-id');
|
||||
$('#confirmRestore #submitRestore').data('backup-name', backupName);
|
||||
$('#confirmRestore #submitRestore').data('instance-id', instanceID);
|
||||
$('#confirmRestore').modal('show');
|
||||
});
|
||||
|
||||
$('#submitRestore').on('click', function(event)
|
||||
{
|
||||
$('#confirmRestore').modal('hide');
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.restoring + '</div>',
|
||||
});
|
||||
|
||||
var instanceID = $(event.target).closest('button').data('instance-id');
|
||||
var backupName = $(event.target).closest('button').data('backup-name');
|
||||
var url = createLink('instance', 'ajaxRestore', '', 'json');
|
||||
$.post(url, { instanceID, backupName }).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.success,
|
||||
message: res.message,
|
||||
callback: function(){window.location.reload();}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.btn-delete-backup').on('click', function(event)
|
||||
{
|
||||
bootbox.confirm(instanceNotices.confirmDelete, function(result)
|
||||
{
|
||||
if(!result) return;
|
||||
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.deleting + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('backup-id');
|
||||
var url = createLink('instance', 'ajaxDeleteBackup', 'id=' + id, 'json');
|
||||
$.post(url).done(function(response)
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.success,
|
||||
message: res.message,
|
||||
callback: function(){window.location.reload();}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('button.db-login').on('click', function(event)
|
||||
{
|
||||
var dbName = $(event.target).data('db-name');
|
||||
var dbType = $(event.target).data('db-type');
|
||||
var instanceID = $(event.target).data('id');
|
||||
|
||||
$.post(createLink('instance', 'ajaxDBAuthUrl'), {dbName, dbType, instanceID}).done(function(res)
|
||||
{
|
||||
var response = JSON.parse(res);
|
||||
if(response.result == 'success')
|
||||
{
|
||||
window.parent.open(response.data.url, 'Adminer');
|
||||
}
|
||||
else
|
||||
{
|
||||
bootbox.alert(response.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var enableTimer = true;
|
||||
window.parent.$(window.parent.document).on('showapp', function(event, app)
|
||||
{
|
||||
enableTimer = app.code == 'space';
|
||||
});
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
if(!enableTimer) return;
|
||||
|
||||
var statusURL = createLink('instance', 'ajaxStatus');
|
||||
$.post(statusURL, {idList: instanceIdList}).done(function(response)
|
||||
{
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success' && res.data instanceof Array)
|
||||
{
|
||||
res.data.forEach(function(instance)
|
||||
{
|
||||
if($(".instance-status[instance-id=" + instance.id + "]").data('status') != instance.status) window.location.reload();
|
||||
});
|
||||
}
|
||||
if(res.locate) window.parent.location.href = res.locate;
|
||||
});
|
||||
}, 1000 * 5);
|
||||
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
/* Count down for demo instance. */
|
||||
setInterval(function()
|
||||
{
|
||||
var nowSeconds = Math.round((new Date).getTime() / 1000);
|
||||
$('.count-down').each(function(index, item)
|
||||
{
|
||||
var createdAt = $(item).data('created-at');
|
||||
var passSeconds = nowSeconds - createdAt;
|
||||
var leftSeconds = (demoAppLife ? demoAppLife : 30) * 60 - passSeconds;
|
||||
|
||||
if(leftSeconds < 0)
|
||||
{
|
||||
window.parent.location.href = createLink('space', 'browse');
|
||||
}
|
||||
else
|
||||
{
|
||||
var minutes = Math.floor(leftSeconds / 60);
|
||||
var seconds = Math.round(leftSeconds % 60);
|
||||
$(item).find('.left-time').text(('0' + minutes).slice(-2) + ':' + ('0' + seconds).slice(-2));
|
||||
}
|
||||
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
$('#replicas-edit').on('click', function()
|
||||
{
|
||||
$('#replicas-input').show()
|
||||
$('#replicas-text').hide()
|
||||
$('#replicas-save').show()
|
||||
$('#replicas-edit').hide()
|
||||
})
|
||||
|
||||
$('#replicas-save').on('click', function()
|
||||
{
|
||||
var loadingDialog = bootbox.dialog(
|
||||
{
|
||||
message: '<div class="text-center"><i class="icon icon-spinner-indicator icon-spin"></i> ' + instanceNotices.adjusting + '</div>',
|
||||
});
|
||||
|
||||
var id = $(event.target).closest('button').attr('instance-id');
|
||||
var url = createLink('instance', 'replicas', 'id=' + id, 'json');
|
||||
var adjustData = {replicas: $('#replicas-input').val()};
|
||||
$.post(url, adjustData).done(function(response)
|
||||
{
|
||||
|
||||
var res = JSON.parse(response);
|
||||
if(res.result == 'success')
|
||||
{
|
||||
window.parent.location.reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
loadingDialog.modal('hide');
|
||||
bootbox.alert(
|
||||
{
|
||||
title: instanceNotices.fail,
|
||||
message: res.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
@@ -582,206 +582,6 @@ class InstanceModel extends model
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
install global SMTP proxy service.
|
||||
*
|
||||
* @param object $app
|
||||
* @param object $smtpSettings
|
||||
* @param string $instanceName
|
||||
* @param string $k8name
|
||||
* @param string $channel
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function installSysSMTP($app, $smtpSettings, $instanceName = '', $k8name = '', $channel = 'stable')
|
||||
{
|
||||
$this->app->loadLang('system');
|
||||
|
||||
$space = $this->loadModel('space')->getSystemSpace($this->app->user->account);
|
||||
|
||||
$customData = new stdclass;
|
||||
$customData->dbType = null;
|
||||
$customData->customDomain = $this->randThirdDomain();
|
||||
|
||||
$instance = $this->createInstance($app, $space, $customData->customDomain, $instanceName, $k8name, $channel);
|
||||
if(!$instance)
|
||||
{
|
||||
dao::$errors[] = $this->lang->system->errors->failToInstallSMTP;
|
||||
return false;
|
||||
}
|
||||
|
||||
$settingsMap = $this->installationSettingsMap($customData, array(), $instance);
|
||||
|
||||
$settingsMap->env = new stdclass;
|
||||
$settingsMap->env->SMTP_HOST = $smtpSettings->host;
|
||||
$settingsMap->env->SMTP_PORT = strval($smtpSettings->port);
|
||||
$settingsMap->env->SMTP_USER = $smtpSettings->user;
|
||||
$settingsMap->env->SMTP_PASS = $smtpSettings->pass;
|
||||
$settingsMap->env->AUTHENTICATE_CODE = helper::randStr(24);
|
||||
|
||||
$instance = $this->doCneInstall($instance, $space, $settingsMap);
|
||||
if(!$instance)
|
||||
{
|
||||
dao::$errors[] = $this->lang->system->errors->failToInstallSMTP;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Post snippet to CNE. */
|
||||
$snippetSettings = new stdclass;
|
||||
$snippetSettings->name = 'snippet-smtp-proxy';
|
||||
$snippetSettings->namespace = $space->k8space;
|
||||
$snippetSettings->auto_import = false;
|
||||
|
||||
$snippetSettings->values = new stdclass;
|
||||
$snippetSettings->values->mail = new stdclass;
|
||||
$snippetSettings->values->mail->enabled = true;
|
||||
$snippetSettings->values->mail->smtp = new stdclass;
|
||||
$snippetSettings->values->mail->smtp->host = "{$instance->k8name}.{$snippetSettings->namespace}.svc";
|
||||
$snippetSettings->values->mail->smtp->port = '1025';
|
||||
$snippetSettings->values->mail->smtp->user = 'smtp-bot@quickon.local'; // This is fake value.
|
||||
$snippetSettings->values->mail->smtp->pass = $settingsMap->env->AUTHENTICATE_CODE; // This is fake value.
|
||||
|
||||
$snippetResult = $this->loadModel('cne')->addSnippet($snippetSettings);
|
||||
if($snippetResult->code != 200)
|
||||
{
|
||||
dao::$errors[] = $this->lang->system->errors->failToInstallSMTP;
|
||||
$this->uninstall($instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Save SMTP settings. */
|
||||
$secretKey = helper::readKey();
|
||||
$settingsMap->env->SMTP_PASS = openssl_encrypt($settingsMap->env->SMTP_PASS, 'DES-ECB', $secretKey);
|
||||
$settingsMap->env->AUTHENTICATE_CODE = openssl_encrypt($settingsMap->env->AUTHENTICATE_CODE, 'DES-ECB', $secretKey);
|
||||
|
||||
$snippetSettings->values->mail->smtp->pass = $settingsMap->env->AUTHENTICATE_CODE;
|
||||
|
||||
$this->loadModel('setting');
|
||||
$this->setting->setItem('system.common.smtp.enabled', true);
|
||||
$this->setting->setItem('system.common.smtp.instanceID', $instance->id);
|
||||
$this->setting->setItem('system.common.smtp.snippetName', $snippetSettings->name);
|
||||
$this->setting->setItem('system.common.smtp.settingsMap', json_encode($settingsMap));
|
||||
$this->setting->setItem('system.common.smtp.snippetSettings', json_encode($snippetSettings));
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install LDAP.
|
||||
*
|
||||
* @param object $app
|
||||
* @param string $thirdDomain
|
||||
* @param string $instanceName
|
||||
* @param string $channel
|
||||
* @access public
|
||||
* @return bool|object
|
||||
*/
|
||||
public function installLDAP($app, $thirdDomain = '', $instanceName = '', $k8name = '', $channel = 'stable')
|
||||
{
|
||||
$this->app->loadLang('system');
|
||||
|
||||
$space = $this->loadModel('space')->getSystemSpace($this->app->user->account);
|
||||
|
||||
$customData = new stdclass;
|
||||
$customData->dbType = null;
|
||||
$customData->customDomain = $thirdDomain ? $thirdDomain : $this->randThirdDomain();
|
||||
|
||||
$instance = $this->createInstance($app, $space, $customData->customDomain, $instanceName, $k8name, $channel);
|
||||
if(!$instance)
|
||||
{
|
||||
dao::$errors[] = $this->lang->system->errors->failToInstallLDAP;
|
||||
return false;
|
||||
}
|
||||
|
||||
$settingMap = $this->installationSettingsMap($customData, array(), $instance);
|
||||
|
||||
$settingMap->auth = new stdclass;
|
||||
$settingMap->auth->username = $app->account ? $app->account->username : 'admin';
|
||||
$settingMap->auth->password = helper::randStr(16);
|
||||
$settingMap->auth->root = 'dc=quickon,dc=org';
|
||||
|
||||
$instance = $this->doCneInstall($instance, $space, $settingMap);
|
||||
if(!$instance)
|
||||
{
|
||||
dao::$errors[] = $this->lang->system->errors->failToInstallLDAP;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Post snippet to CNE. */
|
||||
$snippetSettings = new stdclass;
|
||||
$snippetSettings->name = 'snippet-qucheng-ldap';
|
||||
$snippetSettings->namespace = $space->k8space;
|
||||
$snippetSettings->auto_import = false;
|
||||
|
||||
$snippetSettings->values = new stdclass;
|
||||
$snippetSettings->values->auth = new stdclass;
|
||||
$snippetSettings->values->auth->ldap = new stdclass;
|
||||
$snippetSettings->values->auth->ldap->enabled = true;
|
||||
$snippetSettings->values->auth->ldap->type = 'ldap';
|
||||
$snippetSettings->values->auth->ldap->host = "{$instance->k8name}.{$snippetSettings->namespace}.svc";
|
||||
$snippetSettings->values->auth->ldap->port = '1389';
|
||||
$snippetSettings->values->auth->ldap->bindDN = "cn={$settingMap->auth->username},dc=quickon,dc=org";
|
||||
$snippetSettings->values->auth->ldap->bindPass = $settingMap->auth->password;
|
||||
$snippetSettings->values->auth->ldap->baseDN = $settingMap->auth->root;
|
||||
$snippetSettings->values->auth->ldap->filter = "&(objectClass=posixAccount)(cn=%s)";
|
||||
$snippetSettings->values->auth->ldap->attrUser = 'uid';
|
||||
$snippetSettings->values->auth->ldap->attrEmail = 'mail';
|
||||
|
||||
$snippetResult = $this->loadModel('cne')->addSnippet($snippetSettings);
|
||||
if($snippetResult->code != 200)
|
||||
{
|
||||
dao::$errors[] = $this->lang->system->errors->failToInstallLDAP;
|
||||
$this->uninstall($instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Save LDAP account. */
|
||||
$secretKey = helper::readKey();
|
||||
$settingMap->auth->password = openssl_encrypt($settingMap->auth->password, 'DES-ECB', $secretKey);
|
||||
$this->dao->update(TABLE_INSTANCE)->set('ldapSettings')->eq(json_encode($settingMap))->where('id')->eq($instance->id)->exec();
|
||||
$this->loadModel('setting')->setItem('system.common.ldap.active', 'qucheng');
|
||||
$this->loadModel('setting')->setItem('system.common.ldap.instanceID', $instance->id);
|
||||
$this->loadModel('setting')->setItem('system.common.ldap.snippetName', $snippetSettings->name); // Parameter for App installation API.
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install app through API.
|
||||
*
|
||||
* @param object $cloudApp
|
||||
* @param string $thirdDomain
|
||||
* @param string $name
|
||||
* @param string $channel
|
||||
* @access public
|
||||
* @return bool|object
|
||||
*/
|
||||
public function apiInstall($cloudApp, $thirdDomain = '', $name = '', $k8name = '', $channel = 'stable')
|
||||
{
|
||||
$this->loadModel('space');
|
||||
$space = $this->space->defaultSpace($this->app->user->account);
|
||||
|
||||
$customData = new stdclass;
|
||||
$customData->dbType = null;
|
||||
$customData->customDomain = $thirdDomain ? $thirdDomain : $this->randThirdDomain();
|
||||
|
||||
$dbInfo = new stdclass;
|
||||
$dbList = $this->cne->sharedDBList();
|
||||
if(count($dbList) > 0)
|
||||
{
|
||||
$dbInfo = reset($dbList);
|
||||
|
||||
$customData->dbType = 'sharedDB';
|
||||
$customData->dbService = $dbInfo->name; // Use first shared database.
|
||||
}
|
||||
|
||||
$instance = $this->createInstance($cloudApp, $space, $customData->customDomain, $name, $k8name, $channel);
|
||||
if(!$instance) return false;
|
||||
|
||||
$settingMap = $this->installationSettingsMap($customData, $dbInfo, $instance);
|
||||
return $this->doCneInstall($instance, $space, $settingMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instance recorder for installation.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user