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 {
2024-06-29 01:00:39 +00:00
URL string
// Threads int
2024-06-17 08:06:32 +00:00
// Verbose bool
2024-06-29 01:00:39 +00:00
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" )
2024-06-29 01:00:39 +00:00
// 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" ,
2024-06-29 01:00:39 +00:00
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" ) ,
2024-06-29 01:00:39 +00:00
// 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 {
2024-06-29 01:00:39 +00:00
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
}