Skip to content
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
12 changes: 12 additions & 0 deletions cmd/proxify/proxify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/proxify/internal/runner"
"github.com/projectdiscovery/proxify/pkg/templates"
)

func main() {
Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"),
Expand Down
35 changes: 35 additions & 0 deletions pkg/templates/templates.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading