diff --git a/functions/ExtractDomain.php b/functions/ExtractDomain.php index 1c70a7c..87d3e85 100644 --- a/functions/ExtractDomain.php +++ b/functions/ExtractDomain.php @@ -1,20 +1,11 @@ open('./db/allTlds.db'); // 顶级域名数据库 - } -} - -class icpDB extends SQLite3 { - function __construct() { - $this->open('./db/icpTlds.db'); // 顶级域名数据库 - } -} - class extractDomain { + private $tldDB = './db/allTlds.db'; // 顶级域名数据库 + private $icpDB = './db/icpTlds.db'; // ICP备案数据库 + private function getAllTlds() { // 获取所有顶级域 含次级域 - $db = new tldDB; + $db = new SqliteDB($this->tldDB); $res = $db->query('SELECT tld FROM `tlds`;'); while ($row = $res->fetchArray(SQLITE3_ASSOC)) { $tlds[] = $row['tld']; @@ -28,7 +19,7 @@ class extractDomain { } private function getIcpTlds() { // 获取所有可ICP备案的顶级域 - $db = new icpDB; + $db = new SqliteDB($this->icpDB); $punycode = new Punycode(); $res = $db->query('SELECT tld FROM `tlds`;'); while ($row = $res->fetchArray(SQLITE3_ASSOC)) { diff --git a/functions/SqliteDB.php b/functions/SqliteDB.php new file mode 100644 index 0000000..88aa2d5 --- /dev/null +++ b/functions/SqliteDB.php @@ -0,0 +1,12 @@ +open($filename); + } + public function __destruct() { + $this->close(); + } +} + +?> \ No newline at end of file diff --git a/main.php b/main.php index 70f9b45..b3c1745 100644 --- a/main.php +++ b/main.php @@ -2,6 +2,7 @@ require_once 'cmdRoute.php'; require_once 'functions/Punycode.php'; +require_once 'functions/SqliteDB.php'; require_once 'functions/RedisCache.php'; require_once 'functions/TgInterface.php'; require_once 'functions/ExtractDomain.php'; diff --git a/models/kmsCheck.php b/models/kmsCheck.php index 7c43d25..1cedcfb 100644 --- a/models/kmsCheck.php +++ b/models/kmsCheck.php @@ -1,20 +1,15 @@ open('./db/kmsKeys.db'); // KMS密钥数据库 - } -} - class kmsKeys { + private $kmsDB = './db/kmsKeys.db'; // KMS密钥数据库 private function getVersionName($type, $version_id) { // 获取对应版本的名称 - $db = new kmsDB; + $db = new SqliteDB($this->kmsDB); $res = $db->query('SELECT * FROM `' . $type . '_version` WHERE version_id=' . $version_id . ';'); return $res->fetchArray(SQLITE3_ASSOC)['version_name']; } private function getKmsKeys($type) { // 获取所有版本的KMS密钥 - $db = new kmsDB; + $db = new SqliteDB($this->kmsDB); $res = $db->query('SELECT * FROM `' . $type . '`;'); while ($row = $res->fetchArray(SQLITE3_ASSOC)) { $index = $row['version']; diff --git a/models/ntpCheck.php b/models/ntpCheck.php index f134590..306f2c4 100644 --- a/models/ntpCheck.php +++ b/models/ntpCheck.php @@ -1,20 +1,16 @@ open('./db/ntpServer.db'); // NTP服务器数据库 - } -} - class ntpList { + private $ntpDB = './db/ntpServer.db'; // NTP服务器数据库 + private function getListName($list_id) { // 获取对应组的名称 - $db = new ntpDB; + $db = new SqliteDB($this->ntpDB); $res = $db->query('SELECT * FROM `ntp_list` WHERE id=' . $list_id . ';'); return $res->fetchArray(SQLITE3_ASSOC)['name']; } public function getNtpList() { // 获取所有NTP服务器地址 - $db = new ntpDB; + $db = new SqliteDB($this->ntpDB); $res = $db->query('SELECT * FROM `ntp_host`;'); while ($row = $res->fetchArray(SQLITE3_ASSOC)) { $index = $row['list_id'];