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/common/lang/menu.php b/module/common/lang/menu.php
index f71684422f..4c3c4a864e 100644
--- a/module/common/lang/menu.php
+++ b/module/common/lang/menu.php
@@ -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');
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 baef04813b..4ff34d3e31 100644
--- a/module/zahost/control.php
+++ b/module/zahost/control.php
@@ -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.
*
diff --git a/module/zahost/css/browsetemplate.css b/module/zahost/css/browsetemplate.css
new file mode 100644
index 0000000000..273d944493
--- /dev/null
+++ b/module/zahost/css/browsetemplate.css
@@ -0,0 +1,3 @@
+.c-number {width: 100px;}
+.c-os {width: 130px;}
+.c-lang {width: 150px;}
diff --git a/module/zahost/lang/de.php b/module/zahost/lang/de.php
index 43e485c296..4285d60603 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';
@@ -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';
diff --git a/module/zahost/lang/en.php b/module/zahost/lang/en.php
index 43e485c296..4285d60603 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';
@@ -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';
diff --git a/module/zahost/lang/fr.php b/module/zahost/lang/fr.php
index 43e485c296..4285d60603 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';
@@ -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';
diff --git a/module/zahost/lang/vi.php b/module/zahost/lang/vi.php
index 43e485c296..4285d60603 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';
@@ -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';
diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php
index ad93e16963..cee587d315 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';
@@ -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'] = '已上架';
diff --git a/module/zahost/model.php b/module/zahost/model.php
index c8f576dc25..644c6c32c1 100644
--- a/module/zahost/model.php
+++ b/module/zahost/model.php
@@ -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();
}
}
diff --git a/module/zahost/view/browse.html.php b/module/zahost/view/browse.html.php
index b6830e91da..1fb287e449 100644
--- a/module/zahost/view/browse.html.php
+++ b/module/zahost/view/browse.html.php
@@ -10,7 +10,7 @@
* @link http://www.zentao.net
*/
?>
-getModuleRoot() . 'common/view/header.html.php';?>
+
zahost->confirmDelete)?>
@@ -59,7 +59,7 @@
| id);?> |
- inlink('view', "id=$host->id", 'html', true), $host->name, '', "class='iframe'");?> |
+ inlink('browsetemplate', "id=$host->id"), $host->name) : $host->name;?> |
zahost->zaHostType, $host->hostType);?> |
publicIP;?> |
cpuCores;?> |
diff --git a/module/zahost/view/browsetemplate.html.php b/module/zahost/view/browsetemplate.html.php
new file mode 100755
index 0000000000..3fc3e99193
--- /dev/null
+++ b/module/zahost/view/browsetemplate.html.php
@@ -0,0 +1,74 @@
+
+ * @package zahost
+ * @version $Id$
+ * @link http://www.zentao.net
+ */
+?>
+
+
+' data-module='vmTemplate'>
+
+ recTotal}&recPerPage={$pager->recPerPage}";?>
+
+
+
+ zahost->templateEmpty;?>
+ ' . $lang->zahost->createTemplate, '', 'class="btn btn-info"');?>
+
+
+
+
+
+
+ | idAB);?> |
+ zahost->name);?> |
+ zahost->cpuCoreNum);?> |
+ zahost->memory);?> |
+ zahost->diskSize);?> |
+ zahost->osCategory);?> |
+ zahost->osType);?> |
+ zahost->osVersion);?> |
+ zahost->osLang);?> |
+
+
+
+
+
+ | id;?> |
+ name;?> |
+ cpuCoreNum;?> |
+ memorySize;?> |
+ diskSize;?> |
+ zahost->os->list, $template->osCategory);?> |
+ zahost->os->type[$template->osCategory], $template->osType);?> |
+ zahost->versionList[$template->osType], $template->osVersion);?> |
+ zahost->langList, $template->osLang);?> |
+
+
+
+
+
+
+
+getModuleRoot() . 'common/view/footer.html.php';?>