Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruleset: add support for all literal as a replacement for .* #614

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bind/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,17 @@ func DenyDomains(fs *pflag.FlagSet, cfg *[]ruleset.RegexpListItem) {
fs.Var(anyflag.NewSliceValue[ruleset.RegexpListItem](*cfg, cfg, ruleset.ParseRegexpListItem),
"deny-domains", "[-]<regexp>,..."+
"Deny requests to the specified domains. "+
"Prefix domains with '-' to exclude requests to certain domains from being denied.")
"Prefix domains with '-' to exclude requests to certain domains from being denied. "+
"Special value 'all' matches everything. ",
)
}

func DirectDomains(fs *pflag.FlagSet, cfg *[]ruleset.RegexpListItem) {
fs.Var(anyflag.NewSliceValue[ruleset.RegexpListItem](*cfg, cfg, ruleset.ParseRegexpListItem),
"direct-domains", "[-]<regexp>,..."+
"Connect directly to the specified domains without using the upstream proxy. "+
"Prefix domains with '-' to exclude requests to certain domains from being directed. "+
"Special value 'all' matches everything. "+
"This flag takes precedence over the PAC script.")
}

Expand Down Expand Up @@ -176,6 +179,7 @@ func MITMDomains(fs *pflag.FlagSet, cfg *[]ruleset.RegexpListItem) {
fs.Var(anyflag.NewSliceValue[ruleset.RegexpListItem](*cfg, cfg, ruleset.ParseRegexpListItem),
"mitm-domains", "[-]<regexp>,..."+
"Limit MITM to the specified domains. "+
"Special value 'all' matches everything. "+
"Prefix domains with '-' to exclude requests to certain domains from being MITMed.")
}

Expand Down
7 changes: 7 additions & 0 deletions ruleset/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,15 @@ type RegexpListItem struct {
exclude bool
}

var allRegexp = regexp.MustCompile(`.*`)

func ParseRegexpListItem(val string) (RegexpListItem, error) {
val, exclude := strings.CutPrefix(val, "-")

if val == "all" {
return RegexpListItem{allRegexp, exclude}, nil
}

r, err := regexp.Compile(val)
if err != nil {
return RegexpListItem{}, err
Expand Down
7 changes: 7 additions & 0 deletions ruleset/regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ func TestParseRegexpListItem(t *testing.T) {
exclude: true,
},
},
{
name: "all literal",
input: "all",
expected: RegexpListItem{
Regexp: allRegexp,
},
},
}

for i := range tests {
Expand Down