mirror of
https://github.com/v2fly/domain-list-community.git
synced 2026-01-07 23:33:59 +07:00
Compare commits
7 Commits
2026010608
...
maingo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88a7447d71 | ||
|
|
50f8bbb500 | ||
|
|
e804103951 | ||
|
|
a41228caa6 | ||
|
|
9098d9da53 | ||
|
|
7b4fca575e | ||
|
|
0c623c88d3 |
13
data/apple
13
data/apple
@@ -1,5 +1,5 @@
|
||||
include:apple-ads
|
||||
include:apple-dev # swift inside
|
||||
include:apple-dev
|
||||
# Not include:apple-intelligence
|
||||
include:apple-pki
|
||||
include:apple-tvplus
|
||||
@@ -7,6 +7,7 @@ include:apple-update
|
||||
include:beats
|
||||
include:icloud
|
||||
include:itunes
|
||||
include:swift
|
||||
|
||||
# All .apple domains
|
||||
apple
|
||||
@@ -855,7 +856,7 @@ full:s4.mzstatic.com @cn
|
||||
full:s5.mzstatic.com @cn
|
||||
|
||||
# The rules below are from https://github.com/felixonmars/dnsmasq-china-list/blob/master/apple.china.conf
|
||||
# Revision: f6a2093b254a7d2baca959bd16581666ca394303
|
||||
# Revision: 4d392cc0a822ac5626bb97fef3fe5e04e86b28b0
|
||||
# Duplicates removed
|
||||
# According to the consensus in #503, do not include the domain name apps.apple.com directly.
|
||||
# Use in config file like this: "geosite:apple@cn"
|
||||
@@ -873,6 +874,7 @@ full:cds-cdn.v.aaplimg.com @cn
|
||||
full:cds.apple.com @cn
|
||||
full:cds.apple.com.akadns.net @cn
|
||||
full:cdsassets.apple.com @cn
|
||||
full:certs.apple.com @cn
|
||||
full:cl2-cn.apple.com @cn
|
||||
full:cl4-cn.apple.com @cn
|
||||
full:clientflow.apple.com @cn
|
||||
@@ -880,6 +882,7 @@ full:clientflow.apple.com.akadns.net @cn
|
||||
full:cn-smp-paymentservices.apple.com @cn
|
||||
full:configuration.apple.com @cn
|
||||
full:configuration.apple.com.akadns.net @cn
|
||||
full:crl.apple.com @cn
|
||||
full:cstat.apple.com @cn
|
||||
full:cstat.cdn-apple.com @cn
|
||||
full:dd-cdn.origin-apple.com.akadns.net @cn
|
||||
@@ -932,6 +935,10 @@ full:mesu-china.apple.com.akadns.net @cn
|
||||
full:mesu.apple.com @cn
|
||||
full:ml.cdn-apple.com @cn
|
||||
full:music.apple.com @cn
|
||||
full:ocsp-lb.apple.com.akadns.net @cn
|
||||
full:ocsp.apple.com @cn
|
||||
full:ocsp2-lb.apple.com.akadns.net @cn
|
||||
full:ocsp2.apple.com @cn
|
||||
full:oscdn.apple.com @cn
|
||||
full:oscdn.origin-apple.com.akadns.net @cn
|
||||
full:osxapps.itunes.g.aaplimg.com @cn
|
||||
@@ -974,6 +981,8 @@ full:tj-pod1-smp-device.apple.com @cn
|
||||
full:updates-http.cdn-apple.com @cn
|
||||
full:updates-http.cdn-apple.com.akadns.net @cn
|
||||
full:updates.cdn-apple.com @cn
|
||||
full:valid.apple.com @cn
|
||||
full:valid.origin-apple.com.akadns.net @cn
|
||||
full:weather-data.apple.com @cn
|
||||
full:weather-data.apple.com.akadns.net @cn
|
||||
full:weather-map.apple.com @cn
|
||||
|
||||
@@ -7,4 +7,3 @@ full:ocsp.apple.com @cn
|
||||
full:ocsp2-lb.apple.com.akadns.net @cn
|
||||
full:ocsp2.apple.com @cn
|
||||
full:valid.apple.com @cn
|
||||
full:valid.origin-apple.com.akadns.net @cn
|
||||
|
||||
@@ -8,7 +8,6 @@ orayimg.com
|
||||
sunlogin.net
|
||||
|
||||
## ToDesk
|
||||
todesk.cn
|
||||
todesk.com
|
||||
|
||||
## 连连控
|
||||
|
||||
@@ -79,6 +79,7 @@ include:spaceship
|
||||
include:st
|
||||
include:synology
|
||||
include:symantec
|
||||
include:tailscale
|
||||
include:theboringcompany
|
||||
include:tonec
|
||||
include:uber
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
include:ngrok
|
||||
include:pinggy
|
||||
include:tailscale
|
||||
@@ -117,7 +117,6 @@ full:music-torrent.net
|
||||
full:mvgforumtracker.mvgroup.org
|
||||
full:mvgroup.org
|
||||
full:new-line.net
|
||||
full:nnmclub.to
|
||||
full:nyaa.tracker.wf
|
||||
full:odd-hd.fr
|
||||
full:oh.fuuuuuck.com
|
||||
|
||||
@@ -23,7 +23,6 @@ include:mailru-group
|
||||
include:okko
|
||||
include:ozon
|
||||
include:rutube
|
||||
include:wildberries
|
||||
include:wink
|
||||
include:x5
|
||||
include:yandex
|
||||
|
||||
@@ -4,7 +4,6 @@ citic
|
||||
# All .中信 domains
|
||||
xn--fiq64b
|
||||
|
||||
cfc108.com
|
||||
chinaamc.com
|
||||
citic-prudential.com.cn
|
||||
citicbank.com
|
||||
|
||||
@@ -12,7 +12,6 @@ include:taboola
|
||||
|
||||
# Anti-censorship & Anti-GFW & Privacy protection & VPN tools
|
||||
include:category-anticensorship
|
||||
include:category-proxy-tunnels
|
||||
|
||||
# Art & Design & Photography
|
||||
include:artstation
|
||||
@@ -285,7 +284,6 @@ include:nyaa
|
||||
include:piratebay
|
||||
include:rarbg
|
||||
dmhy.org
|
||||
rutor.info
|
||||
|
||||
# User scripts
|
||||
greasyfork.org
|
||||
|
||||
14
data/google
14
data/google
@@ -544,13 +544,11 @@ full:google-ohttp-relay-safebrowsing.fastly-edge.com
|
||||
|
||||
# Domains and services below are available in China mainland
|
||||
# Use in config file like this: "geosite:google@cn"
|
||||
gvt1-cn.com @cn
|
||||
gvt2-cn.com @cn
|
||||
full:www.recaptcha.net @cn
|
||||
full:safebrowsing-cache.google.com @cn
|
||||
|
||||
# The rules below are from https://github.com/felixonmars/dnsmasq-china-list/blob/master/google.china.conf
|
||||
# Revision: 1c2d107d4e7eaa0b192e08bb0beddde4aab247f6
|
||||
# Duplicates removed
|
||||
# Revision: 1f28a2d5789f411c13de69837bb354f4b21e58ff
|
||||
# Use in config file like this: "geosite:google@cn"
|
||||
full:265.com @cn
|
||||
full:2mdn-cn.net @cn
|
||||
@@ -580,6 +578,7 @@ full:cnappinstall.googleadapis.com @cn
|
||||
full:connectivitycheck.gstatic.com @cn
|
||||
full:content.googleadapis.com @cn
|
||||
full:crashlyticsreports-pa.googleapis.com @cn
|
||||
full:crl.pki.goog @cn
|
||||
full:csi.gstatic.com @cn
|
||||
full:dartsearch-cn.net @cn
|
||||
full:dg-meta.video.google.com @cn
|
||||
@@ -591,6 +590,7 @@ full:download.mlcc.google.com @cn
|
||||
full:download.qatp1.net @cn
|
||||
full:download.tensorflow.google.com @cn
|
||||
full:emmapplecodevice.googleapis.com @cn
|
||||
full:firebase-settings.crashlytics.com @cn
|
||||
full:fontfiles.googleapis.com @cn
|
||||
full:fonts.googleapis.com @cn
|
||||
full:fonts.gstatic.com @cn
|
||||
@@ -629,8 +629,10 @@ full:logger-dev.corp.google.com @cn
|
||||
full:logger.corp.google.com @cn
|
||||
full:login.corp.google.com @cn
|
||||
full:monitoring.qpdp1.net @cn
|
||||
full:ocsp.pki.goog @cn
|
||||
full:pagead-googlehosted.l.google.com @cn
|
||||
full:performanceparameters.googleapis.com @cn
|
||||
full:pki-goog.l.google.com @cn
|
||||
full:prod-controlbe.floonet.goog @cn
|
||||
full:prod-databe.floonet.goog @cn
|
||||
full:prod.databe.floonet.goog @cn
|
||||
@@ -649,6 +651,7 @@ full:redirector.bdn.dev @cn
|
||||
full:redirector.c.chat.google.com @cn
|
||||
full:redirector.c.mail.google.com @cn
|
||||
full:redirector.c.pack.google.com @cn
|
||||
full:redirector.c.play.google.com @cn
|
||||
full:redirector.c.youtubeeducation.com @cn
|
||||
full:redirector.gcpcdn.gvt1.com @cn
|
||||
full:redirector.gvt1.com @cn
|
||||
@@ -687,3 +690,6 @@ full:www.destinationurl.com @cn
|
||||
full:www.gstatic.com @cn
|
||||
full:www.pxcc.com @cn
|
||||
full:xn--flw351e.com @cn
|
||||
|
||||
gvt1-cn.com @cn
|
||||
gvt2-cn.com @cn
|
||||
|
||||
@@ -16,7 +16,6 @@ full:webchannel-alkalimakersuite-pa.clients6.google.com
|
||||
generativeai.google
|
||||
makersuite.google.com
|
||||
|
||||
ai.studio
|
||||
aistudio.google.com
|
||||
bard.google.com
|
||||
gemini.google
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
ngrok-free.app
|
||||
ngrok-free.dev
|
||||
ngrok-free.pizza
|
||||
ngrok.app
|
||||
ngrok.com
|
||||
ngrok.dev
|
||||
ngrok.io
|
||||
ngrok.pizza
|
||||
ngrok.pro
|
||||
@@ -1,2 +0,0 @@
|
||||
pinggy.io
|
||||
pinggy.link
|
||||
@@ -2,7 +2,7 @@ maintracker.org
|
||||
rutracker.cc
|
||||
rutracker.cr
|
||||
rutracker.me
|
||||
rutracker.net
|
||||
rutracker.nl
|
||||
rutracker.org
|
||||
rutrecker.net
|
||||
rutrk.org
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
geobasket.ru
|
||||
paywb.com
|
||||
rwb.ru
|
||||
wb-basket.ru
|
||||
wb.ru
|
||||
wbbasket.ru
|
||||
wbpay.ru
|
||||
wibes.ru
|
||||
wildberries.ru
|
||||
388
main.go
388
main.go
@@ -29,10 +29,29 @@ const (
|
||||
RuleTypeInclude string = "include"
|
||||
)
|
||||
|
||||
var (
|
||||
TypeChecker = regexp.MustCompile(`^(domain|full|keyword|regexp|include)$`)
|
||||
ValueChecker = regexp.MustCompile(`^[a-z0-9!\.-]+$`)
|
||||
AttrChecker = regexp.MustCompile(`^[a-z0-9!-]+$`)
|
||||
)
|
||||
|
||||
var (
|
||||
refMap = make(map[string]*List)
|
||||
plMap = make(map[string]*ParsedList)
|
||||
finalMap = make(map[string]*List)
|
||||
cirIncMap = make(map[string]bool) // Used for circular inclusion detection
|
||||
)
|
||||
|
||||
type Entry struct {
|
||||
Type string
|
||||
Value string
|
||||
Attrs []*router.Domain_Attribute
|
||||
Attrs []string
|
||||
}
|
||||
|
||||
type Inclusion struct {
|
||||
Source string
|
||||
MustAttrs []string
|
||||
BannedAttrs []string
|
||||
}
|
||||
|
||||
type List struct {
|
||||
@@ -41,150 +60,115 @@ type List struct {
|
||||
}
|
||||
|
||||
type ParsedList struct {
|
||||
Name string
|
||||
Inclusion map[string]bool
|
||||
Entry []Entry
|
||||
Name string
|
||||
Inclusions []Inclusion
|
||||
Entry []Entry
|
||||
}
|
||||
|
||||
func (l *ParsedList) toPlainText(listName string) error {
|
||||
func (l *List) toPlainText() error {
|
||||
var entryBytes []byte
|
||||
for _, entry := range l.Entry {
|
||||
var attrString string
|
||||
if entry.Attrs != nil {
|
||||
for _, attr := range entry.Attrs {
|
||||
attrString += "@" + attr.GetKey() + ","
|
||||
}
|
||||
attrString = strings.TrimRight(":"+attrString, ",")
|
||||
attrString = ":@"+strings.Join(entry.Attrs, ",@")
|
||||
}
|
||||
// Entry output format is: type:domain.tld:@attr1,@attr2
|
||||
entryBytes = append(entryBytes, []byte(entry.Type+":"+entry.Value+attrString+"\n")...)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(*outputDir, listName+".txt"), entryBytes, 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(*outputDir, strings.ToLower(l.Name)+".txt"), entryBytes, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *ParsedList) toProto() (*router.GeoSite, error) {
|
||||
func (l *List) toProto() (*router.GeoSite, error) {
|
||||
site := &router.GeoSite{
|
||||
CountryCode: l.Name,
|
||||
}
|
||||
for _, entry := range l.Entry {
|
||||
switch entry.Type {
|
||||
case RuleTypeDomain:
|
||||
site.Domain = append(site.Domain, &router.Domain{
|
||||
Type: router.Domain_RootDomain,
|
||||
Value: entry.Value,
|
||||
Attribute: entry.Attrs,
|
||||
})
|
||||
|
||||
case RuleTypeRegexp:
|
||||
// check regexp validity to avoid runtime error
|
||||
_, err := regexp.Compile(entry.Value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid regexp in list %s: %s", l.Name, entry.Value)
|
||||
}
|
||||
site.Domain = append(site.Domain, &router.Domain{
|
||||
Type: router.Domain_Regex,
|
||||
Value: entry.Value,
|
||||
Attribute: entry.Attrs,
|
||||
pdomain := &router.Domain{Value:entry.Value}
|
||||
for _, attr := range entry.Attrs {
|
||||
pdomain.Attribute = append(pdomain.Attribute, &router.Domain_Attribute{
|
||||
Key: attr,
|
||||
TypedValue: &router.Domain_Attribute_BoolValue{BoolValue: true},
|
||||
})
|
||||
|
||||
case RuleTypeKeyword:
|
||||
site.Domain = append(site.Domain, &router.Domain{
|
||||
Type: router.Domain_Plain,
|
||||
Value: entry.Value,
|
||||
Attribute: entry.Attrs,
|
||||
})
|
||||
|
||||
case RuleTypeFullDomain:
|
||||
site.Domain = append(site.Domain, &router.Domain{
|
||||
Type: router.Domain_Full,
|
||||
Value: entry.Value,
|
||||
Attribute: entry.Attrs,
|
||||
})
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown domain type: %s", entry.Type)
|
||||
}
|
||||
|
||||
switch entry.Type {
|
||||
case RuleTypeDomain:
|
||||
pdomain.Type = router.Domain_RootDomain
|
||||
case RuleTypeRegexp:
|
||||
pdomain.Type = router.Domain_Regex
|
||||
case RuleTypeKeyword:
|
||||
pdomain.Type = router.Domain_Plain
|
||||
case RuleTypeFullDomain:
|
||||
pdomain.Type = router.Domain_Full
|
||||
}
|
||||
site.Domain = append(site.Domain, pdomain)
|
||||
}
|
||||
return site, nil
|
||||
}
|
||||
|
||||
func exportPlainTextList(list []string, refName string, pl *ParsedList) {
|
||||
for _, listName := range list {
|
||||
if strings.EqualFold(refName, listName) {
|
||||
if err := pl.toPlainText(strings.ToLower(refName)); err != nil {
|
||||
fmt.Println("Failed:", err)
|
||||
func exportPlainTextList(exportFiles []string, entryList *List) {
|
||||
for _, exportfilename := range exportFiles {
|
||||
if strings.EqualFold(entryList.Name, exportfilename) {
|
||||
if err := entryList.toPlainText(); err != nil {
|
||||
fmt.Println("Failed to exportPlainTextList:", err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("'%s' has been generated successfully.\n", listName)
|
||||
fmt.Printf("'%s' has been generated successfully.\n", exportfilename)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func removeComment(line string) string {
|
||||
idx := strings.Index(line, "#")
|
||||
if idx == -1 {
|
||||
return line
|
||||
}
|
||||
return strings.TrimSpace(line[:idx])
|
||||
}
|
||||
func parseEntry(line string) (Entry, error) {
|
||||
var entry Entry
|
||||
parts := strings.Fields(line)
|
||||
|
||||
func parseDomain(domain string, entry *Entry) error {
|
||||
kv := strings.Split(domain, ":")
|
||||
// Parse type and value
|
||||
rawTypeVal := parts[0]
|
||||
kv := strings.Split(rawTypeVal, ":")
|
||||
if len(kv) == 1 {
|
||||
entry.Type = RuleTypeDomain
|
||||
entry.Value = strings.ToLower(kv[0])
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(kv) == 2 {
|
||||
entry.Type = RuleTypeDomain // Default type
|
||||
entry.Value = strings.ToLower(rawTypeVal)
|
||||
} else if len(kv) == 2 {
|
||||
entry.Type = strings.ToLower(kv[0])
|
||||
|
||||
if strings.EqualFold(entry.Type, RuleTypeRegexp) {
|
||||
if entry.Type == RuleTypeRegexp {
|
||||
entry.Value = kv[1]
|
||||
} else {
|
||||
entry.Value = strings.ToLower(kv[1])
|
||||
}
|
||||
|
||||
return nil
|
||||
} else {
|
||||
return entry, fmt.Errorf("invalid format: %s", line)
|
||||
}
|
||||
// Check type and value
|
||||
if !TypeChecker.MatchString(entry.Type) {
|
||||
return entry, fmt.Errorf("invalid type: %s", entry.Type)
|
||||
}
|
||||
if entry.Type == RuleTypeRegexp {
|
||||
if _, err := regexp.Compile(entry.Value); err != nil {
|
||||
return entry, fmt.Errorf("invalid regexp: %s", entry.Value)
|
||||
}
|
||||
} else if !ValueChecker.MatchString(entry.Value) {
|
||||
return entry, fmt.Errorf("invalid value: %s", entry.Value)
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid format: %s", domain)
|
||||
}
|
||||
|
||||
func parseAttribute(attr string) (*router.Domain_Attribute, error) {
|
||||
var attribute router.Domain_Attribute
|
||||
if len(attr) == 0 || attr[0] != '@' {
|
||||
return &attribute, fmt.Errorf("invalid attribute: %s", attr)
|
||||
}
|
||||
|
||||
attribute.Key = strings.ToLower(attr[1:]) // Trim attribute prefix `@` character
|
||||
attribute.TypedValue = &router.Domain_Attribute_BoolValue{BoolValue: true}
|
||||
return &attribute, nil
|
||||
}
|
||||
|
||||
func parseEntry(line string) (Entry, error) {
|
||||
line = strings.TrimSpace(line)
|
||||
parts := strings.Split(line, " ")
|
||||
|
||||
var entry Entry
|
||||
if len(parts) == 0 {
|
||||
return entry, fmt.Errorf("empty entry")
|
||||
}
|
||||
|
||||
if err := parseDomain(parts[0], &entry); err != nil {
|
||||
return entry, err
|
||||
}
|
||||
|
||||
for i := 1; i < len(parts); i++ {
|
||||
attr, err := parseAttribute(parts[i])
|
||||
if err != nil {
|
||||
return entry, err
|
||||
// Parse/Check attributes
|
||||
for _, part := range parts[1:] {
|
||||
if !strings.HasPrefix(part, "@") {
|
||||
return entry, fmt.Errorf("invalid attribute: %s", part)
|
||||
}
|
||||
attr := strings.ToLower(part[1:]) // Trim attribute prefix `@` character
|
||||
if !AttrChecker.MatchString(attr) {
|
||||
return entry, fmt.Errorf("invalid attribute key: %s", attr)
|
||||
}
|
||||
entry.Attrs = append(entry.Attrs, attr)
|
||||
}
|
||||
// Sort attributes
|
||||
sort.Slice(entry.Attrs, func(i, j int) bool {
|
||||
return entry.Attrs[i] < entry.Attrs[j]
|
||||
})
|
||||
|
||||
return entry, nil
|
||||
}
|
||||
@@ -201,9 +185,13 @@ func Load(path string) (*List, error) {
|
||||
}
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
line = removeComment(line)
|
||||
if len(line) == 0 {
|
||||
line := scanner.Text()
|
||||
// Remove comments
|
||||
if idx := strings.Index(line, "#"); idx != -1 {
|
||||
line = line[:idx]
|
||||
}
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
entry, err := parseEntry(line)
|
||||
@@ -216,108 +204,87 @@ func Load(path string) (*List, error) {
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func isMatchAttr(Attrs []*router.Domain_Attribute, includeKey string) bool {
|
||||
isMatch := false
|
||||
mustMatch := true
|
||||
matchName := includeKey
|
||||
if strings.HasPrefix(includeKey, "!") {
|
||||
isMatch = true
|
||||
mustMatch = false
|
||||
matchName = strings.TrimLeft(includeKey, "!")
|
||||
}
|
||||
|
||||
for _, Attr := range Attrs {
|
||||
attrName := Attr.Key
|
||||
if mustMatch {
|
||||
if matchName == attrName {
|
||||
isMatch = true
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if matchName == attrName {
|
||||
isMatch = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return isMatch
|
||||
}
|
||||
|
||||
func createIncludeAttrEntrys(list *List, matchAttr *router.Domain_Attribute) []Entry {
|
||||
newEntryList := make([]Entry, 0, len(list.Entry))
|
||||
matchName := matchAttr.Key
|
||||
for _, entry := range list.Entry {
|
||||
matched := isMatchAttr(entry.Attrs, matchName)
|
||||
if matched {
|
||||
newEntryList = append(newEntryList, entry)
|
||||
}
|
||||
}
|
||||
return newEntryList
|
||||
}
|
||||
|
||||
func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
|
||||
pl := &ParsedList{
|
||||
Name: list.Name,
|
||||
Inclusion: make(map[string]bool),
|
||||
}
|
||||
entryList := list.Entry
|
||||
for {
|
||||
newEntryList := make([]Entry, 0, len(entryList))
|
||||
hasInclude := false
|
||||
for _, entry := range entryList {
|
||||
if entry.Type == RuleTypeInclude {
|
||||
refName := strings.ToUpper(entry.Value)
|
||||
if entry.Attrs != nil {
|
||||
for _, attr := range entry.Attrs {
|
||||
InclusionName := strings.ToUpper(refName + "@" + attr.Key)
|
||||
if pl.Inclusion[InclusionName] {
|
||||
continue
|
||||
}
|
||||
pl.Inclusion[InclusionName] = true
|
||||
|
||||
refList := ref[refName]
|
||||
if refList == nil {
|
||||
return nil, fmt.Errorf("list not found: %s", entry.Value)
|
||||
}
|
||||
attrEntrys := createIncludeAttrEntrys(refList, attr)
|
||||
if len(attrEntrys) != 0 {
|
||||
newEntryList = append(newEntryList, attrEntrys...)
|
||||
}
|
||||
}
|
||||
func ParseList(refList *List) (*ParsedList, error) {
|
||||
//TODO: one Entry -> multiple ParsedLists
|
||||
pl := &ParsedList{Name: refList.Name}
|
||||
for _, entry := range refList.Entry {
|
||||
if entry.Type == RuleTypeInclude {
|
||||
inc := Inclusion{Source: strings.ToUpper(entry.Value)}
|
||||
for _, attr := range entry.Attrs {
|
||||
if strings.HasPrefix(attr, "-") {
|
||||
inc.BannedAttrs = append(inc.BannedAttrs, attr[1:]) // Trim attribute prefix `-` character
|
||||
} else {
|
||||
InclusionName := refName
|
||||
if pl.Inclusion[InclusionName] {
|
||||
continue
|
||||
}
|
||||
pl.Inclusion[InclusionName] = true
|
||||
refList := ref[refName]
|
||||
if refList == nil {
|
||||
return nil, fmt.Errorf("list not found: %s", entry.Value)
|
||||
}
|
||||
newEntryList = append(newEntryList, refList.Entry...)
|
||||
inc.MustAttrs = append(inc.MustAttrs, attr)
|
||||
}
|
||||
hasInclude = true
|
||||
} else {
|
||||
newEntryList = append(newEntryList, entry)
|
||||
}
|
||||
}
|
||||
entryList = newEntryList
|
||||
if !hasInclude {
|
||||
break
|
||||
pl.Inclusions = append(pl.Inclusions, inc)
|
||||
} else {
|
||||
pl.Entry = append(pl.Entry, entry)
|
||||
}
|
||||
}
|
||||
pl.Entry = entryList
|
||||
|
||||
return pl, nil
|
||||
}
|
||||
|
||||
func isMatchAttrFilters(entry Entry, incFilter Inclusion) bool {
|
||||
attrMap := make(map[string]bool)
|
||||
for _, attr := range entry.Attrs {
|
||||
attrMap[attr] = true
|
||||
}
|
||||
for _, m := range incFilter.MustAttrs {
|
||||
if !attrMap[m] { return false }
|
||||
}
|
||||
for _, b := range incFilter.BannedAttrs {
|
||||
if attrMap[b] { return false }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func ResolveList(pl *ParsedList) error {
|
||||
if _, pldone := finalMap[pl.Name]; pldone { return nil }
|
||||
|
||||
if cirIncMap[pl.Name] {
|
||||
return fmt.Errorf("circular inclusion in: %s", pl.Name)
|
||||
}
|
||||
cirIncMap[pl.Name] = true
|
||||
defer delete(cirIncMap, pl.Name)
|
||||
|
||||
entry2String := func(e Entry) string { // Attributes already sorted
|
||||
return e.Type+":"+e.Value+"@"+strings.Join(e.Attrs, "@")
|
||||
}
|
||||
bscDupMap := make(map[string]bool) // Used for basic duplicates detection
|
||||
finalList := &List{Name: pl.Name}
|
||||
|
||||
for _, dentry := range pl.Entry {
|
||||
if dstring := entry2String(dentry); !bscDupMap[dstring] {
|
||||
bscDupMap[dstring] = true
|
||||
finalList.Entry = append(finalList.Entry, dentry)
|
||||
}
|
||||
}
|
||||
|
||||
for _, inc := range pl.Inclusions {
|
||||
if err := ResolveList(plMap[inc.Source]); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, ientry := range finalMap[inc.Source].Entry {
|
||||
if isMatchAttrFilters(ientry, inc) {
|
||||
if istring := entry2String(ientry); !bscDupMap[istring] {
|
||||
bscDupMap[istring] = true
|
||||
finalList.Entry = append(finalList.Entry, ientry)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finalMap[pl.Name] = finalList
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
dir := *dataPath
|
||||
fmt.Println("Use domain lists in", dir)
|
||||
|
||||
ref := make(map[string]*List)
|
||||
// Generate refMap
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -329,7 +296,7 @@ func main() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ref[list.Name] = list
|
||||
refMap[list.Name] = list
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -337,6 +304,24 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Generate plMap
|
||||
for refName, refList := range refMap {
|
||||
pl, err := ParseList(refList)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to ParseList:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
plMap[refName] = pl
|
||||
}
|
||||
|
||||
// Generate finalMap
|
||||
for _, pl := range plMap {
|
||||
if err := ResolveList(pl); err != nil {
|
||||
fmt.Println("Failed to ResolveList:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Create output directory if not exist
|
||||
if _, err := os.Stat(*outputDir); os.IsNotExist(err) {
|
||||
if mkErr := os.MkdirAll(*outputDir, 0755); mkErr != nil {
|
||||
@@ -347,13 +332,8 @@ func main() {
|
||||
|
||||
protoList := new(router.GeoSiteList)
|
||||
var existList []string
|
||||
for refName, list := range ref {
|
||||
pl, err := ParseList(list, ref)
|
||||
if err != nil {
|
||||
fmt.Println("Failed:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
site, err := pl.toProto()
|
||||
for _, siteEntries := range finalMap {
|
||||
site, err := siteEntries.toProto()
|
||||
if err != nil {
|
||||
fmt.Println("Failed:", err)
|
||||
os.Exit(1)
|
||||
@@ -363,7 +343,7 @@ func main() {
|
||||
// Flatten and export plaintext list
|
||||
if *exportLists != "" {
|
||||
if existList != nil {
|
||||
exportPlainTextList(existList, refName, pl)
|
||||
exportPlainTextList(existList, siteEntries)
|
||||
} else {
|
||||
exportedListSlice := strings.Split(*exportLists, ",")
|
||||
for _, exportedListName := range exportedListSlice {
|
||||
@@ -376,7 +356,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
if existList != nil {
|
||||
exportPlainTextList(existList, refName, pl)
|
||||
exportPlainTextList(existList, siteEntries)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -389,11 +369,11 @@ func main() {
|
||||
|
||||
protoBytes, err := proto.Marshal(protoList)
|
||||
if err != nil {
|
||||
fmt.Println("Failed:", err)
|
||||
fmt.Println("Failed to marshal:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(*outputDir, *outputName), protoBytes, 0644); err != nil {
|
||||
fmt.Println("Failed:", err)
|
||||
fmt.Println("Failed to write output:", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Println(*outputName, "has been generated successfully.")
|
||||
|
||||
Reference in New Issue
Block a user