From bcbca8e2db8f7857270262eadc14fc1b74863837 Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Wed, 14 Sep 2022 17:23:38 +0800 Subject: [PATCH] * Finish task #68265. --- api/v1/entries/hostheartbeat.php | 35 ++++++++++--- db/update17.6.1.sql | 2 + module/group/lang/resource.php | 8 ++- module/zahost/config.php | 61 +++++++++++++++++++++- module/zahost/control.php | 10 ++-- module/zahost/lang/de.php | 23 ++++---- module/zahost/lang/en.php | 23 ++++---- module/zahost/lang/fr.php | 23 ++++---- module/zahost/lang/vi.php | 23 ++++---- module/zahost/lang/zh-cn.php | 23 ++++---- module/zahost/model.php | 10 ++-- module/zahost/view/browsetemplate.html.php | 14 ++--- 12 files changed, 179 insertions(+), 76 deletions(-) diff --git a/api/v1/entries/hostheartbeat.php b/api/v1/entries/hostheartbeat.php index b4c21df922..aefa6ed248 100644 --- a/api/v1/entries/hostheartbeat.php +++ b/api/v1/entries/hostheartbeat.php @@ -9,7 +9,7 @@ * @version 1 * @link http://www.zentao.net */ -class hostHeartbeatEntry extends Entry +class hostHeartbeatEntry extends baseEntry { /** * Listen host heartbeat. @@ -20,16 +20,39 @@ class hostHeartbeatEntry extends Entry */ public function post() { - $secret = $this->requestBody->secret; + /* Check authorize. */ + $secret = isset($this->requestBody->secret) ? $this->requestBody->secret : ''; + $token = isset($_SERVER['HTTP_TOKEN']) ? $_SERVER['HTTP_TOKEN'] : ''; + if(!$secret and !$token) return $this->sendError(401, 'Unauthorized'); + + /* Check param. */ $status = $this->requestBody->status; $now = helper::now(); - if(!$secret or !$status) return $this->sendError(400, 'Params error.'); + if(!$status) return $this->sendError(400, 'Params error.'); - $this->dao->update(TABLE_HOST)->set('status')->eq($status)->where('secret')->eq($secret)->exec(); + $conditionField = $secret ? 'secret' : 'token'; + $conditionValue = $secret ? $secret : $token; + $host = new stdclass(); + $host->status = $status; + if($secret) + { + $host->token = md5($secret . $now); + $host->expiredDate = date('Y-m-d H:i:s', time() + 7200); + } - $assetID = $this->dao->select('assetID')->from(TABLE_HOST)->where('secret')->eq($secret)->fetch('assetID'); + $this->dao = $this->loadModel('common')->dao; + $assetID = $this->dao->select('assetID')->from(TABLE_HOST) + ->beginIF($secret)->where('secret')->eq($secret)->fi() + ->beginIF(!$secret)->where('token')->eq($token) + ->andWhere('expiredDate')->gt($now)->fi() + ->fetch('assetID'); + if(!$assetID) return $this->sendError(400, 'Secret error.'); + + $this->dao->update(TABLE_HOST)->data($host)->where($conditionField)->eq($conditionValue)->exec(); $this->dao->update(TABLE_ASSET)->set('registerDate')->eq($now)->where('id')->eq($assetID)->exec(); - $this->sendSuccess(200, 'success'); + if(!$secret) return $this->send(200, 'success'); + unset($host->status); + return $this->send(200, $host); } } diff --git a/db/update17.6.1.sql b/db/update17.6.1.sql index 74ee5e7ef6..382c149fbe 100644 --- a/db/update17.6.1.sql +++ b/db/update17.6.1.sql @@ -1,5 +1,7 @@ ALTER TABLE `zt_host` ADD `type` varchar(30) NOT NULL DEFAULT 'normal' AFTER `admin`; ALTER TABLE `zt_host` ADD `secret` varchar(50) NOT NULL DEFAULT '' AFTER `type`; +ALTER TABLE `zt_host` ADD `token` varchar(50) NOT NULL DEFAULT '' AFTER `type`; +ALTER TABLE `zt_host` ADD `expiredDate` datetime NOT NULL AFTER `type`; ALTER TABLE `zt_host` ADD `virtualSoftware` varchar(30) NOT NULL DEFAULT '' AFTER `secret`; ALTER TABLE `zt_asset` ADD `registerDate` datetime NOT NULL AFTER `editedDate`; ALTER TABLE `zt_vmtemplate` ADD `type` varchar(30) NOT NULL DEFAULT 'normal' AFTER `hostID`; diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 2f62a28e6a..17461e0bec 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -1194,9 +1194,13 @@ $lang->automation->methodOrder[0] = 'browse'; $lang->resource->zahost = new stdclass(); $lang->resource->zahost->browse = 'browse'; $lang->resource->zahost->create = 'create'; +$lang->resource->zahost->browseTemplate = 'browseTemplate'; +$lang->resource->zahost->createTemplate = 'createTemplate'; -$lang->zahost->methodOrder[0] = 'browse'; -$lang->zahost->methodOrder[5] = 'create'; +$lang->zahost->methodOrder[0] = 'browse'; +$lang->zahost->methodOrder[5] = 'create'; +$lang->zahost->methodOrder[10] = 'browseTemplate'; +$lang->zahost->methodOrder[15] = 'createTemplate'; $lang->resource->repo = new stdclass(); $lang->resource->repo->browse = 'browseAction'; diff --git a/module/zahost/config.php b/module/zahost/config.php index 351a352051..56f0744e05 100644 --- a/module/zahost/config.php +++ b/module/zahost/config.php @@ -24,7 +24,7 @@ $config->zahost->os->type['linux']['debian'] = 'Debian'; global $lang; $config->zahost->search['module'] = 'zahost'; $config->zahost->search['fields']['name'] = $lang->zahost->name; -$config->zahost->search['fields']['id'] = 'ID'; +$config->zahost->search['fields']['id'] = $lang->zahost->id; $config->zahost->search['fields']['type'] = $lang->zahost->type; $config->zahost->search['fields']['publicIP'] = $lang->zahost->IP; $config->zahost->search['fields']['cpuCores'] = $lang->zahost->cpuCores; @@ -54,3 +54,62 @@ $config->zahost->search['params']['createdDate'] = array('operator' => '=', $config->zahost->search['params']['registerDate'] = array('operator' => '=', 'control' => 'input', 'values' => '', 'class' => 'date'); $config->zahost->search['params']['editedBy'] = array('operator' => '=', 'control' => 'select', 'values' => 'users'); $config->zahost->search['params']['editedDate'] = array('operator' => '=', 'control' => 'input', 'values' => '', 'class' => 'date'); + +$config->vmTemplate = new stdclass(); +$config->vmTemplate->os = new stdClass(); +$config->vmTemplate->os->list = array(); +$config->vmTemplate->os->list['windows'] = 'Windows'; +$config->vmTemplate->os->list['linux'] = 'Linux'; + +$config->vmTemplate->os->cpu = array(); +$config->vmTemplate->os->cpu['1'] = '1'; +$config->vmTemplate->os->cpu['2'] = '2'; +$config->vmTemplate->os->cpu['4'] = '4'; +$config->vmTemplate->os->cpu['6'] = '6'; +$config->vmTemplate->os->cpu['8'] = '8'; +$config->vmTemplate->os->cpu['12'] = '12'; +$config->vmTemplate->os->cpu['16'] = '16'; + +$config->vmTemplate->os->memory = array(); +$config->vmTemplate->os->memory['512'] = '512MB'; +$config->vmTemplate->os->memory['1024'] = '1GB'; +$config->vmTemplate->os->memory['2048'] = '2GB'; +$config->vmTemplate->os->memory['4096'] = '4GB'; +$config->vmTemplate->os->memory['9120'] = '8GB'; +$config->vmTemplate->os->memory['16384'] = '16GB'; + +$config->vmTemplate->os->disk = array(); +$config->vmTemplate->os->disk['10240'] = '10GB'; +$config->vmTemplate->os->disk['20480'] = '20GB'; +$config->vmTemplate->os->disk['40960'] = '40GB'; +$config->vmTemplate->os->disk['61440'] = '60GB'; +$config->vmTemplate->os->disk['81920'] = '80GB'; +$config->vmTemplate->os->disk['102400'] = '100GB'; +$config->vmTemplate->os->disk['204800'] = '200GB'; +$config->vmTemplate->os->disk['307200'] = '300GB'; + +$config->vmTemplate->os->type = array(); +$config->vmTemplate->os->type['windows']['winServer'] = 'Windows Server'; +$config->vmTemplate->os->type['windows']['win11'] = 'Windows 11'; +$config->vmTemplate->os->type['windows']['win10'] = 'Windows 10'; +$config->vmTemplate->os->type['windows']['win7'] = 'Windows 7'; +$config->vmTemplate->os->type['windows']['winxp'] = 'Windows XP'; +$config->vmTemplate->os->type['linux']['ubuntu'] = 'Ubuntu'; +$config->vmTemplate->os->type['linux']['centos'] = 'CentOS'; +$config->vmTemplate->os->type['linux']['debian'] = 'Debian'; + +$config->vmTemplate->search['module'] = 'vmTemplate'; +$config->vmTemplate->search['fields']['id'] = $lang->zahost->id; +$config->vmTemplate->search['fields']['name'] = $lang->zahost->name; +$config->vmTemplate->search['fields']['cpuCoreNum'] = $lang->zahost->cpuCores; +$config->vmTemplate->search['fields']['memorySize'] = $lang->zahost->memory; +$config->vmTemplate->search['fields']['diskSize'] = $lang->zahost->diskSize; +$config->vmTemplate->search['fields']['osType'] = $lang->zahost->vmTemplate->osType; +$config->vmTemplate->search['fields']['osVersion'] = $lang->zahost->vmTemplate->osVersion; + +$config->vmTemplate->search['params']['id'] = array('operator' => '=', 'control' => 'input', 'values' => ''); +$config->vmTemplate->search['params']['name'] = array('operator' => 'include', 'control' => 'input', 'values' => ''); +$config->vmTemplate->search['params']['memorySize'] = array('operator' => '=', 'control' => 'select', 'values' => array('' => '') + $config->vmTemplate->os->memory); +$config->vmTemplate->search['params']['diskSize'] = array('operator' => '=', 'control' => 'select', 'values' => array('' => '') + $config->vmTemplate->os->disk); +$config->vmTemplate->search['params']['osType'] = array('operator' => '=', 'control' => 'select', 'values' => array('' => '') + $config->vmTemplate->os->type['windows'] + $config->vmTemplate->os->type['linux']); +$config->vmTemplate->search['params']['cpuCoreNum'] = array('operator' => '=', 'control' => 'select', 'values' => array('' => '') + $config->vmTemplate->os->cpu); diff --git a/module/zahost/control.php b/module/zahost/control.php index b2fd975525..b8330d4ab4 100644 --- a/module/zahost/control.php +++ b/module/zahost/control.php @@ -118,11 +118,11 @@ class zahost extends control $templateList = $this->zahost->getVMTemplateList($hostID, $browseType, $queryID, $orderBy, $pager); /* Build the search form. */ - //$actionURL = $this->createLink('zahost', 'browseVM', "browseType=bySearch&queryID=myQueryID"); - //$this->config->zaTemplate->search['actionURL'] = $actionURL; - //$this->config->zaTemplate->search['queryID'] = $queryID; - //$this->config->zaTemplate->search['onMenuBar'] = 'no'; - //$this->loadModel('search')->setSearchParams($this->config->zaTemplate->search); + $actionURL = $this->createLink('zahost', 'browseTemplate', "hostID=$hostID&browseType=bySearch&queryID=myQueryID"); + $this->config->vmTemplate->search['actionURL'] = $actionURL; + $this->config->vmTemplate->search['queryID'] = $queryID; + $this->config->vmTemplate->search['onMenuBar'] = 'no'; + $this->loadModel('search')->setSearchParams($this->config->vmTemplate->search); $this->view->title = $this->lang->zahost->vmTemplate->common; $this->view->users = $this->loadModel('user')->getPairs('noletter|nodeleted'); diff --git a/module/zahost/lang/de.php b/module/zahost/lang/de.php index cfc5558906..1c7c7e242c 100644 --- a/module/zahost/lang/de.php +++ b/module/zahost/lang/de.php @@ -1,14 +1,17 @@ zahost->common = 'ZAhost'; -$lang->zahost->browse = 'Host List'; -$lang->zahost->create = 'Add Host'; -$lang->zahost->view = 'Host View'; -$lang->zahost->edit = 'Edit'; -$lang->zahost->editAction = 'Edit Host'; -$lang->zahost->delete = 'Delete'; -$lang->zahost->deleteAction = 'Delete Host'; -$lang->zahost->byQuery = 'Search'; -$lang->zahost->all = 'All'; +$lang->zahost->id = 'ID'; +$lang->zahost->common = 'ZAhost'; +$lang->zahost->browse = 'Host List'; +$lang->zahost->create = 'Add Host'; +$lang->zahost->view = 'Host View'; +$lang->zahost->edit = 'Edit'; +$lang->zahost->editAction = 'Edit Host'; +$lang->zahost->delete = 'Delete'; +$lang->zahost->deleteAction = 'Delete Host'; +$lang->zahost->byQuery = 'Search'; +$lang->zahost->all = 'All'; +$lang->zahost->browseTemplate = 'Template Browse'; +$lang->zahost->createTemplate = 'Create Template'; $lang->zahost->name = 'Name'; $lang->zahost->IP = 'IP'; diff --git a/module/zahost/lang/en.php b/module/zahost/lang/en.php index cfc5558906..1c7c7e242c 100644 --- a/module/zahost/lang/en.php +++ b/module/zahost/lang/en.php @@ -1,14 +1,17 @@ zahost->common = 'ZAhost'; -$lang->zahost->browse = 'Host List'; -$lang->zahost->create = 'Add Host'; -$lang->zahost->view = 'Host View'; -$lang->zahost->edit = 'Edit'; -$lang->zahost->editAction = 'Edit Host'; -$lang->zahost->delete = 'Delete'; -$lang->zahost->deleteAction = 'Delete Host'; -$lang->zahost->byQuery = 'Search'; -$lang->zahost->all = 'All'; +$lang->zahost->id = 'ID'; +$lang->zahost->common = 'ZAhost'; +$lang->zahost->browse = 'Host List'; +$lang->zahost->create = 'Add Host'; +$lang->zahost->view = 'Host View'; +$lang->zahost->edit = 'Edit'; +$lang->zahost->editAction = 'Edit Host'; +$lang->zahost->delete = 'Delete'; +$lang->zahost->deleteAction = 'Delete Host'; +$lang->zahost->byQuery = 'Search'; +$lang->zahost->all = 'All'; +$lang->zahost->browseTemplate = 'Template Browse'; +$lang->zahost->createTemplate = 'Create Template'; $lang->zahost->name = 'Name'; $lang->zahost->IP = 'IP'; diff --git a/module/zahost/lang/fr.php b/module/zahost/lang/fr.php index cfc5558906..1c7c7e242c 100644 --- a/module/zahost/lang/fr.php +++ b/module/zahost/lang/fr.php @@ -1,14 +1,17 @@ zahost->common = 'ZAhost'; -$lang->zahost->browse = 'Host List'; -$lang->zahost->create = 'Add Host'; -$lang->zahost->view = 'Host View'; -$lang->zahost->edit = 'Edit'; -$lang->zahost->editAction = 'Edit Host'; -$lang->zahost->delete = 'Delete'; -$lang->zahost->deleteAction = 'Delete Host'; -$lang->zahost->byQuery = 'Search'; -$lang->zahost->all = 'All'; +$lang->zahost->id = 'ID'; +$lang->zahost->common = 'ZAhost'; +$lang->zahost->browse = 'Host List'; +$lang->zahost->create = 'Add Host'; +$lang->zahost->view = 'Host View'; +$lang->zahost->edit = 'Edit'; +$lang->zahost->editAction = 'Edit Host'; +$lang->zahost->delete = 'Delete'; +$lang->zahost->deleteAction = 'Delete Host'; +$lang->zahost->byQuery = 'Search'; +$lang->zahost->all = 'All'; +$lang->zahost->browseTemplate = 'Template Browse'; +$lang->zahost->createTemplate = 'Create Template'; $lang->zahost->name = 'Name'; $lang->zahost->IP = 'IP'; diff --git a/module/zahost/lang/vi.php b/module/zahost/lang/vi.php index cfc5558906..1c7c7e242c 100644 --- a/module/zahost/lang/vi.php +++ b/module/zahost/lang/vi.php @@ -1,14 +1,17 @@ zahost->common = 'ZAhost'; -$lang->zahost->browse = 'Host List'; -$lang->zahost->create = 'Add Host'; -$lang->zahost->view = 'Host View'; -$lang->zahost->edit = 'Edit'; -$lang->zahost->editAction = 'Edit Host'; -$lang->zahost->delete = 'Delete'; -$lang->zahost->deleteAction = 'Delete Host'; -$lang->zahost->byQuery = 'Search'; -$lang->zahost->all = 'All'; +$lang->zahost->id = 'ID'; +$lang->zahost->common = 'ZAhost'; +$lang->zahost->browse = 'Host List'; +$lang->zahost->create = 'Add Host'; +$lang->zahost->view = 'Host View'; +$lang->zahost->edit = 'Edit'; +$lang->zahost->editAction = 'Edit Host'; +$lang->zahost->delete = 'Delete'; +$lang->zahost->deleteAction = 'Delete Host'; +$lang->zahost->byQuery = 'Search'; +$lang->zahost->all = 'All'; +$lang->zahost->browseTemplate = 'Template Browse'; +$lang->zahost->createTemplate = 'Create Template'; $lang->zahost->name = 'Name'; $lang->zahost->IP = 'IP'; diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php index e9aa7dc6b8..2b9804ba97 100644 --- a/module/zahost/lang/zh-cn.php +++ b/module/zahost/lang/zh-cn.php @@ -1,14 +1,17 @@ zahost->common = '宿主机'; -$lang->zahost->browse = '主机列表'; -$lang->zahost->create = '添加宿主机'; -$lang->zahost->view = '主机详情'; -$lang->zahost->edit = '编辑'; -$lang->zahost->editAction = '编辑主机'; -$lang->zahost->delete = '删除'; -$lang->zahost->deleteAction = '删除主机'; -$lang->zahost->byQuery = '搜索'; -$lang->zahost->all = '所有主机'; +$lang->zahost->id = 'ID'; +$lang->zahost->common = '宿主机'; +$lang->zahost->browse = '主机列表'; +$lang->zahost->create = '添加宿主机'; +$lang->zahost->view = '主机详情'; +$lang->zahost->edit = '编辑'; +$lang->zahost->editAction = '编辑主机'; +$lang->zahost->delete = '删除'; +$lang->zahost->deleteAction = '删除主机'; +$lang->zahost->byQuery = '搜索'; +$lang->zahost->all = '所有主机'; +$lang->zahost->browseTemplate = '虚拟机模板列表'; +$lang->zahost->createTemplate = '创建虚拟机模板'; $lang->zahost->name = '名称'; $lang->zahost->IP = 'IP'; diff --git a/module/zahost/model.php b/module/zahost/model.php index 0392e2154d..644c6c32c1 100644 --- a/module/zahost/model.php +++ b/module/zahost/model.php @@ -198,19 +198,19 @@ class zahostModel extends model $query = $this->loadModel('search')->getQuery($param); if($query) { - $this->session->set('zaTemplateQuery', $query->sql); - $this->session->set('zaTemplateForm', $query->form); + $this->session->set('vmTemplateQuery', $query->sql); + $this->session->set('vmTemplateForm', $query->form); } else { - $this->session->set('zaTemplateQuery', ' 1 = 1'); + $this->session->set('vmTemplateQuery', ' 1 = 1'); } } else { - if($this->session->zaTemplateQuery == false) $this->session->set('zaTemplateQuery', ' 1 = 1'); + if($this->session->vmTemplateQuery == false) $this->session->set('vmTemplateQuery', ' 1 = 1'); } - $query = $this->session->zaTemplateQuery; + $query = $this->session->vmTemplateQuery; } return $this->dao->select('*')->from(TABLE_VMTEMPLATE) diff --git a/module/zahost/view/browsetemplate.html.php b/module/zahost/view/browsetemplate.html.php index f6336cf845..3fc3e99193 100755 --- a/module/zahost/view/browsetemplate.html.php +++ b/module/zahost/view/browsetemplate.html.php @@ -25,7 +25,7 @@ -
' data-module='zahost'>
+
' data-module='vmTemplate'>
recTotal}&recPerPage={$pager->recPerPage}";?> @@ -41,12 +41,12 @@ idAB);?> zahost->name);?> - zahost->cpuCoreNum);?> - zahost->memory);?> - zahost->diskSize);?> - zahost->osCategory);?> - zahost->osType);?> - zahost->osVersion);?> + zahost->cpuCoreNum);?> + zahost->memory);?> + zahost->diskSize);?> + zahost->osCategory);?> + zahost->osType);?> + zahost->osVersion);?> zahost->osLang);?>