diff --git a/app/common.php b/app/common.php index 7ed61d8..b63c4a0 100644 --- a/app/common.php +++ b/app/common.php @@ -232,7 +232,8 @@ function getMillisecond() } function getDnsType($value){ - if(filter_var($value, FILTER_VALIDATE_IP))return 'A'; + if(filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))return 'A'; + else if(filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))return 'AAAA'; else return 'CNAME'; } diff --git a/app/controller/Domain.php b/app/controller/Domain.php index 01976f5..f21b77a 100644 --- a/app/controller/Domain.php +++ b/app/controller/Domain.php @@ -563,6 +563,121 @@ class Domain extends BaseController return json(['code'=>0, 'msg'=>$msg]); } + public function record_batch_edit(){ + $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 $this->alert('error', '无权限'); + + $action = input('post.action', null, 'trim'); + $recordinfo = input('post.recordinfo', null, 'trim'); + $recordinfo = json_decode($recordinfo, true); + + if($action == 'value'){ + $type = input('post.type', null, 'trim'); + $value = input('post.value', null, 'trim'); + + if(empty($recordinfo) || empty($type) || empty($value)){ + return json(['code'=>-1, 'msg'=>'参数不能为空']); + } + + $dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']); + + $success = 0; $fail = 0; + foreach($recordinfo as $record){ + $recordid = $dns->updateDomainRecord($record['recordid'], $record['name'], $type, $value, $record['line'], $record['ttl'], $record['mx'], $record['remark']); + if($recordid){ + $this->add_log($drow['name'], '修改解析', $type.'记录 '.$record['name'].' '.$value.' (线路:'.$record['line'].' TTL:'.$record['ttl'].')'); + $success++; + }else{ + $fail++; + } + } + return json(['code'=>0, 'msg'=>'批量修改解析记录,成功'.$success.'条,失败'.$fail.'条']); + + }else if($action == 'line'){ + $line = input('post.line', null, 'trim'); + + if(empty($recordinfo) || empty($line)){ + return json(['code'=>-1, 'msg'=>'参数不能为空']); + } + + $dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']); + + $success = 0; $fail = 0; + foreach($recordinfo as $record){ + $recordid = $dns->updateDomainRecord($record['recordid'], $record['name'], $record['type'], $record['value'], $line, $record['ttl'], $record['mx'], $record['remark']); + if($recordid){ + $this->add_log($drow['name'], '修改解析', $record['type'].'记录 '.$record['name'].' '.$record['value'].' (线路:'.$line.' TTL:'.$record['ttl'].')'); + $success++; + }else{ + $fail++; + } + } + return json(['code'=>0, 'msg'=>'批量修改解析线路,成功'.$success.'条,失败'.$fail.'条']); + } + } + + public function record_batch_add(){ + $id = input('param.id/d'); + $drow = Db::name('domain')->where('id', $id)->find(); + if(!$drow){ + return $this->alert('error', '域名不存在'); + } + $dnstype = Db::name('account')->where('id', $drow['aid'])->value('type'); + if(!checkPermission(0, $drow['name'])) return $this->alert('error', '无权限'); + + if(request()->isAjax()){ + $record = input('post.record', null, 'trim'); + $type = input('post.type', null, 'trim'); + $line = input('post.line', null, 'trim'); + $ttl = input('post.ttl/d', 600); + $mx = input('post.mx/d', 1); + $recordlist = explode("\n", $record); + + if(empty($record) || empty($recordlist)){ + return json(['code'=>-1, 'msg'=>'参数不能为空']); + } + + $dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']); + + $success = 0; $fail = 0; + foreach($recordlist as $record){ + $record = trim($record); + $arr = explode(' ', $record); + if(empty($record) || empty($arr[0]) || empty($arr[1])) continue; + $thistype = empty($type) ? getDnsType($arr[1]) : $type; + $recordid = $dns->addDomainRecord($arr[0], $thistype, $arr[1], $line, $ttl, $mx); + if($recordid){ + $this->add_log($drow['name'], '添加解析', $thistype.'记录 '.$arr[0].' '.$arr[1].' (线路:'.$line.' TTL:'.$ttl.')'); + $success++; + }else{ + $fail++; + } + } + return json(['code'=>0, 'msg'=>'批量添加解析,成功'.$success.'条,失败'.$fail.'条']); + } + + 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('minTTL', $minTTL?$minTTL:1); + View::assign('dnsconfig', $dnsconfig); + return view('batchadd'); + } + public function record_log(){ $id = input('param.id/d'); $drow = Db::name('domain')->where('id', $id)->find(); diff --git a/app/view/common/layout.html b/app/view/common/layout.html index f371b62..efeb3bd 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/batchadd.html b/app/view/domain/batchadd.html new file mode 100644 index 0000000..7f5f711 --- /dev/null +++ b/app/view/domain/batchadd.html @@ -0,0 +1,139 @@ +{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/app/view/domain/record.html b/app/view/domain/record.html index bff7fdf..cec440f 100644 --- a/app/view/domain/record.html +++ b/app/view/domain/record.html @@ -78,6 +78,78 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px;
    + +
    @@ -99,7 +171,7 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px; 添加记录
    @@ -229,21 +301,23 @@ $(document).ready(function(){ }); $("#form-store").bootstrapValidator(); + $("#form-store2").bootstrapValidator(); }) -function initLine(option){ +function initLine(option, elem){ option = option || ''; - $("#line_list").empty(); + elem = elem || 'line_list'; + $("#"+elem).empty(); $.each(recordLine, function(index, item){ if(item.parent == null){ option += ''; } }) - $("#line_list").append(''); + $("#"+elem).append(''); } -function changeLine(obj){ +function changeLine(obj, elem){ var line = $(obj).val(); var flag = false; - $("#line_list").children().each(function(index, elem){ + $("#"+elem).children().each(function(index, elem){ if(flag) $(elem).remove() if(obj == elem){ flag = true; @@ -256,7 +330,7 @@ function changeLine(obj){ $.each(tempLine, function(index, item){ option += ''; }) - $("#line_list").append(''); + $("#"+elem).append(''); } } function addframe(){ @@ -409,6 +483,22 @@ function operation(action){ layer.msg('请选择要操作的记录'); return; } + if(action == 'edit'){ + var records = []; + $.each(rows, function(index, item){ + records.push({recordid:item.RecordId, name:item.Name, line:item.Line, mx:item.MX, ttl:item.TTL, remark:item.Remark}); + }) + batch_edit(records) + return; + }else if(action == 'editline'){ + var records = []; + $.each(rows, function(index, item){ + records.push({recordid:item.RecordId, name:item.Name, type:item.Type, value:item.Value, mx:item.MX, ttl:item.TTL, remark:item.Remark}); + }) + batch_edit_line(records) + return; + } + var ids = []; $.each(rows, function(index, item){ ids.push(item.RecordId); @@ -437,5 +527,75 @@ function operation(action){ layer.close(confirmobj); }); } +function batch_edit(records){ + var row = $("#listTable").bootstrapTable('getSelections')[0]; + $("#batch_num").text(records.length); + $("#modal-store2").modal('show'); + $("#form-store2 input[name=recordinfo]").val(JSON.stringify(records)); + $("#form-store2 input[name=recordid]").val(row.RecordId); + $("#form-store2 input[name=name]").val(row.Name); + $("#form-store2 select[name=type]").val(row.Type); + $("select[name=type]").change(); + $("#form-store2 input[name=value]").val(row.Value); + $("#form-store2").data("bootstrapValidator").resetForm(); +} +function batch_save(){ + $("#form-store2").data("bootstrapValidator").validate(); + if(!$("#form-store2").data("bootstrapValidator").isValid()){ + return; + } + var ii = layer.load(2); + $.ajax({ + type : 'POST', + url : '/record/batchedit/{$domainId}', + data : $("#form-store2").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-store2").modal('hide'); + searchSubmit(); + }); + }else{ + layer.alert(data.msg, {icon: 2}) + } + } + }); +} +function batch_edit_line(records){ + $("#batch_num").text(records.length); + $("#modal-store3").modal('show'); + $("#form-store3 input[name=recordinfo]").val(JSON.stringify(records)); + initLine('', 'line_list3'); +} +function batch_save_line(){ + var ii = layer.load(2); + $.ajax({ + type : 'POST', + url : '/record/batchedit/{$domainId}', + data : $("#form-store3").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-store3").modal('hide'); + searchSubmit(); + }); + }else{ + layer.alert(data.msg, {icon: 2}) + } + } + }); +} {/block} \ No newline at end of file diff --git a/route/app.php b/route/app.php index 47b94ce..6a4ea27 100644 --- a/route/app.php +++ b/route/app.php @@ -56,6 +56,8 @@ Route::group(function () { Route::post('/record/status/:id', 'domain/record_status'); Route::post('/record/remark/:id', 'domain/record_remark'); Route::post('/record/batch/:id', 'domain/record_batch'); + Route::post('/record/batchedit/:id', 'domain/record_batch_edit'); + 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::get('/record/:id', 'domain/record');