ssl - forms

pull/116/head
Hunter Long 2018-12-06 15:20:20 -08:00
parent 0a22788385
commit 890de5b50d
10 changed files with 84 additions and 32 deletions

View File

@ -16,6 +16,7 @@
package handlers
import (
"crypto/tls"
"encoding/json"
"fmt"
"github.com/gorilla/sessions"
@ -33,35 +34,66 @@ import (
const (
cookieKey = "statping_auth"
timeout = time.Second * 60
)
var (
sessionStore *sessions.CookieStore
httpServer *http.Server
usingSSL bool
)
// RunHTTPServer will start a HTTP server on a specific IP and port
func RunHTTPServer(ip string, port int) error {
host := fmt.Sprintf("%v:%v", ip, port)
utils.Log(1, "Statping HTTP Server running on http://"+host)
//for _, p := range core.CoreApp.AllPlugins {
// info := p.GetInfo()
// for _, route := range p.Routes() {
// path := fmt.Sprintf("%v", route.URL)
// router.Handle(path, http.HandlerFunc(route.Handler)).Methods(route.Method)
// utils.Log(1, fmt.Sprintf("Added Route %v for plugin %v\n", path, info.Name))
// }
//}
router = Router()
httpServer = &http.Server{
Addr: host,
WriteTimeout: time.Second * 60,
ReadTimeout: time.Second * 60,
IdleTimeout: time.Second * 60,
Handler: router,
key := utils.FileExists(utils.Directory + "/server.key")
cert := utils.FileExists(utils.Directory + "/server.crt")
if key && cert {
utils.Log(1, "server.cert and server.key was found in root directory! Starting in SSL mode.")
utils.Log(1, fmt.Sprintf("Statping Secure HTTPS Server running on https://%v:%v", ip, 443))
usingSSL = true
} else {
utils.Log(1, "Statping HTTP Server running on http://"+host)
}
router = Router()
resetCookies()
return httpServer.ListenAndServe()
if usingSSL {
cfg := &tls.Config{
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
}
srv := &http.Server{
Addr: fmt.Sprintf("%v:%v", ip, 443),
Handler: router,
TLSConfig: cfg,
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
WriteTimeout: timeout,
ReadTimeout: timeout,
IdleTimeout: timeout,
}
return srv.ListenAndServeTLS(utils.Directory+"/server.crt", utils.Directory+"/server.key")
} else {
httpServer = &http.Server{
Addr: host,
WriteTimeout: timeout,
ReadTimeout: timeout,
IdleTimeout: timeout,
Handler: router,
}
return httpServer.ListenAndServe()
}
return nil
}
// IsAuthenticated returns true if the HTTP request is authenticated. You can set the environment variable GO_ENV=test
@ -198,8 +230,11 @@ func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data i
return
}
templates := []string{"base.gohtml", "head.gohtml", "nav.gohtml", "footer.gohtml", "scripts.gohtml", "form_service.gohtml", "form_notifier.gohtml", "form_user.gohtml", "form_checkin.gohtml", "form_message.gohtml"}
if usingSSL {
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
}
templates := []string{"base.gohtml", "head.gohtml", "nav.gohtml", "footer.gohtml", "scripts.gohtml", "form_service.gohtml", "form_notifier.gohtml", "form_user.gohtml", "form_checkin.gohtml", "form_message.gohtml"}
javascripts := []string{"charts.js", "chart_index.js"}
render, err := source.TmplBox.String(file)
@ -252,6 +287,9 @@ func executeJSResponse(w http.ResponseWriter, r *http.Request, file string, data
if err != nil {
utils.Log(4, err)
}
if usingSSL {
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
}
t := template.New("charts")
t.Funcs(template.FuncMap{
"safe": func(html string) template.HTML {
@ -274,6 +312,9 @@ func executeJSResponse(w http.ResponseWriter, r *http.Request, file string, data
// error404Handler is a HTTP handler for 404 error pages
func error404Handler(w http.ResponseWriter, r *http.Request) {
if usingSSL {
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
}
w.WriteHeader(http.StatusNotFound)
ExecuteResponse(w, r, "error_404.gohtml", nil, nil)
}

View File

@ -6,7 +6,8 @@
/* Mobile Settings */
/* Mobile Service Container */
HTML, BODY {
background-color: #fcfcfc; }
background-color: #fcfcfc;
padding-bottom: 10px; }
.container {
padding-top: 20px;

View File

@ -3,6 +3,7 @@
HTML,BODY {
background-color: $background-color;
padding-bottom: 10px;
}
.container {

View File

@ -24,7 +24,7 @@
<div class="input-group-prepend">
<div class="input-group-text">Limit</div>
</div>
<input type="text" class="form-control" name="limits" min="1" max="60" id="limits_per_hour_{{underscore $n.Method }}" value="{{$n.Limits}}" placeholder="7">
<input type="number" class="form-control" name="limits" min="1" max="60" id="limits_per_hour_{{underscore $n.Method }}" value="{{$n.Limits}}" placeholder="7">
<div class="input-group-append">
<div class="input-group-text">Per Minute</div>
</div>

View File

@ -9,7 +9,7 @@
<div class="form-group row">
<label for="service_name" class="col-sm-4 col-form-label">Service Name</label>
<div class="col-sm-8">
<input type="text" name="name" class="form-control" id="service_name" value="{{.Name}}" placeholder="Name" required spellcheck="false">
<input type="text" name="name" class="form-control" id="service_name" value="{{.Name}}" placeholder="Name" required spellcheck="false" autocorrect="off">
<small class="form-text text-muted">Give your service a name you can recognize</small>
</div>
</div>
@ -27,7 +27,7 @@
<div class="form-group row">
<label for="service_url" class="col-sm-4 col-form-label">{{if (eq .Type "tcp") or (eq .Type "udp")}}Host/IP Address{{else}}Application Endpoint (URL){{end}}</label>
<div class="col-sm-8">
<input type="text" name="domain" class="form-control" id="service_url" value="{{.Domain}}" placeholder="https://google.com" required autocapitalize="false" spellcheck="false">
<input type="url" name="domain" class="form-control" id="service_url" value="{{.Domain}}" placeholder="https://google.com" required autocapitalize="none" spellcheck="false">
<small class="form-text text-muted">Statping will attempt to connect to this URL</small>
</div>
</div>
@ -47,14 +47,14 @@
<div class="form-group row{{if ne .Method "POST"}} d-none{{end}}">
<label for="post_data" class="col-sm-4 col-form-label">Optional Post Data (JSON)</label>
<div class="col-sm-8">
<textarea name="post_data" class="form-control" id="post_data" rows="3" autocapitalize="false" spellcheck="false" placeholder='{"data": { "method": "success", "id": 148923 } }'>{{.PostData.String}}</textarea>
<textarea name="post_data" class="form-control" id="post_data" rows="3" autocapitalize="none" spellcheck="false" placeholder='{"data": { "method": "success", "id": 148923 } }'>{{.PostData.String}}</textarea>
<small class="form-text text-muted">Insert a JSON string to send data to the endpoint.</small>
</div>
</div>
<div class="form-group row{{if (eq .Type "tcp") or (eq .Type "udp")}} d-none{{end}}">
<label for="service_response" class="col-sm-4 col-form-label">Expected Response (Regex)</label>
<div class="col-sm-8">
<textarea name="expected" class="form-control" id="service_response" rows="3" autocapitalize="false" spellcheck="false" placeholder='(method)": "((\\"|[success])*)"'>{{.Expected.String}}</textarea>
<textarea name="expected" class="form-control" id="service_response" rows="3" autocapitalize="none" spellcheck="false" placeholder='(method)": "((\\"|[success])*)"'>{{.Expected.String}}</textarea>
<small class="form-text text-muted">You can use plain text or insert <a target="_blank" href="https://regex101.com/r/I5bbj9/1">Regex</a> to validate the response</small>
</div>
</div>

View File

@ -9,7 +9,7 @@
<div class="form-group row">
<label for="username" class="col-sm-4 col-form-label">Username</label>
<div class="col-6 col-md-4">
<input type="text" name="username" class="form-control" value="{{.Username}}" id="username" placeholder="Username" required>
<input type="text" name="username" class="form-control" value="{{.Username}}" id="username" placeholder="Username" required autocorrect="off" autocapitalize="none">
</div>
<div class="col-6 col-md-4">
<span class="switch">
@ -21,7 +21,7 @@
<div class="form-group row">
<label for="email" class="col-sm-4 col-form-label">Email Address</label>
<div class="col-sm-8">
<input type="email" name="email" class="form-control" id="email" value="{{.Email}}" placeholder="user@domain.com" required autocapitalize="false" spellcheck="false">
<input type="email" name="email" class="form-control" id="email" value="{{.Email}}" placeholder="user@domain.com" required autocapitalize="none" spellcheck="false">
</div>
</div>
<div class="form-group row">

View File

@ -14,7 +14,7 @@
<div class="form-group row">
<label for="username" class="col-sm-2 col-form-label">Username</label>
<div class="col-sm-10">
<input type="text" name="username" class="form-control" id="username" placeholder="Username" autocapitalize="false" spellcheck="false">
<input type="text" name="username" class="form-control" id="username" placeholder="Username" autocorrect="off" autocapitalize="none">
</div>
</div>
<div class="form-group row">

View File

@ -39,19 +39,24 @@
<div class="form-group row">
<div class="col-8 col-sm-9">
<label for="domain">Domain</label>
<input type="text" name="domain" class="form-control" value="{{ .Domain }}" id="domain">
<input type="url" name="domain" class="form-control" value="{{ .Domain }}" id="domain">
</div>
<div class="col-4 col-sm-3 mt-sm-1 mt-0">
<label for="enable_cdn" class="d-inline d-sm-none">Enable CDN</label>
<label for="enable_cdn" class="d-none d-sm-block">Enable CDN</label>
<span class="switch">
<input type="checkbox" name="enable_cdn" class="switch" id="switch-normal" {{if USE_CDN}}checked{{end}}{{if .UsingAssets}} disabled{{end}}>
<label for="switch-normal" class="mt-2 mt-sm-0"></label>
</span>
<input type="checkbox" name="enable_cdn" class="switch" id="switch-normal" {{if USE_CDN}}checked{{end}}{{if .UsingAssets}} disabled{{end}}>
<label for="switch-normal" class="mt-2 mt-sm-0"></label>
</span>
</div>
</div>
{{if not .Domain}}
<div class="alert alert-danger" role="alert">
Your Statup server does not have a dedicated URL!
</div>
{{end}}
<div class="form-group">
<label for="footer">Custom Footer</label>
<textarea rows="4" name="footer" class="form-control" id="footer">{{ .Footer.String }}</textarea>
@ -113,13 +118,17 @@
<div class="row">
<a href="/settings/export" class="btn btn-sm btn-secondary float-right">Export Settings</a>
{{if .Domain}}
<a href="#" class="btn btn-sm btn-secondary float-right ml-1">Authentication QR Code</a>
{{end}}
</div>
{{if .Domain}}
<div class="row align-content-center">
<img class="rounded text-center" width="300" height="300" src="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl={{ QrAuth }}">
</div>
<a class="btn btn-sm btn-primary" href={{safeURL QrAuth}}>Open in Statping App</a>
{{end}}
</form>