2020-04-03 22:15:39 +00:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-05-01 15:27:33 +00:00
|
|
|
"net/url"
|
2020-04-03 22:15:39 +00:00
|
|
|
|
|
|
|
"github.com/projectdiscovery/gologger"
|
|
|
|
)
|
|
|
|
|
|
|
|
// validateOptions validates the configuration options passed
|
|
|
|
func (options *Options) validateOptions() error {
|
|
|
|
// Both verbose and silent flags were used
|
|
|
|
if options.Verbose && options.Silent {
|
|
|
|
return errors.New("both verbose and silent mode specified")
|
|
|
|
}
|
|
|
|
|
2020-06-26 12:37:55 +00:00
|
|
|
// Check if a list of templates was provided and it exists
|
2020-07-13 22:04:19 +00:00
|
|
|
if len(options.Templates) == 0 && !options.UpdateTemplates {
|
2020-06-26 12:37:55 +00:00
|
|
|
return errors.New("no template/templates provided")
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:10:20 +00:00
|
|
|
if options.Targets == "" && !options.Stdin && options.Target == "" && !options.UpdateTemplates {
|
2020-06-26 12:37:55 +00:00
|
|
|
return errors.New("no target input provided")
|
2020-04-04 10:29:05 +00:00
|
|
|
}
|
2020-05-01 15:27:33 +00:00
|
|
|
|
|
|
|
// Validate proxy options if provided
|
|
|
|
if options.ProxyURL != "" && !isValidProxyURL(options.ProxyURL) {
|
2020-05-01 19:29:25 +00:00
|
|
|
return errors.New("invalid http proxy format (It should be http://username:password@host:port)")
|
2020-05-01 15:27:33 +00:00
|
|
|
}
|
|
|
|
if options.ProxySocksURL != "" && !isValidProxyURL(options.ProxySocksURL) {
|
|
|
|
return errors.New("invalid socks proxy format (It should be socks5://username:password@host:port)")
|
|
|
|
}
|
|
|
|
|
2020-04-03 22:15:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-01 15:27:33 +00:00
|
|
|
func isValidProxyURL(URL string) bool {
|
|
|
|
if _, err := url.Parse(URL); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-04-03 22:15:39 +00:00
|
|
|
// configureOutput configures the output on the screen
|
|
|
|
func (options *Options) configureOutput() {
|
|
|
|
// If the user desires verbose output, show verbose output
|
|
|
|
if options.Verbose {
|
|
|
|
gologger.MaxLevel = gologger.Verbose
|
|
|
|
}
|
|
|
|
if options.NoColor {
|
|
|
|
gologger.UseColors = false
|
|
|
|
}
|
|
|
|
if options.Silent {
|
|
|
|
gologger.MaxLevel = gologger.Silent
|
|
|
|
}
|
|
|
|
}
|