Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions app/controller/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ public function record_add()
return json(['code' => -1, 'msg' => '参数不能为空']);
}

$reservedCheck = $this->checkReservedRecord($name);
if ($reservedCheck['is_reserved']) {
return json(['code' => -1, 'msg' => $reservedCheck['msg']]);
}

$dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']);
$recordid = $dns->addDomainRecord($name, $type, $value, $line, $ttl, $mx, $weight, $remark);
if ($recordid) {
Expand Down Expand Up @@ -604,6 +609,11 @@ public function record_update()
return json(['code' => -1, 'msg' => '参数不能为空']);
}

$reservedCheck = $this->checkReservedRecord($name);
if ($reservedCheck['is_reserved']) {
return json(['code' => -1, 'msg' => $reservedCheck['msg']]);
}

$dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']);
$recordid = $dns->updateDomainRecord($recordid, $name, $type, $value, $line, $ttl, $mx, $weight, $remark);
if ($recordid) {
Expand Down Expand Up @@ -881,10 +891,17 @@ public function record_batch_add()

$success = 0;
$fail = 0;
$reservedList = [];
foreach ($recordlist as $record) {
$record = trim($record);
$arr = explode(' ', $record);
if (empty($record) || empty($arr[0]) || empty($arr[1])) continue;
$reservedCheck = $this->checkReservedRecord($arr[0]);
if ($reservedCheck['is_reserved']) {
$reservedList[] = $arr[0];
$fail++;
continue;
}
$thistype = empty($type) ? getDnsType($arr[1]) : $type;
$recordid = $dns->addDomainRecord($arr[0], $thistype, $arr[1], $line, $ttl, $mx, null, $remark);
if ($recordid) {
Expand Down Expand Up @@ -1469,4 +1486,141 @@ public function domain_set_category()
$count = Db::name('domain')->where('id', 'in', $ids)->update(['cid' => $cid]);
return json(['code' => 0, 'msg' => '成功设置' . $count . '个域名的分类!']);
}

public function record_export()
{
$id = input('param.id/d');
$format = input('get.format', 'json', 'trim');
$page = input('get.page/d', 0);
$pagesize = input('get.pagesize/d', 100);

$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' => '无权限']);

$dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']);

if ($page === 0) {
$recordLine = cache('record_line_' . $id);
$dnstype = Db::name('account')->where('id', $drow['aid'])->value('type');
return json([
'code' => 0,
'data' => [
'domain' => $drow['name'],
'dnstype' => $dnstype,
'recordLine' => $recordLine,
'pagesize' => min($pagesize, 100)
]
]);
}

$domainRecords = $dns->getDomainRecords($page, $pagesize);
if (!$domainRecords) return json(['code' => -1, 'msg' => '获取解析记录失败,' . $dns->getError()]);

$recordLine = cache('record_line_' . $id);
$records = [];
foreach ($domainRecords['list'] as $row) {
$lineName = isset($recordLine[$row['Line']]) ? $recordLine[$row['Line']]['name'] : $row['Line'];
$records[] = [
'Name' => $row['Name'],
'Type' => $row['Type'],
'Value' => is_array($row['Value']) ? implode(',', $row['Value']) : $row['Value'],
'Line' => $row['Line'],
'LineName' => $lineName,
'TTL' => $row['TTL'],
'MX' => $row['MX'] ?? '',
'Weight' => $row['Weight'] ?? '',
'Remark' => $row['Remark'] ?? '',
'Status' => $row['Status'],
];
}

return json([
'code' => 0,
'data' => [
'records' => $records,
'total' => $domainRecords['total'],
'page' => $page,
'hasMore' => count($records) == $pagesize
]
]);
}

public function record_import()
{
$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()) {
$name = input('post.name', null, 'trim');
$type = input('post.type', null, 'trim');
$value = input('post.value', null, 'trim');
$line = input('post.line', null, 'trim');
$ttl = input('post.ttl/d', 600);
$mx = input('post.mx/d', 1);
$weight = input('post.weight/d', 0);
$remark = input('post.remark', null, 'trim');

if (empty($name) || empty($type) || empty($value)) {
return json(['code' => -1, 'msg' => '参数不能为空']);
}

$dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']);
$recordid = $dns->addDomainRecord($name, $type, $value, $line, $ttl, $mx, $weight, $remark);
if ($recordid) {
$this->add_log($drow['name'], '导入解析', $name.' ['.$type.'] '.$value.' (线路:'.$line.' TTL:'.$ttl.')');
return json(['code' => 0, 'msg' => '添加解析记录成功!']);
} else {
return json(['code' => -1, 'msg' => '添加解析记录失败,' . $dns->getError()]);
}
}

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('import');
}

private function checkReservedRecord($recordName)
{
if (isset(request()->user['level']) && request()->user['level'] == 2) {
return ['is_reserved' => false];
}

$reservedConfig = config_get('reserved_records', '');
if (empty($reservedConfig)) {
return ['is_reserved' => false];
}

$reservedList = array_map('trim', explode(',', $reservedConfig));
$reservedList = array_filter($reservedList);

if (in_array($recordName, $reservedList)) {
return [
'is_reserved' => true,
'msg' => '主机记录 "' . $recordName . '" 已被系统预留,无法使用'
];
}

return ['is_reserved' => false];
}
}
27 changes: 27 additions & 0 deletions app/controller/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,31 @@ public function log_data()

return json(['total' => $total, 'rows' => $rows]);
}

public function api_manage()
{
if (!checkPermission(1)) return json(['code' => -1, 'msg' => '无权限']);

$act = input('param.act');
$userId = $this->request->user['id'];

if ($act == 'enable_api') {
$apikey = random(16);
Db::name('user')->where('id', $userId)->update([
'is_api' => 1,
'apikey' => $apikey
]);
return json(['code' => 0, 'msg' => 'API接口已开启', 'apikey' => $apikey]);
} elseif ($act == 'regenerate_apikey') {
$user = Db::name('user')->where('id', $userId)->find();
if ($user['is_api'] != 1) {
return json(['code' => -1, 'msg' => 'API接口未开启']);
}
$apikey = random(16);
Db::name('user')->where('id', $userId)->update(['apikey' => $apikey]);
return json(['code' => 0, 'msg' => 'API密钥已重新生成', 'apikey' => $apikey]);
}

return json(['code' => -3, 'msg' => '未知操作']);
}
}
4 changes: 4 additions & 0 deletions app/view/common/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
{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('setapi')}">
<a href="/setapi"><i class="fa fa-key fa-fw"></i> <span>API对接</span></a>
</li>
<li class="{:checkIfActive('domain,record,record_log,record_batch_add,domain_add,weight,record_batch_add2,record_batch_edit2,expire_notice,smartparse')}">
<a href="/domain"><i class="fa fa-list-ul fa-fw"></i> <span>域名管理</span></a>
</li>
Expand Down Expand Up @@ -175,6 +178,7 @@
<li class="{:checkIfActive('loginset')}"><a href="/system/loginset"><i class="fa fa-circle-o"></i> 登录设置</a></li>
<li class="{:checkIfActive('noticeset')}"><a href="/system/noticeset"><i class="fa fa-circle-o"></i> 通知设置</a></li>
<li class="{:checkIfActive('proxyset')}"><a href="/system/proxyset"><i class="fa fa-circle-o"></i> 代理设置</a></li>
<li class="{:checkIfActive('reservedset')}"><a href="/system/reservedset"><i class="fa fa-circle-o"></i> 保留设置</a></li>
<li><a href="https://www.showdoc.com.cn/dnsmgr/11058996709621562" target="_blank" rel="noreferrer"><i class="fa fa-circle-o"></i> <span>接口文档</span></a></li>
</ul>
</li>
Expand Down
Loading