diff --git a/cmd/proxify/proxify.go b/cmd/proxify/proxify.go index 58dcbac7..f7453af1 100644 --- a/cmd/proxify/proxify.go +++ b/cmd/proxify/proxify.go @@ -8,6 +8,7 @@ import ( "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/proxify/internal/runner" + "github.com/projectdiscovery/proxify/pkg/templates" ) func main() { @@ -17,7 +18,18 @@ func main() { gologger.Fatal().Msgf("Could not parse options: %s\n", err) } + if options.Template != "" { + templateOptions, err := templates.Parse(options.Template) + if err != nil { + gologger.Fatal().Msgf("Could not parse template: %s\n", err) + } + if templateOptions.ListenAddrHTTP != "" { + options.ListenAddrHTTP = templateOptions.ListenAddrHTTP + } + } + proxifyRunner, err := runner.NewRunner(options) + if err != nil { gologger.Fatal().Msgf("Could not create runner: %s\n", err) } diff --git a/internal/runner/options.go b/internal/runner/options.go index 87e1e4e2..e7114165 100644 --- a/internal/runner/options.go +++ b/internal/runner/options.go @@ -60,6 +60,7 @@ type Options struct { MaxSize int DisableUpdateCheck bool // DisableUpdateCheck disables automatic update check OutputJsonl bool // OutputJsonl outputs data in JSONL format + Template string // Template file to use } func ParseOptions() (*Options, error) { @@ -116,6 +117,7 @@ func ParseOptions() (*Options, error) { flagSet.CreateGroup("configuration", "Configuration", flagSet.StringVar(&cfgFile, "config", "", "path to the proxify configuration file"), + flagSet.StringVarP(&options.Template, "template", "t", "", "path to the proxify template file"), flagSet.StringVarP(&options.LoggerConfig, "export-config", "ec", filepath.Join(homeDir, ".config", "proxify", logger.LoggerConfigFilename), "proxify export module configuration file"), flagSet.StringVar(&options.ConfigDir, "config-directory", filepath.Join(homeDir, ".config", "proxify"), "override the default config path ($home/.config/proxify)"), flagSet.IntVar(&options.CertCacheSize, "cert-cache-size", 256, "Number of certificates to cache"), diff --git a/pkg/templates/templates.go b/pkg/templates/templates.go new file mode 100644 index 00000000..06f367e5 --- /dev/null +++ b/pkg/templates/templates.go @@ -0,0 +1,35 @@ +package templates + +import ( + "os" + + "github.com/projectdiscovery/proxify/internal/runner" + "gopkg.in/yaml.v2" +) + +type Template struct { + Proxy Proxy `yaml:"proxy"` +} + +type Proxy struct { + HTTPAddr string `yaml:"http-addr"` +} + +func Parse(templatePath string) (*runner.Options, error) { + file, err := os.ReadFile(templatePath) + if err != nil { + return nil, err + } + + var template Template + err = yaml.Unmarshal(file, &template) + if err != nil { + return nil, err + } + + options := &runner.Options{ + ListenAddrHTTP: template.Proxy.HTTPAddr, + } + + return options, nil +}