From 651132967fc194abbd1f70cb33eaad90a7e02cd5 Mon Sep 17 00:00:00 2001 From: net909 Date: Sat, 5 Apr 2025 23:03:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=98=BF=E9=87=8C=E4=BA=91?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=9D=83=E9=87=8D=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Domain.php | 99 +++++++++++++ app/lib/DnsHelper.php | 4 +- app/lib/dns/aliyun.php | 48 +++++- app/service/CertTaskService.php | 2 +- app/service/OptimizeService.php | 3 + app/view/common/layout.html | 2 +- app/view/domain/record.html | 3 +- app/view/domain/weight.html | 250 ++++++++++++++++++++++++++++++++ route/app.php | 2 + 9 files changed, 404 insertions(+), 9 deletions(-) create mode 100644 app/view/domain/weight.html diff --git a/app/controller/Domain.php b/app/controller/Domain.php index 11eaecd..0bfd519 100644 --- a/app/controller/Domain.php +++ b/app/controller/Domain.php @@ -836,4 +836,103 @@ class Domain extends BaseController if (strlen($data) > 500) $data = substr($data, 0, 500); Db::name('log')->insert(['uid' => request()->user['id'], 'domain' => $domain, 'action' => $action, 'data' => $data, 'addtime' => date("Y-m-d H:i:s")]); } + + + public function weight() + { + $id = input('param.id/d'); + $drow = Db::name('domain')->where('id', $id)->find(); + if (!$drow) { + return $this->alert('error', '域名不存在'); + } + if (!checkPermission(0, $drow['name'])) return $this->alert('error', '无权限'); + if (request()->isAjax()) { + $act = input('param.act'); + if ($act == 'status') { + $subdomain = input('post.subdomain', null, 'trim'); + $status = input('post.status', null, 'trim'); + $type = input('post.type', null, 'trim'); + $line = input('post.line', null, 'trim'); + $dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']); + if ($dns->setWeightStatus($subdomain, $status, $type, $line)) { + return json(['code' => 0, 'msg' => '操作成功']); + } else { + return json(['code' => -1, 'msg' => '操作失败,' . $dns->getError()]); + } + } elseif ($act == 'update') { + $subdomain = input('post.subdomain', null, 'trim'); + $status = input('post.status', '0', 'trim'); + $type = input('post.type', null, 'trim'); + $line = input('post.line', null, 'trim'); + $weight = input('post.weight'); + if (empty($subdomain) || empty($type) || empty($line) || $status == '1' && empty($weight)) { + return json(['code' => -1, 'msg' => '参数不能为空']); + } + $dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']); + if ($dns->setWeightStatus($subdomain, $status, $type, $line)) { + if ($status == '1') { + $success = 0; + foreach($weight as $recordid => $weight) { + if ($dns->updateRecordWeight($recordid, $weight)) { + $success++; + } + } + if ($success > 0) { + return json(['code' => 0, 'msg' => '成功修改' . $success . '条解析记录权重']); + } else { + return json(['code' => -1, 'msg' => '修改权重失败,' . $dns->getError()]); + } + } + return json(['code' => 0, 'msg' => '修改成功']); + } else { + return json(['code' => -1, 'msg' => '修改失败,' . $dns->getError()]); + } + } else { + return json(['code' => -1, 'msg' => '参数错误']); + } + } + + $dnstype = Db::name('account')->where('id', $drow['aid'])->value('type'); + if ($dnstype != 'aliyun') { + return $this->alert('error', '仅支持阿里云解析的域名'); + } + list($recordLine, $minTTL) = $this->get_line_and_ttl($drow); + + $recordLineArr = []; + foreach ($recordLine as $key => $item) { + $recordLineArr[] = ['id' => strval($key), 'name' => $item['name'], 'parent' => $item['parent']]; + } + + $dnsconfig = DnsHelper::$dns_config[$dnstype]; + $dnsconfig['type'] = $dnstype; + + View::assign('domainId', $id); + View::assign('domainName', $drow['name']); + View::assign('recordLine', $recordLineArr); + View::assign('dnsconfig', $dnsconfig); + return view(); + } + + public function weight_data() + { + $id = input('param.id/d'); + $keyword = input('post.keyword', null, 'trim'); + $offset = input('post.offset/d'); + $limit = input('post.limit/d'); + if ($limit == 0) { + $page = 1; + } else { + $page = $offset / $limit + 1; + } + + $drow = Db::name('domain')->where('id', $id)->find(); + if (!$drow) { + return json(['total' => 0, 'rows' => []]); + } + if (!checkPermission(0, $drow['name'])) return json(['total' => 0, 'rows' => []]); + + $dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']); + $domainRecords = $dns->getWeightSubDomains($page, $limit, $keyword); + return json(['total' => $domainRecords['total'], 'rows' => $domainRecords['list']]); + } } diff --git a/app/lib/DnsHelper.php b/app/lib/DnsHelper.php index f9a2db4..5b6ca18 100644 --- a/app/lib/DnsHelper.php +++ b/app/lib/DnsHelper.php @@ -163,8 +163,8 @@ class DnsHelper 'baidu' => ['DEF' => 'default', 'CT' => 'ct', 'CU' => 'cnc', 'CM' => 'cmnet', 'AB' => ''], 'jdcloud' => ['DEF' => '-1', 'CT' => '1', 'CU' => '2', 'CM' => '3', 'AB' => '4'], 'cloudflare' => ['DEF' => '0'], - 'namesilo' => ['DEF' => '0'], - 'powerdns' => ['DEF' => '0'], + 'namesilo' => ['DEF' => 'default'], + 'powerdns' => ['DEF' => 'default'], ]; public static function getList() diff --git a/app/lib/dns/aliyun.php b/app/lib/dns/aliyun.php index d22ae6c..df1c829 100644 --- a/app/lib/dns/aliyun.php +++ b/app/lib/dns/aliyun.php @@ -253,6 +253,46 @@ class aliyun implements DnsInterface return false; } + //获取权重配置子域名列表 + public function getWeightSubDomains($PageNumber = 1, $PageSize = 20, $SubDomain = null) + { + $param = ['Action' => 'DescribeDNSSLBSubDomains', 'DomainName' => $this->domain, 'PageNumber' => $PageNumber, 'PageSize' => $PageSize]; + if (!empty($SubDomain)) { + $param += ['Rr' => $SubDomain]; + } + $data = $this->request($param, true); + if ($data) { + $list = $data['SlbSubDomains']['SlbSubDomain']; + $i = 1; + foreach ($list as &$v) { + $v['id'] = $i++; + $v['rr'] = substr($v['SubDomain'], 0, -strlen($this->domain) - 1); + } + return ['total' => $data['TotalCount'], 'list' => $list]; + } + return false; + } + + //开启关闭权重配置 + public function setWeightStatus($SubDomain, $Open, $Type = null, $Line = null) + { + $param = ['Action' => 'SetDNSSLBStatus', 'DomainName' => $this->domain, 'SubDomain' => $SubDomain, 'Open' => $Open == '1' ? 'true' : 'false']; + if (!empty($Type)) { + $param += ['Type' => $Type]; + } + if (!empty($Line)) { + $param += ['Line' => $Line]; + } + return $this->request($param); + } + + //修改权重 + public function updateRecordWeight($RecordId, $Weight) + { + $param = ['Action' => 'UpdateDNSSLBWeight', 'RecordId' => $RecordId, 'Weight' => $Weight]; + return $this->request($param); + } + private function convertLineCode($line) { $convert_dict = ['0' => 'default', '10=1' => 'unicom', '10=0' => 'telecom', '10=3' => 'mobile', '10=2' => 'edu', '3=0' => 'oversea', '10=22' => 'btvn', '80=0' => 'search', '7=0' => 'internal']; @@ -265,13 +305,13 @@ class aliyun implements DnsInterface private function request($param, $returnData = false) { if (empty($this->AccessKeyId) || empty($this->AccessKeySecret)) return false; - try{ + try { $result = $this->client->request($param); - }catch(Exception $e){ - try{ + } catch (Exception $e) { + try { usleep(50000); $result = $this->client->request($param); - }catch(Exception $e){ + } catch (Exception $e) { $this->setError($e->getMessage()); return false; } diff --git a/app/service/CertTaskService.php b/app/service/CertTaskService.php index b360b3e..af942db 100644 --- a/app/service/CertTaskService.php +++ b/app/service/CertTaskService.php @@ -20,7 +20,7 @@ class CertTaskService private function execute_order() { $days = config_get('cert_renewdays', 7); - $list = Db::name('cert_order')->field('id,status,issend')->whereRaw('isauto=1 AND status NOT IN (3,4) AND (retrytime IS NULL OR retrytime date('Y-m-d H:i:s', time() + $days * 86400)])->select(); + $list = Db::name('cert_order')->field('id,status,issend')->whereRaw('status NOT IN (3,4) AND (retrytime IS NULL OR retrytime date('Y-m-d H:i:s', time() + $days * 86400)])->select(); //print_r($list);exit; $failcount = 0; foreach ($list as $row) { diff --git a/app/service/OptimizeService.php b/app/service/OptimizeService.php index 2e51510..1e73777 100644 --- a/app/service/OptimizeService.php +++ b/app/service/OptimizeService.php @@ -157,6 +157,9 @@ class OptimizeService if ($row['type'] == 1 && $line == 'CT') { $line = 'DEF'; } + if (!isset(DnsHelper::$line_name[$drow['type']][$line])) { + continue; + } $line_name = DnsHelper::$line_name[$drow['type']][$line]; $this->process_dns_line($dns, $row, $domainRecords['list'], $record_num, $get_ips, $line_name, $ip_type); } diff --git a/app/view/common/layout.html b/app/view/common/layout.html index 8ddae69..3373d5d 100644 --- a/app/view/common/layout.html +++ b/app/view/common/layout.html @@ -103,7 +103,7 @@ {if request()->user['type'] eq 'user'}
  • 后台首页
  • {/if} -
  • +
  • 域名管理
  • {if request()->user['level'] eq 2} diff --git a/app/view/domain/record.html b/app/view/domain/record.html index ba93c0f..6b478fa 100644 --- a/app/view/domain/record.html +++ b/app/view/domain/record.html @@ -159,7 +159,7 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px;
    -
    +

    {if request()->user['type'] eq 'user'} 返回{/if}{$domainName}

    @@ -177,6 +177,7 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px; 刷新 添加记录 + {if $dnsconfig.type=='aliyun'}权重配置{/if}
    diff --git a/app/view/domain/weight.html b/app/view/domain/weight.html new file mode 100644 index 0000000..538f13f --- /dev/null +++ b/app/view/domain/weight.html @@ -0,0 +1,250 @@ +{extend name="common/layout" /} +{block name="title"}权重配置 - {$domainName}{/block} +{block name="main"} + + +
    +
    +
    +

    返回权重配置 - {$domainName}

    +
    + +
    +
    + + +
    + + 刷新 +
    + + +
    +
    +
    +
    +
    +{/block} +{block name="script"} + + + + + +{/block} \ No newline at end of file diff --git a/route/app.php b/route/app.php index e9f8321..6d10203 100644 --- a/route/app.php +++ b/route/app.php @@ -66,6 +66,8 @@ Route::group(function () { Route::any('/record/batchadd/:id', 'domain/record_batch_add'); Route::any('/record/log/:id', 'domain/record_log'); Route::post('/record/list', 'domain/record_list'); + Route::post('/record/weight/data/:id', 'domain/weight_data'); + Route::any('/record/weight/:id', 'domain/weight'); Route::get('/record/:id', 'domain/record'); Route::get('/dmonitor/overview', 'dmonitor/overview');