Browse Source

update: new interface of sqlite database

master
Dnomd343 3 years ago
parent
commit
060c3809d4
  1. 19
      functions/ExtractDomain.php
  2. 12
      functions/SqliteDB.php
  3. 1
      main.php
  4. 11
      models/kmsCheck.php
  5. 12
      models/ntpCheck.php

19
functions/ExtractDomain.php

@ -1,20 +1,11 @@
<?php <?php
class tldDB extends SQLite3 {
function __construct() {
$this->open('./db/allTlds.db'); // 顶级域名数据库
}
}
class icpDB extends SQLite3 {
function __construct() {
$this->open('./db/icpTlds.db'); // 顶级域名数据库
}
}
class extractDomain { class extractDomain {
private $tldDB = './db/allTlds.db'; // 顶级域名数据库
private $icpDB = './db/icpTlds.db'; // ICP备案数据库
private function getAllTlds() { // 获取所有顶级域 含次级域 private function getAllTlds() { // 获取所有顶级域 含次级域
$db = new tldDB; $db = new SqliteDB($this->tldDB);
$res = $db->query('SELECT tld FROM `tlds`;'); $res = $db->query('SELECT tld FROM `tlds`;');
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$tlds[] = $row['tld']; $tlds[] = $row['tld'];
@ -28,7 +19,7 @@ class extractDomain {
} }
private function getIcpTlds() { // 获取所有可ICP备案的顶级域 private function getIcpTlds() { // 获取所有可ICP备案的顶级域
$db = new icpDB; $db = new SqliteDB($this->icpDB);
$punycode = new Punycode(); $punycode = new Punycode();
$res = $db->query('SELECT tld FROM `tlds`;'); $res = $db->query('SELECT tld FROM `tlds`;');
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { while ($row = $res->fetchArray(SQLITE3_ASSOC)) {

12
functions/SqliteDB.php

@ -0,0 +1,12 @@
<?php
class SqliteDB extends SQLite3 { // Sqlite3数据库
public function __construct($filename) {
$this->open($filename);
}
public function __destruct() {
$this->close();
}
}
?>

1
main.php

@ -2,6 +2,7 @@
require_once 'cmdRoute.php'; require_once 'cmdRoute.php';
require_once 'functions/Punycode.php'; require_once 'functions/Punycode.php';
require_once 'functions/SqliteDB.php';
require_once 'functions/RedisCache.php'; require_once 'functions/RedisCache.php';
require_once 'functions/TgInterface.php'; require_once 'functions/TgInterface.php';
require_once 'functions/ExtractDomain.php'; require_once 'functions/ExtractDomain.php';

11
models/kmsCheck.php

@ -1,20 +1,15 @@
<?php <?php
class kmsDB extends SQLite3 {
function __construct() {
$this->open('./db/kmsKeys.db'); // KMS密钥数据库
}
}
class kmsKeys { class kmsKeys {
private $kmsDB = './db/kmsKeys.db'; // KMS密钥数据库
private function getVersionName($type, $version_id) { // 获取对应版本的名称 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 . ';'); $res = $db->query('SELECT * FROM `' . $type . '_version` WHERE version_id=' . $version_id . ';');
return $res->fetchArray(SQLITE3_ASSOC)['version_name']; return $res->fetchArray(SQLITE3_ASSOC)['version_name'];
} }
private function getKmsKeys($type) { // 获取所有版本的KMS密钥 private function getKmsKeys($type) { // 获取所有版本的KMS密钥
$db = new kmsDB; $db = new SqliteDB($this->kmsDB);
$res = $db->query('SELECT * FROM `' . $type . '`;'); $res = $db->query('SELECT * FROM `' . $type . '`;');
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$index = $row['version']; $index = $row['version'];

12
models/ntpCheck.php

@ -1,20 +1,16 @@
<?php <?php
class ntpDB extends SQLite3 {
public function __construct() {
$this->open('./db/ntpServer.db'); // NTP服务器数据库
}
}
class ntpList { class ntpList {
private $ntpDB = './db/ntpServer.db'; // NTP服务器数据库
private function getListName($list_id) { // 获取对应组的名称 private function getListName($list_id) { // 获取对应组的名称
$db = new ntpDB; $db = new SqliteDB($this->ntpDB);
$res = $db->query('SELECT * FROM `ntp_list` WHERE id=' . $list_id . ';'); $res = $db->query('SELECT * FROM `ntp_list` WHERE id=' . $list_id . ';');
return $res->fetchArray(SQLITE3_ASSOC)['name']; return $res->fetchArray(SQLITE3_ASSOC)['name'];
} }
public function getNtpList() { // 获取所有NTP服务器地址 public function getNtpList() { // 获取所有NTP服务器地址
$db = new ntpDB; $db = new SqliteDB($this->ntpDB);
$res = $db->query('SELECT * FROM `ntp_host`;'); $res = $db->query('SELECT * FROM `ntp_host`;');
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$index = $row['list_id']; $index = $row['list_id'];

Loading…
Cancel
Save