diff options
| -rw-r--r-- | roseh.moe.go | 59 | ||||
| -rw-r--r-- | templates/otp.html.template | 6 |
2 files changed, 0 insertions, 65 deletions
diff --git a/roseh.moe.go b/roseh.moe.go index 0aa75be..b53f65e 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -832,63 +832,6 @@ func logout(w http.ResponseWriter, r *http.Request) { } var ( - //go:embed templates/otp.html.template - otpString string - otpTemplate = template.Must(outlinedTemplate(otpString)) - - otpMu sync.Mutex - currentOTP string -) - -type otpTemplateArgs struct { - URL string - QR string -} - -func otp(w http.ResponseWriter, r *http.Request) { - buf := make([]byte, 20) - rand.Read(buf) - newOTP := new(strings.Builder) - for i := range 10 { - if i > 0 { - newOTP.WriteString("-") - } - newOTP.WriteString(wordlist.Words[binary.NativeEndian.Uint16(buf[2*i:])&0x1fff]) - } - otpMu.Lock() - currentOTP = newOTP.String() - otpMu.Unlock() - downloadURL := selfURL.String() + "/otp/" + newOTP.String() - if err := otpTemplate.Execute(w, otpTemplateArgs{ - URL: downloadURL, - QR: "/qr.png?" + url.Values{"t": []string{downloadURL}, "s": []string{base64.RawURLEncoding.EncodeToString(mac([]byte(downloadURL), "qr"))}}.Encode(), - }); err != nil { - log.Printf("Warning: otp: %s", err) - } -} - -func otpCode(w http.ResponseWriter, r *http.Request) { - code := r.PathValue("code") - if code == "" { - notFound(w, r) - return - } - matched := false - otpMu.Lock() - if code == currentOTP { - currentOTP = "" - matched = true - } - otpMu.Unlock() - if !matched { - notFound(w, r) - return - } - attachCookie(w) - io.WriteString(w, "logged in\n") -} - -var ( //go:embed templates/note.html.template notepadString string notepadTemplate = template.Must(outlinedTemplate(notepadString)) @@ -1227,8 +1170,6 @@ func main() { mux.HandleFunc("GET /wormhole/{hole}", wormholeDownload) mux.Handle("GET /login", &timeoutHandler{h: http.HandlerFunc(serveLogin), timeout: 5 * time.Minute}) mux.Handle("POST /login", &timeoutHandler{h: http.HandlerFunc(login), timeout: 5 * time.Minute}) - mux.Handle("GET /otp", &timeoutHandler{h: &authHandler{h: http.HandlerFunc(otp)}, timeout: 5 * time.Minute}) - mux.Handle("GET /otp/{code}", &timeoutHandler{h: http.HandlerFunc(otpCode), timeout: 5 * time.Minute}) mux.Handle("GET /logout", &timeoutHandler{h: &authHandler{h: http.HandlerFunc(logout), noRedirect: true}, timeout: 5 * time.Minute}) mux.Handle("GET /notepad", &timeoutHandler{h: &authHandler{h: http.HandlerFunc(notepad)}, timeout: 5 * time.Minute}) mux.Handle("POST /notepad", &timeoutHandler{h: &authHandler{h: http.HandlerFunc(autosave), noRedirect: true}, timeout: 5 * time.Minute}) diff --git a/templates/otp.html.template b/templates/otp.html.template deleted file mode 100644 index 3b765f7..0000000 --- a/templates/otp.html.template +++ /dev/null @@ -1,6 +0,0 @@ -<title>OTP</title> - -<div style="display:flex;flex-direction:column;align-items:center;font-size:50px"> - <p><a href="{{.URL}}">{{.URL}}</a></p> - <img src="{{.QR}}" alt="QR code for {{.URL}}" width="500px"> -</div> |
