diff --git a/.gitignore b/.gitignore index 6ca9f5fb..269b064f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ rice-box.go config.yml statup.db -plugins/*.so \ No newline at end of file +plugins/*.so +data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b4af1429..2a8238a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,17 @@ -FROM alpine +FROM golang:alpine -#RUN apk add --no-cache libc6-compat +RUN apk update && apk add git g++ -ENV VERSION="v0.14" -RUN wget -q https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-static -RUN chmod +x statup-linux-static && mv statup-linux-static /usr/local/bin/statup +WORKDIR $GOPATH/src/github.com/hunterlong/statup/ + +COPY . $GOPATH/src/github.com/hunterlong/statup/ +RUN go get github.com/GeertJohan/go.rice/rice +RUN go get -d -v +RUN rice embed-go +RUN go install +WORKDIR /app +VOLUME /app EXPOSE 8080 -VOLUME /app - ENTRYPOINT statup \ No newline at end of file diff --git a/core.go b/core.go index 82bed73b..2501c966 100644 --- a/core.go +++ b/core.go @@ -17,6 +17,13 @@ type Core struct { PluginFields []PluginSelect } +func (c *Core) Update() (*Core, error) { + res := dbSession.Collection("core").Find().Limit(1) + res.Update(c) + core = c + return c, nil +} + func SelectCore() (*Core, error) { var core Core err := dbSession.Collection("core").Find().One(&core) diff --git a/failures.go b/failures.go index 7df32f61..77979561 100644 --- a/failures.go +++ b/failures.go @@ -34,6 +34,13 @@ func (s *Service) SelectAllFailures() ([]*Failure, error) { return fails, err } +func (s *Service) LimitedFailures() ([]*Failure, error) { + var fails []*Failure + col := dbSession.Collection("failures").Find("session", s.Id).Limit(10) + err := col.All(&fails) + return fails, err +} + func CountFailures() (uint64, error) { col := dbSession.Collection("failures").Find() amount, err := col.Count() diff --git a/html/tmpl/plugins.html b/html/tmpl/plugins.html index bd66087a..5753e2fd 100644 --- a/html/tmpl/plugins.html +++ b/html/tmpl/plugins.html @@ -33,6 +33,23 @@

Settings

+ +
+ +
+ + +
+ +
+ + +
+ + + +
+
diff --git a/web.go b/web.go index b313f725..71cd47b5 100644 --- a/web.go +++ b/web.go @@ -38,7 +38,8 @@ func Router() *mux.Router { r.Handle("/service/{id}/badge.svg", http.HandlerFunc(ServicesBadgeHandler)) r.Handle("/users", http.HandlerFunc(UsersHandler)).Methods("GET") r.Handle("/users", http.HandlerFunc(CreateUserHandler)).Methods("POST") - r.Handle("/settings", http.HandlerFunc(PluginsHandler)) + r.Handle("/settings", http.HandlerFunc(PluginsHandler)).Methods("GET") + r.Handle("/settings", http.HandlerFunc(SaveSettingsHandler)).Methods("POST") r.Handle("/plugins/download/{name}", http.HandlerFunc(PluginsDownloadHandler)) r.Handle("/plugins/{name}/save", http.HandlerFunc(PluginSavedHandler)).Methods("POST") r.Handle("/help", http.HandlerFunc(HelpHandler)) @@ -225,6 +226,21 @@ func IsAuthenticated(r *http.Request) bool { return session.Values["authenticated"].(bool) } +func SaveSettingsHandler(w http.ResponseWriter, r *http.Request) { + auth := IsAuthenticated(r) + if !auth { + http.Redirect(w, r, "/", http.StatusSeeOther) + return + } + r.ParseForm() + name := r.PostForm.Get("name") + description := r.PostForm.Get("description") + core.Name = name + core.Description = description + core.Update() + http.Redirect(w, r, "/settings", http.StatusSeeOther) +} + func PluginsHandler(w http.ResponseWriter, r *http.Request) { auth := IsAuthenticated(r) if !auth {