From 6694631a9aca29e01b0b90b017a5fe2a22a1f68f Mon Sep 17 00:00:00 2001 From: net909 Date: Sat, 17 Jan 2026 22:40:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=9F=E5=90=8D=E8=B4=A6=E6=88=B7=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=94=AF=E6=8C=81=E9=98=BF=E9=87=8C=E4=BA=91ESA?= =?UTF-8?q?=E3=80=81=E8=85=BE=E8=AE=AF=E4=BA=91EO=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E8=B4=A6=E6=88=B7=E6=96=B0=E5=A2=9E/?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 7 + app/controller/Domain.php | 78 +++--- app/controller/Index.php | 20 ++ app/lib/DnsHelper.php | 448 ++++++++++++++++++++++++++++--- app/lib/dns/aliyun.php | 4 +- app/lib/dns/aliyunesa.php | 284 ++++++++++++++++++++ app/lib/dns/baidu.php | 4 +- app/lib/dns/bt.php | 6 +- app/lib/dns/cloudflare.php | 4 +- app/lib/dns/dnsla.php | 4 +- app/lib/dns/dnspod.php | 4 +- app/lib/dns/huawei.php | 14 +- app/lib/dns/huoshan.php | 4 +- app/lib/dns/jdcloud.php | 4 +- app/lib/dns/namesilo.php | 2 +- app/lib/dns/powerdns.php | 4 +- app/lib/dns/spaceship.php | 16 +- app/lib/dns/tencenteo.php | 254 ++++++++++++++++++ app/lib/dns/west.php | 4 +- app/service/OptimizeService.php | 2 +- app/service/ScheduleService.php | 2 +- app/service/TaskRunner.php | 2 +- app/sql/install.sql | 8 +- app/sql/update.sql | 6 +- app/view/cert/certorder.html | 2 +- app/view/common/layout.html | 2 +- app/view/domain/account.html | 155 +---------- app/view/domain/account_add.html | 221 +++++++++++++++ app/view/domain/batchadd2.html | 2 +- app/view/domain/domain.html | 4 +- config/app.php | 4 +- public/static/images/aliyun.ico | Bin 4286 -> 0 bytes public/static/images/bt.ico | Bin 4286 -> 0 bytes public/static/images/litessl.ico | Bin 0 -> 4286 bytes route/app.php | 3 +- 35 files changed, 1312 insertions(+), 266 deletions(-) create mode 100644 app/lib/dns/aliyunesa.php create mode 100644 app/lib/dns/tencenteo.php create mode 100644 app/view/domain/account_add.html delete mode 100644 public/static/images/aliyun.ico delete mode 100644 public/static/images/bt.ico create mode 100644 public/static/images/litessl.ico diff --git a/app/common.php b/app/common.php index 861afb1..9828954 100644 --- a/app/common.php +++ b/app/common.php @@ -605,3 +605,10 @@ function getDomainDate($domain) throw new Exception('查询域名whois失败: ' . $e->getMessage()); } } + +function checkTableExists($table) +{ + $prefix = env('database.prefix', 'dnsmgr_'); + $res = Db::query("SHOW TABLES LIKE '" . $prefix . $table . "'"); + return !empty($res); +} \ No newline at end of file diff --git a/app/controller/Domain.php b/app/controller/Domain.php index dc5081c..89b1faf 100644 --- a/app/controller/Domain.php +++ b/app/controller/Domain.php @@ -16,7 +16,6 @@ class Domain extends BaseController public function account() { if (!checkPermission(2)) return $this->alert('error', '无权限'); - View::assign('dnsconfig', DnsHelper::$dns_config); return view(); } @@ -29,7 +28,7 @@ class Domain extends BaseController $select = Db::name('account'); if (!empty($kw)) { - $select->whereLike('ak|remark', '%' . $kw . '%'); + $select->whereLike('name|remark', '%' . $kw . '%'); } $total = $select->count(); $rows = $select->order('id', 'desc')->limit($offset, $limit)->select(); @@ -37,39 +36,49 @@ class Domain extends BaseController $list = []; foreach ($rows as $row) { $row['typename'] = DnsHelper::$dns_config[$row['type']]['name']; + $row['icon'] = DnsHelper::$dns_config[$row['type']]['icon']; $list[] = $row; } return json(['total' => $total, 'rows' => $list]); } + public function account_add() + { + if (!checkPermission(2)) return json(['total' => 0, 'rows' => []]); + $action = input('param.action'); + + $account = null; + if ($action == 'edit') { + $id = input('get.id/d'); + $account = Db::name('account')->where('id', $id)->find(); + if (empty($account)) return $this->alert('error', '域名账户不存在'); + } + + View::assign('info', $account); + View::assign('typeList', DnsHelper::getList()); + View::assign('action', $action); + return View::fetch(); + } + public function account_op() { if (!checkPermission(2)) return $this->alert('error', '无权限'); - $act = input('param.act'); - if ($act == 'get') { - $id = input('post.id/d'); - $row = Db::name('account')->where('id', $id)->find(); - if (!$row) return json(['code' => -1, 'msg' => '域名账户不存在']); - return json(['code' => 0, 'data' => $row]); - } elseif ($act == 'add') { + $action = input('param.action'); + if ($action == 'add') { $type = input('post.type'); - $ak = input('post.ak', null, 'trim'); - $sk = input('post.sk', null, 'trim'); - $ext = input('post.ext', null, 'trim'); + $name = input('post.name', null, 'trim'); + $config = input('post.config', null, 'trim'); $remark = input('post.remark', null, 'trim'); - $proxy = input('post.proxy/d', 0); - if (empty($ak) || empty($sk)) return json(['code' => -1, 'msg' => 'AccessKey和SecretKey不能为空']); - if (Db::name('account')->where('type', $type)->where('ak', $ak)->find()) { + if (empty($name) || empty($config)) return json(['code' => -1, 'msg' => '必填参数不能为空']); + if (Db::name('account')->where('type', $type)->where('name', $name)->find()) { return json(['code' => -1, 'msg' => '域名账户已存在']); } Db::startTrans(); $id = Db::name('account')->insertGetId([ 'type' => $type, - 'ak' => $ak, - 'sk' => $sk, - 'ext' => $ext, - 'proxy' => $proxy, + 'name' => $name, + 'config' => $config, 'remark' => $remark, 'addtime' => date('Y-m-d H:i:s'), ]); @@ -86,27 +95,24 @@ class Domain extends BaseController Db::rollback(); return json(['code' => -1, 'msg' => 'DNS模块(' . $type . ')不存在']); } - } elseif ($act == 'edit') { + } elseif ($action == 'edit') { $id = input('post.id/d'); $row = Db::name('account')->where('id', $id)->find(); if (!$row) return json(['code' => -1, 'msg' => '域名账户不存在']); $type = input('post.type'); - $ak = input('post.ak', null, 'trim'); - $sk = input('post.sk', null, 'trim'); - $ext = input('post.ext', null, 'trim'); + $name = input('post.name', null, 'trim'); + $config = input('post.config', null, 'trim'); $remark = input('post.remark', null, 'trim'); - $proxy = input('post.proxy/d', 0); - if (empty($ak) || empty($sk)) return json(['code' => -1, 'msg' => 'AccessKey和SecretKey不能为空']); - if (Db::name('account')->where('type', $type)->where('ak', $ak)->where('id', '<>', $id)->find()) { + if (empty($name) || empty($config)) return json(['code' => -1, 'msg' => '必填参数不能为空']); + if (Db::name('account')->where('type', $type)->where('name', $name)->where('id', '<>', $id)->find()) { return json(['code' => -1, 'msg' => '域名账户已存在']); } Db::startTrans(); Db::name('account')->where('id', $id)->update([ 'type' => $type, - 'ak' => $ak, - 'sk' => $sk, - 'ext' => $ext, - 'proxy' => $proxy, + 'name' => $name, + 'config' => $config, + 'remark' => $remark, 'remark' => $remark, ]); $dns = DnsHelper::getModel($id); @@ -122,7 +128,7 @@ class Domain extends BaseController Db::rollback(); return json(['code' => -1, 'msg' => 'DNS模块(' . $type . ')不存在']); } - } elseif ($act == 'del') { + } elseif ($action == 'del') { $id = input('post.id/d'); $dcount = DB::name('domain')->where('aid', $id)->count(); if ($dcount > 0) return json(['code' => -1, 'msg' => '该域名账户下存在域名,无法删除']); @@ -185,11 +191,18 @@ class Domain extends BaseController $order = input('post.order', null, 'trim'); $offset = input('post.offset/d', 0); $limit = input('post.limit/d', 10); + $id = input('post.id'); + $aid = input('post.aid', null, 'trim'); $select = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id'); - if (!empty($kw)) { + if (!empty($id)) { + $select->where('A.id', $id); + } elseif (!empty($kw)) { $select->whereLike('name|A.remark', '%' . $kw . '%'); } + if (!empty($aid)) { + $select->where('A.aid', $aid); + } if (!empty($type)) { $select->whereLike('B.type', $type); } @@ -225,6 +238,7 @@ class Domain extends BaseController $list = []; foreach ($rows as $row) { $row['typename'] = DnsHelper::$dns_config[$row['type']]['name']; + $row['icon'] = DnsHelper::$dns_config[$row['type']]['icon']; $list[] = $row; } diff --git a/app/controller/Index.php b/app/controller/Index.php index e98b4ef..4dfdeb4 100644 --- a/app/controller/Index.php +++ b/app/controller/Index.php @@ -87,6 +87,26 @@ class Index extends BaseController } catch (Exception $e) { } } + if(Db::name('account')->count() > 0 && Db::name('account')->whereNotNull('config')->count() == 0) { + Cache::clear(); + $accounts = Db::name('account')->select(); + foreach ($accounts as $account) { + if (!empty($account['config']) || !isset(\app\lib\DnsHelper::$dns_config[$account['type']])) continue; + $config = []; + $account_fields = ['name', 'sk', 'ext']; + $i = 0; + foreach(\app\lib\DnsHelper::$dns_config[$account['type']]['config'] as $field => $item) { + if ($field == 'proxy') { + $config[$field] = $account['proxy']; + break; + } + if ($i >= 3) break; + $account_field = $account_fields[$i++]; + $config[$field] = isset($account[$account_field]) ? $account[$account_field] : ''; + } + Db::name('account')->where('id', $account['id'])->update(['config' => json_encode($config)]); + } + } } public function changeskin() diff --git a/app/lib/DnsHelper.php b/app/lib/DnsHelper.php index e9edf69..5402d5e 100644 --- a/app/lib/DnsHelper.php +++ b/app/lib/DnsHelper.php @@ -9,9 +9,30 @@ class DnsHelper public static $dns_config = [ 'aliyun' => [ 'name' => '阿里云', + 'icon' => 'aliyun.png', + 'note' => '', 'config' => [ - 'ak' => 'AccessKeyId', - 'sk' => 'AccessKeySecret', + 'AccessKeyId' => [ + 'name' => 'AccessKeyId', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'AccessKeySecret' => [ + 'name' => 'AccessKeySecret', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 1, //是否支持备注,1单独设置备注,2和记录一起设置 'status' => true, //是否支持启用暂停 @@ -23,9 +44,30 @@ class DnsHelper ], 'dnspod' => [ 'name' => '腾讯云', + 'icon' => 'dnspod.ico', + 'note' => '', 'config' => [ - 'ak' => 'SecretId', - 'sk' => 'SecretKey', + 'SecretId' => [ + 'name' => 'SecretId', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'SecretKey' => [ + 'name' => 'SecretKey', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 1, 'status' => true, @@ -37,9 +79,30 @@ class DnsHelper ], 'huawei' => [ 'name' => '华为云', + 'icon' => 'huawei.ico', + 'note' => '', 'config' => [ - 'ak' => 'AccessKeyId', - 'sk' => 'SecretAccessKey', + 'AccessKeyId' => [ + 'name' => 'AccessKeyId', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'SecretAccessKey' => [ + 'name' => 'SecretAccessKey', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 2, 'status' => true, @@ -51,9 +114,30 @@ class DnsHelper ], 'baidu' => [ 'name' => '百度云', + 'icon' => 'baidu.ico', + 'note' => '', 'config' => [ - 'ak' => 'AccessKey', - 'sk' => 'SecretKey', + 'AccessKeyId' => [ + 'name' => 'AccessKeyId', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'SecretAccessKey' => [ + 'name' => 'SecretAccessKey', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 2, 'status' => false, @@ -65,9 +149,30 @@ class DnsHelper ], 'west' => [ 'name' => '西部数码', + 'icon' => 'west.ico', + 'note' => '', 'config' => [ - 'ak' => '用户名', - 'sk' => 'API密码', + 'username' => [ + 'name' => '用户名', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'api_password' => [ + 'name' => 'API密码', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 0, 'status' => true, @@ -79,9 +184,30 @@ class DnsHelper ], 'huoshan' => [ 'name' => '火山引擎', + 'icon' => 'huoshan.ico', + 'note' => '', 'config' => [ - 'ak' => 'AccessKeyId', - 'sk' => 'SecretAccessKey', + 'AccessKeyId' => [ + 'name' => 'AccessKeyId', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'SecretAccessKey' => [ + 'name' => 'SecretAccessKey', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 2, 'status' => true, @@ -93,9 +219,30 @@ class DnsHelper ], 'jdcloud' => [ 'name' => '京东云', + 'icon' => 'jdcloud.ico', + 'note' => '', 'config' => [ - 'ak' => 'AccessKeyId', - 'sk' => 'AccessKeySecret', + 'AccessKeyId' => [ + 'name' => 'AccessKeyId', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'AccessKeySecret' => [ + 'name' => 'AccessKeySecret', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 0, 'status' => true, @@ -107,9 +254,30 @@ class DnsHelper ], 'dnsla' => [ 'name' => 'DNSLA', + 'icon' => 'dnsla.ico', + 'note' => '', 'config' => [ - 'ak' => 'APIID', - 'sk' => 'API密钥', + 'apiid' => [ + 'name' => 'APIID', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'apisecret' => [ + 'name' => 'API密钥', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 0, 'status' => true, @@ -121,10 +289,36 @@ class DnsHelper ], 'bt' => [ 'name' => '宝塔域名', + 'icon' => 'bt.png', + 'note' => '', 'config' => [ - 'ak' => 'Access Key', - 'sk' => 'Secret Key', - 'ext' => 'Account ID', + 'AccessKey' => [ + 'name' => 'Access Key', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'SecretKey' => [ + 'name' => 'Secret Key', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'AccountID' => [ + 'name' => 'Account ID', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 2, 'status' => true, @@ -136,9 +330,30 @@ class DnsHelper ], 'cloudflare' => [ 'name' => 'Cloudflare', + 'icon' => 'cloudflare.ico', + 'note' => '', 'config' => [ - 'ak' => '邮箱地址', - 'sk' => 'API密钥/令牌', + 'email' => [ + 'name' => '邮箱地址', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'apikey' => [ + 'name' => 'API密钥/令牌', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 2, 'status' => true, @@ -150,9 +365,30 @@ class DnsHelper ], 'namesilo' => [ 'name' => 'NameSilo', + 'icon' => 'namesilo.ico', + 'note' => '', 'config' => [ - 'ak' => '账户名', - 'sk' => 'API Key', + 'username' => [ + 'name' => '账户名', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'apikey' => [ + 'name' => 'API Key', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 0, 'status' => false, @@ -164,9 +400,30 @@ class DnsHelper ], 'spaceship' => [ 'name' => 'Spaceship', + 'icon' => 'spaceship.ico', + 'note' => '', 'config' => [ - 'ak' => 'API Key', - 'sk' => 'Api Secret', + 'apikey' => [ + 'name' => 'API Key', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'apisecret' => [ + 'name' => 'API Secret', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 0, 'status' => false, @@ -178,10 +435,36 @@ class DnsHelper ], 'powerdns' => [ 'name' => 'PowerDNS', + 'icon' => 'powerdns.ico', + 'note' => '', 'config' => [ - 'ak' => 'IP地址', - 'sk' => '端口', - 'ext' => 'API KEY', + 'ip' => [ + 'name' => 'IP地址', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'port' => [ + 'name' => '端口', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'apikey' => [ + 'name' => 'API KEY', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], ], 'remark' => 2, 'status' => true, @@ -191,6 +474,96 @@ class DnsHelper 'page' => true, 'add' => true, ], + 'aliyunesa' => [ + 'name' => '阿里云ESA', + 'icon' => 'aliyun.png', + 'note' => '仅支持以NS方式接入阿里云ESA的域名', + 'config' => [ + 'AccessKeyId' => [ + 'name' => 'AccessKeyId', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'AccessKeySecret' => [ + 'name' => 'AccessKeySecret', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'region' => [ + 'name' => 'API接入点', + 'type' => 'select', + 'options' => [ + ['value' => 'cn-hangzhou', 'label' => '中国内地'], + ['value' => 'ap-southeast-1', 'label' => '非中国内地'], + ], + 'value' => 'cn-hangzhou', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], + ], + 'remark' => 2, + 'status' => false, + 'redirect' => false, + 'log' => false, + 'weight' => false, + 'page' => false, + 'add' => false, + ], + 'tencenteo' => [ + 'name' => '腾讯云EO', + 'icon' => 'tencent.png', + 'note' => '仅支持以NS方式接入腾讯云EO的域名', + 'config' => [ + 'SecretId' => [ + 'name' => 'SecretId', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'SecretKey' => [ + 'name' => 'SecretKey', + 'type' => 'input', + 'placeholder' => '', + 'required' => true, + ], + 'site_type' => [ + 'name' => 'API接入点', + 'type' => 'select', + 'options' => [ + ['value' => 'cn', 'label' => '中国内地'], + ['value' => 'intl', 'label' => '非中国内地'], + ], + 'value' => 'cn', + 'required' => true, + ], + 'proxy' => [ + 'name' => '使用代理服务器', + 'type' => 'radio', + 'options' => [ + '0' => '否', + '1' => '是', + ], + 'value' => '0' + ], + ], + 'remark' => 0, + 'status' => true, + 'redirect' => false, + 'log' => false, + 'weight' => true, + 'page' => false, + 'add' => false, + ], ]; public static $line_name = [ @@ -202,10 +575,13 @@ class DnsHelper 'huoshan' => ['DEF' => 'default', 'CT' => 'telecom', 'CU' => 'unicom', 'CM' => 'mobile', 'AB' => 'oversea'], 'baidu' => ['DEF' => 'default', 'CT' => 'ct', 'CU' => 'cnc', 'CM' => 'cmnet', 'AB' => ''], 'jdcloud' => ['DEF' => '-1', 'CT' => '1', 'CU' => '2', 'CM' => '3', 'AB' => '4'], + 'bt' => ['DEF' => '0', 'CT' => '285344768', 'CU' => '285345792', 'CM' => '285346816'], 'cloudflare' => ['DEF' => '0'], 'namesilo' => ['DEF' => 'default'], 'powerdns' => ['DEF' => 'default'], 'spaceship' => ['DEF' => 'default'], + 'aliyunesa' => ['DEF' => '0'], + 'tencenteo' => ['DEF' => 'Default'], ]; public static function getList() @@ -225,11 +601,12 @@ class DnsHelper */ public static function getModel($aid, $domain = null, $domainid = null) { - $config = self::getConfig($aid); - if (!$config) return false; - $dnstype = $config['type']; + $account = self::getConfig($aid); + if (!$account) return false; + $dnstype = $account['type']; $class = "\\app\\lib\\dns\\{$dnstype}"; if (class_exists($class)) { + $config = json_decode($account['config'], true); $config['domain'] = $domain; $config['domainid'] = $domainid; $model = new $class($config); @@ -241,13 +618,14 @@ class DnsHelper /** * @return DnsInterface|bool */ - public static function getModel2($config) + public static function getModel2($account) { - $dnstype = $config['type']; + $dnstype = $account['type']; $class = "\\app\\lib\\dns\\{$dnstype}"; if (class_exists($class)) { - $config['domain'] = $config['name']; - $config['domainid'] = $config['thirdid']; + $config = json_decode($account['config'], true); + $config['domain'] = $account['name']; + $config['domainid'] = $account['thirdid']; $model = new $class($config); return $model; } diff --git a/app/lib/dns/aliyun.php b/app/lib/dns/aliyun.php index c767657..90026ed 100644 --- a/app/lib/dns/aliyun.php +++ b/app/lib/dns/aliyun.php @@ -20,8 +20,8 @@ class aliyun implements DnsInterface public function __construct($config) { - $this->AccessKeyId = $config['ak']; - $this->AccessKeySecret = $config['sk']; + $this->AccessKeyId = $config['AccessKeyId']; + $this->AccessKeySecret = $config['AccessKeySecret']; $proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; $this->client = new AliyunClient($this->AccessKeyId, $this->AccessKeySecret, $this->Endpoint, $this->Version, $proxy); $this->domain = $config['domain']; diff --git a/app/lib/dns/aliyunesa.php b/app/lib/dns/aliyunesa.php new file mode 100644 index 0000000..061b22c --- /dev/null +++ b/app/lib/dns/aliyunesa.php @@ -0,0 +1,284 @@ +AccessKeyId = $config['AccessKeyId']; + $this->AccessKeySecret = $config['AccessKeySecret']; + if (!empty($config['region'])) { + $this->Endpoint = 'esa.'.$config['region'].'.aliyuncs.com'; + } + $proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; + $this->client = new AliyunClient($this->AccessKeyId, $this->AccessKeySecret, $this->Endpoint, $this->Version, $proxy); + $this->domain = $config['domain']; + $this->domainid = $config['domainid']; + } + + public function getError() + { + return $this->error; + } + + public function check() + { + if ($this->getDomainList() != false) { + return true; + } + return false; + } + + //获取域名列表 + public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20) + { + $param = ['Action' => 'ListSites', 'SiteName' => $KeyWord, 'PageNumber' => $PageNumber, 'PageSize' => $PageSize, 'AccessType' => 'NS']; + $data = $this->request($param, 'GET', true); + if ($data) { + $list = []; + foreach ($data['Sites'] as $row) { + $list[] = [ + 'DomainId' => $row['SiteId'], + 'Domain' => $row['SiteName'], + 'RecordCount' => 0, + ]; + } + return ['total' => $data['TotalCount'], 'list' => $list]; + } + return false; + } + + //获取解析记录列表 + public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null) + { + $param = ['Action' => 'ListRecords', 'SiteId' => $this->domainid, 'PageNumber' => $PageNumber, 'PageSize' => $PageSize]; + if (!isNullOrEmpty($SubDomain)) { + $RecordName = $SubDomain == '@' ? $this->domain : $SubDomain . '.' . $this->domain; + $param += ['RecordName' => $RecordName]; + } elseif (!isNullOrEmpty($KeyWord)) { + $RecordName = $KeyWord == '@' ? $this->domain : $KeyWord . '.' . $this->domain; + $param += ['RecordName' => $RecordName]; + } + if (!isNullOrEmpty($Type)) { + if ($Type == 'A' || $Type == 'AAAA') $Type = 'A/AAAA'; + $param += ['Type' => $Type]; + } + if (!isNullOrEmpty($Line)) { + $param += ['Proxied' => $Line == '1' ? 'true' : 'false']; + } + $data = $this->request($param, 'GET', true); + if ($data) { + $list = []; + foreach ($data['Records'] as $row) { + $name = substr($row['RecordName'], 0, - (strlen($this->domain) + 1)); + if ($name == '') $name = '@'; + $value = $row['Data']['Value']; + if ($row['RecordType'] == 'CAA') $value = $row['Data']['Flag'] . ' ' . $row['Data']['Tag'] . ' ' . $row['Data']['Value']; + else if ($row['RecordType'] == 'SRV') $value = $row['Data']['Priority'] . ' ' . $row['Data']['Weight'] . ' ' . $row['Data']['Port'] . ' ' . $row['Data']['Value']; + if ($row['RecordType'] == 'A/AAAA') { + if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + $row['RecordType'] = 'A'; + } elseif (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { + $row['RecordType'] = 'AAAA'; + } + } + $list[] = [ + 'RecordId' => $row['RecordId'], + 'Domain' => $this->domain, + 'Name' => $name, + 'Type' => $row['RecordType'], + 'Value' => $value, + 'Line' => $row['Proxied'] ? '1' : '0', + 'TTL' => $row['Ttl'], + 'MX' => isset($row['Data']['Priority']) ? $row['Data']['Priority'] : null, + 'Status' => '1', + 'Weight' => null, + 'Remark' => isset($row['Comment']) ? $row['Comment'] : null, + 'UpdateTime' => isset($row['UpdateTime']) ? date('Y-m-d H:i:s', strtotime($row['UpdateTime'])) : null, + ]; + } + return ['total' => $data['TotalCount'], 'list' => $list]; + } + return false; + } + + //获取子域名解析记录列表 + public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null) + { + return $this->getDomainRecords($PageNumber, $PageSize, null, $SubDomain, null, $Type, $Line); + } + + //获取解析记录详细信息 + public function getDomainRecordInfo($RecordId) + { + $param = ['Action' => 'GetRecord', 'RecordId' => $RecordId]; + $data = $this->request($param, 'GET', true); + if ($data) { + $row = $data['RecordModel']; + $name = substr($row['RecordName'], 0, - (strlen($this->domain) + 1)); + if ($name == '') $name = '@'; + $value = $row['Data']['Value']; + if ($row['RecordType'] == 'CAA') $value = $row['Data']['Flag'] . ' ' . $row['Data']['Tag'] . ' ' . $row['Data']['Value']; + else if ($row['RecordType'] == 'SRV') $value = $row['Data']['Priority'] . ' ' . $row['Data']['Weight'] . ' ' . $row['Data']['Port'] . ' ' . $row['Data']['Value']; + if ($row['RecordType'] == 'A/AAAA') { + if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + $row['RecordType'] = 'A'; + } elseif (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { + $row['RecordType'] = 'AAAA'; + } + } + return [ + 'RecordId' => $row['RecordId'], + 'Domain' => $this->domain, + 'Name' => $name, + 'Type' => $row['RecordType'], + 'Value' => $value, + 'Line' => $row['Proxied'] ? '1' : '0', + 'TTL' => $row['Ttl'], + 'MX' => isset($row['Data']['Priority']) ? $row['Data']['Priority'] : null, + 'Status' => '1', + 'Weight' => null, + 'Remark' => isset($row['Comment']) ? $row['Comment'] : null, + 'UpdateTime' => isset($row['UpdateTime']) ? date('Y-m-d H:i:s', strtotime($row['UpdateTime'])) : null, + ]; + } + return false; + } + + //添加解析记录 + public function addDomainRecord($Name, $Type, $Value, $Line = 'default', $TTL = 600, $MX = null, $Weight = null, $Remark = null) + { + if ($Name == '@') { + $Name = $this->domain; + } else { + $Name = $Name . '.' . $this->domain; + } + if ($Type == 'A' || $Type == 'AAAA') $Type = 'A/AAAA'; + $data = ['Value' => $Value]; + if ($Type == 'CAA') { + list($flag, $tag, $val) = explode(' ', $Value, 3); + $data = ['Flag' => intval($flag), 'Tag' => $tag, 'Value' => $val]; + } elseif ($Type == 'SRV') { + list($priority, $weight, $port, $val) = explode(' ', $Value, 4); + $data = ['Priority' => intval($priority), 'Weight' => intval($weight), 'Port' => intval($port), 'Value' => $val]; + } elseif ($Type == 'MX') { + $data['Priority'] = intval($MX); + } + $param = ['Action' => 'CreateRecord', 'SiteId' => $this->domainid, 'RecordName' => $Name, 'Type' => $Type, 'Proxied' => $Line == '1' ? 'true' : 'false', 'Ttl' => intval($TTL), 'Data' => json_encode($data), 'Comment' => $Remark]; + if ($Line == '1') $param['BizName'] = 'web'; + $data = $this->request($param, 'POST', true); + if ($data) { + return $data['RecordId']; + } + return false; + } + + //修改解析记录 + public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = 'default', $TTL = 600, $MX = null, $Weight = null, $Remark = null) + { + if ($Name == '@') { + $Name = $this->domain; + } else { + $Name = $Name . '.' . $this->domain; + } + if ($Type == 'A' || $Type == 'AAAA') $Type = 'A/AAAA'; + $data = ['Value' => $Value]; + if ($Type == 'CAA') { + list($flag, $tag, $val) = explode(' ', $Value, 3); + $data = ['Flag' => intval($flag), 'Tag' => $tag, 'Value' => $val]; + } elseif ($Type == 'SRV') { + list($priority, $weight, $port, $val) = explode(' ', $Value, 4); + $data = ['Priority' => intval($priority), 'Weight' => intval($weight), 'Port' => intval($port), 'Value' => $val]; + } elseif ($Type == 'MX') { + $data['Priority'] = intval($MX); + } + $param = ['Action' => 'UpdateRecord', 'RecordId' => $RecordId, 'Type' => $Type, 'Proxied' => $Line == '1' ? 'true' : 'false', 'Ttl' => intval($TTL), 'Data' => json_encode($data), 'Comment' => $Remark]; + if ($Line == '1') $param['BizName'] = 'web'; + return $this->request($param, 'POST'); + } + + //修改解析记录备注 + public function updateDomainRecordRemark($RecordId, $Remark) + { + return false; + } + + //删除解析记录 + public function deleteDomainRecord($RecordId) + { + $param = ['Action' => 'DeleteRecord', 'RecordId' => $RecordId]; + return $this->request($param, 'POST'); + } + + //设置解析记录状态 + public function setDomainRecordStatus($RecordId, $Status) + { + return false; + } + + //获取解析记录操作日志 + public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null) + { + return false; + } + + //获取解析线路列表 + public function getRecordLine() + { + return ['0' => ['name' => '仅DNS', 'parent' => null], '1' => ['name' => '已代理', 'parent' => null]]; + } + + //获取域名信息 + public function getDomainInfo() + { + $param = ['Action' => 'GetSite', 'SiteId' => $this->domainid]; + $data = $this->request($param, 'GET', true); + if ($data) { + return $data; + } + return false; + } + + //获取域名最低TTL + public function getMinTTL() + { + return 1; + } + + public function addDomain($Domain) + { + return false; + } + + private function request($param, $method, $returnData = false) + { + if (empty($this->AccessKeyId) || empty($this->AccessKeySecret)) return false; + try { + $result = $this->client->request($param, $method); + } catch (Exception $e) { + $this->setError($e->getMessage()); + return false; + } + return $returnData ? $result : true; + } + + private function setError($message) + { + $this->error = $message; + //file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND); + } +} diff --git a/app/lib/dns/baidu.php b/app/lib/dns/baidu.php index ad91c53..052e204 100644 --- a/app/lib/dns/baidu.php +++ b/app/lib/dns/baidu.php @@ -18,8 +18,8 @@ class baidu implements DnsInterface public function __construct($config) { - $this->AccessKeyId = $config['ak']; - $this->SecretAccessKey = $config['sk']; + $this->AccessKeyId = $config['AccessKeyId']; + $this->SecretAccessKey = $config['SecretAccessKey']; $proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; $this->client = new BaiduCloud($this->AccessKeyId, $this->SecretAccessKey, $this->endpoint, $proxy); $this->domain = $config['domain']; diff --git a/app/lib/dns/bt.php b/app/lib/dns/bt.php index 21190ce..982ab94 100644 --- a/app/lib/dns/bt.php +++ b/app/lib/dns/bt.php @@ -18,9 +18,9 @@ class bt implements DnsInterface public function __construct($config) { - $this->accountId = $config['ext']; - $this->accessKey = $config['ak']; - $this->secretKey = $config['sk']; + $this->accountId = $config['AccountID']; + $this->accessKey = $config['AccessKey']; + $this->secretKey = $config['SecretKey']; $this->domain = $config['domain']; if ($config['domainid']) { $a = explode('|', $config['domainid']); diff --git a/app/lib/dns/cloudflare.php b/app/lib/dns/cloudflare.php index be2ca48..38591fa 100644 --- a/app/lib/dns/cloudflare.php +++ b/app/lib/dns/cloudflare.php @@ -16,8 +16,8 @@ class cloudflare implements DnsInterface function __construct($config) { - $this->Email = $config['ak']; - $this->ApiKey = $config['sk']; + $this->Email = $config['email']; + $this->ApiKey = $config['apikey']; $this->domain = $config['domain']; $this->domainid = $config['domainid']; $this->proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; diff --git a/app/lib/dns/dnsla.php b/app/lib/dns/dnsla.php index 75c0e71..e2d9d21 100644 --- a/app/lib/dns/dnsla.php +++ b/app/lib/dns/dnsla.php @@ -17,8 +17,8 @@ class dnsla implements DnsInterface public function __construct($config) { - $this->apiid = $config['ak']; - $this->apisecret = $config['sk']; + $this->apiid = $config['apiid']; + $this->apisecret = $config['apisecret']; $this->domain = $config['domain']; $this->domainid = $config['domainid']; $this->proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; diff --git a/app/lib/dns/dnspod.php b/app/lib/dns/dnspod.php index 909155f..a2ef75c 100644 --- a/app/lib/dns/dnspod.php +++ b/app/lib/dns/dnspod.php @@ -21,8 +21,8 @@ class dnspod implements DnsInterface public function __construct($config) { - $this->SecretId = $config['ak']; - $this->SecretKey = $config['sk']; + $this->SecretId = $config['SecretId']; + $this->SecretKey = $config['SecretKey']; $proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; $this->client = new TencentCloud($this->SecretId, $this->SecretKey, $this->endpoint, $this->service, $this->version, null, $proxy); $this->domain = $config['domain']; diff --git a/app/lib/dns/huawei.php b/app/lib/dns/huawei.php index 11a31ba..0d55884 100644 --- a/app/lib/dns/huawei.php +++ b/app/lib/dns/huawei.php @@ -18,8 +18,8 @@ class huawei implements DnsInterface public function __construct($config) { - $this->AccessKeyId = $config['ak']; - $this->SecretAccessKey = $config['sk']; + $this->AccessKeyId = $config['AccessKeyId']; + $this->SecretAccessKey = $config['SecretAccessKey']; $proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; $this->client = new HuaweiCloud($this->AccessKeyId, $this->SecretAccessKey, $this->endpoint, $proxy); $this->domain = $config['domain']; @@ -77,12 +77,13 @@ class huawei implements DnsInterface if ($data) { $list = []; foreach ($data['recordsets'] as $row) { - if ($row['name'] == $row['zone_name']) $row['name'] = '@'; + $name = substr($row['name'], 0, -(strlen($row['zone_name']) + 1)); + if ($name == '') $name = '@'; if ($row['type'] == 'MX') list($row['mx'], $row['records']) = explode(' ', $row['records'][0]); $list[] = [ 'RecordId' => $row['id'], 'Domain' => rtrim($row['zone_name'], '.'), - 'Name' => str_replace('.'.$row['zone_name'], '', $row['name']), + 'Name' => $name, 'Type' => $row['type'], 'Value' => $row['records'], 'Line' => $row['line'], @@ -110,12 +111,13 @@ class huawei implements DnsInterface { $data = $this->send_request('GET', '/v2.1/zones/'.$this->domainid.'/recordsets/'.$RecordId); if ($data) { - if ($data['name'] == $data['zone_name']) $data['name'] = '@'; + $name = substr($data['name'], 0, -(strlen($data['zone_name']) + 1)); + if ($name == '') $name = '@'; if ($data['type'] == 'MX') list($data['mx'], $data['records']) = explode(' ', $data['records'][0]); return [ 'RecordId' => $data['id'], 'Domain' => rtrim($data['zone_name'], '.'), - 'Name' => str_replace('.'.$data['zone_name'], '', $data['name']), + 'Name' => $name, 'Type' => $data['type'], 'Value' => $data['records'], 'Line' => $data['line'], diff --git a/app/lib/dns/huoshan.php b/app/lib/dns/huoshan.php index 4b93136..b25ee64 100644 --- a/app/lib/dns/huoshan.php +++ b/app/lib/dns/huoshan.php @@ -30,8 +30,8 @@ class huoshan implements DnsInterface public function __construct($config) { - $this->AccessKeyId = $config['ak']; - $this->SecretAccessKey = $config['sk']; + $this->AccessKeyId = $config['AccessKeyId']; + $this->SecretAccessKey = $config['SecretAccessKey']; $proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; $this->client = new Volcengine($this->AccessKeyId, $this->SecretAccessKey, $this->endpoint, $this->service, $this->version, $this->region, $proxy); $this->domain = $config['domain']; diff --git a/app/lib/dns/jdcloud.php b/app/lib/dns/jdcloud.php index e69ddb1..41af108 100644 --- a/app/lib/dns/jdcloud.php +++ b/app/lib/dns/jdcloud.php @@ -23,8 +23,8 @@ class jdcloud implements DnsInterface public function __construct($config) { - $this->AccessKeyId = $config['ak']; - $this->AccessKeySecret = $config['sk']; + $this->AccessKeyId = $config['AccessKeyId']; + $this->AccessKeySecret = $config['AccessKeySecret']; $proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; $this->client = new JdcloudClient($this->AccessKeyId, $this->AccessKeySecret, $this->endpoint, $this->service, $this->region, $proxy); $this->domain = $config['domain']; diff --git a/app/lib/dns/namesilo.php b/app/lib/dns/namesilo.php index d852c5e..08fd09d 100644 --- a/app/lib/dns/namesilo.php +++ b/app/lib/dns/namesilo.php @@ -16,7 +16,7 @@ class namesilo implements DnsInterface function __construct($config) { - $this->apikey = $config['sk']; + $this->apikey = $config['apikey']; $this->domain = $config['domain']; $this->proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; } diff --git a/app/lib/dns/powerdns.php b/app/lib/dns/powerdns.php index 339131e..9333fc5 100644 --- a/app/lib/dns/powerdns.php +++ b/app/lib/dns/powerdns.php @@ -17,8 +17,8 @@ class powerdns implements DnsInterface function __construct($config) { - $this->url = 'http://' . $config['ak'] . ':' . $config['sk'] . '/api/v1'; - $this->apikey = $config['ext']; + $this->url = 'http://' . $config['ip'] . ':' . $config['port'] . '/api/v1'; + $this->apikey = $config['apikey']; $this->proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; $this->domain = $config['domain']; $this->domainid = $config['domainid']; diff --git a/app/lib/dns/spaceship.php b/app/lib/dns/spaceship.php index 9546681..538acf1 100644 --- a/app/lib/dns/spaceship.php +++ b/app/lib/dns/spaceship.php @@ -18,8 +18,8 @@ class spaceship implements DnsInterface public function __construct($config) { - $this->apiKey = $config['ak']; - $this->apiSecret = $config['sk']; + $this->apiKey = $config['apikey']; + $this->apiSecret = $config['apisecret']; $this->domain = $config['domain']; $this->proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; } @@ -60,8 +60,9 @@ class spaceship implements DnsInterface public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null) { $param = ['take' => $PageSize, 'skip' => ($PageNumber - 1) * $PageSize]; - if (!isNullOrEmpty(($SubDomain))) { - $param['host'] = $SubDomain; + if (!isNullOrEmpty($SubDomain)) { + $param['take'] = 100; + $param['skip'] = 0; } $data = $this->send_reuqest('GET', '/dns/records/' . $this->domain, $param); if ($data) { @@ -106,6 +107,11 @@ class spaceship implements DnsInterface 'UpdateTime' => null, ]; } + if(!isNullOrEmpty($SubDomain)){ + $list = array_values(array_filter($list, function($v) use ($SubDomain){ + return strcasecmp($v['Name'], $SubDomain) === 0; + })); + } return ['total' => $data['total'], 'list' => $list]; } return false; @@ -124,7 +130,7 @@ class spaceship implements DnsInterface return false; } - private function convertRecordItem($Name, $Type, $Value, $MX = 1) + private function convertRecordItem($Name, $Type, $Value, $MX) { $item = [ 'type' => $Type, diff --git a/app/lib/dns/tencenteo.php b/app/lib/dns/tencenteo.php new file mode 100644 index 0000000..1729175 --- /dev/null +++ b/app/lib/dns/tencenteo.php @@ -0,0 +1,254 @@ +SecretId = $config['SecretId']; + $this->SecretKey = $config['SecretKey']; + if (isset($config['site_type']) && $config['site_type'] == 'intl') { + $this->endpoint = "teo.intl.tencentcloudapi.com"; + } + $proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; + $this->client = new TencentCloud($this->SecretId, $this->SecretKey, $this->endpoint, $this->service, $this->version, null, $proxy); + $this->domain = $config['domain']; + $this->domainid = $config['domainid']; + } + + public function getError() + { + return $this->error; + } + + public function check() + { + if ($this->getDomainList() != false) { + return true; + } + return false; + } + + //获取域名列表 + public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20) + { + $action = 'DescribeZones'; + $offset = ($PageNumber - 1) * $PageSize; + $filters = [['Name' => 'zone-type', 'Values' => ['full']]]; + if (!isNullOrEmpty($KeyWord)) { + $filters[] = ['Name' => 'zone-name', 'Values' => [$KeyWord]]; + } + $param = ['Offset' => $offset, 'Limit' => $PageSize, 'Filters' => $filters]; + $data = $this->send_request($action, $param); + if ($data) { + $list = []; + foreach ($data['Zones'] as $row) { + $list[] = [ + 'DomainId' => $row['ZoneId'], + 'Domain' => $row['ZoneName'], + 'RecordCount' => 0, + ]; + } + return ['total' => $data['TotalCount'], 'list' => $list]; + } + return false; + } + + //获取解析记录列表 + public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null) + { + $offset = ($PageNumber - 1) * $PageSize; + $action = 'DescribeDnsRecords'; + $filters = []; + if (!isNullOrEmpty($SubDomain)) { + $name = $SubDomain == '@' ? $this->domain : $SubDomain . '.' . $this->domain; + $filters[] = ['Name' => 'name', 'Values' => [$name]]; + } elseif (!isNullOrEmpty($KeyWord)) { + $name = $KeyWord == '@' ? $this->domain : $KeyWord . '.' . $this->domain; + $filters[] = ['Name' => 'name', 'Values' => [$name]]; + } + if (!isNullOrEmpty($Value)) { + $filters[] = ['Name' => 'content', 'Values' => [$Value], 'Fuzzy' => true]; + } + if (!isNullOrEmpty($Type)) { + $filters[] = ['Name' => 'type', 'Values' => [$Type]]; + } + $param = ['ZoneId' => $this->domainid, 'Offset' => $offset, 'Limit' => $PageSize, 'Filters' => $filters]; + $data = $this->send_request($action, $param); + if ($data) { + $list = []; + foreach ($data['DnsRecords'] as $row) { + $name = substr($row['Name'], 0, - (strlen($this->domain) + 1)); + if ($name == '') $name = '@'; + $list[] = [ + 'RecordId' => $row['RecordId'], + 'Domain' => $this->domain, + 'Name' => $name, + 'Type' => $row['Type'], + 'Value' => $row['Content'], + 'Line' => $row['Location'], + 'TTL' => $row['TTL'], + 'MX' => $row['Priority'], + 'Status' => $row['Status'] == 'enable' ? '1' : '0', + 'Weight' => $row['Weight'] == -1 ? null : $row['Weight'], + 'Remark' => null, + 'UpdateTime' => $row['ModifiedOn'], + ]; + } + return ['total' => $data['TotalCount'], 'list' => $list]; + } + return false; + } + + //获取子域名解析记录列表 + public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null) + { + if ($SubDomain == '') $SubDomain = '@'; + return $this->getDomainRecords($PageNumber, $PageSize, null, $SubDomain, null, $Type, $Line); + } + + //获取解析记录详细信息 + public function getDomainRecordInfo($RecordId) + { + $action = 'DescribeDnsRecords'; + $param = ['ZoneId' => $this->domainid, 'Filters' => [['Name' => 'id', 'Values' => [$RecordId]]]]; + $data = $this->send_request($action, $param); + if ($data) { + $row = $data['DnsRecords'][0]; + $name = substr($row['Name'], 0, - (strlen($this->domain) + 1)); + if ($name == '') $name = '@'; + return [ + 'RecordId' => $row['RecordId'], + 'Domain' => $this->domain, + 'Name' => $name, + 'Type' => $row['Type'], + 'Value' => $row['Content'], + 'Line' => $row['Location'], + 'TTL' => $row['TTL'], + 'MX' => $row['Priority'], + 'Status' => $row['Status'] == 'enable' ? '1' : '0', + 'Weight' => $row['Weight'] == -1 ? null : $row['Weight'], + 'Remark' => null, + 'UpdateTime' => $row['ModifiedOn'], + ]; + } + return false; + } + + //添加解析记录 + public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null) + { + $action = 'CreateDnsRecord'; + if ($Name == '@') { + $Name = $this->domain; + } else { + $Name = $Name . '.' . $this->domain; + } + $param = ['ZoneId' => $this->domainid, 'Name' => $Name, 'Type' => $Type, 'Content' => $Value, 'Location' => $Line, 'TTL' => intval($TTL), 'Weight' => empty($Weight) ? -1 : intval($Weight)]; + if ($Type == 'MX') $param['Priority'] = intval($MX); + $data = $this->send_request($action, $param); + return is_array($data) ? $data['RecordId'] : false; + } + + //修改解析记录 + public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null) + { + $action = 'ModifyDnsRecord'; + if ($Name == '@') { + $Name = $this->domain; + } else { + $Name = $Name . '.' . $this->domain; + } + $param = ['ZoneId' => $this->domainid, 'DnsRecordId' => $RecordId, 'Name' => $Name, 'Type' => $Type, 'Content' => $Value, 'Location' => $Line, 'TTL' => intval($TTL), 'Weight' => empty($Weight) ? -1 : intval($Weight)]; + if ($Type == 'MX') $param['Priority'] = intval($MX); + $data = $this->send_request($action, $param); + return is_array($data); + } + + //修改解析记录备注 + public function updateDomainRecordRemark($RecordId, $Remark) + { + return false; + } + + //删除解析记录 + public function deleteDomainRecord($RecordId) + { + $action = 'DeleteDnsRecords'; + $param = ['ZoneId' => $this->domainid, 'RecordIds' => [$RecordId]]; + $data = $this->send_request($action, $param); + return is_array($data); + } + + //设置解析记录状态 + public function setDomainRecordStatus($RecordId, $Status) + { + $action = 'ModifyDnsRecordsStatus'; + $param = ['ZoneId' => $this->domainid]; + if ($Status == '1') $param['RecordsToEnable'] = [$RecordId]; + else $param['RecordsToDisable'] = [$RecordId]; + $data = $this->send_request($action, $param); + return is_array($data); + } + + //获取解析记录操作日志 + public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null) + { + return false; + } + + //获取解析线路列表 + public function getRecordLine() + { + return ['Default' => ['name' => '默认', 'parent' => null]]; + } + + //获取域名概览信息 + public function getDomainInfo() + { + return false; + } + + //获取域名最低TTL + public function getMinTTL() + { + return 60; + } + + public function addDomain($Domain) + { + return false; + } + + private function send_request($action, $param) + { + try{ + return $this->client->request($action, $param); + }catch(Exception $e){ + $this->setError($e->getMessage()); + return false; + } + } + + private function setError($message) + { + $this->error = $message; + //file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND); + } +} diff --git a/app/lib/dns/west.php b/app/lib/dns/west.php index adfbf9d..95d7c41 100644 --- a/app/lib/dns/west.php +++ b/app/lib/dns/west.php @@ -19,8 +19,8 @@ class west implements DnsInterface public function __construct($config) { - $this->username = $config['ak']; - $this->api_password = $config['sk']; + $this->username = $config['username']; + $this->api_password = $config['api_password']; $this->domain = $config['domain']; $this->proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; } diff --git a/app/service/OptimizeService.php b/app/service/OptimizeService.php index 02b3ca5..bbd84a2 100644 --- a/app/service/OptimizeService.php +++ b/app/service/OptimizeService.php @@ -132,7 +132,7 @@ class OptimizeService continue; } - $drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.id', $row['did'])->field('A.*,B.type,B.ak,B.sk,B.ext')->find(); + $drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.id', $row['did'])->field('A.*,B.type')->find(); if (!$drow) { throw new Exception('域名不存在(ID:'.$row['did'].')'); } diff --git a/app/service/ScheduleService.php b/app/service/ScheduleService.php index 69168bd..33f11b0 100644 --- a/app/service/ScheduleService.php +++ b/app/service/ScheduleService.php @@ -33,7 +33,7 @@ class ScheduleService public function execute_one($row) { - $drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.id', $row['did'])->field('A.*,B.type,B.ak,B.sk,B.ext')->find(); + $drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.id', $row['did'])->field('A.*,B.type,B.config')->find(); if (!$drow) throw new Exception('域名不存在'); Db::name('sctask')->where('id', $row['id'])->update(['updatetime' => time()]); diff --git a/app/service/TaskRunner.php b/app/service/TaskRunner.php index 73ab2e3..f401a39 100644 --- a/app/service/TaskRunner.php +++ b/app/service/TaskRunner.php @@ -71,7 +71,7 @@ class TaskRunner } if ($action > 0) { - $drow = $this->db()->name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.id', $row['did'])->field('A.*,B.type,B.ak,B.sk,B.ext')->find(); + $drow = $this->db()->name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.id', $row['did'])->field('A.*,B.type,B.config')->find(); if (!$drow) { echo '域名不存在(ID:'.$row['did'].')'."\n"; $this->closeDb(); diff --git a/app/sql/install.sql b/app/sql/install.sql index 43462c7..b37415d 100644 --- a/app/sql/install.sql +++ b/app/sql/install.sql @@ -5,7 +5,7 @@ CREATE TABLE `dnsmgr_config` ( PRIMARY KEY (`key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -INSERT INTO `dnsmgr_config` VALUES ('version', '1040'); +INSERT INTO `dnsmgr_config` VALUES ('version', '1045'); INSERT INTO `dnsmgr_config` VALUES ('notice_mail', '0'); INSERT INTO `dnsmgr_config` VALUES ('notice_wxtpl', '0'); INSERT INTO `dnsmgr_config` VALUES ('mail_smtp', 'smtp.qq.com'); @@ -15,10 +15,8 @@ DROP TABLE IF EXISTS `dnsmgr_account`; CREATE TABLE `dnsmgr_account` ( `id` int(11) unsigned NOT NULL auto_increment, `type` varchar(20) NOT NULL, - `ak` varchar(256) DEFAULT NULL, - `sk` varchar(256) DEFAULT NULL, - `ext` varchar(256) DEFAULT NULL, - `proxy` tinyint(1) NOT NULL DEFAULT '0', + `name` varchar(255) NOT NULL, + `config` text DEFAULT NULL, `remark` varchar(100) DEFAULT NULL, `addtime` datetime DEFAULT NULL, PRIMARY KEY (`id`) diff --git a/app/sql/update.sql b/app/sql/update.sql index 42420e5..b69eda9 100644 --- a/app/sql/update.sql +++ b/app/sql/update.sql @@ -185,4 +185,8 @@ CREATE TABLE IF NOT EXISTS `dnsmgr_sctask` ( `remark` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`), KEY `did` (`did`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +ALTER TABLE `dnsmgr_account` +ADD COLUMN `config` text DEFAULT NULL, +CHANGE COLUMN `ak` `name` varchar(255) NOT NULL; \ No newline at end of file diff --git a/app/view/cert/certorder.html b/app/view/cert/certorder.html index 923da4a..7634f8c 100644 --- a/app/view/cert/certorder.html +++ b/app/view/cert/certorder.html @@ -124,7 +124,7 @@ $(document).ready(function(){ field: 'end_day', title: '到期时间', formatter: function(value, row, index) { - if(value){ + if(value != null){ if(value > 7){ return '剩余' + value + '天'; }else if(value > 0){ diff --git a/app/view/common/layout.html b/app/view/common/layout.html index 888903b..6b3fefc 100644 --- a/app/view/common/layout.html +++ b/app/view/common/layout.html @@ -110,7 +110,7 @@ 域名管理 {if request()->user['level'] eq 2} -
  • +
  • 域名账户
  • diff --git a/app/view/domain/account.html b/app/view/domain/account.html index b1c3f13..e5e66fe 100644 --- a/app/view/domain/account.html +++ b/app/view/domain/account.html @@ -1,70 +1,6 @@ {extend name="common/layout" /} {block name="title"}域名账户{/block} {block name="main"} -
    @@ -77,7 +13,7 @@
    刷新 - 添加 + 添加 @@ -93,7 +29,6 @@ + + + +{/block} diff --git a/app/view/domain/batchadd2.html b/app/view/domain/batchadd2.html index 91be23f..72ab519 100644 --- a/app/view/domain/batchadd2.html +++ b/app/view/domain/batchadd2.html @@ -81,7 +81,7 @@ tbody tr>td:nth-child(3){min-width:300px;word-break:break-all;} - + diff --git a/app/view/domain/domain.html b/app/view/domain/domain.html index c0ec509..65e860a 100644 --- a/app/view/domain/domain.html +++ b/app/view/domain/domain.html @@ -127,6 +127,8 @@
    + +
    @@ -196,7 +198,7 @@ $(document).ready(function(){ field: 'typename', title: '平台账户', formatter: function(value, row, index) { - return ''+(row.aremark?row.aremark:value+'('+row.aid+')'); + return ''+(row.aremark?row.aremark:value+'('+row.aid+')'); } }, { diff --git a/config/app.php b/config/app.php index 9b89298..b7ea814 100644 --- a/config/app.php +++ b/config/app.php @@ -31,7 +31,7 @@ return [ 'show_error_msg' => true, 'exception_tmpl' => \think\facade\App::getAppPath() . 'view/exception.tpl', - 'version' => '1044', + 'version' => '1045', - 'dbversion' => '1040' + 'dbversion' => '1045' ]; diff --git a/public/static/images/aliyun.ico b/public/static/images/aliyun.ico deleted file mode 100644 index a566910127486459f94263068146e62eeddea8cd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmeHKF>-@25IhfsixhZLqzz@Bp)O4doWLSg{My90BN4`-YMB5xnBE7l&|{T`5a zn*&F{MqonE40tBOr8YhCu?EJKf=BLt%=29{N2yhjkK96$-y)~W_j$T8<^trzdP(ml zkjFUJGU=7;H8&==*O>G0)mY5wE}26eT&vH^jUATgYdG*fC~DYgw3g(+dl&OxqI(Hv zsXurbV3f#0HT}ZBjB!WvK^879G`6G$7_14;kNUd$tI++5oVV=3J7{^b8)KE%0LecBXlA9M_n#Lr)RTE=#wb~XH$Hvx{ONES@I-QpO# z@_6q#_vHNk&-0vf&%@Xb{P8@a|4e*=u^h%&DGXgqfKk7E;obk`s`BeJc3Hwa!N&P=@jg-;ry7C}4)8^rzUf1-nO zj9AZGJh>bGCbH={1z&PN2Qp#EP`RhAM!_VFye}(uN%s(IcWbTAw{%hYiXPp1; z)fUD4wvoDw^G{q66!RN~Y#HabUp}aqU)itAIA0J;6!Q=CH&QgjmKSG?k{X2j@83aJXT`2*O;NHK`fOyjbdpQY7sNe;nQ>$ zQ(W--s?GQn{n~wC-$mSSVqQ7cG(Y-6&@+Pbu)WgHYv{MN=ZaL&R*Jq)akh0J)}==# zEwYd9V6g_QcGw7bAy~X73FG-D?Czmp(Y|C2So1vmcfI;u14GTDv3v8|pk)|#2Rcx5 z$u&qA?OAX;G1lBTWL33Zs#bwdK6X;=h55r+Yq464zk~i^*My-B>tFNs)ng1}UC^ja z<|npM_w1@W7mZ=fpfRi5_oB(>&F=tv23np_TwoEj$v?7)lbB$`W?XViOr}P0znr_H zQ?{LgSiCEdk?I+7)gb0KFhBV^1MVsKYN{D9$a6uL+U_e5@Xn8M%cwb*;iC_J2}dtl zWr}N!w9qs!u}AhG2DiYyB?L=$ry06! zudq%=o#Xn^Z3ApEF>=v_m^W=P>_7clieFE4lC+d9Nnh`fB*vt5#(KzBaTF;sLFJZy oH%d=d-3v?Z)$H}`r5>8^>8e}zc<yhMBeMX^NO~4-{CiR=G;5;%sKbYnRCXNBHl_%jozEr z#m1BvV@?v9%qgPw+{L*MCmhaTj8vpjh4jx|W{|*L+)rotT0&-hq^H-@;>{cE7&vxyGD+=d@A4mC3>mKZjJeyEAhbea1ZJ zcU1Z99oTmtA(#5{X-D(lr*AC~#`1T_y%9*&^`q0@-DOOE0y8`pU*^a>@RfX?g&muK zH1tH#j_?20Z`e2QA?^1e&5ZNqeuqB3*at1`Us(J%x166fHzB95K+ars zlyN-xyzkYH@4xE5oP^ZfjvD9vy211K{wMlL{FC#SeE+mAi#$R)a_8)y|U~UQcwF#`P1KACLHLe{Uht%FWZ2ryPe>L^O z4vxa6$H)uEqi3%6Jg+sjx6cgAcl&G+`cJK8FWhjwjP^4DRqTx_V`~TfXNtKyLjN7s Sd&kz+{(F%;4E_iBU*kV&IlBP> literal 0 HcmV?d00001 diff --git a/route/app.php b/route/app.php index 7dccb74..09efa14 100644 --- a/route/app.php +++ b/route/app.php @@ -47,7 +47,8 @@ Route::group(function () { Route::get('/log', 'user/log'); Route::post('/account/data', 'domain/account_data'); - Route::post('/account/op', 'domain/account_op'); + Route::post('/account/:action', 'domain/account_op'); + Route::get('/account/:action', 'domain/account_add'); Route::get('/account', 'domain/account'); Route::any('/domain/expirenotice', 'domain/expire_notice');
    {{item.id}}{{item.name}}{{item.name}}