From 8f257664aedafc12a1e6cc32dc115b5ea1fa87db Mon Sep 17 00:00:00 2001 From: net909 Date: Mon, 22 Apr 2024 23:08:21 +0800 Subject: [PATCH] fix --- app/controller/Dmonitor.php | 8 +++++--- app/lib/CheckUtils.php | 16 +++++++++++++++- app/lib/TaskRunner.php | 2 +- app/lib/dns/huawei.php | 6 ++++-- app/sql/install.sql | 2 +- app/sql/update.sql | 2 +- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/controller/Dmonitor.php b/app/controller/Dmonitor.php index b530f75..b287dfb 100644 --- a/app/controller/Dmonitor.php +++ b/app/controller/Dmonitor.php @@ -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(); $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', [ '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_error' => config_get('run_error', null, true), 'switch_count' => $switch_count, @@ -257,7 +258,8 @@ class Dmonitor extends BaseController 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'; } } \ No newline at end of file diff --git a/app/lib/CheckUtils.php b/app/lib/CheckUtils.php index e143f8e..6aebc31 100644 --- a/app/lib/CheckUtils.php +++ b/app/lib/CheckUtils.php @@ -4,10 +4,20 @@ namespace app\lib; class CheckUtils { - public static function curl($url, $timeout) + public static function curl($url, $timeout, $ip = null) { $status = true; $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(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); @@ -20,6 +30,10 @@ class CheckUtils curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $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); $errno = curl_errno($ch); if ($errno) { diff --git a/app/lib/TaskRunner.php b/app/lib/TaskRunner.php index fd28164..f6e4cbd 100644 --- a/app/lib/TaskRunner.php +++ b/app/lib/TaskRunner.php @@ -28,7 +28,7 @@ class TaskRunner public function execute($row) { 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){ $result = CheckUtils::tcp($row['main_value'], $row['tcpport'], $row['timeout']); }else{ diff --git a/app/lib/dns/huawei.php b/app/lib/dns/huawei.php index 8efb0ba..781c428 100644 --- a/app/lib/dns/huawei.php +++ b/app/lib/dns/huawei.php @@ -112,7 +112,8 @@ class huawei implements DnsInterface { //添加解析记录 public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Remark = null){ $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); $data = $this->send_reuqest('POST', '/v2.1/zones/'.$this->domainid.'/recordsets', null, $params); 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){ $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); $data = $this->send_reuqest('PUT', '/v2.1/zones/'.$this->domainid.'/recordsets/'.$RecordId, null, $params); return is_array($data); diff --git a/app/sql/install.sql b/app/sql/install.sql index e35c242..bc0a520 100644 --- a/app/sql/install.sql +++ b/app/sql/install.sql @@ -86,7 +86,7 @@ CREATE TABLE `dnsmgr_dmtask` ( `backup_value` varchar(128) DEFAULT NULL, `checktype` tinyint(1) NOT NULL DEFAULT 0, `checkurl` varchar(512) DEFAULT NULL, - `tcpport` tinyint(5) DEFAULT NULL, + `tcpport` int(5) DEFAULT NULL, `frequency` tinyint(5) NOT NULL, `cycle` tinyint(5) NOT NULL DEFAULT 3, `timeout` tinyint(5) NOT NULL DEFAULT 2, diff --git a/app/sql/update.sql b/app/sql/update.sql index c4956c8..65aae20 100644 --- a/app/sql/update.sql +++ b/app/sql/update.sql @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `dnsmgr_dmtask` ( `backup_value` varchar(128) DEFAULT NULL, `checktype` tinyint(1) NOT NULL DEFAULT 0, `checkurl` varchar(512) DEFAULT NULL, - `tcpport` tinyint(5) DEFAULT NULL, + `tcpport` int(5) DEFAULT NULL, `frequency` tinyint(5) NOT NULL, `cycle` tinyint(5) NOT NULL DEFAULT 3, `timeout` tinyint(5) NOT NULL DEFAULT 2,