Skip to content
Permalink
Browse files

BASE_PATH

  • Loading branch information
hunterlong committed Jan 13, 2020
1 parent 479763f commit 217a45425de63e29a198a636e1982ba019e29b25
@@ -49,8 +49,8 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
session.Values["user_id"] = user.Id
session.Values["admin"] = user.Admin.Bool
session.Save(r, w)
log.Infoln(fmt.Sprintf("User %v logged in from IP %v", user.Username, r.RemoteAddr))
http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
utils.Log.Infoln(fmt.Sprintf("User %v logged in from IP %v", user.Username, r.RemoteAddr))
http.Redirect(w, r, basePath+"dashboard", http.StatusSeeOther)
} else {
err := core.ErrorResponse{Error: "Incorrect login information submitted, try again."}
ExecuteResponse(w, r, "login.gohtml", err, nil)
@@ -23,6 +23,7 @@ import (
"html/template"
"net/http"
"os"
"path"
"strings"
"time"

@@ -51,10 +52,6 @@ var (
func RunHTTPServer(ip string, port int) error {
host := fmt.Sprintf("%v:%v", ip, port)

if os.Getenv("BASE_PATH") != "" {
basePath = "/" + os.Getenv("BASE_PATH")
}

key := utils.FileExists(utils.Directory + "/server.key")
cert := utils.FileExists(utils.Directory + "/server.crt")

@@ -220,7 +217,7 @@ func loadTemplate(w http.ResponseWriter, r *http.Request) (*template.Template, e
// ExecuteResponse will render a HTTP response for the front end user
func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}, redirect interface{}) {
if url, ok := redirect.(string); ok {
http.Redirect(w, r, basePath+url, http.StatusSeeOther)
http.Redirect(w, r, path.Join(basePath, url), http.StatusSeeOther)
return
}
if usingSSL {
@@ -45,27 +45,31 @@ func Router() *mux.Router {
authPass = os.Getenv("AUTH_PASSWORD")
r.Use(basicAuthHandler)
}
if basePath != "/" {
r = r.PathPrefix(basePath).Subrouter()

if os.Getenv("BASE_PATH") != "" {
basePath = "/" + os.Getenv("BASE_PATH") + "/"
r = r.PathPrefix("/" + os.Getenv("BASE_PATH")).Subrouter()
r.Handle("", http.HandlerFunc(indexHandler))
} else {
r.Handle("/", http.HandlerFunc(indexHandler))
}

r.Use(sendLog)
r.Handle("/", http.HandlerFunc(indexHandler))
if source.UsingAssets(dir) {
indexHandler := http.FileServer(http.Dir(dir + "/assets/"))
r.PathPrefix("/css/").Handler(http.StripPrefix(basePath+"/css/", http.FileServer(http.Dir(dir+"/assets/css"))))
r.PathPrefix("/font/").Handler(http.StripPrefix(basePath+"/font/", http.FileServer(http.Dir(dir+"/assets/font"))))
r.PathPrefix("/js/").Handler(http.StripPrefix(basePath+"/js/", http.FileServer(http.Dir(dir+"/assets/js"))))
r.PathPrefix("/robots.txt").Handler(indexHandler)
r.PathPrefix("/favicon.ico").Handler(indexHandler)
r.PathPrefix("/banner.png").Handler(indexHandler)
r.PathPrefix("/css/").Handler(http.StripPrefix(basePath+"css/", http.FileServer(http.Dir(dir+"/assets/css"))))
r.PathPrefix("/font/").Handler(http.StripPrefix(basePath+"font/", http.FileServer(http.Dir(dir+"/assets/font"))))
r.PathPrefix("/js/").Handler(http.StripPrefix(basePath+"js/", http.FileServer(http.Dir(dir+"/assets/js"))))
r.PathPrefix("/robots.txt").Handler(http.StripPrefix(basePath, indexHandler))
r.PathPrefix("/favicon.ico").Handler(http.StripPrefix(basePath, indexHandler))
r.PathPrefix("/banner.png").Handler(http.StripPrefix(basePath, indexHandler))
} else {
r.PathPrefix("/css/").Handler(http.StripPrefix(basePath+"/css/", http.FileServer(source.CssBox.HTTPBox())))
r.PathPrefix("/font/").Handler(http.StripPrefix(basePath+"/font/", http.FileServer(source.FontBox.HTTPBox())))
r.PathPrefix("/js/").Handler(http.StripPrefix(basePath+"/js/", http.FileServer(source.JsBox.HTTPBox())))
r.PathPrefix("/robots.txt").Handler(http.FileServer(source.TmplBox.HTTPBox()))
r.PathPrefix("/favicon.ico").Handler(http.FileServer(source.TmplBox.HTTPBox()))
r.PathPrefix("/banner.png").Handler(http.FileServer(source.TmplBox.HTTPBox()))
r.PathPrefix("/css/").Handler(http.StripPrefix(basePath+"css/", http.FileServer(source.CssBox.HTTPBox())))
r.PathPrefix("/font/").Handler(http.StripPrefix(basePath+"font/", http.FileServer(source.FontBox.HTTPBox())))
r.PathPrefix("/js/").Handler(http.StripPrefix(basePath+"js/", http.FileServer(source.JsBox.HTTPBox())))
r.PathPrefix("/robots.txt").Handler(http.StripPrefix(basePath, http.FileServer(source.TmplBox.HTTPBox())))
r.PathPrefix("/favicon.ico").Handler(http.StripPrefix(basePath, http.FileServer(source.TmplBox.HTTPBox())))
r.PathPrefix("/banner.png").Handler(http.StripPrefix(basePath, http.FileServer(source.TmplBox.HTTPBox())))
}
r.Handle("/charts.js", http.HandlerFunc(renderServiceChartsHandler))
r.Handle("/setup", http.HandlerFunc(setupHandler)).Methods("GET")
@@ -93,7 +93,7 @@ $('.toggle-service').on('click',function(e) {
let d = confirm("Do you want to "+(eval(online) ? "stop" : "start")+" checking this service?");
if (d) {
$.ajax({
url: "/api/services/" + serviceId + "/running",
url: "api/services/" + serviceId + "/running",
type: 'POST',
success: function (data) {
if (online === "true") {
@@ -166,7 +166,7 @@ function UTCTime() {
}

function ChartLatency(service, start=0, end=9999999999, group="hour", retry=true) {
let url = "/api/services/" + service + "/data?start=" + start + "&end=" + end + "&group=" + group;
let url = "api/services/" + service + "/data?start=" + start + "&end=" + end + "&group=" + group;
return new Promise(resolve => {
$.ajax({
url: url,
@@ -182,7 +182,7 @@ function ChartLatency(service, start=0, end=9999999999, group="hour", retry=true
function ChartHeatmap(service) {
return new Promise(resolve => {
$.ajax({
url: "/api/services/" + service + "/heatmap",
url: "api/services/" + service + "/heatmap",
type: 'GET',
success: function (data) {
resolve(data);
@@ -202,7 +202,7 @@ function FailureAnnotations(chart, service, start=0, end=9999999999, group="hour
};
var dataArr = [];
$.ajax({
url: "/api/services/"+service+"/failures?start="+start+"&end="+end+"&group="+group,
url: "api/services/"+service+"/failures?start="+start+"&end="+end+"&group="+group,
type: 'GET',
success: function(data) {
data.forEach(function (d) {
@@ -227,7 +227,7 @@ $('input[type=checkbox]').on('change', function() {

function PingAjaxChart(chart, service, start=0, end=9999999999, group="hour") {
$.ajax({
url: "/api/services/"+service+"/ping?start="+start+"&end="+end+"&group="+group,
url: "api/services/"+service+"/ping?start="+start+"&end="+end+"&group="+group,
type: 'GET',
success: function(data) {
chart.data.labels.pop();
@@ -349,8 +349,8 @@ function CreateService(output) {
<td class="d-none d-md-table-cell">${data.online}<span class="badge badge-success">ONLINE</span></td>
<td class="text-right">
<div class="btn-group">
<a href="/service/${data.id}" class="btn btn-outline-secondary"><i class="fas fa-chart-area"></i> View</a>
<a href="/api/services/${data.id}" class="ajax_delete btn btn-danger confirm-btn" data-method="DELETE" data-obj="service_${data.id}" data-id="${data.id}"><i class="fas fa-times"></i></a>
<a href="service/${data.id}" class="btn btn-outline-secondary"><i class="fas fa-chart-area"></i> View</a>
<a href="api/services/${data.id}" class="ajax_delete btn btn-danger confirm-btn" data-method="DELETE" data-obj="service_${data.id}" data-id="${data.id}"><i class="fas fa-times"></i></a>
</div>
</td>
</tr>`;
@@ -365,8 +365,8 @@ function CreateUser(output) {
<td>${form.username}</td>
<td class="text-right">
<div class="btn-group">
<a href="/user/${data.id}" class="btn btn-outline-secondary"><i class="fas fa-user-edit"></i> Edit</a>
<a href="/api/users/${data.id}" class="ajax_delete btn btn-danger confirm-btn" data-method="DELETE" data-obj="user_${data.id}" data-id="${data.id}"><i class="fas fa-times"></i></a>
<a href="user/${data.id}" class="btn btn-outline-secondary"><i class="fas fa-user-edit"></i> Edit</a>
<a href="api/users/${data.id}" class="ajax_delete btn btn-danger confirm-btn" data-method="DELETE" data-obj="user_${data.id}" data-id="${data.id}"><i class="fas fa-times"></i></a>
</div>
</td>
</tr>`;
@@ -21,7 +21,7 @@
{{ range Services }}
<div class="col-12 card mb-3" style="min-height: 260px">
<div class="card-body">
<h5 class="card-title"><a href="/service/{{.Id}}">{{.Name}}</a> {{if .Online}}<span class="badge float-right badge-success">ONLINE</span>{{else}}<span class="badge float-right badge-danger">OFFLINE</span>{{end}}</h5>
<h5 class="card-title"><a href="service/{{.Id}}">{{.Name}}</a> {{if .Online}}<span class="badge float-right badge-success">ONLINE</span>{{else}}<span class="badge float-right badge-danger">OFFLINE</span>{{end}}</h5>
<div class="row">
<div class="col-md-3 col-sm-6">
<div id="spark_service_{{.Id}}_1"></div>
@@ -46,7 +46,7 @@
<div class="jumbotron jumbotron-fluid">
<div class="text-center">
<h1 class="display-4">No Services!</h1>
<a class="lead">You don't have any websites or applications being monitored by your Statping server. <p><a href="/service/create" class="btn btn-secondary mt-3">Add Service</a></p></p>
<a class="lead">You don't have any websites or applications being monitored by your Statping server. <p><a href="service/create" class="btn btn-secondary mt-3">Add Service</a></p></p>
</div>
</div>
{{end}}
@@ -3,7 +3,7 @@
{{ if CoreApp.Footer.String }}
{{ safe CoreApp.Footer.String }}
{{ else }}
<a href="https://github.com/hunterlong/statping" target="_blank">Statping {{VERSION}} made with <i class="text-danger fas fa-heart"></i></a> | <a href="/dashboard">Dashboard</a>
<a href="https://github.com/hunterlong/statping" target="_blank">Statping {{VERSION}} made with <i class="text-danger fas fa-heart"></i></a> | <a href="dashboard">Dashboard</a>
{{ end }}
</div>
{{ end }}
@@ -159,7 +159,7 @@
</div>
{{if ne .Id 0}}
<div class="col-6">
<a href="/service/{{ .Id }}/delete_failures" data-method="GET" data-redirect="/service/{{ .Id }}" class="btn btn-danger btn-block confirm-btn">Delete All Failures</a>
<a href="service/{{ .Id }}/delete_failures" data-method="GET" data-redirect="/service/{{ .Id }}" class="btn btn-danger btn-block confirm-btn">Delete All Failures</a>
</div>
{{end}}
</div>
@@ -4,7 +4,7 @@
<title>{{block "title" .}} {{end}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0, user-scalable=0">
<meta name="description" content="{{block "description" .}}{{end}}">
<base href="{{BasePath}}/">
<base href="{{BasePath}}">
{{if USE_CDN}}
<link rel="shortcut icon" type="image/x-icon" href="https://assets.statping.com/favicon.ico">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
@@ -6,7 +6,7 @@
{{end}}
<div class="col-12 bg-white p-4">
<div class="col-12 col-md-8 offset-md-2 mb-4 mt-3">
<img class="col-12 mt-5 mt-md-0" src="/banner.png">
<img class="col-12 mt-5 mt-md-0" src="banner.png">
</div>
<h3>Index</h3>
{{ safe . }}
@@ -47,7 +47,7 @@
{{ if not .Services }}
<div class="alert alert-danger" role="alert">
<h4 class="alert-heading">No Services to Monitor!</h4>
<p>Your Statping Status Page is working correctly, but you don't have any services to monitor. Go to the <a href="/dashboard">Dashboard</a> and add a website to begin really using your status page!</p>
<p>Your Statping Status Page is working correctly, but you don't have any services to monitor. Go to the <a href="dashboard">Dashboard</a> and add a website to begin really using your status page!</p>
<hr>
<p class="mb-0">If this is a bug, please make an issue in the Statping Github Repo. <a href="https://github.com/hunterlong/statping" class="btn btn-sm btn-outline-danger float-right">Statping Github Repo</a></p>
</div>
@@ -59,7 +59,7 @@
<div class="card">
<div class="card-body">
<div class="col-12">
<h4 class="mt-3"><a href="/service/{{ServiceLink .}}"{{if not .Online}} class="text-danger"{{end}}>{{ .Name }}</a>
<h4 class="mt-3"><a href="service/{{ServiceLink .}}"{{if not .Online}} class="text-danger"{{end}}>{{ .Name }}</a>
{{if .Online}}
<span class="badge bg-success float-right">ONLINE</span>
{{ else }}
@@ -93,7 +93,7 @@
<span class="d-none d-md-inline">{{.SmallText}}</span>
</div>
<div class="col-sm-12 col-md-2">
<a href="/service/{{ServiceLink .}}" class="btn {{if .Online}}btn-success{{else}}btn-danger{{end}} btn-sm float-right dyn-dark btn-block">View Service</a>
<a href="service/{{ServiceLink .}}" class="btn {{if .Online}}btn-success{{else}}btn-danger{{end}} btn-sm float-right dyn-dark btn-block">View Service</a>
</div>
</div>

@@ -104,5 +104,5 @@
</div>
{{end}}
{{define "extra_scripts"}}
<script src="/charts.js"></script>
<script src="charts.js"></script>
{{end}}
@@ -78,7 +78,7 @@
type: "POST",
data: sendData,
success: function (data) {
var box = `<div class="alert alert-success" role="alert">Service '${data.output.name}' Added <a href="/service/${data.output.id}" class="badge badge-secondary mt-1 float-right">View</a></div>`;
var box = `<div class="alert alert-success" role="alert">Service '${data.output.name}' Added <a href="service/${data.output.id}" class="badge badge-secondary mt-1 float-right">View</a></div>`;
$("#imported_area").append(box);
}
});
@@ -3,7 +3,7 @@
<div class="container col-md-7 col-sm-12 mt-md-5 bg-light">
<div class="col-10 offset-1 col-md-8 offset-md-2 mt-md-2">
<div class="col-12 col-md-8 offset-md-2 mb-4">
<img class="col-12 mt-5 mt-md-0" src="/banner.png">
<img class="col-12 mt-5 mt-md-0" src="banner.png">
</div>
{{ if .Error }}
<div class="alert alert-danger" role="alert">
@@ -9,11 +9,11 @@
</div>
{{end}}
{{define "extra_css"}}
<link rel="stylesheet" href="/css/flatpickr.min.css">
<link rel="stylesheet" href="css/flatpickr.min.css">
{{end}}
{{define "extra_scripts"}}
<script src="/js/flatpickr.js"></script>
<script src="/js/rangePlugin.js"></script>
<script src="js/flatpickr.js"></script>
<script src="js/rangePlugin.js"></script>
<script>
$(document).ready(function() {
$("#start_on").flatpickr({
@@ -24,4 +24,4 @@ $(document).ready(function() {
});
});
</script>
{{end}}
{{end}}
@@ -18,12 +18,12 @@
{{range .}}
<tr id="message_{{.Id}}">
<td>{{.Title}}</td>
<td class="d-none d-md-table-cell">{{if .Service}}<a href="/service/{{.Service.Id}}">{{.Service.Name}}</a>{{end}}</td>
<td class="d-none d-md-table-cell">{{if .Service}}<a href="service/{{.Service.Id}}">{{.Service.Name}}</a>{{end}}</td>
<td class="d-none d-md-table-cell">{{ToString .StartOn}}</td>
<td class="text-right">
{{if Auth}}<div class="btn-group">
<a href="/message/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-exclamation-triangle"></i> Edit</a>
<a href="/api/messages/{{.Id}}" class="ajax_delete btn btn-danger" data-method="DELETE" data-obj="message_{{.Id}}" data-id="{{.Id}}"><i class="fas fa-times"></i></a>
<a href="message/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-exclamation-triangle"></i> Edit</a>
<a href="api/messages/{{.Id}}" class="ajax_delete btn btn-danger" data-method="DELETE" data-obj="message_{{.Id}}" data-id="{{.Id}}"><i class="fas fa-times"></i></a>
</div>{{end}}
</td>
</tr>
@@ -41,11 +41,11 @@
</div>
{{end}}
{{define "extra_css"}}
<link rel="stylesheet" href="/css/flatpickr.min.css">
<link rel="stylesheet" href="css/flatpickr.min.css">
{{end}}
{{define "extra_scripts"}}
<script src="/js/flatpickr.js"></script>
<script src="/js/rangePlugin.js"></script>
<script src="js/flatpickr.js"></script>
<script src="js/rangePlugin.js"></script>
<script>
$(document).ready(function() {
$("#start_on").flatpickr({
@@ -1,7 +1,7 @@
{{define "nav"}}
{{$isAdmin := Auth}}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Statping</a>
<a class="navbar-brand" href="">Statping</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
@@ -5,10 +5,10 @@
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<script src="https://assets.statping.com/main.js"></script>
{{ else }}
<script src="{{BasePath}}/js/jquery-3.3.1.min.js"></script>
<script src="{{BasePath}}/js/bootstrap.min.js"></script>
<script src="{{BasePath}}/js/apexcharts.min.js"></script>
<script src="{{BasePath}}/js/main.js"></script>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/apexcharts.min.js"></script>
<script src="js/main.js"></script>
{{end}}
{{block "extra_scripts" .}} {{end}}
{{end}}
@@ -20,7 +20,7 @@
<span class="mt-3 mb-3 text-white d-md-none btn bg-danger d-block d-md-none">OFFLINE</span>
{{end}}

<h4 class="mt-2"><a href="/">{{CoreApp.Name}}</a> - {{ $s.Name }}
<h4 class="mt-2"><a href="">{{CoreApp.Name}}</a> - {{ $s.Name }}
{{if $s.Online }}
<span class="badge bg-success float-right d-none d-md-block">ONLINE</span>
{{ else }}
@@ -168,7 +168,7 @@
{{ if lt $ch.Expected 0}}{{Duration $ch.Expected}} ago{{else}}in {{Duration $ch.Expected}}{{end}}
{{end}}
</td>
<td><a href="/api/checkin/{{$ch.ApiKey}}" data-method="DELETE" data-obj="checkin_{{$ch.Id}}" data-id="{{$ch.Id}}" class="ajax_delete btn btn-sm btn-danger">Delete</a></td>
<td><a href="api/checkin/{{$ch.ApiKey}}" data-method="DELETE" data-obj="checkin_{{$ch.Id}}" data-id="{{$ch.Id}}" class="ajax_delete btn btn-sm btn-danger">Delete</a></td>
</tr>
{{end}}
</tbody>
@@ -231,12 +231,12 @@
</div>
{{end}}
{{define "extra_css"}}
<link rel="stylesheet" href="/css/flatpickr.min.css">
<link rel="stylesheet" href="css/flatpickr.min.css">
{{end}}
{{define "extra_scripts"}}
{{$s := .Service}}
<script src="/js/flatpickr.js"></script>
<script src="/js/rangePlugin.js"></script>
<script src="js/flatpickr.js"></script>
<script src="js/rangePlugin.js"></script>
<script>

let options = {

0 comments on commit 217a454

Please sign in to comment.
You can’t perform that action at this time.