diff --git a/api/v1/entries/executionnodeheartbeat.php b/api/v1/entries/executionnodeheartbeat.php new file mode 100644 index 0000000000..8a2d30dc34 --- /dev/null +++ b/api/v1/entries/executionnodeheartbeat.php @@ -0,0 +1,65 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class executionnodeHeartbeatEntry extends baseEntry +{ + /** + * Listen vm heartbeat. + * + * @param int|string $userID + * @access public + * @return void + */ + public function post() + { + /* Check authorize. */ + $header = getallheaders(); + $token = isset($header['Authorization']) ? substr($header['Authorization'], 7) : ''; + $secret = isset($this->requestBody->secret) ? $this->requestBody->secret : ''; + if(!$secret and !$token) return $this->sendError(401, 'Unauthorized'); + + /* Check param. */ + $status = $this->requestBody->status; + $now = helper::now(); + if(!$status) return $this->sendError(400, 'Params error.'); + + $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.'); + + $conditionField = $secret ? 'secret' : 'token'; + $conditionValue = $secret ? $secret : $token; + if($secret) + { + $host = new stdclass(); + $host->token = md5($secret . $now); + $host->expiredDate = date('Y-m-d H:i:s', time() + 7200); + $this->dao->update(TABLE_HOST)->data($host)->where($conditionField)->eq($conditionValue)->exec(); + } + + $node = new stdclass(); + $node->vmIP = $this->requestBody->ip; + $node->agentPort = $this->requestBody->agentPortOnHost; + $node->status = $this->requestBody->status; + $this->dao->update(TABLE_VM)->data($node)->where('macAddress')->eq($this->requestBody->macAddress)->exec(); + + if(!$secret) return $this->sendSuccess(200, 'success'); + + $host->expiredTimeUnix = strtotime($host->expiredDate); + unset($host->status); + unset($host->expiredDate); + return $this->send(200, $host); + } +} diff --git a/config/routes.php b/config/routes.php index f67bf12993..af01f4c018 100644 --- a/config/routes.php +++ b/config/routes.php @@ -162,6 +162,8 @@ $routes['/reports'] = 'reports'; $routes['/host/heartbeat'] = 'hostHeartbeat'; +$routes['/executionnode/heartbeat'] = 'executionnodeHeartbeat'; + $routes['/z/folders'] = 'zfolders'; $routes['/z/folders/:id'] = 'zfolder'; $routes['/z/files/:id'] = 'zfile'; diff --git a/module/repo/control.php b/module/repo/control.php index a7c4a8abc7..d6fe50149d 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -287,6 +287,7 @@ class repo extends control $this->view->oldRevision = $revision; $this->view->file = $file; $this->view->entry = $entry; + $this->view->info = $info; $this->view->content = ''; $this->view->pathInfo = $pathInfo; $this->view->suffix = 'c'; diff --git a/module/zahost/lang/de.php b/module/zahost/lang/de.php index b37b2f3183..b34bfae7a7 100644 --- a/module/zahost/lang/de.php +++ b/module/zahost/lang/de.php @@ -59,6 +59,7 @@ $lang->zahost->langList['en_us'] = 'American English'; $lang->zahost->empty = 'No Host'; $lang->zahost->templateEmpty = 'No Template'; +$lang->zahost->statusList['ready'] = 'Ready'; $lang->zahost->statusList['online'] = 'Online'; $lang->zahost->virtualSoftware = 'VM Software'; diff --git a/module/zahost/lang/en.php b/module/zahost/lang/en.php index b37b2f3183..b34bfae7a7 100644 --- a/module/zahost/lang/en.php +++ b/module/zahost/lang/en.php @@ -59,6 +59,7 @@ $lang->zahost->langList['en_us'] = 'American English'; $lang->zahost->empty = 'No Host'; $lang->zahost->templateEmpty = 'No Template'; +$lang->zahost->statusList['ready'] = 'Ready'; $lang->zahost->statusList['online'] = 'Online'; $lang->zahost->virtualSoftware = 'VM Software'; diff --git a/module/zahost/lang/fr.php b/module/zahost/lang/fr.php index b7e7aec83d..a3be1a830d 100644 --- a/module/zahost/lang/fr.php +++ b/module/zahost/lang/fr.php @@ -59,6 +59,7 @@ $lang->zahost->langList['en_us'] = 'American English'; $lang->zahost->empty = 'No Host'; $lang->zahost->templateEmpty = 'No Template'; +$lang->zahost->statusList['ready'] = 'Ready'; $lang->zahost->statusList['online'] = 'Online'; $lang->zahost->virtualSoftware = 'VM Software'; diff --git a/module/zahost/lang/vi.php b/module/zahost/lang/vi.php index c3d3b78464..0f06360118 100644 --- a/module/zahost/lang/vi.php +++ b/module/zahost/lang/vi.php @@ -59,6 +59,7 @@ $lang->zahost->langList['zh_cn'] = 'Simplified Chinese'; $lang->zahost->langList['zh_tw'] = 'Traditional Chinese'; $lang->zahost->langList['en_us'] = 'American English'; +$lang->zahost->statusList['ready'] = 'Ready'; $lang->zahost->statusList['online'] = 'Online'; $lang->zahost->virtualSoftware = 'VM Software'; diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php index 1a3c7fb169..626b6d68be 100644 --- a/module/zahost/lang/zh-cn.php +++ b/module/zahost/lang/zh-cn.php @@ -59,6 +59,7 @@ $lang->zahost->langList['en_us'] = '美式英语'; $lang->zahost->empty = '暂时没有主机'; $lang->zahost->templateEmpty = '暂时没有模板'; +$lang->zahost->statusList['ready'] = '准备中'; $lang->zahost->statusList['online'] = '已上架'; $lang->zahost->virtualSoftware = '虚拟化软件'; diff --git a/module/zahost/view/browsetemplate.html.php b/module/zahost/view/browsetemplate.html.php index 2ca98ad271..e9a7fb7d47 100755 --- a/module/zahost/view/browsetemplate.html.php +++ b/module/zahost/view/browsetemplate.html.php @@ -13,6 +13,7 @@