tempus/options.go

76 lines
2.0 KiB
Go
Raw Normal View History

2024-06-17 08:06:32 +00:00
package main
import (
2024-07-02 09:17:21 +00:00
"os"
2024-06-17 08:06:32 +00:00
"errors"
"github.com/projectdiscovery/goflags"
"sync"
)
var onceOptions sync.Once
var options = &Options{}
type Options struct {
URL string
// Threads int
2024-06-17 08:06:32 +00:00
// Verbose bool
SkipSave bool
Calendar string
2024-06-19 19:27:13 +00:00
User string
Password string
2024-07-02 09:17:21 +00:00
Proxy string
2024-06-17 08:06:32 +00:00
}
func ParseOptions() (*Options, error) {
var err error
onceOptions.Do(func() {
flagSet := goflags.NewFlagSet()
flagSet.SetDescription("Example - description TODO")
// flagSet.CreateGroup("input", "Input",
// flagSet.IntVarP(&options.Threads, "t", "threads", 10, "threads to run"), //TODO add estimate counter to packets/s
// flagSet.StringVarP(&options.URL, "u", "url", "", "verbose"),
// )
2024-06-19 19:27:13 +00:00
flagSet.CreateGroup("debug", "WebDAV Debug",
flagSet.StringVarP(&options.URL, "u", "url", "", "target's url"),
flagSet.StringVarP(&options.User, "l", "login", "", "WebDAV login username"),
flagSet.StringVarP(&options.Password, "p", "password", "", "WebDAV password (forbid filesystem access in WebDAV and don't forget to clean shell history!)"),
flagSet.StringVarP(&options.Calendar, "c", "calendar", "", "CalDAV calendar (to-do list) name to use (works only with -u,-l,-p flags)"),
2024-07-02 09:17:21 +00:00
flagSet.StringVarP(&options.Proxy, "P", "proxy", "", "HTTP proxy to debug errors"),
// flagSet.BoolVarP(&options.SkipSave, "s", "no-save", false, "skip save to keyring"), //TODO
2024-06-19 19:27:13 +00:00
)
2024-06-21 18:38:41 +00:00
2024-06-19 19:27:13 +00:00
// flagSet.CreateGroup("debug", "Debug",
// flagSet.BoolVarP(&options.Verbose, "v", "verbose", false, "verbose output with debugging information"),
// )
2024-06-17 08:06:32 +00:00
_ = flagSet.Parse()
err = options.SanityCheck()
})
return options, err
}
func (options *Options) SanityCheck() error {
if (options.URL != "") || (options.User != "") || (options.Password != "") {
if (options.URL != "") && (options.User != "") && (options.Password != "") {
} else {
return errors.New("-u,-l,-p flags must present")
}
2024-06-17 08:06:32 +00:00
}
2024-07-02 09:17:21 +00:00
if options.Proxy != "" {os.Setenv("HTTP_PROXY", options.Proxy)}
2024-06-17 08:06:32 +00:00
return nil
}