|
@ -1,14 +1,14 @@ |
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
class tldQueryEntry { |
|
|
class tldQueryEntry { // TLD信息查询入口 |
|
|
private $tldDB = './db/tldInfo.db'; |
|
|
private $tldDB = './db/tldInfo.db'; // TLD信息数据库 |
|
|
|
|
|
|
|
|
private function getTldInfo($tld) { |
|
|
private function getTldInfo($tld) { // 获取TLD详细信息 |
|
|
$db = new SqliteDB($this->tldDB); |
|
|
$db = new SqliteDB($this->tldDB); |
|
|
$res = $db->query('SELECT * FROM `iana` WHERE tld="' . $tld . '";'); |
|
|
$res = $db->query('SELECT * FROM `iana` WHERE tld="' . $tld . '";'); |
|
|
$info = $res->fetchArray(SQLITE3_ASSOC); |
|
|
$info = $res->fetchArray(SQLITE3_ASSOC); |
|
|
if (!$info) { return null; } |
|
|
if (!$info) { return null; } // 查无该TLD |
|
|
$info['manager'] = json_decode(base64_decode($info['manager']), true); |
|
|
$info['manager'] = json_decode(base64_decode($info['manager']), true); // Base64解码 + JSON解码 |
|
|
$info['admin_contact'] = json_decode(base64_decode($info['admin_contact']), true); |
|
|
$info['admin_contact'] = json_decode(base64_decode($info['admin_contact']), true); |
|
|
$info['tech_contact'] = json_decode(base64_decode($info['tech_contact']), true); |
|
|
$info['tech_contact'] = json_decode(base64_decode($info['tech_contact']), true); |
|
|
$info['nameserver'] = json_decode(base64_decode($info['nameserver']), true); |
|
|
$info['nameserver'] = json_decode(base64_decode($info['nameserver']), true); |
|
@ -16,14 +16,14 @@ class tldQueryEntry { |
|
|
return $info; |
|
|
return $info; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private function genMessage($info) { // 生成返回消息 |
|
|
private function genMessage($info, $icp, $subTld) { // 生成返回消息 |
|
|
$msg = '`' . $info['tld'] . '` `(` `' . $info['type']; |
|
|
$msg = '`' . (new Punycode)->decode($info['tld']) . '` `(` `' . $info['type']; |
|
|
if ($info['active'] === 'yes') { |
|
|
if ($info['active'] === 'yes') { // TLD是否有效解析 |
|
|
$msg .= '` `)`' . PHP_EOL; |
|
|
$msg .= '` `)`' . PHP_EOL; |
|
|
} else { |
|
|
} else { |
|
|
$msg .= ' not active` `)`' . PHP_EOL; |
|
|
$msg .= ' not active` `)`' . PHP_EOL; |
|
|
} |
|
|
} |
|
|
if (count($info['manager']) !== 0) { |
|
|
if (count($info['manager']) !== 0) { // 域名管理者信息 |
|
|
$msg .= '*Manager*' . PHP_EOL; |
|
|
$msg .= '*Manager*' . PHP_EOL; |
|
|
foreach ($info['manager']['name'] as $row) { |
|
|
foreach ($info['manager']['name'] as $row) { |
|
|
$msg .= ' ' . $row . PHP_EOL; |
|
|
$msg .= ' ' . $row . PHP_EOL; |
|
@ -32,7 +32,7 @@ class tldQueryEntry { |
|
|
$msg .= ' _' . $row . '_' . PHP_EOL; |
|
|
$msg .= ' _' . $row . '_' . PHP_EOL; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (count($info['admin_contact']) !== 0) { |
|
|
if (count($info['admin_contact']) !== 0) { // 域名管理员联系人 |
|
|
$contact = $info['admin_contact']; |
|
|
$contact = $info['admin_contact']; |
|
|
$msg .= '*Administrative Contact*' . PHP_EOL; |
|
|
$msg .= '*Administrative Contact*' . PHP_EOL; |
|
|
$msg .= ' ' . $contact['name'] . PHP_EOL; |
|
|
$msg .= ' ' . $contact['name'] . PHP_EOL; |
|
@ -50,7 +50,7 @@ class tldQueryEntry { |
|
|
$msg .= ' Fax: _' . $contact['fax'] . '_' . PHP_EOL; |
|
|
$msg .= ' Fax: _' . $contact['fax'] . '_' . PHP_EOL; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (count($info['tech_contact']) !== 0) { |
|
|
if (count($info['tech_contact']) !== 0) { // 域名技术支持联系人 |
|
|
$contact = $info['tech_contact']; |
|
|
$contact = $info['tech_contact']; |
|
|
$msg .= '*Technical Contact*' . PHP_EOL; |
|
|
$msg .= '*Technical Contact*' . PHP_EOL; |
|
|
$msg .= ' ' . $contact['name'] . PHP_EOL; |
|
|
$msg .= ' ' . $contact['name'] . PHP_EOL; |
|
@ -68,7 +68,7 @@ class tldQueryEntry { |
|
|
$msg .= ' Fax: _' . $contact['fax'] . '_' . PHP_EOL; |
|
|
$msg .= ' Fax: _' . $contact['fax'] . '_' . PHP_EOL; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (count($info['nameserver']) !== 0) { |
|
|
if (count($info['nameserver']) !== 0) { // 域名NS服务器信息 |
|
|
$nameserver = $info['nameserver']; |
|
|
$nameserver = $info['nameserver']; |
|
|
$msg .= '*Name Servers*' . PHP_EOL; |
|
|
$msg .= '*Name Servers*' . PHP_EOL; |
|
|
foreach ($nameserver as $host => $ips) { |
|
|
foreach ($nameserver as $host => $ips) { |
|
@ -78,52 +78,28 @@ class tldQueryEntry { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (count($info['dnssec']) !== 0) { |
|
|
if ($subTld !== null) { // 输出次级顶级域 |
|
|
|
|
|
$msg .= '*Sub TLD*' . PHP_EOL; |
|
|
|
|
|
foreach ($subTld as $tld) { |
|
|
|
|
|
$msg .= ' `' . (new Punycode)->decode($tld) . '`' . PHP_EOL; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (count($info['dnssec']) !== 0) { // 域名DNSSEC状态 |
|
|
if ($info['dnssec']['type'] === 1) { // 正常DNSSEC |
|
|
if ($info['dnssec']['type'] === 1) { // 正常DNSSEC |
|
|
$msg .= '*DNSSEC*' . PHP_EOL; |
|
|
$msg .= '*DNSSEC*' . PHP_EOL; |
|
|
foreach ($info['dnssec']['ds'] as $ds) { |
|
|
foreach ($info['dnssec']['ds'] as $ds) { |
|
|
$msg .= ' *Tag: ' . $ds['tag'] . '*' . PHP_EOL; |
|
|
$msg .= ' *Tag: ' . $ds['tag'] . '*' . PHP_EOL; |
|
|
if (strlen($ds['hash']) === 64) { |
|
|
if (strlen($ds['hash']) === 64) { // SHA256 |
|
|
$msg .= ' `' . substr($ds['hash'], 0, 32) . '`' . PHP_EOL; |
|
|
$msg .= ' `' . substr($ds['hash'], 0, 32) . '`' . PHP_EOL; |
|
|
$msg .= ' `' . substr($ds['hash'], -32) . '`' . PHP_EOL; |
|
|
$msg .= ' `' . substr($ds['hash'], -32) . '`' . PHP_EOL; |
|
|
} else if (strlen($ds['hash']) === 40){ |
|
|
} else if (strlen($ds['hash']) === 40){ // SHA1 |
|
|
$msg .= ' `' . substr($ds['hash'], 0, 32) . '`' . PHP_EOL; |
|
|
$msg .= ' `' . substr($ds['hash'], 0, 32) . '`' . PHP_EOL; |
|
|
$msg .= ' `' . substr($ds['hash'], -8) . '`' . PHP_EOL; |
|
|
$msg .= ' `' . substr($ds['hash'], -8) . '`' . PHP_EOL; |
|
|
} |
|
|
} |
|
|
$msg .= ' Algorithm: _' . $ds['algorithm']; |
|
|
$msg .= ' Algorithm: _' . $ds['algorithm'] . ' ('; // 算法类型 |
|
|
if ($ds['algorithm'] === '1') { |
|
|
$msg .= (new DNSSEC)->algorithmDesc($ds['algorithm']) . ')_' . PHP_EOL; |
|
|
$msg .= ' (RSA/MD5)'; |
|
|
$msg .= ' Digest type: _' . $ds['digest'] . ' ('; // 摘要类型 |
|
|
} else if ($ds['algorithm'] === '3') { |
|
|
$msg .= (new DNSSEC)->digestDesc($ds['digest']) . ')_' . PHP_EOL; |
|
|
$msg .= ' (DSA/SHA1)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '5') { |
|
|
|
|
|
$msg .= ' (RSA/SHA-1)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '6') { |
|
|
|
|
|
$msg .= ' (DSA-NSEC3-SHA1)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '7') { |
|
|
|
|
|
$msg .= ' (RSASHA1-NSEC3-SHA1)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '8') { |
|
|
|
|
|
$msg .= ' (RSA/SHA-256)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '10') { |
|
|
|
|
|
$msg .= ' (RSA/SHA-512)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '12') { |
|
|
|
|
|
$msg .= ' (GOST R 34.10-2001)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '13') { |
|
|
|
|
|
$msg .= ' (ECDSA Curve P-256 with SHA-256)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '14') { |
|
|
|
|
|
$msg .= ' (ECDSA Curve P-384 with SHA-384)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '15') { |
|
|
|
|
|
$msg .= ' (Ed25519)'; |
|
|
|
|
|
} else if ($ds['algorithm'] === '16') { |
|
|
|
|
|
$msg .= ' (Ed448)'; |
|
|
|
|
|
} |
|
|
|
|
|
$msg .= '_' . PHP_EOL; |
|
|
|
|
|
$msg .= ' Digest type: _' . $ds['digest']; |
|
|
|
|
|
if ($ds['digest'] === '1') { |
|
|
|
|
|
$msg .= ' (SHA-1)'; |
|
|
|
|
|
} else if ($ds['digest'] === '2') { |
|
|
|
|
|
$msg .= ' (SHA-256)'; |
|
|
|
|
|
} |
|
|
|
|
|
$msg .= '_' . PHP_EOL; |
|
|
|
|
|
} |
|
|
} |
|
|
} else if ($info['dnssec']['type'] === 3) { // 启用DNSSEC 但未部署DS记录 |
|
|
} else if ($info['dnssec']['type'] === 3) { // 启用DNSSEC 但未部署DS记录 |
|
|
$msg .= '*DNSSEC:* signed, but without DS record.' . PHP_EOL; |
|
|
$msg .= '*DNSSEC:* signed, but without DS record.' . PHP_EOL; |
|
@ -131,28 +107,53 @@ class tldQueryEntry { |
|
|
$msg .= '*DNSSEC:* unsigned' . PHP_EOL; |
|
|
$msg .= '*DNSSEC:* unsigned' . PHP_EOL; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if ($info['website'] != '') { |
|
|
if ($icp !== null) { // ICP备案信息 |
|
|
|
|
|
$msg .= '*ICP Detail*' . PHP_EOL; |
|
|
|
|
|
$msg .= ' 管理机构: '; |
|
|
|
|
|
if ($icp['org'] === '空') { |
|
|
|
|
|
$msg .= '未知' . PHP_EOL; |
|
|
|
|
|
} else { |
|
|
|
|
|
$msg .= $icp['org'] . PHP_EOL; |
|
|
|
|
|
$msg .= ' 机构主页: '; |
|
|
|
|
|
foreach ($icp['site'] as $site) { |
|
|
|
|
|
$msg .= '`' . $site . '` '; |
|
|
|
|
|
} |
|
|
|
|
|
$msg .= PHP_EOL; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if ($info['website'] != '') { // 所有者主页 |
|
|
$msg .= '*Website:* ' . $info['website'] . PHP_EOL; |
|
|
$msg .= '*Website:* ' . $info['website'] . PHP_EOL; |
|
|
} |
|
|
} |
|
|
if ($info['whois'] != '') { |
|
|
if ($info['whois'] != '') { // Whois服务器信息 |
|
|
$msg .= '*Whois Server:* `' . $info['whois'] . '`' . PHP_EOL; |
|
|
$msg .= '*Whois Server:* `' . $info['whois'] . '`' . PHP_EOL; |
|
|
} |
|
|
} |
|
|
$msg .= '*Registration date:* _' . $info['regist_date'] . '_' . PHP_EOL; |
|
|
$msg .= '*Registration date:* _' . $info['regist_date'] . '_' . PHP_EOL; // 注册日期 |
|
|
$msg .= '*Record last updated:* _' . $info['last_updated'] . '_' . PHP_EOL; |
|
|
$msg .= '*Record last updated:* _' . $info['last_updated'] . '_' . PHP_EOL; // 最后更改时间 |
|
|
return $msg; |
|
|
return $msg; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function query($rawParam) { // TLD数据查询入口 |
|
|
public function query($rawParam) { // TLD数据查询入口 |
|
|
|
|
|
if ($rawParam == '' || $rawParam === 'help') { |
|
|
|
|
|
tgApi::sendMessage(array( // 发送使用说明 |
|
|
|
|
|
'parse_mode' => 'Markdown', |
|
|
|
|
|
'text' => '*Usage:* `/tld top-level-domain`', |
|
|
|
|
|
)); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
if (substr($rawParam, 0, 1) !== '.') { // 补上. |
|
|
if (substr($rawParam, 0, 1) !== '.') { // 补上. |
|
|
$rawParam = '.' . $rawParam; |
|
|
$rawParam = '.' . $rawParam; |
|
|
} |
|
|
} |
|
|
|
|
|
$rawParam = (new Punycode)->encode($rawParam); |
|
|
$info = $this->getTldInfo($rawParam); |
|
|
$info = $this->getTldInfo($rawParam); |
|
|
if (!$info) { |
|
|
if (!$info) { // 查无该TLD |
|
|
tgApi::sendMarkdown('`' . $rawParam . '`' . PHP_EOL . 'TLD not found'); |
|
|
$rawParam = (new Punycode)->decode($rawParam); |
|
|
|
|
|
tgApi::sendMarkdown('`' . $rawParam . '`' . ' not found'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
$icp = (new Domain)->icpTldInfo($rawParam); // 查询ICP信息 |
|
|
|
|
|
$subTld = (new Domain)->getSubTld($rawParam); // 查询次级域信息 |
|
|
tgApi::sendMessage(array( |
|
|
tgApi::sendMessage(array( |
|
|
'text' => $this->genMessage($info), |
|
|
'text' => $this->genMessage($info, $icp, $subTld), |
|
|
'parse_mode' => 'Markdown', // Markdown格式输出 |
|
|
'parse_mode' => 'Markdown', // Markdown格式输出 |
|
|
'disable_web_page_preview' => 'true' // 不显示页面预览 |
|
|
'disable_web_page_preview' => 'true' // 不显示页面预览 |
|
|
)); |
|
|
)); |
|
|