支持阿里云解析权重修改

This commit is contained in:
net909 2025-04-05 23:03:20 +08:00
parent 81a85fce45
commit 651132967f
9 changed files with 404 additions and 9 deletions

View File

@ -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']]);
}
}

View File

@ -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()

View File

@ -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;
}

View File

@ -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<NOW()) OR status=3 AND expiretime<:expiretime', ['expiretime' => 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<NOW()) OR status=3 AND isauto=1 AND expiretime<:expiretime', ['expiretime' => date('Y-m-d H:i:s', time() + $days * 86400)])->select();
//print_r($list);exit;
$failcount = 0;
foreach ($list as $row) {

View File

@ -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);
}

View File

@ -103,7 +103,7 @@
{if request()->user['type'] eq 'user'}<li class="{:checkIfActive('index')}">
<a href="/"><i class="fa fa-home fa-fw"></i> <span>后台首页</span></a>
</li>{/if}
<li class="{:checkIfActive('domain,record,record_log,record_batch_add,domain_add')}">
<li class="{:checkIfActive('domain,record,record_log,record_batch_add,domain_add,weight')}">
<a href="/domain"><i class="fa fa-list-ul fa-fw"></i> <span>域名管理</span></a>
</li>
{if request()->user['level'] eq 2}

View File

@ -159,7 +159,7 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px;
</div>
<div class="row">
<div class="col-xs-12 center-block" style="float: none;">
<div class="panel panel-default panel-default">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{if request()->user['type'] eq 'user'}<a href="/domain" class="btn btn-sm btn-default pull-right" style="margin-top:-6px"><i class="fa fa-reply fa-fw"></i> 返回</a>{/if}{$domainName}</h3>
</div>
@ -177,6 +177,7 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px;
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
<a href="javascript:searchClear()" class="btn btn-default" title="刷新解析记录列表"><i class="fa fa-refresh"></i> 刷新</a>
<a href="javascript:addframe()" class="btn btn-success"><i class="fa fa-plus"></i> 添加记录</a>
{if $dnsconfig.type=='aliyun'}<a href="/record/weight/{$domainId}" class="btn btn-default">权重配置</a>{/if}
<div class="btn-group" role="group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">批量操作 <span class="caret"></span></button>
<ul class="dropdown-menu"><li><a href="/record/batchadd/{$domainId}">添加</a></li><li><a href="javascript:operation('open')">启用</a></li><li><a href="javascript:operation('pause')">暂停</a></li><li><a href="javascript:operation('edit')">修改记录</a></li><li><a href="javascript:operation('editline')">修改线路</a></li>{if $dnsconfig.remark == 1}<li><a href="javascript:operation('editremark')">修改备注</a></li>{/if}<li><a href="javascript:operation('delete')">删除</a></li></ul>

250
app/view/domain/weight.html Normal file
View File

@ -0,0 +1,250 @@
{extend name="common/layout" /}
{block name="title"}权重配置 - {$domainName}{/block}
{block name="main"}
<style>
.table-bordered>tbody>tr>td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:200px;vertical-align:middle;}
</style>
<div class="modal" id="modal-store" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content animated flipInX">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span
aria-hidden="true">&times;</span><span
class="sr-only">Close</span></button>
<h4 class="modal-title" id="modal-title">设置权重</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="form-store" onsubmit="return save(this)">
<input type="hidden" name="id"/>
<input type="hidden" name="subdomain"/>
<input type="hidden" name="type"/>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right">选择线路</label>
<div class="col-sm-9">
<select name="line" id="line" class="form-control" onchange="changeLine()"></select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right">线路权重开关</label>
<div class="col-sm-9">
<div class="material-switch" style="padding-top:7px"><input id="weight-switch" name="status" type="checkbox" value="1" checked onchange="changeOpen()"/><label for="weight-switch" class="label-primary"></label></div>
</div>
</div>
<table class="table table-striped table-hover table-bordered">
<thead>
<tr><th>主机记录</th><th>记录类型</th><th>记录值</th><th>权重</th></tr>
</thead>
<tbody id="weight-list">
<tr><td colspan="4" class="text-center">正在加载...</td></tr>
</tbody>
</table>
<span class="text-muted">提示权重范围为数字0-100</span>
<div class="form-group">
<div class="col-sm-12 text-right">
<button type="submit" class="btn btn-primary">保存</button>
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 center-block" style="float: none;">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><a href="/record/{$domainId}" class="btn btn-sm btn-default pull-right" style="margin-top:-6px"><i class="fa fa-reply fa-fw"></i> 返回</a>权重配置 - {$domainName}</h3></div>
<div class="panel-body">
<form onsubmit="return searchSubmit()" method="GET" class="form-inline" id="searchToolbar">
<div class="form-group">
<label>搜索</label>
<input type="text" class="form-control" name="keyword" placeholder="子域名">
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
<a href="javascript:searchClear()" class="btn btn-default" title="刷新权重配置列表"><i class="fa fa-refresh"></i> 刷新</a>
</form>
<table id="listTable">
</table>
</div>
</div>
</div>
</div>
{/block}
{block name="script"}
<script src="{$cdnpublic}layer/3.1.1/layer.js"></script>
<script src="{$cdnpublic}bootstrap-table/1.21.4/bootstrap-table.min.js"></script>
<script src="{$cdnpublic}bootstrap-table/1.21.4/extensions/page-jump-to/bootstrap-table-page-jump-to.min.js"></script>
<script src="/static/js/custom.js"></script>
<script>
var dnsconfig = {$dnsconfig|json_encode|raw};
var recordLine = {$recordLine|json_encode|raw};
var domainId = {$domainId};
var weightList = [];
var lineList = [];
$(document).ready(function(){
updateToolbar();
const defaultPageSize = 15;
const pageNumber = typeof window.$_GET['pageNumber'] != 'undefined' ? parseInt(window.$_GET['pageNumber']) : 1;
const pageSize = typeof window.$_GET['pageSize'] != 'undefined' ? parseInt(window.$_GET['pageSize']) : defaultPageSize;
$("#listTable").bootstrapTable({
url: '/record/weight/data/{$domainId}',
pageNumber: pageNumber,
pageSize: pageSize,
classes: 'table table-striped table-hover table-bordered',
uniqueId: 'id',
columns: [
{
field: 'SubDomain',
title: '子域名'
},
{
field: 'Type',
title: '记录类型'
},
{
field: 'RecordCount',
title: '记录数量'
},
{
field: 'Open',
title: '权重配置状态',
formatter: function(value, row, index) {
if(value == 1){
return '<font color="green"><i class="fa fa-check-circle"></i>已开启</font>';
}else{
return '<font color="#b5bbc8"><i class="fa fa-pause-circle"></i>已关闭</font>';
}
}
},
{
field: '',
title: '操作',
formatter: function(value, row, index) {
var html = '';
if(row.Open == 1){
if(row.Type == 'CNAME'){
html += '<a class="btn btn-warning btn-xs" title="CNAME类型解析默认必须开权重模式每次解析应答只返回一条解析结果记录值" disabled>关闭权重</a>&nbsp;&nbsp;';
}else{
html += '<a href="javascript:setWeightStatus(\''+row.SubDomain+'\', \'0\')" class="btn btn-warning btn-xs">关闭权重</a>&nbsp;&nbsp;';
}
}else{
html += '<a href="javascript:setWeightStatus(\''+row.SubDomain+'\', \'1\')" class="btn btn-success btn-xs">开启权重</a>&nbsp;&nbsp;';
}
html += '<a href="javascript:editframe('+row.id+')" class="btn btn-primary btn-xs">设置权重</a>';
return html;
}
},
],
})
})
function editframe(id){
var row = $("#listTable").bootstrapTable('getRowByUniqueId', id);
var ii = layer.load(2);
$.ajax({
type : 'POST',
url : '/record/list',
data : {id: domainId, rr: row.rr},
dataType : 'json',
success : function(data) {
layer.close(ii);
if(data.code == 0){
$("#modal-store").modal('show');
$("#modal-title").html("设置权重 - "+row.SubDomain);
$("#form-store input[name=id]").val(id);
$("#form-store input[name=subdomain]").val(row.SubDomain);
$("#form-store input[name=type]").val(row.Type);
lineList = [];
$.each(recordLine, function(i, item){
if(data.data.find(x => x.Line == item.id)){
item.open = row.Open;
if(row.LineAlgorithms && row.LineAlgorithms.LineAlgorithm.length > 0){
var tmpLine = row.LineAlgorithms.LineAlgorithm.find(x => x.Line == item.id);
if(tmpLine) item.open = tmpLine.Open;
}
lineList.push(item);
}
});
$("#line").empty();
$.each(lineList, function(i, item){
$("#line").append('<option value="'+item.id+'">'+item.name+'</option>');
});
weightList = data.data;
changeLine();
}else{
layer.alert(data.msg, {icon: 2})
}
}
});
}
function changeLine(){
var line = $("#line").val();
$("#weight-switch").prop("checked", lineList.find(x => x.id == line).open);
$("#weight-list").empty();
$.each(weightList, function(i, item){
if(item.Line == line){
$("#weight-list").append('<tr><td>'+item.Name+'</td><td>'+item.Type+'</td><td>'+item.Value+'</td><td><input type="number" class="form-control" name="weight['+item.RecordId+']" value="'+item.Weight+'" style="width:80px;" min="0" max="100"/></td></tr>');
}
});
changeOpen();
}
function changeOpen(){
if($("#weight-switch").is(':checked')){
$("#weight-list input[name^='weight']").prop("disabled", false);
}else{
$("#weight-list input[name^='weight']").prop("disabled", true);
}
}
function save(){
if($("#form-store input[name=username]").val()==''){
layer.alert('请确保各项不能为空!');return false;
}
var act = $("#form-store input[name=action]").val();
var ii = layer.load(2);
$.ajax({
type : 'POST',
url : '/record/weight/{$domainId}/act/update',
data : $("#form-store").serialize(),
dataType : 'json',
success : function(data) {
layer.close(ii);
if(data.code == 0){
layer.alert(data.msg,{
icon: 1,
closeBtn: false
}, function(){
layer.closeAll();
$("#modal-store").modal('hide');
searchRefresh();
});
}else{
layer.alert(data.msg, {icon: 2})
}
}
});
return false;
}
function setWeightStatus(subdomain, status){
var ii = layer.load(2);
$.ajax({
type : 'POST',
url : '/record/weight/{$domainId}/act/status',
data : {subdomain: subdomain, status: status},
dataType : 'json',
success : function(data) {
layer.close(ii);
if(data.code == 0){
layer.closeAll();
searchRefresh();
}else{
layer.alert(data.msg, {icon: 2});
}
}
});
}
</script>
{/block}

View File

@ -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');