From 06b43fa33fbe2b2acad25230a94e0c403d642f84 Mon Sep 17 00:00:00 2001 From: net909 Date: Tue, 24 Dec 2024 20:41:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=8E=E4=B8=BA=E4=BA=91?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0TXT=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/dns/huawei.php | 6 ++---- app/utils/CertDnsUtils.php | 26 +++++++++++++++++++++++++- config/app.php | 2 +- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/lib/dns/huawei.php b/app/lib/dns/huawei.php index b4ffe0f..b709118 100644 --- a/app/lib/dns/huawei.php +++ b/app/lib/dns/huawei.php @@ -78,7 +78,6 @@ class huawei implements DnsInterface foreach ($data['recordsets'] as $row) { if ($row['name'] == $row['zone_name']) $row['name'] = '@'; if ($row['type'] == 'MX') list($row['mx'], $row['records']) = explode(' ', $row['records'][0]); - if ($row['type'] == 'TXT') $row['records'] = array_map(function($v){return trim($v, '"');}, $row['records']); $list[] = [ 'RecordId' => $row['id'], 'Domain' => rtrim($row['zone_name'], '.'), @@ -112,7 +111,6 @@ class huawei implements DnsInterface if ($data) { if ($data['name'] == $data['zone_name']) $data['name'] = '@'; if ($data['type'] == 'MX') list($data['mx'], $data['records']) = explode(' ', $data['records'][0]); - if ($data['type'] == 'TXT') $data['records'] = array_map(function($v){return trim($v, '"');}, $data['records']); return [ 'RecordId' => $data['id'], 'Domain' => rtrim($data['zone_name'], '.'), @@ -136,7 +134,7 @@ class huawei implements DnsInterface { $Name = $this->getHost($Name); if ($Type == 'TXT' && substr($Value, 0, 1) != '"') $Value = '"' . $Value . '"'; - $records = explode(',', $Value); + $records = array_reverse(explode(',', $Value)); $params = ['name' => $Name, 'type' => $this->convertType($Type), 'records' => $records, 'line' => $Line, 'ttl' => intval($TTL), 'description' => $Remark]; if ($Type == 'MX') $params['records'][0] = intval($MX) . ' ' . $Value; if ($Weight > 0) $params['weight'] = intval($Weight); @@ -149,7 +147,7 @@ class huawei implements DnsInterface { $Name = $this->getHost($Name); if ($Type == 'TXT' && substr($Value, 0, 1) != '"') $Value = '"' . $Value . '"'; - $records = explode(',', $Value); + $records = array_reverse(explode(',', $Value)); $params = ['name' => $Name, 'type' => $this->convertType($Type), 'records' => $records, 'line' => $Line, 'ttl' => intval($TTL), 'description' => $Remark]; if ($Type == 'MX') $params['records'][0] = intval($MX) . ' ' . $Value; if ($Weight > 0) $params['weight'] = intval($Weight); diff --git a/app/utils/CertDnsUtils.php b/app/utils/CertDnsUtils.php index 185521a..dd7621a 100644 --- a/app/utils/CertDnsUtils.php +++ b/app/utils/CertDnsUtils.php @@ -39,6 +39,9 @@ class CertDnsUtils usort($list, function ($a, $b) { return strcmp($a['name'], $b['name']); }); + if ($drow['type'] == 'huawei') { + $list = self::getHuaweiDnsRecords($list); + } $records = []; foreach ($list as $row) { $domain = $row['name'] . '.' . $mainDomain; @@ -46,7 +49,8 @@ class CertDnsUtils if (!$records[$row['name']]) throw new Exception('获取'.$domain.'记录列表失败,'.$dns->getError()); $filter_records = array_filter($records[$row['name']]['list'], function ($v) use ($row) { - return $v['Type'] == $row['type'] && $v['Value'] == $row['value']; + if (is_array($v['Value'])) $v['Value'] = implode(',', $v['Value']); + return $v['Type'] == $row['type'] && ($v['Value'] == $row['value'] || rtrim($v['Value'], '.') == $row['value']); }); if (!empty($filter_records)) { foreach ($filter_records as $recordid => $record) { @@ -76,6 +80,22 @@ class CertDnsUtils } } + private static function getHuaweiDnsRecords($list) + { + //将name相同的TXT记录合并 + $txt_records = []; + foreach ($list as $key => $row) { + if ($row['type'] == 'TXT') { + $txt_records[$row['name']][] = $row['value']; + unset($list[$key]); + } + } + foreach ($txt_records as $name => $rows) { + $list[] = ['name' => $name, 'type' => 'TXT', 'value' => '"' . implode('","', $rows) . '"']; + } + return $list; + } + public static function delDns($dnsList, callable $log, $cname = false) { $cnameDomainList = []; @@ -107,6 +127,9 @@ class CertDnsUtils usort($list, function ($a, $b) { return strcmp($a['name'], $b['name']); }); + if ($drow['type'] == 'huawei') { + $list = self::getHuaweiDnsRecords($list); + } $records = []; foreach ($list as $row) { //if ($row['type'] == 'CAA') continue; @@ -115,6 +138,7 @@ class CertDnsUtils if (!$records[$row['name']]) throw new Exception('获取'.$domain.'记录列表失败,'.$dns->getError()); $filter_records = array_filter($records[$row['name']]['list'], function ($v) use ($row) { + if (is_array($v['Value'])) $v['Value'] = implode(',', $v['Value']); return $v['Type'] == $row['type'] && ($v['Value'] == $row['value'] || rtrim($v['Value'], '.') == $row['value']); }); if (empty($filter_records)) continue; diff --git a/config/app.php b/config/app.php index e6cd05a..12b3569 100644 --- a/config/app.php +++ b/config/app.php @@ -31,7 +31,7 @@ return [ 'show_error_msg' => true, 'exception_tmpl' => \think\facade\App::getAppPath() . 'view/exception.tpl', - 'version' => '1021', + 'version' => '1022', 'dbversion' => '1021' ];