Skip to content
Merged
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
50 changes: 39 additions & 11 deletions cmd/dmsg-socks5/commands/dmsg-socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var (
httpClient *http.Client
dmsgSessions int
dlog *logging.Logger
dmsgHTTPPath string
err error
)

// Execute executes root CLI command.
Expand All @@ -50,24 +52,26 @@ func init() {
proxyCmd,
)

serveCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to serve socks5")
serveCmd.Flags().StringVarP(&wl, "wl", "w", "", "whitelist keys, comma separated")
serveCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url")
serveCmd.Flags().BoolVarP(&useHTTP, "http", "z", false, "use regular http to connect to dmsg discovery")
serveCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to serve socks5\033[0m\n\r")
serveCmd.Flags().StringVarP(&wl, "wl", "w", "", "whitelist keys, comma separated\033[0m\n\r")
serveCmd.Flags().StringVarP(&dmsgHTTPPath, "dmsgconf", "F", "", "dmsghttp-config path\033[0m\n\r")
serveCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url\033[0m\n\r")
serveCmd.Flags().BoolVarP(&useHTTP, "http", "z", false, "use regular http to connect to dmsg discovery\033[0m\n\r")
if os.Getenv("DMSGSK") != "" {
sk.Set(os.Getenv("DMSGSK")) //nolint
}
serveCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r")
serveCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\033[0m\n\r")

proxyCmd.Flags().IntVarP(&proxyPort, "port", "p", 1081, "TCP port to serve SOCKS5 proxy locally")
proxyCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to connect to socks5 server")
proxyCmd.Flags().StringVarP(&pubk, "pk", "k", "", "dmsg socks5 proxy server public key to connect to")
proxyCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url")
proxyCmd.Flags().BoolVarP(&useHTTP, "http", "z", false, "use regular http to connect to dmsg discovery")
proxyCmd.Flags().IntVarP(&proxyPort, "port", "p", 1081, "TCP port to serve SOCKS5 proxy locally\033[0m\n\r")
proxyCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to connect to socks5 server\033[0m\n\r")
proxyCmd.Flags().StringVarP(&pubk, "pk", "k", "", "dmsg socks5 proxy server public key to connect to\033[0m\n\r")
proxyCmd.Flags().StringVarP(&dmsgHTTPPath, "dmsgconf", "F", "", "dmsghttp-config path\033[0m\n\r")
proxyCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url\033[0m\n\r")
proxyCmd.Flags().BoolVarP(&useHTTP, "http", "z", false, "use regular http to connect to dmsg discovery\033[0m\n\r")
if os.Getenv("DMSGSK") != "" {
sk.Set(os.Getenv("DMSGSK")) //nolint
}
proxyCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r")
proxyCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\033[0m\n\r")

}

Expand Down Expand Up @@ -104,6 +108,18 @@ var serveCmd = &cobra.Command{
dlog.Info("Interrupt received. Shutting down...")
os.Exit(0)
}()

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
if err != nil {
dlog.WithError(err).Fatal("Failed to read specified dmsghttp-config")
}
err = dmsg.InitConfig()
if err != nil {
dlog.WithError(err).Fatal("Failed to unmarshal dmsghttp-config")
}
}

pk, err := sk.PubKey()
if err != nil {
pk, sk = cipher.GenerateKeyPair()
Expand Down Expand Up @@ -197,6 +213,18 @@ var proxyCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Run: func(_ *cobra.Command, _ []string) {
dlog = logging.MustGetLogger("dmsg-proxy-client")

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
if err != nil {
dlog.WithError(err).Fatal("Failed to read specified dmsghttp-config")
}
err = dmsg.InitConfig()
if err != nil {
dlog.WithError(err).Fatal("Failed to unmarshal dmsghttp-config")
}
}

var pubKey cipher.PubKey
err := pubKey.Set(pubk)
if err != nil {
Expand Down
16 changes: 15 additions & 1 deletion cmd/dmsgcurl/commands/dmsgcurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
dmsgSessions int
dmsgcurlData string
sk cipher.SecKey
pk cipher.PubKey
dlog = logging.MustGetLogger("dmsgcurl")
dmsgcurlAgent string
logLvl string
Expand All @@ -48,6 +49,7 @@ var (
dialer = proxy.Direct //nolint unused
dmsgHTTPPath string
useHTTP bool
err error
)

func init() {
Expand Down Expand Up @@ -87,7 +89,19 @@ var RootCmd = &cobra.Command{
logging.SetLevel(lvl)
}
}
pk, err := sk.PubKey()

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
if err != nil {
dlog.WithError(err).Fatal("Failed to read specified dmsghttp-config")
}
err = dmsg.InitConfig()
if err != nil {
dlog.WithError(err).Fatal("Failed to unmarshal dmsghttp-config")
}
}

pk, err = sk.PubKey()
if err != nil {
pk, sk = cipher.GenerateKeyPair()
}
Expand Down
22 changes: 16 additions & 6 deletions cmd/dmsghttp/commands/dmsghttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ var (
func init() {
RootCmd.Flags().SortFlags = false
RootCmd.Flags().BoolVarP(&useHTTP, "http", "z", false, "use regular http to connect to dmsg discovery")
//RootCmd.Flags().StringSliceVarP(&dmsgDiscs, "dmsg-disc", "c", []string{dmsg.DiscAddr(false)}, "dmsg discovery url(s)\033[0m\n\r")
RootCmd.Flags().StringVarP(&dmsgHTTPPath, "dmsgconf", "F", "", "dmsghttp-config path")
RootCmd.Flags().StringVarP(&proxyAddr, "proxy", "p", proxyAddr, "connect to dmsg via proxy (i.e. '127.0.0.1:1080')")
RootCmd.Flags().IntVarP(&dmsgSessions, "sess", "e", 1, "number of dmsg servers to connect to\033[0m\n\r")
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "debug", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m\n\r")
RootCmd.Flags().StringVarP(&serveDir, "dir", "r", ".", "local dir to serve via dmsghttp")
RootCmd.Flags().UintVarP(&dmsgPort, "port", "d", 80, "dmsg port to serve from")
RootCmd.Flags().StringVarP(&wl, "wl", "w", "", "whitelist keys, comma separated")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url")
RootCmd.Flags().StringVarP(&serveDir, "dir", "r", ".", "local dir to serve via dmsghttp\033[0m\n\r")
RootCmd.Flags().UintVarP(&dmsgPort, "port", "d", 80, "dmsg port to serve from\033[0m\n\r")
RootCmd.Flags().StringVarP(&wl, "wl", "w", "", "whitelist keys to access server, comma separated")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url\033[0m\n\r")
if os.Getenv("DMSGHTTP_SK") != "" {
sk.Set(os.Getenv("DMSGHTTP_SK")) //nolint
}
Expand Down Expand Up @@ -85,7 +84,18 @@ func server() {
wg := new(sync.WaitGroup)
wg.Add(1)

log := logging.MustGetLogger("dmsgvlc")
log := logging.MustGetLogger("dmsghttp")

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
if err != nil {
dlog.WithError(err).Fatal("Failed to read specified dmsghttp-config")
}
err = dmsg.InitConfig()
if err != nil {
dlog.WithError(err).Fatal("Failed to unmarshal dmsghttp-config")
}
}

pk, err = sk.PubKey()
if err != nil {
Expand Down
20 changes: 17 additions & 3 deletions cmd/dmsgip/commands/dmsgip.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ var (
httpClient *http.Client
useHTTP bool
dmsgSessions int
dmsgHTTPPath string
err error
)

func init() {
RootCmd.Flags().BoolVarP(&useHTTP, "http", "z", false, "use regular http to connect to dmsg discovery")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "c", dmsgDisc, "dmsg discovery url\033[0m")
RootCmd.Flags().StringVarP(&dmsgHTTPPath, "dmsgconf", "F", "", "dmsghttp-config path")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "c", dmsgDisc, "dmsg discovery url\033[0m\n\r")
RootCmd.Flags().IntVarP(&dmsgSessions, "sess", "e", 1, "number of dmsg servers to connect to\033[0m\n\r")
RootCmd.Flags().StringVarP(&proxyAddr, "proxy", "p", "", "connect to dmsg via proxy (i.e. '127.0.0.1:1080')")
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "fatal", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m")
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "fatal", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m\n\r")
if os.Getenv("DMSGIP_SK") != "" {
sk.Set(os.Getenv("DMSGIP_SK")) //nolint
}
RootCmd.Flags().StringSliceVarP(&dmsgServers, "srv", "d", []string{}, "dmsg server public keys\n\r\033[0m")
RootCmd.Flags().StringSliceVarP(&dmsgServers, "srv", "d", []string{}, "dmsg server public keys")
RootCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r\033[0m")
}

Expand All @@ -68,6 +71,17 @@ var RootCmd = &cobra.Command{
}
}

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
if err != nil {
dlog.WithError(err).Fatal("Failed to read specified dmsghttp-config")
}
err = dmsg.InitConfig()
if err != nil {
dlog.WithError(err).Fatal("Failed to unmarshal dmsghttp-config")
}
}

var srvs []cipher.PubKey
for _, srv := range dmsgServers {
var pk cipher.PubKey
Expand Down
29 changes: 23 additions & 6 deletions cmd/dmsgweb/commands/dmsgweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,22 @@ func init() {
RootCmd.Flags().BoolVarP(&useHTTP, "http", "z", false, "use regular http to connect to dmsg discovery")
RootCmd.Flags().StringVarP(&filterDomainSuffix, "filter", "f", ".dmsg", "domain suffix to filter\033[0m\n\r")
RootCmd.Flags().UintVarP(&proxyPort, "socks", "q", proxyPort, "port to serve the socks5 proxy\033[0m\n\r")
RootCmd.Flags().StringVarP(&addProxy, "addproxy", "r", addProxy, "configure additional socks5 proxy for dmsgweb (i.e. 127.0.0.1:1080)\033[0m\n\r")
RootCmd.Flags().StringVarP(&addProxy, "addproxy", "r", addProxy, "configure additional socks5 proxy for dmsgweb (i.e. 127.0.0.1:1080)")
RootCmd.Flags().UintSliceVarP(&webPort, "port", "p", webPort, "port(s) to serve the web application\033[0m\n\r")
RootCmd.Flags().StringSliceVarP(&resolveDmsgAddr, "resolve", "t", resolveDmsgAddr, "resolve the specified dmsg address:port on the local port & disable proxy\033[0m\n\r")
RootCmd.Flags().StringSliceVarP(&resolveDmsgAddr, "resolve", "t", resolveDmsgAddr, "resolve the specified dmsg address:port on the local port & disable proxy")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url\033[0m\n\r")
RootCmd.Flags().StringVarP(&proxyAddr, "proxy", "x", "", "connect to dmsg via proxy (i.e. '127.0.0.1:1080')\033[0m\n\r")
RootCmd.Flags().StringVarP(&dmsgHTTPPath, "dmsgconf", "F", "", "dmsghttp-config path")
RootCmd.Flags().StringVarP(&proxyAddr, "proxy", "x", "", "connect to dmsg via proxy (i.e. '127.0.0.1:1080')")
RootCmd.Flags().IntVarP(&dmsgSessions, "sess", "e", dmsgSess, "number of dmsg servers to connect to\033[0m\n\r")
RootCmd.Flags().BoolSliceVarP(&rawTCP, "rt", "c", rawTCP, "proxy local port as raw TCP\033[0m\n\r")
RootCmd.Flags().BoolSliceVarP(&rawTCP, "rt", "c", rawTCP, "proxy local port as raw TCP, comma separated"+func() string {
if len(rawTCP) > 0 {
return "\033[0m\n\r"
}
return ""
}())
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "debug", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m\n\r")
RootCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r")
RootCmd.Flags().BoolVarP(&isEnvs, "envs", "Z", false, "show example .conf file\033[0m\n\r")
RootCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\033[0m\n\r")
RootCmd.Flags().BoolVarP(&isEnvs, "envs", "Z", false, "show example .conf file")

}

Expand Down Expand Up @@ -119,6 +125,17 @@ dmsgweb conf file detected: ` + dwcfg
dlog.Fatal("Dmsg Discovery URL not specified")
}

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
if err != nil {
dlog.WithError(err).Fatal("Failed to read specified dmsghttp-config")
}
err = dmsg.InitConfig()
if err != nil {
dlog.WithError(err).Fatal("Failed to unmarshal dmsghttp-config")
}
}

if len(resolveDmsgAddr) > 0 && len(webPort) != len(resolveDmsgAddr) {
dlog.Fatal("-resolve --t flag cannot contain a different number of elements than -port -p flag")
}
Expand Down
31 changes: 27 additions & 4 deletions cmd/dmsgweb/commands/dmsgwebsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,24 @@ func init() {
srvCmd.Flags().BoolVarP(&useHTTP, "http", "z", false, "use regular http to connect to dmsg discovery")
srvCmd.Flags().UintSliceVarP(&localPort, "lport", "p", localPort, "local application interface port(s)\033[0m\n\r")
srvCmd.Flags().UintSliceVarP(&dmsgPort, "dport", "d", dmsgPort, "DMSG port(s) to serve\033[0m\n\r")
srvCmd.Flags().StringSliceVarP(&wl, "wl", "w", wl, "whitelisted keys for DMSG authenticated routes\033[0m\n\r")
srvCmd.Flags().StringSliceVarP(&wl, "wl", "w", wl, "whitelisted keys for DMSG authenticated routes"+func() string {
if len(wl) > 0 {
return "\033[0m\n\r"
}
return ""
}())
srvCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "DMSG discovery URL\033[0m\n\r")
srvCmd.Flags().StringVarP(&proxyAddr, "proxy", "x", proxyAddr, "connect to DMSG via proxy (e.g., '127.0.0.1:1080')\033[0m\n\r")
srvCmd.Flags().StringVarP(&dmsgHTTPPath, "dmsgconf", "F", "", "dmsghttp-config path")
srvCmd.Flags().StringVarP(&proxyAddr, "proxy", "x", proxyAddr, "connect to DMSG via proxy (e.g., '127.0.0.1:1080')")
srvCmd.Flags().IntVarP(&dmsgSess, "dsess", "e", dmsgSess, "DMSG sessions\033[0m\n\r")
srvCmd.Flags().BoolSliceVarP(&rawTCP, "rt", "c", rawTCP, "proxy local port as raw TCP, comma separated\033[0m\n\r")
srvCmd.Flags().BoolSliceVarP(&rawTCP, "rt", "c", rawTCP, "proxy local port as raw TCP, comma separated"+func() string {
if len(rawTCP) > 0 {
return "\033[0m\n\r"
}
return ""
}())
srvCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "debug", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m\n\r")
srvCmd.Flags().BoolVarP(&isEnvs, "envs", "Z", false, "show example .conf file\033[0m\n\r")
srvCmd.Flags().BoolVarP(&isEnvs, "envs", "Z", false, "show example .conf file")
srvCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\033[0m\n\r")
srvCmd.CompletionOptions.DisableDefaultCmd = true
}
Expand All @@ -76,6 +87,18 @@ var srvCmd = &cobra.Command{
}
}
dlog = logging.MustGetLogger("dmsgwebsrv")

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
if err != nil {
dlog.WithError(err).Fatal("Failed to read specified dmsghttp-config")
}
err = dmsg.InitConfig()
if err != nil {
dlog.WithError(err).Fatal("Failed to unmarshal dmsghttp-config")
}
}

if len(localPort) != len(dmsgPort) || len(localPort) != len(rawTCP) {
dlog.Fatal("The number of local ports, DMSG ports, and raw TCP flags must be the same")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/dmsgweb/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var (
httpClient *http.Client //nolint unused
dialer proxy.Dialer = proxy.Direct
useHTTP bool
dmsgHTTPPath string
)

// Execute executes root CLI command.
Expand Down
15 changes: 12 additions & 3 deletions pkg/dmsg/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,26 @@ type DmsghttpConfig struct {
}

func init() {
err := InitConfig()
if err != nil {
log.Panic(err)
}
}

// InitConfig initialized the config
func InitConfig() error {
var envServices skywire.EnvServices
err := json.Unmarshal(DmsghttpJSON, &envServices)
if err != nil {
log.Panic(err)
return err
}
err = json.Unmarshal(envServices.Prod, &Prod)
if err != nil {
log.Panic(err)
return err
}
err = json.Unmarshal(envServices.Test, &Test)
if err != nil {
log.Panic(err)
return err
}
return nil
}
Loading