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{
Username: `root`,
Admin: true,
}, `root`)
}, `rootroot`)
return db, nil
}

View File

@ -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))
}
}

View File

@ -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()