Browse Source

feature: add --query argument to enable custom query parameters

make_cert_optional
Otto Suess 6 years ago
parent
commit
7d5798e813
No known key found for this signature in database GPG Key ID: F7EFC44C2C240A11
  1. 2
      README.md
  2. 19
      config.go
  3. 30
      lndconnect.go

2
README.md

@ -29,6 +29,8 @@ lndconnect
-o, --image Output QRCode to file
--invoice Use invoice macaroon
--readonly Use readonly macaroon
-q, --query= Add additional url query parameters
--lnddir= The base directory that contains lnd's data, logs, configuration
file, etc.
--configfile= Path to configuration file

19
config.go

@ -42,15 +42,18 @@ type chainConfig struct {
RegTest bool `long:"regtest" description:"Use the regression test network"`
}
type arrayFlags []string
type lndConnectConfig struct {
LocalIp bool `short:"i" long:"localip" description:"Include local ip in QRCode"`
Localhost bool `short:"l" long:"localhost" description:"Use 127.0.0.1 for ip"`
Host string `long:"host" description:"Use specific host name"`
Port uint16 `short:"p" long:"port" description:"Use this port"`
Url bool `short:"j" long:"url" description:"Display url instead of a QRCode"`
Image bool `short:"o" long:"image" description:"Output QRCode to file"`
Invoice bool `long:"invoice" description:"use invoice macaroon"`
Readonly bool `long:"readonly" description:"use readonly macaroon"`
LocalIp bool `short:"i" long:"localip" description:"Include local ip in QRCode"`
Localhost bool `short:"l" long:"localhost" description:"Use 127.0.0.1 for ip"`
Host string `long:"host" description:"Use specific host name"`
Port uint16 `short:"p" long:"port" description:"Use this port"`
Url bool `short:"j" long:"url" description:"Display url instead of a QRCode"`
Image bool `short:"o" long:"image" description:"Output QRCode to file"`
Invoice bool `long:"invoice" description:"use invoice macaroon"`
Readonly bool `long:"readonly" description:"use readonly macaroon"`
Query arrayFlags `short:"q" long:"query" description:"Add additional url query parameters"`
}
// config defines the configuration options for lndconnect.

30
lndconnect.go

@ -6,7 +6,9 @@ import (
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"strings"
"github.com/Baozisoftware/qrcode-terminal-go"
"github.com/glendc/go-external-ip"
@ -86,20 +88,34 @@ func main() {
ipString = getPublicIP()
}
ipString = net.JoinHostPort(
ipString, fmt.Sprint(loadedConfig.LndConnect.Port),
)
ipString = net.JoinHostPort(ipString, fmt.Sprint(loadedConfig.LndConnect.Port))
urlString := fmt.Sprintf("lndconnect://%s?cert=%s&macaroon=%s", ipString, certificate, macaroonB64)
u := url.URL{Scheme: "lndconnect", Host: ipString}
q := u.Query()
q.Add("cert", certificate)
q.Add("macaroon", macaroonB64)
for _, s := range loadedConfig.LndConnect.Query {
queryParts := strings.Split(s, "=")
if len(queryParts) != 2 {
fmt.Println("Invalid Query Argument:", s)
return
}
q.Add(queryParts[0], queryParts[1])
}
u.RawQuery = q.Encode()
if loadedConfig.LndConnect.Url {
fmt.Println(urlString)
fmt.Println(u.String())
} else if loadedConfig.LndConnect.Image {
qrcode.WriteFile(urlString, qrcode.Medium, 512, "lndconnect-qr.png")
qrcode.WriteFile(u.String(), qrcode.Medium, 512, "lndconnect-qr.png")
fmt.Println("Wrote QR Code to file \"lndconnect-qr.png\"")
} else {
obj := qrcodeTerminal.New()
obj.Get(urlString).Print()
obj.Get(u.String()).Print()
fmt.Println("\n⚠️ Press \"cmd + -\" a few times to see the full QR Code!\nIf that doesn't work run \"lndconnect -j\" to get a code you can copy paste into the app.")
}
}

Loading…
Cancel
Save