aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-09-10 20:16:28 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-09-11 20:41:32 +0100
commit65151dd29dc01c6d1f6ff79ab6f8e049e925ce25 (patch)
tree2db5267b573f2a58ffff94de7f9b9af5f9767d82 /cmd
parent2e7c8c2f521c9e50bb3aea4df16771c22fe70e58 (diff)
Add a toggle for unexpired certs
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cashierd/main.go30
1 files changed, 18 insertions, 12 deletions
diff --git a/cmd/cashierd/main.go b/cmd/cashierd/main.go
index e71c126..6e52ddf 100644
--- a/cmd/cashierd/main.go
+++ b/cmd/cashierd/main.go
@@ -15,6 +15,7 @@ import (
"net"
"net/http"
"os"
+ "strconv"
"strings"
"golang.org/x/oauth2"
@@ -231,20 +232,24 @@ func listAllCertsHandler(a *appContext, w http.ResponseWriter, r *http.Request)
if !a.isLoggedIn(w, r) {
return a.login(w, r)
}
- certs, err := a.certstore.List()
- if err != nil {
- return http.StatusInternalServerError, err
+ tmpl := template.Must(template.New("certs.html").Parse(templates.Certs))
+ tmpl.Execute(w, map[string]interface{}{
+ csrf.TemplateTag: csrf.TemplateField(r),
+ })
+ return http.StatusOK, nil
+}
+
+func listCertsJSONHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int, error) {
+ if !a.isLoggedIn(w, r) {
+ return http.StatusUnauthorized, errors.New(http.StatusText(http.StatusUnauthorized))
}
- page := struct {
- Certs []*store.CertRecord
- CSRF template.HTML
- }{
- Certs: certs,
- CSRF: csrf.TemplateField(r),
+ includeExpired, _ := strconv.ParseBool(r.URL.Query().Get("all"))
+ certs, err := a.certstore.List(includeExpired)
+ j, err := json.Marshal(certs)
+ if err != nil {
+ return http.StatusInternalServerError, errors.New(http.StatusText(http.StatusInternalServerError))
}
-
- tmpl := template.Must(template.New("certs.html").Parse(templates.Certs))
- tmpl.Execute(w, page)
+ w.Write(j)
return http.StatusOK, nil
}
@@ -397,6 +402,7 @@ func main() {
r.Methods("GET").Path("/revoked").Handler(appHandler{ctx, listRevokedCertsHandler})
r.Methods("POST").Path("/admin/revoke").Handler(CSRF(appHandler{ctx, revokeCertHandler}))
r.Methods("GET").Path("/admin/certs").Handler(CSRF(appHandler{ctx, listAllCertsHandler}))
+ r.Methods("GET").Path("/admin/certs.json").Handler(appHandler{ctx, listCertsJSONHandler})
r.PathPrefix("/").Handler(http.FileServer(static.FS(false)))
h := handlers.LoggingHandler(logfile, r)