added redirection url in args, changed docs

This commit is contained in:
mleku
2023-10-29 19:31:54 -01:00
parent e9fcbb27ef
commit 58d06d5aa8
2 changed files with 20 additions and 16 deletions

View File

@@ -36,13 +36,15 @@ put the details of your desired setup with the parameters you use to launch name
#!/usr/bin/bash #!/usr/bin/bash
/home/<username>/.local/bin/namestr -vc mleku.online npub1mlekuhhxqq6p8w9x5fs469cjk3fu9zw7uptujr55zmpuhhj48u3qnwx3q5 a.nos.lol bevo.nostr1.com bitcoiner.social nos.lol nostr.wine relay.nostr.band Bevo.nostr1.com ae.purplerelay.com nostr.plebchain.org christpill.nostr1.com relay.nostr.me relay.devstr.org relay.primal.net /home/<username>/.local/bin/namestr -vc mleku.online npub1mlekuhhxqq6p8w9x5fs469cjk3fu9zw7uptujr55zmpuhhj48u3qnwx3q5 github.com/mleku a.nos.lol bevo.nostr1.com bitcoiner.social nos.lol nostr.wine relay.nostr.band Bevo.nostr1.com ae.purplerelay.com nostr.plebchain.org christpill.nostr1.com relay.nostr.me relay.devstr.org relay.primal.net
The `-vc` enables logging, which prints the URL requests that came in. it only sends a proper answer to the NIP-05 request path, all others return the text "gfy". (hah, if you want to change it, just edit the file `cmd/root.go` and look for "gfy" and change it) The `-vc` enables logging, which prints the URL requests that came in. it only sends a proper answer to the NIP-05 request path, all others return the text "gfy". (hah, if you want to change it, just edit the file `cmd/root.go` and look for "gfy" and change it)
after that is the domain name. this is intended for a domain name that is your nostr display name, mleku.online in my case. after that is the domain name. this is intended for a domain name that is your nostr display name, mleku.online in my case.
after that, you put the npub. this is automatically decoded to hex for the json response. then you put the npub. this is automatically decoded to hex for the json response.
third element is a URL that you want to be given as a redirect, such as your github profile or other social network profile.
after that, zero or more of just the domain names of the relays that you usually use to post with. the `wss://` prefix is not needed. after that, zero or more of just the domain names of the relays that you usually use to post with. the `wss://` prefix is not needed.

View File

@@ -13,9 +13,11 @@ import (
) )
type config struct { type config struct {
c *cobra.Command c *cobra.Command
DataDir, message string DataDir, message string
verbose, color bool domain, npub, redirection string
relays []string
verbose, color bool
} }
var s config var s config
@@ -23,7 +25,7 @@ var DataDirPerm os.FileMode = 0700
// rootCmd represents the base command when called without any subcommands // rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "namestr <domain> <npub> <email> [<relays>...]", Use: "namestr <domain> <npub> <redirection> [<relays>...]",
Short: "zero configuration NIP-05 DNS<->npub identity verification", Short: "zero configuration NIP-05 DNS<->npub identity verification",
Long: `namestr Long: `namestr
@@ -47,12 +49,12 @@ optionally a list of relays can be named, only their domain name is required, th
s.c.Help() s.c.Help()
s.Fatal("at least domain name and npub is required\n") s.Fatal("at least domain name and npub is required\n")
} }
domain, npub, relays := args[0], args[1], args[2:] s.domain, s.npub, s.redirection, s.relays = args[0], args[1], args[2], args[3:]
s.Log("domain %v\n", domain) s.Log("domain %v\n", s.domain)
s.Log("npub %v\n", npub) s.Log("npub %v\n", s.npub)
s.Log("relays %v\n", relays) s.Log("relays %v\n", s.relays)
pk, err := nostr.NpubToPublicKey(npub) pk, err := nostr.NpubToPublicKey(s.npub)
if err != nil { if err != nil {
s.Fatal("%s\n", err) s.Fatal("%s\n", err)
} }
@@ -68,8 +70,8 @@ optionally a list of relays can be named, only their domain name is required, th
"relays": { "relays": {
"` + pkHex + `": [ "` + pkHex + `": [
` `
rl := len(relays) - 1 rl := len(s.relays) - 1
for i, rel := range relays { for i, rel := range s.relays {
if i < rl { if i < rl {
jsonText += jsonText +=
` ` + `"wss://` + rel + `", ` ` + `"wss://` + rel + `",
@@ -103,7 +105,7 @@ optionally a list of relays can be named, only their domain name is required, th
} }
} }
s.Log("starting up server\n") s.Log("starting up server\n")
autotls.Run(s, domain) autotls.Run(s, s.domain)
s.Log("finished running server\n") s.Log("finished running server\n")
}, },
} }
@@ -121,11 +123,11 @@ func CheckFileExists(name string) (fi os.FileInfo, exists bool, err error) {
func (s config) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.Log("%s\n", r.RequestURI) s.Log("%s\n", r.RequestURI)
w.WriteHeader(http.StatusOK)
if r.RequestURI == "/.well-known/nostr.json?name=_" { if r.RequestURI == "/.well-known/nostr.json?name=_" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(s.message)) w.Write([]byte(s.message))
} else { } else {
w.Write([]byte("gfy")) http.Redirect(w, r, s.redirection, http.StatusSeeOther)
} }
} }