Code cleanup and bug fixes

master
J. David Lee 2019-06-10 22:18:48 +02:00
parent ceb53970a1
commit cd332ce483
4 changed files with 11 additions and 11 deletions

2
db.go
View File

@ -36,7 +36,7 @@ func newDB(dbPath string) (*dbal, error) {
_ = db.UserInsert(User{ _ = db.UserInsert(User{
Username: `root`, Username: `root`,
Admin: true, Admin: true,
}, `root`) }, `rootroot`)
return db, nil return db, nil
} }

View File

@ -3,6 +3,7 @@ package am
import ( import (
"flag" "flag"
"html/template" "html/template"
"log"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -66,8 +67,10 @@ func Main() {
handle_user("/log/list", handleLogList) handle_user("/log/list", handleLogList)
if port == "443" { 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 { } else {
http.ListenAndServe(listenAddr, nil) log.Printf("Listening on %s...", listenAddr)
log.Fatal(http.ListenAndServe(listenAddr, nil))
} }
} }

View File

@ -321,7 +321,6 @@ type logListArgs struct {
BeforeID int64 BeforeID int64
SourceID string SourceID string
Type string // One of "all", "alert", "log". Type string // One of "all", "alert", "log".
Limit int64
} }
func handleLogList(w http.ResponseWriter, r *http.Request) { func handleLogList(w http.ResponseWriter, r *http.Request) {
@ -329,17 +328,15 @@ func handleLogList(w http.ResponseWriter, r *http.Request) {
args := logListArgs{ args := logListArgs{
BeforeID: formGetInt(r, "BeforeID"), BeforeID: formGetInt(r, "BeforeID"),
Limit: formGetInt(r, "Limit"),
SourceID: r.Form.Get("SourceID"), SourceID: r.Form.Get("SourceID"),
Type: r.Form.Get("Type"), Type: r.Form.Get("Type"),
} }
if args.Limit < 1 {
args.Limit = 100 limit := int64(200)
}
listArgs := LogListArgs{ listArgs := LogListArgs{
BeforeID: args.BeforeID, BeforeID: args.BeforeID,
Limit: args.Limit + 1, Limit: limit + 1,
SourceID: args.SourceID, SourceID: args.SourceID,
} }
@ -361,10 +358,10 @@ func handleLogList(w http.ResponseWriter, r *http.Request) {
nextURL := "" nextURL := ""
if len(l) > int(args.Limit) { if len(l) > int(limit) {
l = l[:len(l)-1] l = l[:len(l)-1]
nextURL = fmt.Sprintf("?Limit=%d&BeforeID=%d&SourceID=%s&Type=%s", 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() sources, err := db.SourceList()