From a4fe9393b836c55df35dbc0df922cccf86811d00 Mon Sep 17 00:00:00 2001 From: net909 Date: Sat, 9 May 2026 12:42:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E8=85=BE=E8=AE=AF?= =?UTF-8?q?=E4=BA=91DNS=E6=94=AF=E6=8C=81=E8=A7=A3=E6=9E=90=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Domain.php | 44 ++++++++++++++++++++ app/lib/dns/aliyun.php | 24 ++++++++++- app/lib/dns/dnspod.php | 26 +++++++++++- app/view/domain/record.html | 82 ++++++++++++++++++++++++++++++++++++- public/.htaccess | 3 +- public/static/js/custom.js | 2 +- route/app.php | 1 + 7 files changed, 176 insertions(+), 6 deletions(-) diff --git a/app/controller/Domain.php b/app/controller/Domain.php index b68bf80..905b711 100644 --- a/app/controller/Domain.php +++ b/app/controller/Domain.php @@ -771,6 +771,18 @@ class Domain extends BaseController } } $msg = '批量修改备注,成功' . $success . '条,失败' . $fail . '条'; + } else if ($action == 'group') { + $dnstype = Db::name('account')->where('id', $drow['aid'])->value('type'); + if (!in_array($dnstype, ['aliyun', 'dnspod'])) { + return json(['code' => -1, 'msg' => '该DNS类型不支持分组']); + } + $groupid = input('post.groupid', '', 'trim'); + $recordIdList = array_column($recordinfo, 'RecordId'); + if ($dns->changeRecordGroup($recordIdList, $groupid)) { + $msg = '成功修改' . count($recordIdList) . '条记录的分组'; + } else { + return json(['code' => -1, 'msg' => '修改分组失败,' . $dns->getError()]); + } } return json(['code' => 0, 'msg' => $msg]); } @@ -1078,6 +1090,38 @@ class Domain extends BaseController } } + public function record_groups() + { + $id = input('param.id/d'); + $drow = Db::name('domain')->where('id', $id)->find(); + if (!$drow) { + return json(['code' => -1, 'msg' => '域名不存在']); + } + if (!checkPermission(0, $drow['name'])) return json(['code' => -1, 'msg' => '无权限']); + + $dnstype = Db::name('account')->where('id', $drow['aid'])->value('type'); + if (!in_array($dnstype, ['aliyun', 'dnspod'])) { + return json(['code' => -1, 'msg' => '该DNS类型不支持分组']); + } + + $dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']); + $groups = $dns->getRecordGroups(); + if ($groups === false) { + return json(['code' => -1, 'msg' => '获取分组列表失败,' . $dns->getError()]); + } + $groupList = []; + if ($dnstype == 'dnspod') { + $groupList[] = ['id' => '', 'name' => '全部记录']; + } + foreach ($groups as $group) { + $groupList[] = [ + 'id' => $group['GroupId'], + 'name' => $group['GroupName'] . (isset($group['RecordCount']) ? '(' . $group['RecordCount'] . ')' : ''), + ]; + } + return json(['code' => 0, 'data' => $groupList]); + } + private function add_log($domain, $action, $data) { if (strlen($data) > 500) $data = substr($data, 0, 500); diff --git a/app/lib/dns/aliyun.php b/app/lib/dns/aliyun.php index 90026ed..ce475e2 100644 --- a/app/lib/dns/aliyun.php +++ b/app/lib/dns/aliyun.php @@ -72,6 +72,10 @@ class aliyun implements DnsInterface $Status = $Status == '1' ? 'Enable' : 'Disable'; $param += ['Status' => $Status]; } + $groupid = request()->post('groupid'); + if (!empty($groupid)) { + $param += ['GroupId' => $groupid]; + } $data = $this->request($param, true); if ($data) { $list = []; @@ -234,7 +238,7 @@ class aliyun implements DnsInterface public function getDomainInfo() { if (!empty($this->domainInfo)) return $this->domainInfo; - $param = ['Action' => 'DescribeDomainInfo', 'DomainName' => $this->domain, 'NeedDetailAttributes' => 'true']; + $param = ['Action' => 'DescribeDomainInfo', 'DomainName' => $this->domain, 'NeedDetailAttributes' => 'true', 'Lang' => 'zh']; $data = $this->request($param, true); if ($data) { $this->domainInfo = $data; @@ -253,6 +257,24 @@ class aliyun implements DnsInterface return false; } + //获取解析记录分组列表 + public function getRecordGroups() + { + $param = ['Action' => 'DescribeRecordGroups', 'DomainName' => $this->domain, 'PageSize' => 100, 'Lang' => 'zh']; + $data = $this->request($param, true); + if ($data) { + return $data['RecordGroups']['RecordGroup']; + } + return false; + } + + //修改解析记录分组 + public function changeRecordGroup($RecordIdList, $GroupId) + { + $param = ['Action' => 'ChangeRecordGroup', 'DomainName' => $this->domain, 'RecordIdList' => json_encode($RecordIdList), 'GroupId' => $GroupId]; + return $this->request($param); + } + //获取权重配置子域名列表 public function getWeightSubDomains($PageNumber = 1, $PageSize = 20, $SubDomain = null) { diff --git a/app/lib/dns/dnspod.php b/app/lib/dns/dnspod.php index 61eee98..bb2363d 100644 --- a/app/lib/dns/dnspod.php +++ b/app/lib/dns/dnspod.php @@ -66,7 +66,8 @@ class dnspod implements DnsInterface public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null) { $offset = ($PageNumber - 1) * $PageSize; - if (!isNullOrEmpty($Status) || !isNullOrEmpty($Value)) { + $groupid = request()->post('groupid'); + if (!isNullOrEmpty($Status) || !isNullOrEmpty($Value) || !empty($groupid)) { $action = 'DescribeRecordFilterList'; $param = ['Domain' => $this->domain, 'Offset' => $offset, 'Limit' => $PageSize, 'RecordValue' => $Value]; if (!isNullOrEmpty($SubDomain)) $param['SubDomain'] = $SubDomain; @@ -78,6 +79,7 @@ class dnspod implements DnsInterface } if (!isNullOrEmpty($Type)) $param['RecordType'] = [$this->convertType($Type)]; if (!isNullOrEmpty($Line)) $param['RecordLine'] = [$Line]; + if (!empty($groupid)) $param['GroupId'] = [intval($groupid)]; } else { $action = 'DescribeRecordList'; $param = ['Domain' => $this->domain, 'Subdomain' => $SubDomain, 'RecordType' => $this->convertType($Type), 'RecordLineId' => $Line, 'Keyword' => $KeyWord, 'Offset' => $offset, 'Limit' => $PageSize]; @@ -365,6 +367,28 @@ class dnspod implements DnsInterface return is_array($data); } + //获取解析记录分组列表 + public function getRecordGroups() + { + $action = 'DescribeRecordGroupList'; + $param = ['Domain' => $this->domain]; + $data = $this->send_request($action, $param); + if ($data) { + return $data['GroupList']; + } + return false; + } + + //将记录移动到分组 + public function changeRecordGroup($RecordIdList, $GroupId) + { + $action = 'ModifyRecordToGroup'; + $RecordIdList = implode('|', $RecordIdList); + $param = ['Domain' => $this->domain, 'GroupId' => intval($GroupId), 'RecordId' => strval($RecordIdList)]; + $data = $this->send_request($action, $param); + return is_array($data); + } + private function convertLineCode($line) { $convert_dict = ['default' => '0', 'unicom' => '10=1', 'telecom' => '10=0', 'mobile' => '10=3', 'edu' => '10=2', 'oversea' => '3=0', 'btvn' => '10=22', 'search' => '80=0', 'internal' => '7=0']; diff --git a/app/view/domain/record.html b/app/view/domain/record.html index 0148fe8..4d72dee 100644 --- a/app/view/domain/record.html +++ b/app/view/domain/record.html @@ -188,7 +188,7 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px; {if $dnsconfig.type=='dnspod'}域名别名{/if}
- +
@@ -223,6 +223,11 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px;
+ {if $dnsconfig.type=='aliyun' || $dnsconfig.type=='dnspod'} +
+ +
+ {/if} 刷新 收起 @@ -241,7 +246,7 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px; - +