This commit is contained in:
net909 2024-04-22 23:08:21 +08:00
parent 8d653b872a
commit 8f257664ae
6 changed files with 27 additions and 9 deletions

View File

@ -16,10 +16,11 @@ class Dmonitor extends BaseController
$switch_count = Db::name('dmlog')->where('date', '>=', date("Y-m-d H:i:s",strtotime("-1 days")))->count(); $switch_count = Db::name('dmlog')->where('date', '>=', date("Y-m-d H:i:s",strtotime("-1 days")))->count();
$fail_count = Db::name('dmlog')->where('date', '>=', date("Y-m-d H:i:s",strtotime("-1 days")))->where('action', 1)->count(); $fail_count = Db::name('dmlog')->where('date', '>=', date("Y-m-d H:i:s",strtotime("-1 days")))->where('action', 1)->count();
$run_state = config_get('run_time', null, true) ? (time()-strtotime(config_get('run_time')) > 10 ? 0 : 1) : 0; $run_time = config_get('run_time', null, true);
$run_state = $run_time ? (time()-strtotime($run_time) > 10 ? 0 : 1) : 0;
View::assign('info', [ View::assign('info', [
'run_count' => config_get('run_count', null, true) ?? 0, 'run_count' => config_get('run_count', null, true) ?? 0,
'run_time' => config_get('run_time', null, true) ?? '无', 'run_time' => $run_time ?? '无',
'run_state' => $run_state, 'run_state' => $run_state,
'run_error' => config_get('run_error', null, true), 'run_error' => config_get('run_error', null, true),
'switch_count' => $switch_count, 'switch_count' => $switch_count,
@ -257,7 +258,8 @@ class Dmonitor extends BaseController
public function status() public function status()
{ {
$run_state = config_get('run_time', null, true) ? (time()-strtotime(config_get('run_time')) > 10 ? 0 : 1) : 0; $run_time = config_get('run_time', null, true);
$run_state = $run_time ? (time()-strtotime($run_time) > 10 ? 0 : 1) : 0;
return $run_state == 1 ? 'ok' : 'error'; return $run_state == 1 ? 'ok' : 'error';
} }
} }

View File

@ -4,10 +4,20 @@ namespace app\lib;
class CheckUtils class CheckUtils
{ {
public static function curl($url, $timeout) public static function curl($url, $timeout, $ip = null)
{ {
$status = true; $status = true;
$errmsg = null; $errmsg = null;
$urlarr = parse_url($url);
if (!empty($ip) && !filter_var($urlarr['host'], FILTER_VALIDATE_IP)) {
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
$ip = gethostbyname($ip);
}
if (!empty($ip) && filter_var($ip, FILTER_VALIDATE_IP)) {
$port = isset($urlarr['port']) ? $urlarr['port'] : ($urlarr['scheme'] == 'https' ? 443 : 80);
$resolve = $urlarr['host'] . ':' . $port . ':' . $ip;
}
}
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
@ -20,6 +30,10 @@ class CheckUtils
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if(!empty($resolve)){
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
curl_setopt($ch, CURLOPT_RESOLVE, [$resolve]);
}
curl_exec($ch); curl_exec($ch);
$errno = curl_errno($ch); $errno = curl_errno($ch);
if ($errno) { if ($errno) {

View File

@ -28,7 +28,7 @@ class TaskRunner
public function execute($row) public function execute($row)
{ {
if($row['checktype'] == 2){ if($row['checktype'] == 2){
$result = CheckUtils::curl($row['checkurl'], $row['timeout']); $result = CheckUtils::curl($row['checkurl'], $row['timeout'], $row['main_value']);
}else if($row['checktype'] == 1){ }else if($row['checktype'] == 1){
$result = CheckUtils::tcp($row['main_value'], $row['tcpport'], $row['timeout']); $result = CheckUtils::tcp($row['main_value'], $row['tcpport'], $row['timeout']);
}else{ }else{

View File

@ -112,7 +112,8 @@ class huawei implements DnsInterface {
//添加解析记录 //添加解析记录
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Remark = null){ public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Remark = null){
$Name = $this->getHost($Name); $Name = $this->getHost($Name);
$params = ['name' => $Name, 'type' => $this->convertType($Type), 'records' => [$Value], 'line'=>$Line, 'ttl' => intval($TTL), 'description' => $Remark]; $records = explode(',', $Value);
$params = ['name' => $Name, 'type' => $this->convertType($Type), 'records' => $records, 'line'=>$Line, 'ttl' => intval($TTL), 'description' => $Remark];
if($Type == 'MX')$param['weight'] = intval($MX); if($Type == 'MX')$param['weight'] = intval($MX);
$data = $this->send_reuqest('POST', '/v2.1/zones/'.$this->domainid.'/recordsets', null, $params); $data = $this->send_reuqest('POST', '/v2.1/zones/'.$this->domainid.'/recordsets', null, $params);
return is_array($data) ? $data['id'] : false; return is_array($data) ? $data['id'] : false;
@ -121,7 +122,8 @@ class huawei implements DnsInterface {
//修改解析记录 //修改解析记录
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Remark = null){ public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Remark = null){
$Name = $this->getHost($Name); $Name = $this->getHost($Name);
$params = ['name' => $Name, 'type' => $this->convertType($Type), 'records' => [$Value], 'line'=>$Line, 'ttl' => intval($TTL), 'description' => $Remark]; $records = explode(',', $Value);
$params = ['name' => $Name, 'type' => $this->convertType($Type), 'records' => $records, 'line'=>$Line, 'ttl' => intval($TTL), 'description' => $Remark];
if($Type == 'MX')$param['weight'] = intval($MX); if($Type == 'MX')$param['weight'] = intval($MX);
$data = $this->send_reuqest('PUT', '/v2.1/zones/'.$this->domainid.'/recordsets/'.$RecordId, null, $params); $data = $this->send_reuqest('PUT', '/v2.1/zones/'.$this->domainid.'/recordsets/'.$RecordId, null, $params);
return is_array($data); return is_array($data);

View File

@ -86,7 +86,7 @@ CREATE TABLE `dnsmgr_dmtask` (
`backup_value` varchar(128) DEFAULT NULL, `backup_value` varchar(128) DEFAULT NULL,
`checktype` tinyint(1) NOT NULL DEFAULT 0, `checktype` tinyint(1) NOT NULL DEFAULT 0,
`checkurl` varchar(512) DEFAULT NULL, `checkurl` varchar(512) DEFAULT NULL,
`tcpport` tinyint(5) DEFAULT NULL, `tcpport` int(5) DEFAULT NULL,
`frequency` tinyint(5) NOT NULL, `frequency` tinyint(5) NOT NULL,
`cycle` tinyint(5) NOT NULL DEFAULT 3, `cycle` tinyint(5) NOT NULL DEFAULT 3,
`timeout` tinyint(5) NOT NULL DEFAULT 2, `timeout` tinyint(5) NOT NULL DEFAULT 2,

View File

@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `dnsmgr_dmtask` (
`backup_value` varchar(128) DEFAULT NULL, `backup_value` varchar(128) DEFAULT NULL,
`checktype` tinyint(1) NOT NULL DEFAULT 0, `checktype` tinyint(1) NOT NULL DEFAULT 0,
`checkurl` varchar(512) DEFAULT NULL, `checkurl` varchar(512) DEFAULT NULL,
`tcpport` tinyint(5) DEFAULT NULL, `tcpport` int(5) DEFAULT NULL,
`frequency` tinyint(5) NOT NULL, `frequency` tinyint(5) NOT NULL,
`cycle` tinyint(5) NOT NULL DEFAULT 3, `cycle` tinyint(5) NOT NULL DEFAULT 3,
`timeout` tinyint(5) NOT NULL DEFAULT 2, `timeout` tinyint(5) NOT NULL DEFAULT 2,