add basic routing and block ads, remove old geo assets
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
@@ -383,24 +384,68 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
Rules: routeRules,
|
||||
AutoDetectInterface: true,
|
||||
OverrideAndroidVPN: true,
|
||||
// RuleSet: []option.RuleSet{
|
||||
// {
|
||||
// Type: C.RuleSetTypeRemote,
|
||||
// Tag: "geoip-" + opt,
|
||||
// RemoteOptions: option.RemoteRuleSet{
|
||||
// URL: "https://raw.githubusercontent.com/Chocolate4U/Iran-sing-box-rules/rule-set/geoip-ir.srs",
|
||||
// UpdateInterval: option.Duration(5 * time.day),
|
||||
// },
|
||||
// },
|
||||
// RuleSet: []option.RuleSet{},
|
||||
// GeoIP: &option.GeoIPOptions{
|
||||
// Path: opt.GeoIPPath,
|
||||
// },
|
||||
// Geosite: &option.GeositeOptions{
|
||||
// Path: opt.GeoSitePath,
|
||||
// },
|
||||
GeoIP: &option.GeoIPOptions{
|
||||
Path: opt.GeoIPPath,
|
||||
},
|
||||
Geosite: &option.GeositeOptions{
|
||||
Path: opt.GeoSitePath,
|
||||
},
|
||||
}
|
||||
fmt.Println("Region==========================", opt.Region)
|
||||
if opt.Region != "other" {
|
||||
|
||||
options.Route.RuleSet = append(options.Route.RuleSet, option.RuleSet{
|
||||
Type: C.RuleSetTypeRemote,
|
||||
Tag: "geoip-" + opt.Region,
|
||||
RemoteOptions: option.RemoteRuleSet{
|
||||
URL: "https://raw.githubusercontent.com/Chocolate4U/Iran-sing-box-rules/rule-set/geoip-" + opt.Region + ".srs",
|
||||
UpdateInterval: option.Duration(5 * time.Hour * 24),
|
||||
},
|
||||
})
|
||||
options.Route.RuleSet = append(options.Route.RuleSet, option.RuleSet{
|
||||
Type: C.RuleSetTypeRemote,
|
||||
Tag: "geosite-" + opt.Region,
|
||||
RemoteOptions: option.RemoteRuleSet{
|
||||
URL: "https://raw.githubusercontent.com/Chocolate4U/Iran-sing-box-rules/rule-set/geosite-" + opt.Region + ".srs",
|
||||
UpdateInterval: option.Duration(5 * time.Hour * 24),
|
||||
},
|
||||
})
|
||||
|
||||
routeRuleIp := option.Rule{
|
||||
Type: C.RuleTypeDefault,
|
||||
DefaultOptions: option.DefaultRule{
|
||||
RuleSet: []string{"geoip-" + opt.Region},
|
||||
Outbound: OutboundDirectTag,
|
||||
},
|
||||
}
|
||||
routeRuleSite := option.Rule{
|
||||
Type: C.RuleTypeDefault,
|
||||
DefaultOptions: option.DefaultRule{
|
||||
RuleSet: []string{"geosite-" + opt.Region},
|
||||
Outbound: OutboundDirectTag,
|
||||
},
|
||||
}
|
||||
options.Route.Rules = append([]option.Rule{routeRuleIp, routeRuleSite}, options.Route.Rules...)
|
||||
}
|
||||
if opt.BlockAds {
|
||||
options.Route.RuleSet = append(options.Route.RuleSet, option.RuleSet{
|
||||
Type: C.RuleSetTypeRemote,
|
||||
Tag: "geosite-ads",
|
||||
RemoteOptions: option.RemoteRuleSet{
|
||||
URL: "https://raw.githubusercontent.com/Chocolate4U/Iran-sing-box-rules/rule-set/geosite-ads.srs",
|
||||
UpdateInterval: option.Duration(5 * time.Hour * 24),
|
||||
},
|
||||
})
|
||||
routeRule := option.Rule{
|
||||
Type: C.RuleTypeDefault,
|
||||
DefaultOptions: option.DefaultRule{
|
||||
RuleSet: []string{"geosite-ads"},
|
||||
Outbound: OutboundBlockTag,
|
||||
},
|
||||
}
|
||||
options.Route.Rules = append([]option.Rule{routeRule}, options.Route.Rules...)
|
||||
}
|
||||
var outbounds []option.Outbound
|
||||
var tags []string
|
||||
OutboundMainProxyTag = OutboundSelectTag
|
||||
|
||||
@@ -6,18 +6,20 @@ import (
|
||||
)
|
||||
|
||||
type ConfigOptions struct {
|
||||
EnableFullConfig bool `json:"enable-full-config"`
|
||||
LogLevel string `json:"log-level"`
|
||||
EnableClashApi bool `json:"enable-clash-api"`
|
||||
ClashApiPort uint16 `json:"clash-api-port"`
|
||||
ClashApiSecret string `json:"web-secret"`
|
||||
GeoIPPath string `json:"geoip-path"`
|
||||
GeoSitePath string `json:"geosite-path"`
|
||||
Rules []Rule `json:"rules"`
|
||||
Warp WarpOptions `json:"warp"`
|
||||
Warp2 WarpOptions `json:"warp2"`
|
||||
Mux MuxOptions `json:"mux"`
|
||||
TLSTricks TLSTricks `json:"tls-tricks"`
|
||||
EnableFullConfig bool `json:"enable-full-config"`
|
||||
LogLevel string `json:"log-level"`
|
||||
EnableClashApi bool `json:"enable-clash-api"`
|
||||
ClashApiPort uint16 `json:"clash-api-port"`
|
||||
ClashApiSecret string `json:"web-secret"`
|
||||
Region string `json:"region"`
|
||||
BlockAds bool `json:"block-ads"`
|
||||
// GeoIPPath string `json:"geoip-path"`
|
||||
// GeoSitePath string `json:"geosite-path"`
|
||||
Rules []Rule `json:"rules"`
|
||||
Warp WarpOptions `json:"warp"`
|
||||
Warp2 WarpOptions `json:"warp2"`
|
||||
Mux MuxOptions `json:"mux"`
|
||||
TLSTricks TLSTricks `json:"tls-tricks"`
|
||||
DNSOptions
|
||||
InboundOptions
|
||||
URLTestOptions
|
||||
@@ -124,9 +126,9 @@ func DefaultConfigOptions() *ConfigOptions {
|
||||
EnableClashApi: true,
|
||||
ClashApiPort: 6756,
|
||||
ClashApiSecret: "",
|
||||
GeoIPPath: "geoip.db",
|
||||
GeoSitePath: "geosite.db",
|
||||
Rules: []Rule{},
|
||||
// GeoIPPath: "geoip.db",
|
||||
// GeoSitePath: "geosite.db",
|
||||
Rules: []Rule{},
|
||||
Mux: MuxOptions{
|
||||
Enable: false,
|
||||
Padding: true,
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
)
|
||||
|
||||
type Rule struct {
|
||||
Domains string `json:"domains"`
|
||||
IP string `json:"ip"`
|
||||
Port string `json:"port"`
|
||||
Network string `json:"network"`
|
||||
Protocol string `json:"protocol"`
|
||||
Outbound string `json:"outbound"`
|
||||
RuleSetUrl string `json:"rule-set-url"`
|
||||
Domains string `json:"domains"`
|
||||
IP string `json:"ip"`
|
||||
Port string `json:"port"`
|
||||
Network string `json:"network"`
|
||||
Protocol string `json:"protocol"`
|
||||
Outbound string `json:"outbound"`
|
||||
}
|
||||
|
||||
func (r *Rule) MakeRule() option.DefaultRule {
|
||||
|
||||
Reference in New Issue
Block a user