From b03f7a5ca6c2425afea9a452d490336ca79cb88a Mon Sep 17 00:00:00 2001 From: Moses Narrow <36607567+0pcom@users.noreply.github.com> Date: Sun, 9 Jul 2023 13:33:11 -0500 Subject: [PATCH] source a .conf file with skywire-cli config gen (#1644) * include accidentally omitted * revert skywire-cli ut to previous state * update go.mod ; make format check --- cmd/skywire-cli/commands/config/gen.go | 196 +++++++++++++++--- cmd/skywire-cli/commands/config/root.go | 142 ++++++------- go.mod | 4 +- go.sum | 8 +- .../skywire-utilities/pkg/httputil/health.go | 1 + vendor/modules.txt | 4 +- 6 files changed, 247 insertions(+), 108 deletions(-) diff --git a/cmd/skywire-cli/commands/config/gen.go b/cmd/skywire-cli/commands/config/gen.go index dafe4a843c..9bf3f9de91 100644 --- a/cmd/skywire-cli/commands/config/gen.go +++ b/cmd/skywire-cli/commands/config/gen.go @@ -173,18 +173,18 @@ func init() { genConfigCmd.Flags().BoolVar(&isAll, "all", false, "show all flags") genConfigCmd.Flags().StringVar(&binPath, "binpath", scriptExecString("${BINPATH}"), "set bin_path\033[0m") gHiddenFlags = append(gHiddenFlags, "binpath") - // genConfigCmd.Flags().StringVar(&addSkysocksClientSrv, "proxyclientpk", scriptExecString("${PROXYCLIENTPK}"), "set server public key for proxy client") - // genConfigCmd.Flags().BoolVar(&proxyClientAutostart, "startproxyclient", scriptExecBool("${STARTPROXYCLIENT:-false}"), "autostart proxy client") - // genConfigCmd.Flags().BoolVar(&disableProxyServerAutostart, "noproxyserver", scriptExecBool("${NOPROXYSERVER:-false}"), "disable autostart of proxy server") - // genConfigCmd.Flags().StringVar(&proxyServerPass, "proxyserverpass", "", "set password for the proxy server") - // genConfigCmd.Flags().StringVar(&proxyClientPass, "proxyclientpass", "", "set password for the proxy client to access the proxy server (if needed)") - // // TODO: Password for accessing proxy client - // genConfigCmd.Flags().StringVar(&setVPNClientKillswitch, "killsw", "", "vpn client killswitch") - // genConfigCmd.Flags().StringVar(&addVPNClientSrv, "addvpn", "", "set vpn server public key for vpn client") - // genConfigCmd.Flags().StringVar(&addVPNClientPasscode, "vpnpass", "", "password for vpn client to access the vpn server (if needed)") - // genConfigCmd.Flags().StringVar(&addVPNServerPasscode, "vpnserverpass", "", "set password to the vpn server") - // genConfigCmd.Flags().StringVar(&setVPNServerSecure, "secure", "", "change secure mode status of vpn server") - // genConfigCmd.Flags().StringVar(&setVPNServerNetIfc, "netifc", "", "VPN Server network interface (detected: "+getInterfaceNames()+")") + genConfigCmd.Flags().StringVar(&addSkysocksClientSrv, "proxyclientpk", scriptExecString("${PROXYCLIENTPK}"), "set server public key for proxy client") + genConfigCmd.Flags().BoolVar(&enableProxyClientAutostart, "startproxyclient", scriptExecBool("${STARTPROXYCLIENT:-false}"), "autostart proxy client") + genConfigCmd.Flags().BoolVar(&disableProxyServerAutostart, "noproxyserver", scriptExecBool("${NOPROXYSERVER:-false}"), "disable autostart of proxy server") + genConfigCmd.Flags().StringVar(&proxyServerPass, "proxyserverpass", scriptExecString("${PROXYSEVERPASS}"), "set proxy server password") + genConfigCmd.Flags().StringVar(&proxyClientPass, "proxyclientpass", scriptExecString("${PROXYCLIENTPASS}"), "password for the proxy client to access the server (if needed)") + // TODO: Password for accessing proxy client + genConfigCmd.Flags().StringVar(&setVPNClientKillswitch, "killsw", scriptExecString("${VPNKS}"), "vpn client killswitch") + genConfigCmd.Flags().StringVar(&addVPNClientSrv, "addvpn", scriptExecString("${ADDVPNPK}"), "set vpn server public key for vpn client") + genConfigCmd.Flags().StringVar(&addVPNClientPasscode, "vpnpass", scriptExecString("${VPNCLIENTPASS}"), "password for vpn client to access the vpn server (if needed)") + genConfigCmd.Flags().StringVar(&addVPNServerPasscode, "vpnserverpass", scriptExecString("${VPNSEVERPASS}"), "set password to the vpn server") + genConfigCmd.Flags().StringVar(&setVPNServerSecure, "secure", scriptExecString("${VPNSEVERSECURE}"), "change secure mode status of vpn server") + genConfigCmd.Flags().StringVar(&setVPNServerNetIfc, "netifc", scriptExecString("${VPNSEVERNETIFC}"), "VPN Server network interface (detected: "+getInterfaceNames()+")") genConfigCmd.Flags().BoolVarP(&isEnvs, "envs", "q", false, "show the environmental variable settings") gHiddenFlags = append(gHiddenFlags, "envs") genConfigCmd.Flags().BoolVar(&noFetch, "nofetch", false, "do not fetch the services from the service conf url") @@ -497,24 +497,23 @@ var genConfigCmd = &cobra.Command{ log.WithError(err).Error("Failed to fetch servers\n") log.Warn("Falling back on hardcoded servers") } - } else { - // nil error from client.Get - if res.Body != nil { - defer res.Body.Close() //nolint - } - body, err := io.ReadAll(res.Body) - if err != nil { - log.WithError(err).Fatal("Failed to read response\n") - } - //fill in services struct with the response - err = json.Unmarshal(body, &services) - if err != nil { - log.WithError(err).Fatal("Failed to unmarshal json response\n") - } - if !isStdout { - log.Infof("Fetched service endpoints from '%s'", serviceConfURL) - } } + if res.Body != nil { + defer res.Body.Close() //nolint + } + body, err := io.ReadAll(res.Body) + if err != nil { + log.WithError(err).Fatal("Failed to read response\n") + } + //fill in services struct with the response + err = json.Unmarshal(body, &services) + if err != nil { + log.WithError(err).Fatal("Failed to unmarshal json response\n") + } + if !isStdout { + log.Infof("Fetched service endpoints from '%s'", serviceConfURL) + } + // reset the state of isStdout isStdout = wasStdout } @@ -990,6 +989,79 @@ var genConfigCmd = &cobra.Command{ newConfLauncherApps := append(conf.Launcher.Apps, exampleApps...) conf.Launcher.Apps = newConfLauncherApps } + + if addVPNServerPasscode != "" { + changeAppsConfig(conf, "vpn-server", "--passcode", addVPNServerPasscode) + } + if setVPNServerNetIfc != "" { + changeAppsConfig(conf, "vpn-server", "--netifc", setVPNServerNetIfc) + } + switch setVPNServerSecure { + case "true": + changeAppsConfig(conf, "vpn-server", "--secure", setVPNServerSecure) + case "false": + changeAppsConfig(conf, "vpn-server", "--secure", setVPNServerSecure) + } + switch setVPNServerAutostart { + case "true": + for i, app := range conf.Launcher.Apps { + if app.Name == "vpn-server" { + conf.Launcher.Apps[i].AutoStart = true + } + } + case "false": + for i, app := range conf.Launcher.Apps { + if app.Name == "vpn-server" { + conf.Launcher.Apps[i].AutoStart = false + } + } + } + + switch setVPNClientKillswitch { + case "true": + changeAppsConfig(conf, "vpn-client", "--killswitch", setVPNClientKillswitch) + case "false": + changeAppsConfig(conf, "vpn-client", "--killswitch", setVPNClientKillswitch) + } + if addVPNClientSrv != "" { + keyParsed, err := coinCipher.PubKeyFromHex(strings.TrimSpace(addVPNClientSrv)) + if err != nil { + log.WithError(err).Fatalf("Failed to parse hypervisor private key: %s.", addVPNClientSrv) + } + changeAppsConfig(conf, "vpn-client", "--srv", keyParsed.Hex()) + } + + if addVPNClientPasscode != "" { + changeAppsConfig(conf, "vpn-client", "--passcode", addVPNClientPasscode) + } + if addSkysocksClientSrv != "" { + keyParsed, err := coinCipher.PubKeyFromHex(strings.TrimSpace(addSkysocksClientSrv)) + if err != nil { + logger.WithError(err).Fatalf("Failed to parse public key: %s.", addSkysocksClientSrv) + } + changeAppsConfig(conf, "skysocks-client", "--srv", keyParsed.Hex()) + } + if proxyServerPass != "" { + changeAppsConfig(conf, "skysocks", "--passcode", proxyServerPass) + } + if proxyClientPass != "" { + changeAppsConfig(conf, "skysocks-client", "--passcode", proxyClientPass) + } + + if disableProxyServerAutostart { + for i, app := range conf.Launcher.Apps { + if app.Name == "skysocks" { + conf.Launcher.Apps[i].AutoStart = false + } + } + } + if enableProxyClientAutostart { + for i, app := range conf.Launcher.Apps { + if app.Name == "skysocks-client" { + conf.Launcher.Apps[i].AutoStart = true + } + } + } if isHypervisor { // Disable hypervisor UI authentication --disable-auth flag if isDisableAuth { @@ -1152,6 +1224,40 @@ const envfileLinux = `# #-- Set app bin_path #BINPATH='./apps' +#-- Set server public key for proxy client to connect to +#PROXYCLIENTPK='' + +#-- Enable autostart of the proxy client +#STARTPROXYCLIENT=true + +#-- Disable autostart of proxy server +#NOPROXYSERVER=true + +#-- Set a password for the proxy server +#PROXYSEVERPASS='' + +#-- Password for the proxy client to access the server (if password is set for the server) +#PROXYCLIENTPASS='' + +#-- Set VPN client killswitch +#VPNKS=true + +#-- Set vpn server public key for the vpn client to use +#ADDVPNPK='' + +#-- Password for vpn client to access the server (if password is set forthe server) +#VPNCLIENTPASS='' + +#-- Set password to the vpn server +#VPNSEVERPASS='' + +#-- Change secure mode status of vpn server +#VPNSEVERSECURE='' + +#-- Set VPN Server network interface +#VPNSEVERNETIFC='' + + ` const envfileWindows = `# # C:\ProgramData\skywire.ps1 @@ -1218,4 +1324,36 @@ const envfileWindows = `# #-- Set app bin_path #$BINPATH='./apps' +#-- Set server public key for proxy client to connect to +#$PROXYCLIENTPK='' + +#-- Enable autostart of the proxy client +#$STARTPROXYCLIENT=true + +#-- Disable autostart of proxy server +#$NOPROXYSERVER=true + +#-- Set a password for the proxy server +#$PROXYSEVERPASS='' + +#-- Password for the proxy client to access the server (if password is set for the server) +#$PROXYCLIENTPASS='' + +#-- Set VPN client killswitch +#$VPNKS=true + +#-- Set vpn server public key for the vpn client to use +#$ADDVPNPK='' + +#-- Password for vpn client to access the server (if password is set forthe server) +#$VPNCLIENTPASS='' + +#-- Set password to the vpn server +#$VPNSEVERPASS='' + +#-- Change secure mode status of vpn server +#$VPNSEVERSECURE='' + +#-- Set VPN Server network interface +#$VPNSEVERNETIFC='' ` diff --git a/cmd/skywire-cli/commands/config/root.go b/cmd/skywire-cli/commands/config/root.go index abbb30b3b4..aa6c856552 100644 --- a/cmd/skywire-cli/commands/config/root.go +++ b/cmd/skywire-cli/commands/config/root.go @@ -15,83 +15,83 @@ import ( var logger = logging.MustGetLogger("skywire-cli") -// proxyClientAutostart bool //nolint Note: pending implementation for config gen -// disableProxyServerAutostart bool //nolint Note: pending implementation for config gen -// proxyServerPass string //nolint Note: pending implementation for config gen -// proxyClientPass string //nolint Note: pending implementation for config gen var ( conf = new(visorconfig.V1) dmsgHTTPServersList = &visorconfig.DmsgHTTPServers{ Test: visorconfig.DmsgHTTPServersData{DMSGServers: []*disc.Entry{}}, Prod: visorconfig.DmsgHTTPServersData{DMSGServers: []*disc.Entry{}}, } - noFetch bool - noDefaults bool - stcprPort int - sudphPort int - sk cipher.SecKey - output string - confPath string - configName string //nolint Note: configName used, but golangci-lint marked it unused in wrong - isStdout bool - isRegen bool - isRetainHypervisors bool - isTestEnv bool - pText string - isPkgEnv bool - isUsrEnv bool - isHypervisor bool - hypervisorPKs string - dmsgptyWlPKs string - surveyWhitelistPKs string - routeSetupNodes string - transportSetupPKs string - isDmsgHTTP bool - isVpnServerEnable bool - isDisableAuth bool - isEnableAuth bool - selectedOS string - disableApps string - isBestProtocol bool - serviceConfURL string - services *visorconfig.Services - isForce bool - isHide bool - isAll bool - isOutUnset bool - ver string - isRoot = visorconfig.IsRoot() - svcConf = strings.ReplaceAll(utilenv.ServiceConfAddr, "http://", "") //visorconfig.DefaultServiceConfAddr - testConf = strings.ReplaceAll(utilenv.TestServiceConfAddr, "http://", "") //visorconfig.DefaultServiceConfAddr - gHiddenFlags []string - uHiddenFlags []string - binPath string - logLevel string - isPkg bool - input string - isUpdateEndpoints bool - addHypervisorPKs string - isResetHypervisor bool - setVPNClientKillswitch string - addVPNClientSrv string - addVPNClientPasscode string - isResetVPNclient bool - addVPNServerPasscode string - setVPNServerSecure string - setVPNServerAutostart string - setVPNServerNetIfc string - isResetVPNServer bool - addSkysocksClientSrv string - isResetSkysocksClient bool - skysocksPasscode string - isResetSkysocks bool - setPublicAutoconnect string - minHops int - isUsr bool - isPublic bool - disablePublicAutoConn bool - isDisplayNodeIP bool - addExampleApps bool + noFetch bool + noDefaults bool + stcprPort int + sudphPort int + sk cipher.SecKey + output string + confPath string + configName string //nolint Note: configName used, but golangci-lint marked it unused in wrong + isStdout bool + isRegen bool + isRetainHypervisors bool + isTestEnv bool + pText string + isPkgEnv bool + isUsrEnv bool + isHypervisor bool + hypervisorPKs string + dmsgptyWlPKs string + surveyWhitelistPKs string + routeSetupNodes string + transportSetupPKs string + isDmsgHTTP bool + isVpnServerEnable bool + isDisableAuth bool + isEnableAuth bool + selectedOS string + disableApps string + isBestProtocol bool + serviceConfURL string + services *visorconfig.Services + isForce bool + isHide bool + isAll bool + isOutUnset bool + ver string + isRoot = visorconfig.IsRoot() + svcConf = strings.ReplaceAll(utilenv.ServiceConfAddr, "http://", "") //visorconfig.DefaultServiceConfAddr + testConf = strings.ReplaceAll(utilenv.TestServiceConfAddr, "http://", "") //visorconfig.DefaultServiceConfAddr + gHiddenFlags []string + uHiddenFlags []string + binPath string + logLevel string + isPkg bool + input string + isUpdateEndpoints bool + addHypervisorPKs string + isResetHypervisor bool + setVPNClientKillswitch string + addVPNClientSrv string + addVPNClientPasscode string + isResetVPNclient bool + addVPNServerPasscode string + setVPNServerSecure string + setVPNServerAutostart string + setVPNServerNetIfc string + isResetVPNServer bool + addSkysocksClientSrv string + isResetSkysocksClient bool + skysocksPasscode string + isResetSkysocks bool + setPublicAutoconnect string + minHops int + isUsr bool + isPublic bool + disablePublicAutoConn bool + isDisplayNodeIP bool + addExampleApps bool + enableProxyClientAutostart bool + disableProxyServerAutostart bool + proxyServerPass string + proxyClientPass string ) // RootCmd contains commands that interact with the config of local skywire-visor diff --git a/go.mod b/go.mod index 0986478430..5a6c1b33b7 100644 --- a/go.mod +++ b/go.mod @@ -51,8 +51,8 @@ require ( github.com/lib/pq v1.10.7 github.com/orandin/lumberjackrus v1.0.1 github.com/pterm/pterm v0.12.49 - github.com/skycoin/dmsg v1.3.0-rc1.0.20230609193507-b02bb8f7d1bc - github.com/skycoin/skywire-utilities v0.0.0-20230601232053-0abbc9604fbc + github.com/skycoin/dmsg v1.3.11 + github.com/skycoin/skywire-utilities v0.0.0-20230609191923-1e678802e17e github.com/skycoin/systray v1.10.0 github.com/spf13/pflag v1.0.5 github.com/zcalusic/sysinfo v0.9.5 diff --git a/go.sum b/go.sum index 72f8836038..0bafe52e37 100644 --- a/go.sum +++ b/go.sum @@ -317,14 +317,14 @@ github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5k github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/skycoin/dmsg v1.3.0-rc1.0.20230609193507-b02bb8f7d1bc h1:tpY1mZI6ZZ5vI8Ato5S1V4Mfs8gqErM2yE6B/nftof0= -github.com/skycoin/dmsg v1.3.0-rc1.0.20230609193507-b02bb8f7d1bc/go.mod h1:Cw6rzzqGU75yHJZB+PFnZa4jhhinZvD+UrtpaTEkBJ0= +github.com/skycoin/dmsg v1.3.11 h1:l2T8SuAHYrrgCfzgJIqaT/9rwlBgTyRwsfNOBbsWCX0= +github.com/skycoin/dmsg v1.3.11/go.mod h1:3j74fE5sFiMJoMfqF9qGhC6GVRqCMkX4l2EHc0OQkGc= github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA= github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:UXghlricA7J3aRD/k7p/zBObQfmBawwCxIVPVjz2Q3o= github.com/skycoin/skycoin v0.27.1 h1:HatxsRwVSPaV4qxH6290xPBmkH/HgiuAoY2qC+e8C9I= github.com/skycoin/skycoin v0.27.1/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw= -github.com/skycoin/skywire-utilities v0.0.0-20230601232053-0abbc9604fbc h1:gEoSRbVm1AeHkKHqXocftHoESJAaabeYxWSffLdP0P8= -github.com/skycoin/skywire-utilities v0.0.0-20230601232053-0abbc9604fbc/go.mod h1:X5H+fKC3rD11/sm4t9V2FWy/aet7OdEilaO2Ar3waXY= +github.com/skycoin/skywire-utilities v0.0.0-20230609191923-1e678802e17e h1:ozVF7awMYpXZqIOMMFYUAifB+kaaEldfisvtoVpuWNE= +github.com/skycoin/skywire-utilities v0.0.0-20230609191923-1e678802e17e/go.mod h1:X5H+fKC3rD11/sm4t9V2FWy/aet7OdEilaO2Ar3waXY= github.com/skycoin/systray v1.10.0 h1:fQZJHMylpVvfmOOTLvUssfyHVDoC8Idx6Ba2BlLEuGg= github.com/skycoin/systray v1.10.0/go.mod h1:/i17Eni5GxFiboIZceeamY5LktDSFFRCvd3fBMerQ+4= github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8= diff --git a/vendor/github.com/skycoin/skywire-utilities/pkg/httputil/health.go b/vendor/github.com/skycoin/skywire-utilities/pkg/httputil/health.go index 1249324700..6963bf2da7 100644 --- a/vendor/github.com/skycoin/skywire-utilities/pkg/httputil/health.go +++ b/vendor/github.com/skycoin/skywire-utilities/pkg/httputil/health.go @@ -15,6 +15,7 @@ var path = "/health" type HealthCheckResponse struct { BuildInfo *buildinfo.Info `json:"build_info,omitempty"` StartedAt time.Time `json:"started_at"` + DmsgAddr string `json:"dmsg_address,omitempty"` } // GetServiceHealth gets the response from the given service url diff --git a/vendor/modules.txt b/vendor/modules.txt index 5ab6dbec5c..eec022a62a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -291,7 +291,7 @@ github.com/shirou/gopsutil/v3/process ## explicit; go 1.13 github.com/sirupsen/logrus github.com/sirupsen/logrus/hooks/syslog -# github.com/skycoin/dmsg v1.3.0-rc1.0.20230609193507-b02bb8f7d1bc +# github.com/skycoin/dmsg v1.3.11 ## explicit; go 1.18 github.com/skycoin/dmsg/internal/servermetrics github.com/skycoin/dmsg/pkg/direct @@ -315,7 +315,7 @@ github.com/skycoin/skycoin/src/cipher/ripemd160 github.com/skycoin/skycoin/src/cipher/secp256k1-go github.com/skycoin/skycoin/src/cipher/secp256k1-go/secp256k1-go2 github.com/skycoin/skycoin/src/util/logging -# github.com/skycoin/skywire-utilities v0.0.0-20230601232053-0abbc9604fbc +# github.com/skycoin/skywire-utilities v0.0.0-20230609191923-1e678802e17e ## explicit; go 1.17 github.com/skycoin/skywire-utilities/pkg/buildinfo github.com/skycoin/skywire-utilities/pkg/cipher