Added basic authentication in debug/vars
Using a simple http auth middleware. https://github.com/goji/httpauth
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"Host": ":8080",
|
"Host": ":8080",
|
||||||
"Expvar": true,
|
"Expvar": true,
|
||||||
|
"User": "Username",
|
||||||
|
"Password": "123456",
|
||||||
"Apps": [
|
"Apps": [
|
||||||
{
|
{
|
||||||
"ApplicationDisabled": false,
|
"ApplicationDisabled": false,
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import "errors"
|
|||||||
|
|
||||||
// The config file
|
// The config file
|
||||||
type ConfigFile struct {
|
type ConfigFile struct {
|
||||||
Host string // The host, eg: :8080 will start on 0.0.0.0:8080
|
Host string // The host, eg: :8080 will start on 0.0.0.0:8080
|
||||||
Expvar bool
|
Expvar bool
|
||||||
Apps []*App
|
User string
|
||||||
|
Password string
|
||||||
|
Apps []*App
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error for App not found
|
// Error for App not found
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import (
|
|||||||
_ "expvar"
|
_ "expvar"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/goji/httpauth"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
@@ -19,7 +21,11 @@ func NewRouter() *mux.Router {
|
|||||||
router := mux.NewRouter().StrictSlash(true)
|
router := mux.NewRouter().StrictSlash(true)
|
||||||
|
|
||||||
if Conf.Expvar {
|
if Conf.Expvar {
|
||||||
router.Handle("/debug/vars", http.DefaultServeMux)
|
if len(strings.TrimSpace(Conf.User)) == 0 || len(strings.TrimSpace(Conf.Password)) == 0 {
|
||||||
|
panic("Your are exporting debug variables and you are not defining an User and a Password")
|
||||||
|
}
|
||||||
|
|
||||||
|
router.Handle("/debug/vars", httpauth.SimpleBasicAuth(Conf.User, Conf.Password)(http.DefaultServeMux))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
|
|||||||
Reference in New Issue
Block a user