Merge branch 'zenops_46' into sprint/220

This commit is contained in:
tanghucheng
2022-12-09 13:49:30 +08:00
1391 changed files with 943851 additions and 1505 deletions
+85
View File
@@ -0,0 +1,85 @@
<?php
/**
* The host entry point 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 Yuchun Li <liyuchun@easycorp.ltd>
* @package entries
* @version 1
* @link http://www.zentao.net
*/
class hostHeartbeatEntry extends baseEntry
{
/**
* Listen host 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;
$vms = $this->requestBody->Vms;
$zap = $this->requestBody->port;
$now = helper::now();
if(!$status) return $this->sendError(400, 'Params error.');
$conditionField = $secret ? 'secret' : 'tokenSN';
$conditionValue = $secret ? $secret : $token;
$host = new stdclass();
$host->status = $status;
if($secret)
{
$host->tokenSN = md5($secret . $now);
$host->tokenTime = date('Y-m-d H:i:s', time() + 7200);
}
$this->dao = $this->loadModel('common')->dao;
$id = $this->dao->select('id')->from(TABLE_ZAHOST)
->beginIF($secret)->where('secret')->eq($secret)->fi()
->beginIF(!$secret)->where('tokenSN')->eq($token)
->andWhere('tokenTime')->gt($now)->fi()
->fetch('id');
if(!$id) return $this->sendError(400, 'Secret error.');
$this->dao->update(TABLE_ZAHOST)->data($host)->where($conditionField)->eq($conditionValue)->exec();
$this->dao->update(TABLE_ZAHOST)
->set('heartbeat')->eq($now)
->set('zap')->eq($zap)
->where('id')->eq($id)->exec();
if($vms)
{
foreach($vms as $vm)
{
if(!empty($vm->vncPortOnHost))
{
$this->dao->update(TABLE_ZAHOST)
->set('vnc')->eq($vm->vncPortOnHost)
->set('zap')->eq($vm->agentPortOnHost)
->set('ztf')->eq($vm->ztfPortOnHost)
->set('zd')->eq($vm->zdPortOnHost)
->set('ssh')->eq($vm->sshPortOnHost)
->set('status')->eq($vm->status)
->where('mac')->eq($vm->macAddress)->exec();
}
}
}
if(!$secret) return $this->sendSuccess(200, 'success');
$host->tokenTimeUnix = strtotime($host->tokenTime);
unset($host->status);
unset($host->tokenTime);
return $this->send(200, $host);
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
/**
* The host entry point 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 Ke Zhao <zhaoke@easycorp.ltd>
* @package entries
* @version 1
* @link http://www.zentao.net
*/
class hostSubmitEntry extends baseEntry
{
/**
* Listen host task finish submit.
*
* @param int|string $userID
* @access public
* @return void
*/
public function post()
{
/* Check authorize. */
$header = getallheaders();
$token = isset($header['Authorization']) ? substr($header['Authorization'], 7) : '';
if(!$token) return $this->sendError(401, 'Unauthorized');
$now = helper::now();
/* Check param. */
$image = new stdclass();
$task = $this->requestBody->task;
$image->status = $this->requestBody->status;
$this->dao = $this->loadModel('common')->dao;
$id = $this->dao->select('id')->from(TABLE_ZAHOST)
->where('tokenSN')->eq($token)
->andWhere('tokenTime')->gt($now)->fi()
->fetch('id');
if(!$id) return $this->sendError(400, 'Secret error.');
$this->dao->update(TABLE_IMAGE)->data($image)->where("id")->eq($task)->exec();
return $this->sendSuccess(200, 'success');
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
/**
* The zanode entry point 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 Yuchun Li <liyuchun@easycorp.ltd>
* @package entries
* @version 1
* @link http://www.zentao.net
*/
class zanodeHeartbeatEntry 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 = isset($this->requestBody->status) ? $this->requestBody->status : '';
$mac = isset($this->requestBody->macAddress) ? $this->requestBody->macAddress : '';
$now = helper::now();
if(!$status || !$mac) return $this->sendError(400, 'Params error.');
$this->dao = $this->loadModel('common')->dao;
$host = $this->dao->select('id,extranet')->from(TABLE_ZAHOST)
->beginIF($secret)->where('secret')->eq($secret)->fi()
->beginIF(!$secret)->where('tokenSN')->eq($token)
->andWhere('tokenTime')->gt($now)->fi()
->fetch();
if(empty($host)) return $this->sendError(400, 'Secret error.');
$node = $this->dao->select('id,parent')->from(TABLE_ZAHOST)
->where('mac')->eq($mac)
->fetch();
if(empty($node) || ($node->parent != $host->id && $node->id != $host->id)) return $this->sendError(400, 'Secret error.');
$node->zap = $this->requestBody->agentPortOnHost;
$node->status = $this->requestBody->status;
if($secret)
{
$node->tokenSN = md5($secret . $now);
$node->tokenTime = date('Y-m-d H:i:s', time() + 7200);
}
$this->dao->update(TABLE_ZAHOST)->data($node)->where('id')->eq($node->id)->exec();
if($secret)
{
//install services
$node->ip = $host->extranet;
$nodeStatus = $this->loadModel('zanode')->getServiceStatus($node);
if($nodeStatus['ZTF'] != "ready")
{
$node->secret = $secret;
$node->extranet = $host->extranet;
$this->loadModel('zanode')->installService($node, "ZTF");
}
}
if(!$secret) return $this->sendSuccess(200, 'success');
$node->tokenTimeUnix = strtotime($node->tokenTime);
unset($node->status);
unset($node->tokenTime);
return $this->send(200, $node);
}
}