Code cleanup and bug fixes
parent
ceb53970a1
commit
cd332ce483
2
db.go
2
db.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
7
main.go
7
main.go
|
@ -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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Reference in New Issue