mirror of
https://github.com/v2fly/domain-list-community.git
synced 2026-01-01 20:40:31 +07:00
Compare commits
6 Commits
2026010111
...
maingo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d73db400e | ||
|
|
c83bb86d06 | ||
|
|
58f79fa579 | ||
|
|
969e6baad8 | ||
|
|
bbd5b64219 | ||
|
|
6b10d69246 |
@@ -1,31 +0,0 @@
|
|||||||
argo-bdp.com
|
|
||||||
bang-dream.com
|
|
||||||
bushi-navi.com
|
|
||||||
bushimo.jp
|
|
||||||
bushiroad-creative.com
|
|
||||||
bushiroad-global-online-store.com
|
|
||||||
bushiroad-move.com
|
|
||||||
bushiroad-music.com
|
|
||||||
bushiroad-store.com
|
|
||||||
bushiroad-works.com
|
|
||||||
bushiroad.co.jp
|
|
||||||
bushiroad.com
|
|
||||||
bushiroadgames.com
|
|
||||||
cf-vanguard.com
|
|
||||||
comic-growl.com
|
|
||||||
comicbushi-web.com
|
|
||||||
d4dj-pj.com
|
|
||||||
dreamorder.com
|
|
||||||
fc-buddyfight.com
|
|
||||||
gamebiz.jp
|
|
||||||
gekkan-bushi.com
|
|
||||||
hibiki-cast.jp
|
|
||||||
hikosen.co.jp
|
|
||||||
njpw.co.jp
|
|
||||||
njpw1972.com
|
|
||||||
rebirth-fy.com
|
|
||||||
revuestarlight.com
|
|
||||||
shadowverse-evolve.com
|
|
||||||
ws-blau.com
|
|
||||||
ws-tcg.com
|
|
||||||
wwr-stardom.com
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
include:akamai
|
|
||||||
include:cdn77
|
|
||||||
include:cloudflare
|
|
||||||
include:fastly
|
|
||||||
include:imgix
|
|
||||||
include:limelight
|
|
||||||
include:pagecdn
|
|
||||||
include:quantil
|
|
||||||
include:stackpath
|
|
||||||
include:vrcdn
|
|
||||||
|
|
||||||
# Bunny CDN
|
|
||||||
b-cdn.net
|
|
||||||
bunny.net
|
|
||||||
bunnycdn.com
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
include:baishancloud
|
|
||||||
include:bootcdn
|
|
||||||
include:cloudflare-cn
|
|
||||||
include:dwion
|
|
||||||
include:qiniu
|
|
||||||
include:upai
|
|
||||||
include:wangsu
|
|
||||||
|
|
||||||
## 创世云
|
|
||||||
chuangcache.com
|
|
||||||
chuangcdn.com
|
|
||||||
## FUNCDN
|
|
||||||
funcdn.com
|
|
||||||
## 北京知道创宇信息技术股份有限公司
|
|
||||||
jiashule.com
|
|
||||||
jiasule.com
|
|
||||||
yunaq.com
|
|
||||||
@@ -14,7 +14,6 @@ include:bahamut
|
|||||||
include:bandcamp
|
include:bandcamp
|
||||||
include:bangumi
|
include:bangumi
|
||||||
include:boomerang
|
include:boomerang
|
||||||
include:bushiroad
|
|
||||||
include:catchplay
|
include:catchplay
|
||||||
include:copymanga
|
include:copymanga
|
||||||
include:dailymotion
|
include:dailymotion
|
||||||
@@ -127,6 +126,8 @@ eroge-road.com
|
|||||||
famitsu.com
|
famitsu.com
|
||||||
## 遊戲基地
|
## 遊戲基地
|
||||||
gamebase.com.tw
|
gamebase.com.tw
|
||||||
|
## gamebiz
|
||||||
|
gamebiz.jp
|
||||||
## IID, Inc.
|
## IID, Inc.
|
||||||
gamebusiness.jp
|
gamebusiness.jp
|
||||||
gamespark.jp
|
gamespark.jp
|
||||||
|
|||||||
@@ -49,10 +49,18 @@ include:stripe
|
|||||||
include:visa
|
include:visa
|
||||||
|
|
||||||
# CDN companies & Services
|
# CDN companies & Services
|
||||||
include:category-cdn-!cn
|
include:akamai
|
||||||
|
|
||||||
include:awempire
|
include:awempire
|
||||||
|
include:cdn77
|
||||||
|
include:cloudflare
|
||||||
|
include:fastly
|
||||||
|
include:imgix
|
||||||
|
include:limelight
|
||||||
|
include:pagecdn
|
||||||
|
include:quantil
|
||||||
include:scaleflex
|
include:scaleflex
|
||||||
|
include:stackpath
|
||||||
|
include:vrcdn
|
||||||
include:wistia
|
include:wistia
|
||||||
|
|
||||||
# Certificate authorities
|
# Certificate authorities
|
||||||
|
|||||||
@@ -52,18 +52,26 @@ lufaxcdn.com
|
|||||||
pospal.cn
|
pospal.cn
|
||||||
|
|
||||||
# CDN or SDWAN
|
# CDN or SDWAN
|
||||||
include:category-cdn-cn
|
|
||||||
|
|
||||||
include:aws-cn
|
include:aws-cn
|
||||||
|
include:baishancloud
|
||||||
|
include:bootcdn
|
||||||
|
include:cloudflare-cn
|
||||||
include:ctyun
|
include:ctyun
|
||||||
|
include:dwion
|
||||||
include:maocloud
|
include:maocloud
|
||||||
include:qingcloud
|
include:qingcloud
|
||||||
|
include:qiniu
|
||||||
include:snodehome
|
include:snodehome
|
||||||
include:ucloud
|
include:ucloud
|
||||||
|
include:upai
|
||||||
|
include:wangsu
|
||||||
include:yunfanjiasu
|
include:yunfanjiasu
|
||||||
|
|
||||||
## 百家云
|
## 百家云
|
||||||
baijiayun.com
|
baijiayun.com
|
||||||
|
## 创世云
|
||||||
|
chuangcache.com
|
||||||
|
chuangcdn.com
|
||||||
## 123 云盘 CDN
|
## 123 云盘 CDN
|
||||||
cjjd19.com
|
cjjd19.com
|
||||||
## 明源云
|
## 明源云
|
||||||
@@ -72,6 +80,12 @@ mingyuanyun.com
|
|||||||
mypaas.com
|
mypaas.com
|
||||||
mypaas.com.cn
|
mypaas.com.cn
|
||||||
myypark.com
|
myypark.com
|
||||||
|
## FUNCDN
|
||||||
|
funcdn.com
|
||||||
|
## 北京知道创宇信息技术股份有限公司
|
||||||
|
jiashule.com
|
||||||
|
jiasule.com
|
||||||
|
yunaq.com
|
||||||
## 即刻雾联(北京)
|
## 即刻雾联(北京)
|
||||||
## https://github.com/v2fly/domain-list-community/pull/1352#issuecomment-1345476790
|
## https://github.com/v2fly/domain-list-community/pull/1352#issuecomment-1345476790
|
||||||
jikeiot.cloud
|
jikeiot.cloud
|
||||||
|
|||||||
336
main.go
336
main.go
@@ -29,6 +29,19 @@ const (
|
|||||||
RuleTypeInclude string = "include"
|
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 Entry struct {
|
||||||
Type string
|
Type string
|
||||||
Value string
|
Value string
|
||||||
@@ -40,15 +53,21 @@ type List struct {
|
|||||||
Entry []Entry
|
Entry []Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParsedList struct {
|
type Inclusion struct {
|
||||||
Name string
|
Source string
|
||||||
Inclusion map[string]bool
|
MustAttrs []*router.Domain_Attribute
|
||||||
Entry []Entry
|
BannedAttrs []*router.Domain_Attribute
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ParsedList) toPlainText(listName string) error {
|
type ParsedList struct {
|
||||||
|
Name string
|
||||||
|
Inclusions []Inclusion
|
||||||
|
Entry []Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entryList *List) toPlainText() error {
|
||||||
var entryBytes []byte
|
var entryBytes []byte
|
||||||
for _, entry := range l.Entry {
|
for _, entry := range entryList.Entry {
|
||||||
var attrString string
|
var attrString string
|
||||||
if entry.Attrs != nil {
|
if entry.Attrs != nil {
|
||||||
for _, attr := range entry.Attrs {
|
for _, attr := range entry.Attrs {
|
||||||
@@ -59,13 +78,13 @@ func (l *ParsedList) toPlainText(listName string) error {
|
|||||||
// Entry output format is: type:domain.tld:@attr1,@attr2
|
// Entry output format is: type:domain.tld:@attr1,@attr2
|
||||||
entryBytes = append(entryBytes, []byte(entry.Type+":"+entry.Value+attrString+"\n")...)
|
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(entryList.Name)+".txt"), entryBytes, 0644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ParsedList) toProto() (*router.GeoSite, error) {
|
func (l *List) toProto() (*router.GeoSite, error) {
|
||||||
site := &router.GeoSite{
|
site := &router.GeoSite{
|
||||||
CountryCode: l.Name,
|
CountryCode: l.Name,
|
||||||
}
|
}
|
||||||
@@ -79,11 +98,6 @@ func (l *ParsedList) toProto() (*router.GeoSite, error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
case RuleTypeRegexp:
|
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{
|
site.Domain = append(site.Domain, &router.Domain{
|
||||||
Type: router.Domain_Regex,
|
Type: router.Domain_Regex,
|
||||||
Value: entry.Value,
|
Value: entry.Value,
|
||||||
@@ -103,89 +117,73 @@ func (l *ParsedList) toProto() (*router.GeoSite, error) {
|
|||||||
Value: entry.Value,
|
Value: entry.Value,
|
||||||
Attribute: entry.Attrs,
|
Attribute: entry.Attrs,
|
||||||
})
|
})
|
||||||
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("unknown domain type: %s", entry.Type)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return site, nil
|
return site, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportPlainTextList(list []string, refName string, pl *ParsedList) {
|
func exportPlainTextList(exportFiles []string, entryList *List) {
|
||||||
for _, listName := range list {
|
for _, exportfilename := range exportFiles {
|
||||||
if strings.EqualFold(refName, listName) {
|
if strings.EqualFold(entryList.Name, exportfilename) {
|
||||||
if err := pl.toPlainText(strings.ToLower(refName)); err != nil {
|
if err := entryList.toPlainText(); err != nil {
|
||||||
fmt.Println("Failed:", err)
|
fmt.Println("Failed to exportPlainTextList:", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("'%s' has been generated successfully.\n", listName)
|
fmt.Printf("'%s' has been generated successfully.\n", exportfilename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeComment(line string) string {
|
func parseEntry(line string) (Entry, error) {
|
||||||
idx := strings.Index(line, "#")
|
var entry Entry
|
||||||
if idx == -1 {
|
parts := strings.Fields(line)
|
||||||
return line
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(line[:idx])
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseDomain(domain string, entry *Entry) error {
|
// Parse/Check type and value
|
||||||
kv := strings.Split(domain, ":")
|
rawTypeVal := parts[0]
|
||||||
|
kv := strings.Split(rawTypeVal, ":")
|
||||||
if len(kv) == 1 {
|
if len(kv) == 1 {
|
||||||
entry.Type = RuleTypeDomain
|
entry.Type = RuleTypeDomain // Default type
|
||||||
entry.Value = strings.ToLower(kv[0])
|
entry.Value = strings.ToLower(rawTypeVal)
|
||||||
return nil
|
} else if len(kv) == 2 {
|
||||||
}
|
|
||||||
|
|
||||||
if len(kv) == 2 {
|
|
||||||
entry.Type = strings.ToLower(kv[0])
|
entry.Type = strings.ToLower(kv[0])
|
||||||
|
if entry.Type == RuleTypeRegexp {
|
||||||
if strings.EqualFold(entry.Type, RuleTypeRegexp) {
|
|
||||||
entry.Value = kv[1]
|
entry.Value = kv[1]
|
||||||
} else {
|
} else {
|
||||||
entry.Value = strings.ToLower(kv[1])
|
entry.Value = strings.ToLower(kv[1])
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
return nil
|
return entry, fmt.Errorf("invalid format: %s", line)
|
||||||
}
|
}
|
||||||
|
if !TypeChecker.MatchString(entry.Type) {
|
||||||
return fmt.Errorf("invalid format: %s", domain)
|
return entry, fmt.Errorf("invalid type: %s", entry.Type)
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
if entry.Type == RuleTypeRegexp {
|
||||||
attribute.Key = strings.ToLower(attr[1:]) // Trim attribute prefix `@` character
|
if _, err := regexp.Compile(entry.Value); err != nil {
|
||||||
attribute.TypedValue = &router.Domain_Attribute_BoolValue{BoolValue: true}
|
return entry, fmt.Errorf("invalid regexp: %s", entry.Value)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
entry.Attrs = append(entry.Attrs, attr)
|
} else if !ValueChecker.MatchString(entry.Value) {
|
||||||
|
return entry, fmt.Errorf("invalid value: %s", entry.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse/Check attributes
|
||||||
|
for _, part := range parts[1:] {
|
||||||
|
if !strings.HasPrefix(part, "@") {
|
||||||
|
return entry, fmt.Errorf("invalid attribute: %s", part)
|
||||||
|
}
|
||||||
|
attrKey := strings.ToLower(part[1:]) // Trim attribute prefix `@` character
|
||||||
|
if !AttrChecker.MatchString(attrKey) {
|
||||||
|
return entry, fmt.Errorf("invalid attribute key: %s", attrKey)
|
||||||
|
}
|
||||||
|
entry.Attrs = append(entry.Attrs, &router.Domain_Attribute{
|
||||||
|
Key: attrKey,
|
||||||
|
TypedValue: &router.Domain_Attribute_BoolValue{BoolValue: true},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// Sort attributes
|
||||||
|
sort.Slice(entry.Attrs, func(i, j int) bool {
|
||||||
|
return entry.Attrs[i].Key < entry.Attrs[j].Key
|
||||||
|
})
|
||||||
|
|
||||||
return entry, nil
|
return entry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,9 +199,13 @@ func Load(path string) (*List, error) {
|
|||||||
}
|
}
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := strings.TrimSpace(scanner.Text())
|
line := scanner.Text()
|
||||||
line = removeComment(line)
|
// Remove comments
|
||||||
if len(line) == 0 {
|
if idx := strings.Index(line, "#"); idx != -1 {
|
||||||
|
line = line[:idx]
|
||||||
|
}
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if line == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
entry, err := parseEntry(line)
|
entry, err := parseEntry(line)
|
||||||
@@ -216,108 +218,77 @@ func Load(path string) (*List, error) {
|
|||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isMatchAttr(Attrs []*router.Domain_Attribute, includeKey string) bool {
|
func ParseList(refList *List) (*ParsedList, error) {
|
||||||
isMatch := false
|
pl := &ParsedList{Name: refList.Name}
|
||||||
mustMatch := true
|
for _, entry := range refList.Entry {
|
||||||
matchName := includeKey
|
if entry.Type == RuleTypeInclude {
|
||||||
if strings.HasPrefix(includeKey, "!") {
|
inc := Inclusion{Source: strings.ToUpper(entry.Value)}
|
||||||
isMatch = true
|
for _, attr := range entry.Attrs {
|
||||||
mustMatch = false
|
if strings.HasPrefix(attr.Key, "-") {
|
||||||
matchName = strings.TrimLeft(includeKey, "!")
|
inc.BannedAttrs = append(inc.BannedAttrs, &router.Domain_Attribute{
|
||||||
}
|
Key: attr.Key[1:], // Trim attribute prefix `-` character
|
||||||
|
TypedValue: &router.Domain_Attribute_BoolValue{BoolValue: true},
|
||||||
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...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
InclusionName := refName
|
inc.MustAttrs = append(inc.MustAttrs, attr)
|
||||||
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...)
|
|
||||||
}
|
}
|
||||||
hasInclude = true
|
|
||||||
} else {
|
|
||||||
newEntryList = append(newEntryList, entry)
|
|
||||||
}
|
}
|
||||||
}
|
pl.Inclusions = append(pl.Inclusions, inc)
|
||||||
entryList = newEntryList
|
} else {
|
||||||
if !hasInclude {
|
pl.Entry = append(pl.Entry, entry)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pl.Entry = entryList
|
|
||||||
|
|
||||||
return pl, nil
|
return pl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isMatchAttrFilters(entry Entry, incFilter Inclusion) bool {
|
||||||
|
attrMap := make(map[string]bool)
|
||||||
|
for _, attr := range entry.Attrs {
|
||||||
|
attrMap[attr.Key] = true
|
||||||
|
}
|
||||||
|
for _, m := range incFilter.MustAttrs {
|
||||||
|
if !attrMap[m.Key] { return false }
|
||||||
|
}
|
||||||
|
for _, b := range incFilter.BannedAttrs {
|
||||||
|
if attrMap[b.Key] { return false }
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResolveList(pl *ParsedList) error {
|
||||||
|
//TODO: deduplicate
|
||||||
|
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)
|
||||||
|
|
||||||
|
finalList := &List{Name: pl.Name}
|
||||||
|
finalList.Entry = append(finalList.Entry, pl.Entry...)
|
||||||
|
|
||||||
|
for _, inc := range pl.Inclusions {
|
||||||
|
if err := ResolveList(plMap[inc.Source]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, entry := range finalMap[inc.Source].Entry {
|
||||||
|
if isMatchAttrFilters(entry, inc) {
|
||||||
|
finalList.Entry = append(finalList.Entry, entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finalMap[pl.Name] = finalList
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
dir := *dataPath
|
dir := *dataPath
|
||||||
fmt.Println("Use domain lists in", dir)
|
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 {
|
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -329,7 +300,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ref[list.Name] = list
|
refMap[list.Name] = list
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -337,6 +308,24 @@ func main() {
|
|||||||
os.Exit(1)
|
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
|
// Create output directory if not exist
|
||||||
if _, err := os.Stat(*outputDir); os.IsNotExist(err) {
|
if _, err := os.Stat(*outputDir); os.IsNotExist(err) {
|
||||||
if mkErr := os.MkdirAll(*outputDir, 0755); mkErr != nil {
|
if mkErr := os.MkdirAll(*outputDir, 0755); mkErr != nil {
|
||||||
@@ -347,13 +336,8 @@ func main() {
|
|||||||
|
|
||||||
protoList := new(router.GeoSiteList)
|
protoList := new(router.GeoSiteList)
|
||||||
var existList []string
|
var existList []string
|
||||||
for refName, list := range ref {
|
for _, siteEntries := range finalMap {
|
||||||
pl, err := ParseList(list, ref)
|
site, err := siteEntries.toProto()
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed:", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
site, err := pl.toProto()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed:", err)
|
fmt.Println("Failed:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -363,7 +347,7 @@ func main() {
|
|||||||
// Flatten and export plaintext list
|
// Flatten and export plaintext list
|
||||||
if *exportLists != "" {
|
if *exportLists != "" {
|
||||||
if existList != nil {
|
if existList != nil {
|
||||||
exportPlainTextList(existList, refName, pl)
|
exportPlainTextList(existList, siteEntries)
|
||||||
} else {
|
} else {
|
||||||
exportedListSlice := strings.Split(*exportLists, ",")
|
exportedListSlice := strings.Split(*exportLists, ",")
|
||||||
for _, exportedListName := range exportedListSlice {
|
for _, exportedListName := range exportedListSlice {
|
||||||
@@ -376,7 +360,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if existList != nil {
|
if existList != nil {
|
||||||
exportPlainTextList(existList, refName, pl)
|
exportPlainTextList(existList, siteEntries)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,11 +373,11 @@ func main() {
|
|||||||
|
|
||||||
protoBytes, err := proto.Marshal(protoList)
|
protoBytes, err := proto.Marshal(protoList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed:", err)
|
fmt.Println("Failed to Marshal:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(filepath.Join(*outputDir, *outputName), protoBytes, 0644); err != nil {
|
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)
|
os.Exit(1)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(*outputName, "has been generated successfully.")
|
fmt.Println(*outputName, "has been generated successfully.")
|
||||||
|
|||||||
Reference in New Issue
Block a user