From 388ae5a23dc72b1a21a1aad13beeb21f349b6502 Mon Sep 17 00:00:00 2001 From: astra Date: Sun, 9 Jun 2024 00:35:51 +0100 Subject: [PATCH] first commit --- go.mod | 3 +++ main.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 go.mod create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c66f1cf --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.zio.sh/astra/gearheads-webfinger + +go 1.21.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..8291ca1 --- /dev/null +++ b/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "net/http" +) + +var redirects map[string][]string + +func HandleWebfinger(w http.ResponseWriter, req *http.Request) { + olduser := req.URL.Query().Get("resource")[5:] + newuser, ok := redirects[olduser] + if !ok { + w.WriteHeader(404) + return + } + + s := `{ + "subject": "acct:%[1]s@%[2]s", + "aliases": [ + "https://%[2]s/@%[1]s", + "https://%[2]s/users/%[1]s" + ], + "links": [ + { + "rel": "http://webfinger.net/rel/profile-page", + "type": "text/html", + "href": "https://%[2]s/@%[1]s" + }, + { + "rel": "self", + "type": "application/activity+json", + "href": "https://%[2]s/users/%[1]s" + } + ] +}` + w.Header().Set("Content-Type", "application/json") + fmt.Fprintln(w, fmt.Sprintf(s, newuser[0], newuser[1])) +} + +func main() { + redirects = make(map[string][]string) + redirects["ducky@gearheads.social"] = []string{"ducky", "ap.zio.sh"} + redirects["astra@gearheads.social"] = []string{"astra", "ap.zio.sh"} + + http.HandleFunc("/.well-known/webfinger", HandleWebfinger) + http.ListenAndServe(":8888", nil) +}