Merge branch 'zenops_46' into zenops_46_wangjianhua_68264

This commit is contained in:
wangjianhua
2022-09-14 22:08:11 +08:00
15 changed files with 463 additions and 96 deletions
+29 -6
View File
@@ -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);
}
}
+2
View File
@@ -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`;
+1 -1
View File
@@ -397,7 +397,7 @@ $lang->qa->menuOrder[40] = 'caselib';
$lang->qa->menuOrder[45] = 'zahost';
$lang->qa->menu->zahost['subMenu'] = new stdclass();
$lang->qa->menu->zahost['subMenu']->browse = array('link' => "{$lang->zahost->common}|zahost|browse", 'alias' => 'browse,create,createtemplate');
$lang->qa->menu->zahost['subMenu']->browse = array('link' => "{$lang->zahost->common}|zahost|browse", 'alias' => 'browse,create,createtemplate,browsetemplate');
// $lang->qa->menu->automation['subMenu'] = new stdclass();
// $lang->qa->menu->automation['subMenu']->browse = array('link' => "{$lang->automation->common}|zahost|browse", 'alias' => 'create');
+6 -2
View File
@@ -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';
+60 -1
View File
@@ -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);
+41
View File
@@ -95,6 +95,47 @@ class zahost extends control
$this->display();
}
/*
* Browse VM template.
*
* @param int $hostID
* @param string $browseType
* @param string $param
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function browseTemplate($hostID, $browseType = 'all', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$browseType = strtolower($browseType);
$this->app->loadClass('pager', true);
$queryID = ($browseType == 'bysearch') ? (int)$param : 0;
$pager = pager::init($recTotal, $recPerPage, $pageID);
$templateList = $this->zahost->getVMTemplateList($hostID, $browseType, $queryID, $orderBy, $pager);
/* Build the search form. */
$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');
$this->view->templateList = $templateList;
$this->view->hostID = $hostID;
$this->view->pager = $pager;
$this->view->param = $param;
$this->view->orderBy = $orderBy;
$this->view->browseType = $browseType;
$this->display();
}
/**
* Ping publicIP by http.
*
+3
View File
@@ -0,0 +1,3 @@
.c-number {width: 100px;}
.c-os {width: 130px;}
.c-lang {width: 150px;}
+35 -11
View File
@@ -1,14 +1,17 @@
<?php
$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->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';
@@ -26,7 +29,28 @@ $lang->zahost->editedBy = 'EditedBy';
$lang->zahost->editedDate = 'EditedDate';
$lang->zahost->registerDate = 'RegisterDate';
$lang->zahost->empty = 'No Host';
$lang->zahost->memorySize = $lang->zahost->memory;
$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->osType = 'Os Version';
$lang->zahost->osCategory = 'System';
$lang->zahost->osVersion = 'Os Version No';
$lang->zahost->osLang = 'Language';
$lang->zahost->imageFile = 'Image File';
$lang->zahost->vmTemplate = new stdclass;
$lang->zahost->vmTemplate->name = 'Name';
$lang->zahost->vmTemplate->common = 'VM Template';
$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory;
$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize;
$lang->zahost->vmTemplate->osType = $lang->zahost->osType;
$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory;
$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion;
$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang;
$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile;
$lang->zahost->empty = 'No Host';
$lang->zahost->templateEmpty = 'No Template';
$lang->zahost->statusList['online'] = 'Online';
+35 -11
View File
@@ -1,14 +1,17 @@
<?php
$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->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';
@@ -26,7 +29,28 @@ $lang->zahost->editedBy = 'EditedBy';
$lang->zahost->editedDate = 'EditedDate';
$lang->zahost->registerDate = 'RegisterDate';
$lang->zahost->empty = 'No Host';
$lang->zahost->memorySize = $lang->zahost->memory;
$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->osType = 'Os Version';
$lang->zahost->osCategory = 'System';
$lang->zahost->osVersion = 'Os Version No';
$lang->zahost->osLang = 'Language';
$lang->zahost->imageFile = 'Image File';
$lang->zahost->vmTemplate = new stdclass;
$lang->zahost->vmTemplate->name = 'Name';
$lang->zahost->vmTemplate->common = 'VM Template';
$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory;
$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize;
$lang->zahost->vmTemplate->osType = $lang->zahost->osType;
$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory;
$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion;
$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang;
$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile;
$lang->zahost->empty = 'No Host';
$lang->zahost->templateEmpty = 'No Template';
$lang->zahost->statusList['online'] = 'Online';
+35 -11
View File
@@ -1,14 +1,17 @@
<?php
$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->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';
@@ -26,7 +29,28 @@ $lang->zahost->editedBy = 'EditedBy';
$lang->zahost->editedDate = 'EditedDate';
$lang->zahost->registerDate = 'RegisterDate';
$lang->zahost->empty = 'No Host';
$lang->zahost->memorySize = $lang->zahost->memory;
$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->osType = 'Os Version';
$lang->zahost->osCategory = 'System';
$lang->zahost->osVersion = 'Os Version No';
$lang->zahost->osLang = 'Language';
$lang->zahost->imageFile = 'Image File';
$lang->zahost->vmTemplate = new stdclass;
$lang->zahost->vmTemplate->name = 'Name';
$lang->zahost->vmTemplate->common = 'VM Template';
$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory;
$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize;
$lang->zahost->vmTemplate->osType = $lang->zahost->osType;
$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory;
$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion;
$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang;
$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile;
$lang->zahost->empty = 'No Host';
$lang->zahost->templateEmpty = 'No Template';
$lang->zahost->statusList['online'] = 'Online';
+35 -11
View File
@@ -1,14 +1,17 @@
<?php
$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->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';
@@ -26,7 +29,28 @@ $lang->zahost->editedBy = 'EditedBy';
$lang->zahost->editedDate = 'EditedDate';
$lang->zahost->registerDate = 'RegisterDate';
$lang->zahost->empty = 'No Host';
$lang->zahost->memorySize = $lang->zahost->memory;
$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->osType = 'Os Version';
$lang->zahost->osCategory = 'System';
$lang->zahost->osVersion = 'Os Version No';
$lang->zahost->osLang = 'Language';
$lang->zahost->imageFile = 'Image File';
$lang->zahost->vmTemplate = new stdclass;
$lang->zahost->vmTemplate->name = 'Name';
$lang->zahost->vmTemplate->common = 'VM Template';
$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory;
$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize;
$lang->zahost->vmTemplate->osType = $lang->zahost->osType;
$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory;
$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion;
$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang;
$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile;
$lang->zahost->empty = 'No Host';
$lang->zahost->templateEmpty = 'No Template';
$lang->zahost->statusList['online'] = 'Online';
+16 -13
View File
@@ -1,14 +1,17 @@
<?php
$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->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';
@@ -26,8 +29,6 @@ $lang->zahost->editedBy = '由谁修改';
$lang->zahost->editedDate = '最后修改时间';
$lang->zahost->registerDate = '最后注册时间';
$lang->zahost->createTemplate = '创建虚拟机模板';
$lang->zahost->memorySize = $lang->zahost->memory;
$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->osType = '操作系统版本';
@@ -38,6 +39,7 @@ $lang->zahost->imageFile = '镜像文件';
$lang->zahost->vmTemplate = new stdclass;
$lang->zahost->vmTemplate->name = '名称';
$lang->zahost->vmTemplate->common = '虚拟机模板';
$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory;
$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize;
@@ -52,7 +54,8 @@ $lang->zahost->langList['zh_cn'] = '简体中文';
$lang->zahost->langList['zh_tw'] = '繁体中文';
$lang->zahost->langList['en_us'] = '美式英语';
$lang->zahost->empty = '暂时没有主机';
$lang->zahost->empty = '暂时没有主机';
$lang->zahost->templateEmpty = '暂时没有模板';
$lang->zahost->statusList['online'] = '已上架';
+89 -27
View File
@@ -24,18 +24,6 @@ class zahostModel extends model
$this->app->lang->vmtemplate = $this->lang->zahost;
}
/**
* Get host by id.
*
* @param int $hostID
* @access public
* @return object
*/
public function getById($hostID)
{
return $this->dao->select('*')->from(TABLE_ZAHOST)->where('id')->eq($hostID)->fetch();
}
/**
* Create a host.
*
@@ -87,6 +75,58 @@ class zahostModel extends model
return false;
}
/**
* Create vm template.
*
* @access public
* @return void
*/
public function createTemplate()
{
$template = fixer::input('post')
->setIF($this->post->diskSize > 0, 'diskSize', $this->post->diskSize * 1024)
->get();
$this->dao->insert(TABLE_VMTEMPLATE)->data($template)
->batchCheck($this->config->zahost->createTemplate->requiredFields, 'notempty')
->batchCheck('cpuCoreNum,diskSize,memorySize', 'gt', 0)
->autoCheck()
->exec();
if(dao::isError()) return false;
$templateID = $this->dao->lastInsertID();
$this->loadModel('action')->create('vmtemplate', $templateID, 'Created');
}
/**
* Get host by id.
*
* @param int $hostID
* @access public
* @return object
*/
public function getById($hostID)
{
return $this->dao->select('*')->from(TABLE_ZAHOST)->where('id')->eq($hostID)->fetch();
}
/**
* Get pairs.
*
* @param string $idFrom
* @access public
* @return array
*/
public function getPairs($idForm = 'asset')
{
$field = $idForm == 'asset' ? 't1.id' : 't2.id';
return $this->dao->select("$field,t1.name")->from(TABLE_ASSET)->alias('t1')
->leftJoin(TABLE_HOST)->alias('t2')->on('t1.id = t2.assetID')
->where('t1.deleted')->eq('0')
->orderBy('`group`')
->fetchPairs('id', 'name');
}
/**
* Get host list.
*
@@ -137,25 +177,47 @@ class zahostModel extends model
}
/**
* Create vm template.
* Get VM template list.
*
* @param int $hostID
* @param string $browseType
* @param int $param
* @param string $orderBy
* @param int $pager
* @access public
* @return void
* @return array
*/
public function createTemplate()
public function getVmTemplateList($hostID, $browseType = 'all', $param = 0, $orderBy = 'id_desc', $pager = null)
{
$template = fixer::input('post')
->setIF($this->post->diskSize > 0, 'diskSize', $this->post->diskSize * 1024)
->get();
$query = '';
if($browseType == 'bysearch')
{
/* Concatenate the conditions for the query. */
if($param)
{
$query = $this->loadModel('search')->getQuery($param);
if($query)
{
$this->session->set('vmTemplateQuery', $query->sql);
$this->session->set('vmTemplateForm', $query->form);
}
else
{
$this->session->set('vmTemplateQuery', ' 1 = 1');
}
}
else
{
if($this->session->vmTemplateQuery == false) $this->session->set('vmTemplateQuery', ' 1 = 1');
}
$query = $this->session->vmTemplateQuery;
}
$this->dao->insert(TABLE_VMTEMPLATE)->data($template)
->batchCheck($this->config->zahost->createTemplate->requiredFields, 'notempty')
->batchCheck('cpuCoreNum,diskSize,memorySize', 'gt', 0)
->autoCheck()
->exec();
if(dao::isError()) return false;
$templateID = $this->dao->lastInsertID();
$this->loadModel('action')->create('vmtemplate', $templateID, 'Created');
return $this->dao->select('*')->from(TABLE_VMTEMPLATE)
->where('hostID')->eq($hostID)
->beginIF($query)->andWhere($query)->fi()
->orderBy($orderBy)
->page($pager)
->fetchAll();
}
}
+2 -2
View File
@@ -10,7 +10,7 @@
* @link http://www.zentao.net
*/
?>
<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('confirmDelete', $lang->zahost->confirmDelete)?>
<?php js::set('browseType', $browseType)?>
<div id='mainMenu' class='clearfix'>
@@ -59,7 +59,7 @@
<?php foreach($hostList as $host):?>
<tr class='text-left'>
<td><?php printf('%03d', $host->id);?></td>
<td title='<?php echo $host->name?>'><?php echo html::a($this->inlink('view', "id=$host->id", 'html', true), $host->name, '', "class='iframe'");?></td>
<td title='<?php echo $host->name?>'><?php echo common::hasPriv('zahost', 'browsetemplate') ? html::a($this->inlink('browsetemplate', "id=$host->id"), $host->name) : $host->name;?></td>
<td><?php echo zget($lang->zahost->zaHostType, $host->hostType);?></td>
<td><?php echo $host->publicIP;?></td>
<td><?php echo $host->cpuCores;?></td>
+74
View File
@@ -0,0 +1,74 @@
<?php
/**
* The template browse view file of zahost module of ZenTaoPMS.
*
* @copyright Copyright 2009-2022 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author xiawenlong <liyuchun@easycorp.ltd>
* @package zahost
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id='mainMenu' class='clearfix'>
<div class='pull-left btn-toolbar'>
<a href='#' class='btn btn-link querybox-toggle' id='bysearchTab'><i class='icon-search icon'></i> <?php echo $lang->zahost->byQuery;?></a>
</div>
<?php if(common::hasPriv('zahost', 'createTemplate')):?>
<div class="btn-toolbar pull-right" id='createActionMenu'>
<?php
$misc = "class='btn btn-primary'";
$link = $this->createLink('zahost', 'createTemplate');
echo html::a($link, "<i class='icon icon-plus'></i>" . $lang->zahost->createTemplate, '', $misc);
?>
</div>
<?php endif;?>
</div>
<div id='queryBox' class='cell <?php if($browseType =='bysearch') echo 'show';?>' data-module='vmTemplate'></div>
<div id='mainContent' class='main-table'>
<?php $vars = "hostID=$hostID&browseType=all&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}";?>
<?php if(empty($templateList)):?>
<div class="table-empty-tip">
<p>
<span class="text-muted"><?php echo $lang->zahost->templateEmpty;?></span>
<?php if(common::hasPriv('zahost', 'createTemplate')) common::printLink('zahost', 'createTemplate', '', '<i class="icon icon-plus"></i> ' . $lang->zahost->createTemplate, '', 'class="btn btn-info"');?>
</p>
</div>
<?php else:?>
<table class='table has-sort-head table-fixed' id='vmList'>
<thead>
<tr>
<th class='c-id'><?php common::printOrderLink('id', $orderBy, $vars, $lang->idAB);?></th>
<th class='c-name'><?php common::printOrderLink('name', $orderBy, $vars, $lang->zahost->name);?></th>
<th class='c-number'><?php common::printOrderLink('cpuCoreNum', $orderBy, $vars, $lang->zahost->cpuCoreNum);?></th>
<th class='c-number'><?php common::printOrderLink('memorySize', $orderBy, $vars, $lang->zahost->memory);?></th>
<th class='c-number'><?php common::printOrderLink('diskSize', $orderBy, $vars, $lang->zahost->diskSize);?></th>
<th class='c-os'><?php common::printOrderLink('osCategory', $orderBy, $vars, $lang->zahost->osCategory);?></th>
<th class='c-os'><?php common::printOrderLink('osType', $orderBy, $vars, $lang->zahost->osType);?></th>
<th class='c-os'><?php common::printOrderLink('osVersion', $orderBy, $vars, $lang->zahost->osVersion);?></th>
<th class='c-lang'><?php common::printOrderLink('osLang', $orderBy, $vars, $lang->zahost->osLang);?></th>
</tr>
</thead>
<tbody>
<?php foreach($templateList as $template):?>
<tr>
<td><?php echo $template->id;?></td>
<td title="<?php echo $template->name;?>"><?php echo $template->name;?></td>
<td><?php echo $template->cpuCoreNum;?></td>
<td><?php echo $template->memorySize;?></td>
<td><?php echo $template->diskSize;?></td>
<td><?php echo zget($config->zahost->os->list, $template->osCategory);?></td>
<td><?php echo zget($config->zahost->os->type[$template->osCategory], $template->osType);?></td>
<td><?php echo zget($lang->zahost->versionList[$template->osType], $template->osVersion);?></td>
<td><?php echo zget($lang->zahost->langList, $template->osLang);?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<div class='table-footer'>
<?php $pager->show('right', 'pagerjs');?>
</div>
<?php endif;?>
</div>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>