From cd332ce4837b182572101887822d99cbedeaf2f8 Mon Sep 17 00:00:00 2001 From: "J. David Lee" Date: Mon, 10 Jun 2019 22:18:48 +0200 Subject: [PATCH] Code cleanup and bug fixes --- alert.go => actions.go | 0 db.go | 2 +- main.go | 7 +++++-- user-handlers.go | 13 +++++-------- 4 files changed, 11 insertions(+), 11 deletions(-) rename alert.go => actions.go (100%) diff --git a/alert.go b/actions.go similarity index 100% rename from alert.go rename to actions.go diff --git a/db.go b/db.go index 4110b17..cab8ba7 100644 --- a/db.go +++ b/db.go @@ -36,7 +36,7 @@ func newDB(dbPath string) (*dbal, error) { _ = db.UserInsert(User{ Username: `root`, Admin: true, - }, `root`) + }, `rootroot`) return db, nil } diff --git a/main.go b/main.go index ad3b5ca..3e5c3ac 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package am import ( "flag" "html/template" + "log" "net/http" "os" "strings" @@ -66,8 +67,10 @@ func Main() { handle_user("/log/list", handleLogList) if port == "443" { - http.Serve(autocert.NewListener(host), http.DefaultServeMux) + log.Printf("Listening on %s...", host) + log.Fatal(http.Serve(autocert.NewListener(host), http.DefaultServeMux)) } else { - http.ListenAndServe(listenAddr, nil) + log.Printf("Listening on %s...", listenAddr) + log.Fatal(http.ListenAndServe(listenAddr, nil)) } } diff --git a/user-handlers.go b/user-handlers.go index e1f88e9..c1ca0b9 100644 --- a/user-handlers.go +++ b/user-handlers.go @@ -321,7 +321,6 @@ type logListArgs struct { BeforeID int64 SourceID string Type string // One of "all", "alert", "log". - Limit int64 } func handleLogList(w http.ResponseWriter, r *http.Request) { @@ -329,17 +328,15 @@ func handleLogList(w http.ResponseWriter, r *http.Request) { args := logListArgs{ BeforeID: formGetInt(r, "BeforeID"), - Limit: formGetInt(r, "Limit"), SourceID: r.Form.Get("SourceID"), Type: r.Form.Get("Type"), } - if args.Limit < 1 { - args.Limit = 100 - } + + limit := int64(200) listArgs := LogListArgs{ BeforeID: args.BeforeID, - Limit: args.Limit + 1, + Limit: limit + 1, SourceID: args.SourceID, } @@ -361,10 +358,10 @@ func handleLogList(w http.ResponseWriter, r *http.Request) { nextURL := "" - if len(l) > int(args.Limit) { + if len(l) > int(limit) { l = l[:len(l)-1] nextURL = fmt.Sprintf("?Limit=%d&BeforeID=%d&SourceID=%s&Type=%s", - args.Limit, l[len(l)-1].LogID, args.SourceID, args.Type) + limit, l[len(l)-1].LogID, args.SourceID, args.Type) } sources, err := db.SourceList()