pull/10/head
Hunter Long 2018-06-18 17:01:03 -07:00
parent 9c2cc65c7c
commit 3cd46fa6c4
6 changed files with 61 additions and 9 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@
rice-box.go
config.yml
statup.db
plugins/*.so
plugins/*.so
data

View File

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

View File

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

View File

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

View File

@ -33,6 +33,23 @@
<div class="tab-content" id="v-pills-tabContent">
<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
<h3>Settings</h3>
<form method="POST" action="/settings">
<div class="form-group">
<label for="formGroupExampleInput">Project Name</label>
<input type="text" name="project" class="form-control" value="{{ .Name }}" id="formGroupExampleInput" placeholder="Great Uptime">
</div>
<div class="form-group">
<label for="formGroupExampleInput">Project Description</label>
<input type="text" name="description" class="form-control" value="{{ .Description }}" id="formGroupExampleInput" placeholder="Great Uptime">
</div>
<button type="submit" class="btn btn-primary btn-block">Save Settings</button>
</form>
</div>
<div class="tab-pane fade" id="v-pills-browse" role="tabpanel" aria-labelledby="v-pills-browse-tab">

18
web.go
View File

@ -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 {