diff --git a/app/common.php b/app/common.php index 2f391d9..d833b2b 100644 --- a/app/common.php +++ b/app/common.php @@ -456,4 +456,19 @@ function curl_set_proxy(&$ch) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_userpwd); } curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy_type); +} + +function convertDomainToAscii($domain) { + if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $domain)) { + return idn_to_ascii($domain); + } else { + return $domain; + } +} +function convertDomainToUtf8($domain) { + if (preg_match('/^xn--/', $domain)) { + return idn_to_utf8($domain); + } else { + return $domain; + } } \ No newline at end of file diff --git a/app/controller/Cert.php b/app/controller/Cert.php index d8d56f7..5e039e8 100644 --- a/app/controller/Cert.php +++ b/app/controller/Cert.php @@ -272,7 +272,7 @@ class Cert extends BaseController foreach($domains as $domain){ $domainList[] = [ 'oid' => $id, - 'domain' => $domain, + 'domain' => convertDomainToAscii($domain), 'sort' => $i++, ]; } @@ -310,7 +310,7 @@ class Cert extends BaseController foreach($domains as $domain){ $domainList[] = [ 'oid' => $id, - 'domain' => $domain, + 'domain' => convertDomainToAscii($domain), 'sort' => $i++, ]; } @@ -441,7 +441,8 @@ class Cert extends BaseController } foreach($domains as $domain){ - if(!$wildcard && strpos($domain, '*') !== false) return ['code' => -1, 'msg' => '该证书账户类型不支持泛域名']; + if (!$wildcard && strpos($domain, '*') !== false) return ['code' => -1, 'msg' => '该证书账户类型不支持泛域名']; + if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $domain) && !function_exists('idn_to_ascii')) return ['code' => -1, 'msg' => '域名包含中文,请开启intl扩展']; $mainDomain = getMainDomain($domain); $drow = Db::name('domain')->where('name', $mainDomain)->find(); if (!$drow) { diff --git a/app/controller/Dmonitor.php b/app/controller/Dmonitor.php index f62120f..9361cb9 100644 --- a/app/controller/Dmonitor.php +++ b/app/controller/Dmonitor.php @@ -87,6 +87,7 @@ class Dmonitor extends BaseController 'cycle' => input('post.cycle/d'), 'timeout' => input('post.timeout/d'), 'proxy' => input('post.proxy/d'), + 'cdn' => input('post.cdn') == 'true' || input('post.cdn') == '1' ? 1 : 0, 'remark' => input('post.remark', null, 'trim'), 'recordinfo' => input('post.recordinfo', null, 'trim'), 'addtime' => time(), @@ -123,6 +124,7 @@ class Dmonitor extends BaseController 'cycle' => input('post.cycle/d'), 'timeout' => input('post.timeout/d'), 'proxy' => input('post.proxy/d'), + 'cdn' => input('post.cdn') == 'true' || input('post.cdn') == '1' ? 1 : 0, 'remark' => input('post.remark', null, 'trim'), 'recordinfo' => input('post.recordinfo', null, 'trim'), ]; @@ -163,8 +165,9 @@ class Dmonitor extends BaseController } $domains = []; - foreach (Db::name('domain')->select() as $row) { - $domains[$row['id']] = $row['name']; + $domainList = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->field('A.id,A.name,B.type')->select(); + foreach ($domainList as $row) { + $domains[] = ['id'=>$row['id'], 'name'=>$row['name'], 'type'=>$row['type']]; } View::assign('domains', $domains); diff --git a/app/controller/Domain.php b/app/controller/Domain.php index 2fa559c..8abac0b 100644 --- a/app/controller/Domain.php +++ b/app/controller/Domain.php @@ -241,6 +241,7 @@ class Domain extends BaseController $is_hide = input('post.is_hide/d'); $is_sso = input('post.is_sso/d'); $remark = input('post.remark', null, 'trim'); + if (empty($remark)) $remark = null; Db::name('domain')->where('id', $id)->update([ 'is_hide' => $is_hide, 'is_sso' => $is_sso, @@ -273,6 +274,22 @@ class Domain extends BaseController } Db::name('domain')->insertAll($data); return json(['code' => 0, 'msg' => '成功添加' . count($data) . '个域名!']); + } elseif ($act == 'batchedit') { + if (!checkPermission(2)) return $this->alert('error', '无权限'); + $ids = input('post.ids'); + if (empty($ids)) return json(['code' => -1, 'msg' => '参数不能为空']); + $remark = input('post.remark', null, 'trim'); + if (empty($remark)) $remark = null; + Db::name('domain')->where('id', 'in', $ids)->update(['remark' => $remark]); + return json(['code' => 0, 'msg' => '成功修改' . count($ids) . '个域名!']); + } elseif ($act == 'batchdel') { + if (!checkPermission(2)) return $this->alert('error', '无权限'); + $ids = input('post.ids'); + if (empty($ids)) return json(['code' => -1, 'msg' => '参数不能为空']); + Db::name('domain')->where('id', 'in', $ids)->delete(); + Db::name('dmtask')->where('did', 'in', $ids)->delete(); + Db::name('optimizeip')->where('did', 'in', $ids)->delete(); + return json(['code' => 0, 'msg' => '成功删除' . count($ids) . '个域名!']); } return json(['code' => -3]); } diff --git a/app/service/CertOrderService.php b/app/service/CertOrderService.php index 7acc67e..d26a2eb 100644 --- a/app/service/CertOrderService.php +++ b/app/service/CertOrderService.php @@ -68,7 +68,11 @@ class CertOrderService $cname = CertHelper::$cert_config[$this->atype]['cname']; foreach($this->domainList as $domain){ $mainDomain = getMainDomain($domain); - if (!Db::name('domain')->where('name', $mainDomain)->find()) { + $drow = Db::name('domain')->where('name', $mainDomain)->find(); + if (!$drow && preg_match('/^xn--/', $mainDomain)) { + $drow = Db::name('domain')->where('name', idn_to_utf8($mainDomain))->find(); + } + if (!$drow) { if (substr($domain, 0, 2) == '*.') $domain = substr($domain, 2); $cname_row = Db::name('cert_cname')->where('domain', $domain)->where('status', 1)->find(); if (!$cname || !$cname_row) { diff --git a/app/service/TaskRunner.php b/app/service/TaskRunner.php index 387bba2..5f0fd8e 100644 --- a/app/service/TaskRunner.php +++ b/app/service/TaskRunner.php @@ -83,6 +83,9 @@ class TaskRunner if ($row['type'] == 2) { $dns = DnsHelper::getModel2($drow); $recordinfo = json_decode($row['recordinfo'], true); + if ($drow['type'] == 'cloudflare' && $row['cdn'] == 1) { + $recordinfo['Line'] = '1'; + } $res = $dns->updateDomainRecord($row['recordid'], $row['rr'], getDnsType($row['backup_value']), $row['backup_value'], $recordinfo['Line'], $recordinfo['TTL']); if (!$res) { $this->db()->name('log')->insert(['uid' => 0, 'domain' => $drow['name'], 'action' => '修改解析失败', 'data' => $dns->getError(), 'addtime' => date("Y-m-d H:i:s")]); @@ -98,6 +101,9 @@ class TaskRunner if ($row['type'] == 2) { $dns = DnsHelper::getModel2($drow); $recordinfo = json_decode($row['recordinfo'], true); + if ($drow['type'] == 'cloudflare' && $row['cdn'] == 1) { + $recordinfo['Line'] = '0'; + } $res = $dns->updateDomainRecord($row['recordid'], $row['rr'], getDnsType($row['main_value']), $row['main_value'], $recordinfo['Line'], $recordinfo['TTL']); if (!$res) { $this->db()->name('log')->insert(['uid' => 0, 'domain' => $drow['name'], 'action' => '修改解析失败', 'data' => $dns->getError(), 'addtime' => date("Y-m-d H:i:s")]); diff --git a/app/sql/install.sql b/app/sql/install.sql index 6a2a092..de1fd85 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', '1021'); +INSERT INTO `dnsmgr_config` VALUES ('version', '1028'); 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'); @@ -96,6 +96,7 @@ CREATE TABLE `dnsmgr_dmtask` ( `timeout` tinyint(5) NOT NULL DEFAULT 2, `remark` varchar(100) DEFAULT NULL, `proxy` tinyint(1) NOT NULL DEFAULT 0, + `cdn` tinyint(1) NOT NULL DEFAULT 0, `addtime` int(11) NOT NULL DEFAULT 0, `checktime` int(11) NOT NULL DEFAULT 0, `checknexttime` int(11) NOT NULL DEFAULT 0, diff --git a/app/sql/update.sql b/app/sql/update.sql index 05d3ac7..a6e415c 100644 --- a/app/sql/update.sql +++ b/app/sql/update.sql @@ -152,4 +152,7 @@ CREATE TABLE IF NOT EXISTS `dnsmgr_cert_cname` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ALTER TABLE `dnsmgr_account` -ADD COLUMN `proxy` tinyint(1) NOT NULL DEFAULT '0'; \ No newline at end of file +ADD COLUMN `proxy` tinyint(1) NOT NULL DEFAULT '0'; + +ALTER TABLE `dnsmgr_dmtask` +ADD COLUMN `cdn` tinyint(1) NOT NULL DEFAULT 0; \ No newline at end of file diff --git a/app/utils/CertDnsUtils.php b/app/utils/CertDnsUtils.php index f1f951b..0c58ada 100644 --- a/app/utils/CertDnsUtils.php +++ b/app/utils/CertDnsUtils.php @@ -13,6 +13,9 @@ class CertDnsUtils $cnameDomainList = []; foreach ($dnsList as $mainDomain => $list) { $drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.name', $mainDomain)->field('A.*,B.type')->find(); + if (!$drow && preg_match('/^xn--/', $mainDomain)) { + $drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.name', idn_to_utf8($mainDomain))->field('A.*,B.type')->find(); + } if (!$drow) { if ($cname) { foreach ($list as $key => $row) { @@ -102,6 +105,9 @@ class CertDnsUtils $cnameDomainList = []; foreach ($dnsList as $mainDomain => $list) { $drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.name', $mainDomain)->field('A.*,B.type')->find(); + if (!$drow && preg_match('/^xn--/', $mainDomain)) { + $drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.name', idn_to_utf8($mainDomain))->field('A.*,B.type')->find(); + } if (!$drow) { if ($cname) { foreach ($list as $key => $row) { diff --git a/app/view/common/layout.html b/app/view/common/layout.html index c177a6c..8ddae69 100644 --- a/app/view/common/layout.html +++ b/app/view/common/layout.html @@ -119,8 +119,8 @@