-
-
Notifications
You must be signed in to change notification settings - Fork 254
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
feat: add support for pattern file #144
base: main
Are you sure you want to change the base?
Conversation
There was a bit of refactoring on util package. parsing arguments should be done in |
bbe891c
to
2cb675a
Compare
Updated the PR. Put file loading into |
I don't really think we need to add
type Args struct {
Addr *string
Port *int
DnsAddr *string
DnsPort *int
EnableDoh *bool
Debug *bool
NoBanner *bool
SystemProxy *bool
Timeout *int
AllowedPattern *StringArray
PatternFile *string // Added here
WindowSize *int
Version *bool
}
func ParseArgs() *Args {
// ...
args.PatternFile = flag.String(...)
// ...
}
func (c *Config) ReadFile(path *string) (string) {
var content string
// read the file content here
return content
}
func (c *Config) Load(args *Args) {
c.Addr = args.Addr
c.Port = args.Port
c.DnsAddr = args.DnsAddr
c.DnsPort = args.DnsPort
c.Debug = args.Debug
c.EnableDoh = args.EnableDoh
c.NoBanner = args.NoBanner
c.SystemProxy = args.SystemProxy
c.Timeout = args.Timeout
c.AllowedPatterns = parseAllowedPattern(args.AllowedPattern, patternFile)
c.WindowSize = args.WindowSize
}
func parseAllowedPattern(patterns *StringArray, patternFile *string) []*regexp.Regexp {
var allowedPatterns []*regexp.Regexp
for _, pattern := range *patterns {
allowedPatterns = append(allowedPatterns, regexp.MustCompile(pattern))
}
for _, pattern := range strings.Split(ReadFile(patternFile), "\n") {
allowedPatterns = append(allowedPatterns, regexp.MustCompile(pattern))
}
return allowedPatterns
} Good luck with your contribution! |
I will update this PR in a couple of days. |
2cb675a
to
fe1f129
Compare
fe1f129
to
0122043
Compare
Updated the implementation. Pattern file is no longer present in config. I had to change signatures a bit, to let errors bubble to main. |
What about we utilize some kind of file which is like yaml or json? so that we can set the default value of the other arguments too. because of in my country there is some site that blocks my ip when i try to send payload with |
I think this is a good idea. I tried to workaround the lack of antipattern with regex lookaround, but Go doesn't support it. |
I put some though into it, and I think that we should abstract file reading/parsing. My initial proposal was to accept a file with a list of patterns/domains separated by newlines. It is the most common and simple format there is, and it doesn't require any preprocessing, which makes me think that it should be supported. But structured format have it's benefits. The best of both worlds, I guess, would be supporting both a simple .txt and structured .yaml files that are parsed into some common data structure. |
Hmm, then i think the simple txt file support should be prioritized. because yaml, json or whatever formats are basically common things to software engineers, however not every users of this application is software engineer. |
What about we check if each given value of --pattern argument is a file? by using os.path.exists()? Also, i've been thinking about separate the --pattern option into two different options that are --allow and --deny or something else |
I think that it would be too implicit. I don't see anything bad in adding options as long as their names are unambiguous and clearly reflect intentions, and they do not conflict with each other. |
Hey guys, it's a nice feature, it would be cool to finish it. |
This PR adds support for pattern file. The file can be used to provide a custom list of regex patterns or domains (e.g. from GoodbyeDPI) that must be proxified.
P.S. Had to re-create the branch, which automatically closed #127.