* Finish task 77678.

This commit is contained in:
zhaoke
2022-12-02 06:51:11 +00:00
parent 8955e37d09
commit d1e95a46cd
7 changed files with 86 additions and 1 deletions
+12 -1
View File
@@ -88,6 +88,10 @@ class zahost extends control
{
return $this->send(array('result' => 'fail', 'message' => dao::getError()));
}
elseif($hostID === false)
{
return $this->send(array('result' => 'fail', 'message' => array("extranet" => array($this->lang->zahost->netError))));
}
$initLink = $this->createLink('zahost', 'inithost', "hostID=$hostID");
return print("<script>showModal('$initLink')</script>");
@@ -111,7 +115,14 @@ class zahost extends control
if($_POST)
{
$changes = $this->zahost->update($hostID);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
if(dao::isError())
{
return $this->send(array('result' => 'fail', 'message' => dao::getError()));
}
elseif($hostID === false)
{
return $this->send(array('result' => 'fail', 'message' => array("extranet" => array($this->lang->zahost->netError))));
}
if(!empty($changes))
{
+1
View File
@@ -40,6 +40,7 @@ $lang->zahost->createZanode = 'Create Zanode';
$lang->zahost->initHostNotice = 'Save successfully, initialize the ZAhost or return list';
$lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode';
$lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode';
$lang->zahost->netError = 'Unable to connect to the host, please check the network and try again.';
$lang->zahost->initHost = new stdclass;
$lang->zahost->initHost->checkStatus = "Check Service Status";
+1
View File
@@ -40,6 +40,7 @@ $lang->zahost->createZanode = 'Create Zanode';
$lang->zahost->initHostNotice = 'Save successfully, initialize the ZAhost or return list';
$lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode';
$lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode';
$lang->zahost->netError = 'Unable to connect to the host, please check the network and try again.';
$lang->zahost->initHost = new stdclass;
$lang->zahost->initHost->checkStatus = "Check Service Status";
+1
View File
@@ -40,6 +40,7 @@ $lang->zahost->createZanode = 'Create Zanode';
$lang->zahost->initHostNotice = 'Save successfully, initialize the ZAhost or return list';
$lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode';
$lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode';
$lang->zahost->netError = 'Unable to connect to the host, please check the network and try again.';
$lang->zahost->initHost = new stdclass;
$lang->zahost->initHost->checkStatus = "Check Service Status";
+6
View File
@@ -39,6 +39,12 @@ $lang->zahost->osVersion = 'Os Version No';
$lang->zahost->osLang = 'Language';
$lang->zahost->imageName = 'Image File';
$lang->zahost->createZanode = 'Create Zanode';
$lang->zahost->initHostNotice = 'Save successfully, initialize the ZAhost or return list';
$lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode';
$lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode';
$lang->zahost->netError = 'Unable to connect to the host, please check the network and try again.';
$lang->zahost->initHost = new stdclass;
$lang->zahost->initHost->checkStatus = "Check Service Status";
$lang->zahost->initHost->not_install = "Not installed";
+1
View File
@@ -40,6 +40,7 @@ $lang->zahost->createZanode = '创建执行节点';
$lang->zahost->initHostNotice = '保存成功,请您初始化宿主机或返回列表。';
$lang->zahost->createZanodeNotice = '初始化成功,您现在可以创建执行节点了。';
$lang->zahost->downloadImageNotice = '初始化成功,请下载镜像用于创建执行节点。';
$lang->zahost->netError = '无法连接到宿主机,请检查网络后重试。';
$lang->zahost->initHost = new stdclass;
$lang->zahost->initHost->statusTitle = "服务状态";
+64
View File
@@ -49,6 +49,12 @@ class zahostModel extends model
->autoCheck();
if(dao::isError()) return false;
$ping = $this->checkAddress($hostInfo->extranet);
if(!$ping)
{
return false;
}
$this->dao->insert(TABLE_ZAHOST)->data($hostInfo)->autoCheck()->exec();
$hostID = $this->dao->lastInsertID();
if(!dao::isError())
@@ -79,6 +85,12 @@ class zahostModel extends model
->batchCheck('diskSize,memory', 'float');
if(dao::isError()) return false;
$ping = $this->checkAddress($hostInfo->extranet);
if(!$ping)
{
return false;
}
$this->dao->update(TABLE_ZAHOST)->data($hostInfo, 'name')->autoCheck()
->batchCheck('cpuCores,diskSize', 'gt', 0)
->batchCheck('diskSize,memory', 'float')
@@ -86,6 +98,58 @@ class zahostModel extends model
return common::createChanges($oldHost, $hostInfo);
}
/**
* Ping ip/domain.
*
* @param string $address
* @access public
* @return bool
*/
public function ping($address)
{
if (strcasecmp(PHP_OS, 'WINNT') === 0)
{
exec("ping -n 1 {$address}", $outcome, $status);
}
elseif (strcasecmp(PHP_OS, 'Linux') === 0)
{
exec("ping -c 1 {$address}", $outcome, $status);
}
if (0 == $status)
{
$status = true;
}
else
{
$status = false;
}
return $status;
}
/**
* Telnet ip/domain.
*
* @param string $address
* @access public
* @return bool
*/
public function checkAddress($address)
{
$address = str_replace(array('https://', 'http://'), '', $address);
if ($this->ping($address)) return true;
foreach(array(80, 443, 8086) as $port)
{
$fp = fsockopen($address, $port, $errno, $errstr, 3);
if ($fp) return true;
}
return false;
}
/**
* Get image by ID.
*