mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
Remove deprecated code
Signed-off-by: zu1k <i@zu1k.com>
This commit is contained in:
parent
d37da69c0f
commit
faf39c246f
@ -311,8 +311,7 @@ export NALI_HOME=/var/nali
|
||||
|
||||
## 感谢列表
|
||||
|
||||
- [纯真QQIP离线数据库](http://www.cz88.net/fox/ipdat.shtml)
|
||||
- [qqwry mirror](https://qqwry.mirror.noc.one/)
|
||||
- [纯真QQIP离线数据库](http://www.cz88.net)
|
||||
- [qqwry纯真数据库解析](https://github.com/yinheli/qqwry)
|
||||
- [ZX公网ipv6数据库](https://ip.zxinc.org/ipquery/)
|
||||
- [Geoip2 city数据库](https://www.maxmind.com/en/geoip2-precision-city-service)
|
||||
@ -323,7 +322,6 @@ export NALI_HOME=/var/nali
|
||||
- [ip2region数据库](https://github.com/lionsoul2014/ip2region)
|
||||
- [IP2Location DB3 LITE](https://lite.ip2location.com/database/db3-ip-country-region-city)
|
||||
- [Cobra CLI库](https://github.com/spf13/cobra)
|
||||
- [Nali-cli](https://github.com/SukkaW/nali-cli)
|
||||
|
||||
感谢 JetBrains 提供开源项目免费License
|
||||
|
||||
|
@ -237,7 +237,7 @@ supported database:
|
||||
- Geoip2 `['geoip', 'geoip2']`
|
||||
- Chunzhen `['chunzhen', 'qqwry']`
|
||||
- IPIP `['ipip']`
|
||||
- Ip2Resion `['ip2region', 'i2r']`
|
||||
- Ip2Region `['ip2region', 'i2r']`
|
||||
- DBIP `['dbip', 'db-ip']`
|
||||
- IP2Location `['ip2location']`
|
||||
|
||||
@ -304,8 +304,7 @@ export NALI_HOME=/home/nali
|
||||
|
||||
## Thanks
|
||||
|
||||
- [纯真QQIP离线数据库](http://www.cz88.net/fox/ipdat.shtml)
|
||||
- [qqwry mirror](https://qqwry.mirror.noc.one/)
|
||||
- [纯真QQIP离线数据库](http://www.cz88.net)
|
||||
- [qqwry纯真数据库解析](https://github.com/yinheli/qqwry)
|
||||
- [ZX公网ipv6数据库](https://ip.zxinc.org/ipquery/)
|
||||
- [Geoip2 city数据库](https://www.maxmind.com/en/geoip2-precision-city-service)
|
||||
@ -316,7 +315,6 @@ export NALI_HOME=/home/nali
|
||||
- [ip2region数据库](https://github.com/lionsoul2014/ip2region)
|
||||
- [IP2Location DB3 LITE](https://lite.ip2location.com/database/db3-ip-country-region-city) *use the IPv6 BIN as it contains both IPv4 & IPv6*
|
||||
- [Cobra CLI库](https://github.com/spf13/cobra)
|
||||
- [Nali-cli](https://github.com/SukkaW/nali-cli)
|
||||
|
||||
Thanks to JetBrains for the Open Source License
|
||||
|
||||
|
@ -5,10 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zu1k/nali/pkg/cdn"
|
||||
"github.com/zu1k/nali/pkg/download"
|
||||
"github.com/zu1k/nali/pkg/ip2region"
|
||||
"github.com/zu1k/nali/pkg/qqwry"
|
||||
"github.com/zu1k/nali/pkg/zxipv6wry"
|
||||
)
|
||||
|
||||
@ -57,15 +54,6 @@ func getUpdateFuncByName(name string) (func() error, string) {
|
||||
|
||||
// intenel download func
|
||||
switch db.Format {
|
||||
case FormatQQWry:
|
||||
return func() error {
|
||||
log.Println("正在下载最新 纯真 IPv4数据库...")
|
||||
_, err := qqwry.Download(getDbByName("qqwry").File)
|
||||
if err != nil {
|
||||
log.Println("数据库 QQWry 下载失败:", err)
|
||||
}
|
||||
return err
|
||||
}, FormatQQWry
|
||||
case FormatZXIPv6Wry:
|
||||
return func() error {
|
||||
log.Println("正在下载最新 ZX IPv6数据库...")
|
||||
@ -75,24 +63,6 @@ func getUpdateFuncByName(name string) (func() error, string) {
|
||||
}
|
||||
return err
|
||||
}, FormatZXIPv6Wry
|
||||
case FormatIP2Region:
|
||||
return func() error {
|
||||
log.Println("正在下载最新 Ip2Region 数据库...")
|
||||
_, err := ip2region.Download(getDbByName("ip2region").File)
|
||||
if err != nil {
|
||||
log.Println("数据库 Ip2Region 下载失败:", err)
|
||||
}
|
||||
return err
|
||||
}, FormatZXIPv6Wry
|
||||
case FormatCDNYml:
|
||||
return func() error {
|
||||
log.Println("正在下载最新 CDN服务提供商数据库...")
|
||||
_, err := cdn.Download(getDbByName("cdn").File)
|
||||
if err != nil {
|
||||
log.Println("数据库 CDN 下载失败:", err)
|
||||
}
|
||||
return err
|
||||
}, FormatZXIPv6Wry
|
||||
default:
|
||||
return func() error {
|
||||
log.Println("暂不支持该类型数据库的自动更新")
|
||||
|
@ -9,11 +9,19 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/zu1k/nali/pkg/download"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/zu1k/nali/pkg/re"
|
||||
)
|
||||
|
||||
var DownloadUrls = []string{
|
||||
"https://cdn.jsdelivr.net/gh/4ft35t/cdn/src/cdn.yml",
|
||||
"https://raw.githubusercontent.com/4ft35t/cdn/master/src/cdn.yml",
|
||||
"https://raw.githubusercontent.com/SukkaLab/cdn/master/src/cdn.yml",
|
||||
}
|
||||
|
||||
type CDN struct {
|
||||
Map map[string]CDNResult
|
||||
ReMap []CDNReTuple
|
||||
@ -38,7 +46,7 @@ func NewCDN(filePath string) (*CDN, error) {
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
log.Println("文件不存在,尝试从网络获取最新CDN数据库")
|
||||
fileData, err = Download(filePath)
|
||||
fileData, err = download.Download(filePath, DownloadUrls...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
package cdn
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/zu1k/nali/pkg/common"
|
||||
)
|
||||
|
||||
var DownloadUrls = []string{
|
||||
"https://cdn.jsdelivr.net/gh/4ft35t/cdn/src/cdn.yml",
|
||||
"https://raw.githubusercontent.com/4ft35t/cdn/master/src/cdn.yml",
|
||||
"https://raw.githubusercontent.com/SukkaLab/cdn/master/src/cdn.yml",
|
||||
}
|
||||
|
||||
// Deprecated: This will be removed from 0.5.0, use package download instead
|
||||
func Download(filePath ...string) (data []byte, err error) {
|
||||
data, err = common.GetHttpClient().Get(DownloadUrls...)
|
||||
if err != nil {
|
||||
log.Printf("CDN数据库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
||||
log.Println("下载链接:", DownloadUrls)
|
||||
return
|
||||
}
|
||||
|
||||
if len(filePath) == 1 {
|
||||
if err := common.SaveFile(filePath[0], data); err == nil {
|
||||
log.Printf("已将最新的 CDN数据库 保存到本地: %s \n", filePath)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
@ -8,11 +8,18 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/zu1k/nali/pkg/download"
|
||||
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/ip2region"
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
"github.com/zu1k/nali/pkg/common"
|
||||
)
|
||||
|
||||
var DownloadUrls = []string{
|
||||
"https://cdn.jsdelivr.net/gh/lionsoul2014/ip2region/data/ip2region.xdb",
|
||||
"https://raw.githubusercontent.com/lionsoul2014/ip2region/master/data/ip2region.xdb",
|
||||
}
|
||||
|
||||
type Ip2Region struct {
|
||||
seacher *xdb.Searcher
|
||||
db_old *ip2region.Ip2Region
|
||||
@ -22,7 +29,7 @@ func NewIp2Region(filePath string) (*Ip2Region, error) {
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
log.Println("文件不存在,尝试从网络获取最新 ip2region 库")
|
||||
_, err = Download(filePath)
|
||||
_, err = download.Download(filePath, DownloadUrls...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
package ip2region
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/zu1k/nali/pkg/common"
|
||||
)
|
||||
|
||||
var DownloadUrls = []string{
|
||||
"https://cdn.jsdelivr.net/gh/lionsoul2014/ip2region/data/ip2region.xdb",
|
||||
"https://raw.githubusercontent.com/lionsoul2014/ip2region/master/data/ip2region.xdb",
|
||||
}
|
||||
|
||||
// Deprecated: This will be removed from 0.5.0, use package download instead
|
||||
func Download(filePath ...string) (data []byte, err error) {
|
||||
data, err = common.GetHttpClient().Get(DownloadUrls...)
|
||||
if err != nil {
|
||||
log.Printf("CDN数据库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
||||
log.Println("下载链接:", DownloadUrls)
|
||||
return
|
||||
}
|
||||
|
||||
if len(filePath) == 1 {
|
||||
if err := common.SaveFile(filePath[0], data); err == nil {
|
||||
log.Println("已将最新的 ip2region 保存到本地:", filePath)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
@ -10,10 +10,16 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/zu1k/nali/pkg/download"
|
||||
|
||||
"github.com/zu1k/nali/pkg/common"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
)
|
||||
|
||||
var DownloadUrls = []string{
|
||||
"https://99wry.cf/qqwry.dat",
|
||||
}
|
||||
|
||||
type QQwry struct {
|
||||
common.IPDB
|
||||
}
|
||||
@ -26,7 +32,7 @@ func NewQQwry(filePath string) (*QQwry, error) {
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
log.Println("文件不存在,尝试从网络获取最新纯真 IP 库")
|
||||
fileData, err = Download(filePath)
|
||||
fileData, err = download.Download(filePath, DownloadUrls...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
package qqwry
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/zu1k/nali/pkg/common"
|
||||
)
|
||||
|
||||
var DownloadUrls = []string{
|
||||
"https://99wry.cf/qqwry.dat",
|
||||
}
|
||||
|
||||
func Download(filePath ...string) (data []byte, err error) {
|
||||
fmt.Println("此方式更新的 QQWry 数据库版本过旧,请手动下载最新版纯真免费IP库: https://www.cz88.net/help")
|
||||
|
||||
data, err = downloadAndDecrypt()
|
||||
if err != nil {
|
||||
log.Printf("纯真IP库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
||||
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
|
||||
return
|
||||
}
|
||||
|
||||
if len(filePath) == 1 {
|
||||
if err := common.SaveFile(filePath[0], data); err == nil {
|
||||
log.Println("已将最新的 纯真IP库 保存到本地:", filePath)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
mirror = "https://qqwry.mirror.noc.one/qqwry.rar"
|
||||
key = "https://qqwry.mirror.noc.one/copywrite.rar"
|
||||
)
|
||||
|
||||
func downloadAndDecrypt() (data []byte, err error) {
|
||||
data, err = common.GetHttpClient().Get(mirror)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
key, err := getCopyWriteKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return unRar(data, key)
|
||||
}
|
||||
|
||||
func unRar(data []byte, key uint32) ([]byte, error) {
|
||||
for i := 0; i < 0x200; i++ {
|
||||
key = key * 0x805
|
||||
key++
|
||||
key = key & 0xff
|
||||
|
||||
data[i] = byte(uint32(data[i]) ^ key)
|
||||
}
|
||||
|
||||
reader, err := zlib.NewReader(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ioutil.ReadAll(reader)
|
||||
}
|
||||
|
||||
func getCopyWriteKey() (uint32, error) {
|
||||
body, err := common.GetHttpClient().Get(key)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return binary.LittleEndian.Uint32(body[5*4:]), nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user