From e6a79496e84b8feb13d1c0394a8fa45e620a3323 Mon Sep 17 00:00:00 2001 From: Jon Lundy Date: Sun, 12 Dec 2021 06:34:58 -0700 Subject: [PATCH] save changes --- Makefile | 1 + main.go | 2 +- pkg/app/keyproofs/proofs.go | 13 ++++++++++++- pkg/app/wkd/app.go | 16 +++++++++------- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 58460a4..141ff78 100644 --- a/Makefile +++ b/Makefile @@ -36,3 +36,4 @@ install: $(NAME) install ./$(NAME) /usr/local/bin install ./$(NAME).service /lib/systemd/system systemctl daemon-reload + systemctl restart $(NAME) diff --git a/main.go b/main.go index 14d18a5..af99c50 100644 --- a/main.go +++ b/main.go @@ -139,7 +139,7 @@ func run(ctx context.Context) error { } if env("DISABLE_WKD", "false") == "false" { - app, err := app_wkd.New(ctx, env("WKD_PATH", "pub"), env("WKD_DOMAIN", "pub")) + app, err := app_wkd.New(ctx, env("WKD_PATH", "pub"), env("WKD_DOMAIN", "sour.is")) if err != nil { return err } diff --git a/pkg/app/keyproofs/proofs.go b/pkg/app/keyproofs/proofs.go index 244edd8..5133897 100644 --- a/pkg/app/keyproofs/proofs.go +++ b/pkg/app/keyproofs/proofs.go @@ -206,7 +206,7 @@ func NewProof(ctx context.Context, uri, fingerprint string) ProofResolver { return &httpResolve{p, url, nil} } - case strings.Contains(p.URI.Path, "/conv/"), strings.Contains(p.URI.Path, "/twt/"): + case strings.Contains(p.URI.Path, "/conv/"): if sp := strings.SplitN(p.URI.Path, "/", 3); len(sp) == 3 { p.Icon = "fas fa-comment-alt" p.Service = "Twtxt" @@ -217,6 +217,17 @@ func NewProof(ctx context.Context, uri, fingerprint string) ProofResolver { return &twtxtResolve{p, url, sp[2], nil} } + case strings.Contains(p.URI.Path, "/twt/"): + if sp := strings.SplitN(p.URI.Path, "/", 3); len(sp) == 3 { + p.Icon = "fas fa-comment-alt" + p.Service = "Twtxt" + p.Name = fmt.Sprintf("...@%s", p.URI.Host) + p.Link = fmt.Sprintf("https://%s", p.URI.Host) + + url := fmt.Sprintf("https://%s/twt/%v", p.URI.Host, sp[2]) + return &httpResolve{p, url, nil} + } + default: if sp := strings.SplitN(p.URI.Path, "/", 3); len(sp) > 1 { p.Icon = "fas fa-project-diagram" diff --git a/pkg/app/wkd/app.go b/pkg/app/wkd/app.go index abdc944..f8530b6 100644 --- a/pkg/app/wkd/app.go +++ b/pkg/app/wkd/app.go @@ -137,7 +137,7 @@ func (app *wkdApp) getRedirect(w http.ResponseWriter, r *http.Request) { log.Debug().Str("hash", hash).Str("domain", domain).Msg("redirect") if host, adv := getWKDDomain(ctx, domain); adv { log.Debug().Str("host", host).Str("domain", domain).Bool("adv", adv).Msg("redirect") - http.Redirect(w, r, fmt.Sprintf("https://%s/.well-known/openpgpkey/hu/%s/%s", host, domain, hash), http.StatusTemporaryRedirect) + http.Redirect(w, r, fmt.Sprintf("https://%s/.well-known/openpgpkey/%s/hu/%s", host, domain, hash), http.StatusTemporaryRedirect) } else { log.Debug().Str("host", host).Str("domain", domain).Bool("adv", adv).Msg("redirect") http.Redirect(w, r, fmt.Sprintf("https://%s/.well-known/openpgpkey/hu/%s", domain, hash), http.StatusTemporaryRedirect) @@ -149,18 +149,18 @@ func (app *wkdApp) getRedirect(w http.ResponseWriter, r *http.Request) { writeText(w, http.StatusBadRequest, "Bad Request") } +func (app *wkdApp) getPolicy(w http.ResponseWriter, r *http.Request) { + writeText(w, 200, "") + return +} + func (app *wkdApp) get(w http.ResponseWriter, r *http.Request) { ctx := r.Context() log := log.Ctx(ctx) - log.Print(r.Host) + log.Debug().Msgf("Host: %v %v %v", r.Host, app.domain, "foo") hash := chi.URLParam(r, "hash") - if hash == "policy" { - writeText(w, 200, "") - return - } - domain := chi.URLParam(r, "domain") if domain == "" { domain = app.domain @@ -192,6 +192,8 @@ func (app *wkdApp) Routes(r *chi.Mux) { r.MethodFunc("POST", "/pks/add", app.postKey) r.MethodFunc("GET", "/.well-known/openpgpkey/hu/{hash}", app.get) r.MethodFunc("GET", "/.well-known/openpgpkey/{domain}/hu/{hash}", app.get) + r.MethodFunc("GET", "/.well-known/openpgpkey/policy", app.getPolicy) + r.MethodFunc("GET", "/.well-known/openpgpkey/{domain}/policy", app.getPolicy) } func (app *wkdApp) createLinks(kind, name string) error {