From 64ab30f95c79b3a926e9c6165371150ddba9406e Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 12 Aug 2021 00:18:06 +0800 Subject: [PATCH] update: dump kms keys from sqlite3 database locally --- db/kmsKeys.db | Bin 0 -> 20480 bytes models/kmsCheck.php | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 db/kmsKeys.db diff --git a/db/kmsKeys.db b/db/kmsKeys.db new file mode 100644 index 0000000000000000000000000000000000000000..9e77a9c1c5f87cbe3342fb549b5ef04c910f3d81 GIT binary patch literal 20480 zcmeI3U6AF*Rmbnl)qHgH4483aRGS+$-I4`kY@MwWR*{-OA7HUf!`k^z6lFwlCXG>yFmcRBO|=Tdfww z*9^Y;+X;MQ^*`YMsgd`S-qIHQ>%%K})LQ=4R_F26?UgU%n`UbWGz1y~4S|M0L!cqh z5NHTA1pc2BxN_W@TYK=qsTV(fdHVxT?>x7A0WR%a{OHcb;ky}8bkFFnth@c`0&p2WA~%`OS{irShsgCT;BP)or|}d ziSy}}F3y}y_3e$R^F{Y;klJy#wjWyW`*_$cx~f}rQ_HnhhK2pb88zLQ&-+~fKA``5Ji8FHHlUK3w>s{ zqU(iZW2W7pTii~epWu^|=w`*)A&4RJ25r4cH+d;m6d+teWwVZ|91Kii2jj2kpJcG={=jzbw1YW z{72_n=X;&M?tHcLGJb5fhCoB0ANo#=mbe_~^Ky4`wU z@OgP^W#@5OSZWC}r{oeav@m=NC9p&$XrF1SfhNrLE%%)hEmN6=q{LoJOCM6U3T9DU?sF)Av~2+ataD zGS>RQ+D_}z1lXTdnqYnCyv{*nx#t06xf0e--))^a%AVckJn$^mIlz2i zX$bRDFeNa0G)Mno_5Je=xO^p|VB0^RmMB+*u$C&ooeDOBJ(JZ4RO%xQN;W$Vn7&8>gkp)!5 z&-L`F1~G z!skGWI?tz1%^hg3ZCow+Fe0B;{zc= zxKKt8VGx8WG7x$)q-Xq0&qg2vB0rS9uf>2r?;Y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r!8E$GB%ijeVqr1!8;iopen('./db/kmsKeys.db'); // KMS密钥数据库 + } +} + +class kmsKeys { + private function getVersionName($type, $version_id) { // 获取对应版本的名称 + $db = new 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; + $res = $db->query('SELECT * FROM `' . $type . '`;'); + while ($row = $res->fetchArray(SQLITE3_ASSOC)) { + $index = $row['version']; + unset($row['version']); + $data[$this->getVersionName($type, $index)][] = $row; + } + return $data; + } - public function getKmsKeys($type) { + public function getKeys($type) { // 获取指定类型KMS密钥 switch ($type) { case '': - $url = $this->api . 'json'; - break; + return $this->getKmsKeys('win') + $this->getKmsKeys('win-server'); case 'win': + return $this->getKmsKeys('win'); case 'win-server': - $url = $this->api . $type . '/json'; - break; + return $this->getKmsKeys('win-server'); default: return array(); } - return json_decode(file_get_contents($url), true); } +} + +class kmsCheck { + private $api = 'https://kms.343.re/'; public function kmsStatus($host, $port) { $server = $host . ':' . $port; @@ -108,7 +131,7 @@ class kmsCheckEntry { } private function getKmsVersions($type) { // 获取win或win-server的版本列表 - $kmsKeys = (new kmsCheck)->getKmsKeys($type); + $kmsKeys = (new kmsKeys)->getKeys($type); foreach ($kmsKeys as $version => $kmsKey) { $buttons[] = array([ // 生成按钮列表 'text' => $version, @@ -128,7 +151,7 @@ class kmsCheckEntry { } private function getKmsKeys($targetVersion) { // 显示指定版本的KMS密钥列表 - $kmsKeys = (new kmsCheck)->getKmsKeys(''); + $kmsKeys = (new kmsKeys)->getKeys(''); foreach ($kmsKeys as $version => $kmsKey) { // 比对压缩以后的名称 if ($this->simpStr($version) === $targetVersion) { break; } // 匹配成功 }