Documentation
¶
Overview ¶
Package commands cmd/dmsg/dmsgcurl/commands/dmsgcurl.go c1-net-dmsg
Package commands cmd/dmsg/dmsgcurl/commands/errors.go c1-net-dmsg
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RootCmd = &cobra.Command{ Use: "curl", Short: "DMSG curl utility", Long: calvin.AsciiFont("dmsgcurl") + ` DMSG curl utility`, SilenceErrors: true, SilenceUsage: true, DisableSuggestions: true, DisableFlagsInUseLine: true, Version: buildinfo.Version(), RunE: func(_ *cobra.Command, args []string) error { if logLvl != "" { if lvl, err := logging.LevelFromString(logLvl); err == nil { logging.SetLevel(lvl) } } if dmsgclient.DmsgHTTPPath != "" { dmsg.DmsghttpJSON, err = os.ReadFile(dmsgclient.DmsgHTTPPath) 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 { _, sk = cipher.GenerateKeyPair() pk, err = sk.PubKey() if err != nil { dlog.WithError(err).Fatal("Failed to derive public key from secret key") } } if len(args) == 0 { dlog.WithError(fmt.Errorf("no URL(s) provided")).Error(errorDesc["FAILED_INIT"] + "\n") os.Exit(errorCode["FAILED_INIT"]) } if len(args) > 1 { dlog.WithError(fmt.Errorf("multiple URLs are not yet supported")).Error(errorDesc["FAILED_INIT"] + "\n") os.Exit(errorCode["FAILED_INIT"]) } parsedURL, err := url.Parse(args[0]) if err != nil { dlog.WithError(fmt.Errorf("failed to parse provided URL")).Error(errorDesc["URL_MALFORMAT"] + "\n") os.Exit(errorCode["URL_MALFORMAT"]) } destSlc := strings.Split(parsedURL.Host, ":") if len(destSlc) == 1 { destSlc = append(destSlc, "80") } err = destPK.Set(destSlc[0]) if err != nil { dlog.WithError(err).Fatal("bad PK for host\n") } var cErr curlError ctx, cancel := cmdutil.SignalContext(context.Background(), dlog) defer cancel() httpClient := &http.Client{} if proxyAddr != "" { dialer, err := proxy.SOCKS5("tcp", proxyAddr, nil, proxy.Direct) if err != nil { dlog.WithError(fmt.Errorf("Error creating SOCKS5 dialer: %v", err)).Error(errorDesc["COULDNT_RESOLVE_PROXY"]) os.Exit(errorCode["COULDNT_RESOLVE_PROXY"]) } transport := &http.Transport{ DialContext: dialer.(proxy.ContextDialer).DialContext, } httpClient = &http.Client{ Transport: transport, } ctx = context.WithValue(ctx, "socks5_proxy", proxyAddr) } if anyServer { ctx = dmsg.WithServerSweep(ctx) } cErr = handleRequest(ctx, pk, sk, httpClient, parsedURL, dmsgcurlData) if cErr.Code == 0 { return nil } if cErr.Code != 0 { dlog.WithError(cErr.Error).Error("An error occurred\n") return cErr.Error } return err }, }
RootCmd contains the root cli command
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.