[Skip CI]
This commit is contained in:
@ -41,6 +41,7 @@ type General struct {
|
||||
LogLevel log.LogLevel `json:"log-level"`
|
||||
IPv6 bool `json:"ipv6"`
|
||||
Interface string `json:"-"`
|
||||
GeodataMode string `json:"geodata-mode"`
|
||||
GeodataLoader string `json:"geodata-loader"`
|
||||
AutoIptables bool `json:"auto-iptables"`
|
||||
}
|
||||
@ -172,6 +173,7 @@ type RawConfig struct {
|
||||
ExternalUI string `yaml:"external-ui"`
|
||||
Secret string `yaml:"secret"`
|
||||
Interface string `yaml:"interface-name"`
|
||||
GeodataMode string `yaml:"geodata-mode"`
|
||||
GeodataLoader string `yaml:"geodata-loader"`
|
||||
AutoIptables bool `yaml:"auto-iptables"`
|
||||
|
||||
@ -204,6 +206,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
||||
AllowLan: false,
|
||||
BindAddress: "*",
|
||||
Mode: T.Rule,
|
||||
GeodataMode: "dat",
|
||||
GeodataLoader: "memconservative",
|
||||
AutoIptables: false,
|
||||
UnifiedDelay: false,
|
||||
|
@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Dreamacro/clash/component/geodata"
|
||||
"github.com/Dreamacro/clash/component/mmdb"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -11,6 +12,8 @@ import (
|
||||
"github.com/Dreamacro/clash/log"
|
||||
)
|
||||
|
||||
var GeodataMode bool
|
||||
|
||||
func downloadMMDB(path string) (err error) {
|
||||
resp, err := http.Get("https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country.mmdb")
|
||||
if err != nil {
|
||||
@ -71,16 +74,38 @@ func initGeoSite() error {
|
||||
log.Infoln("Download GeoSite.dat finish")
|
||||
}
|
||||
|
||||
if !geodata.Verify(C.GeositeName) {
|
||||
log.Warnln("GeoSite.dat invalid, remove and download")
|
||||
if err := os.Remove(C.Path.GeoSite()); err != nil {
|
||||
return fmt.Errorf("can't remove invalid GeoSite.dat: %s", err.Error())
|
||||
}
|
||||
if err := downloadGeoSite(C.Path.GeoSite()); err != nil {
|
||||
return fmt.Errorf("can't download GeoSite.dat: %s", err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func initGeoIP() error {
|
||||
if _, err := os.Stat(C.Path.GeoIP()); os.IsNotExist(err) {
|
||||
log.Infoln("Need GeoIP but can't find GeoIP.dat, start download")
|
||||
if err := downloadGeoIP(C.Path.GeoIP()); err != nil {
|
||||
return fmt.Errorf("can't download GeoIP.dat: %s", err.Error())
|
||||
if GeodataMode {
|
||||
if _, err := os.Stat(C.Path.GeoIP()); os.IsNotExist(err) {
|
||||
log.Infoln("Need GeoIP but can't find GeoIP.dat, start download")
|
||||
if err := downloadGeoIP(C.Path.GeoIP()); err != nil {
|
||||
return fmt.Errorf("can't download GeoIP.dat: %s", err.Error())
|
||||
}
|
||||
log.Infoln("Download GeoIP.dat finish")
|
||||
}
|
||||
log.Infoln("Download GeoIP.dat finish")
|
||||
|
||||
if !geodata.Verify(C.GeoipName) {
|
||||
log.Warnln("GeoIP.dat invalid, remove and download")
|
||||
if err := os.Remove(C.Path.GeoIP()); err != nil {
|
||||
return fmt.Errorf("can't remove invalid GeoIP.dat: %s", err.Error())
|
||||
}
|
||||
if err := downloadGeoIP(C.Path.GeoIP()); err != nil {
|
||||
return fmt.Errorf("can't download GeoIP.dat: %s", err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := os.Stat(C.Path.MMDB()); os.IsNotExist(err) {
|
||||
|
Reference in New Issue
Block a user