From 09bd5b58354dbb47f832a7e61fd7335d527a7f1a Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 12 Aug 2021 16:18:14 +0800 Subject: [PATCH] update: filter of ICP tlds, remove .lnk from icpTlds.db --- db/icpTlds.db | Bin 20480 -> 20480 bytes models/icpQuery.php | 31 ++++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/db/icpTlds.db b/db/icpTlds.db index 2b5682d5b6e39e5172483b71ac40c27c6bd8c7a8..591deee99edb1ac191c345a06479a016418473c6 100644 GIT binary patch delta 87 zcmZozz}T>Wae}lUHvWae}lUCj$cmD-go~^F$qEeoh8G>yNxZAx8cd2L6`Kf&yavn_KuB44Bo} zOeV8Ccr&q?Y%F}hD#6{T#3CxptCy3P{e0yvlSV}rNl#V1#N^3}TDqGn-P$<;2;vuf diff --git a/models/icpQuery.php b/models/icpQuery.php index 87b5c02..2980686 100644 --- a/models/icpQuery.php +++ b/models/icpQuery.php @@ -50,6 +50,26 @@ class icpQuery { } class icpQueryEntry { + private function getIcpTlds() { // 获取所有可ICP备案的顶级域 + $db = new icpDB; + $punycode = new Punycode(); + $res = $db->query('SELECT tld FROM `tlds`;'); + while ($row = $res->fetchArray(SQLITE3_ASSOC)) { + $tlds[] = $punycode->encode($row['tld']); // 转为Punycode编码 + } + return $tlds; // Unicode字符使用Punycode编码 + } + + private function isIcpEnable($tld) { // 检查TLD是否允许ICP备案 + $icpTlds = $this->getIcpTlds(); + foreach ($icpTlds as $icpTld) { // 遍历所有可ICP域名 + if ($icpTld === $tld) { + return true; // 允许备案 + } + } + return false; // 无法备案 + } + private function check($str) { // 检查输入参数 $content = (new extractDomain)->analyse($str); if (!isset($content['domain'])) { // 格式错误 @@ -64,6 +84,12 @@ class icpQueryEntry { 'message' => 'Unknow TLD' ); } + if (!$this->isIcpEnable($content['tld'])) { + return array( + 'status' => 'error', + 'message' => '`' . $content['tld'] . '` is not allowed in ICP' + ); + } return array( 'status' => 'ok', 'domain' => $content['site'] // 返回主域名 @@ -80,7 +106,10 @@ class icpQueryEntry { } $content = $this->check($rawParam); if ($content['status'] !== 'ok') { // 请求参数错误 - tgApi::sendText($content['message']); + tgApi::sendMessage(array( + 'parse_mode' => 'Markdown', + 'text' => $content['message'] + )); return; } $domain = $content['domain'];