Add config file setting
This commit is contained in:
parent
a7e2bbe74c
commit
bf0542bf18
@ -47,8 +47,8 @@ func (svr *Service) RunAdminServer(address string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subRouter := router.NewRoute().Subrouter()
|
subRouter := router.NewRoute().Subrouter()
|
||||||
user, passwd := svr.cfg.AdminUser, svr.cfg.AdminPwd
|
user, passwd, hashed := svr.cfg.AdminUser, svr.cfg.AdminPwd, svr.cfg.HashedPwd
|
||||||
subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd).Middleware)
|
subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd, hashed).Middleware)
|
||||||
|
|
||||||
// api, see admin_api.go
|
// api, see admin_api.go
|
||||||
subRouter.HandleFunc("/api/reload", svr.apiReload).Methods("GET")
|
subRouter.HandleFunc("/api/reload", svr.apiReload).Methods("GET")
|
||||||
|
@ -49,6 +49,7 @@ var (
|
|||||||
dashboardPort int
|
dashboardPort int
|
||||||
dashboardUser string
|
dashboardUser string
|
||||||
dashboardPwd string
|
dashboardPwd string
|
||||||
|
hashedPwd bool
|
||||||
enablePrometheus bool
|
enablePrometheus bool
|
||||||
assetsDir string
|
assetsDir string
|
||||||
logFile string
|
logFile string
|
||||||
@ -80,6 +81,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().IntVarP(&dashboardPort, "dashboard_port", "", 0, "dashboard port")
|
rootCmd.PersistentFlags().IntVarP(&dashboardPort, "dashboard_port", "", 0, "dashboard port")
|
||||||
rootCmd.PersistentFlags().StringVarP(&dashboardUser, "dashboard_user", "", "admin", "dashboard user")
|
rootCmd.PersistentFlags().StringVarP(&dashboardUser, "dashboard_user", "", "admin", "dashboard user")
|
||||||
rootCmd.PersistentFlags().StringVarP(&dashboardPwd, "dashboard_pwd", "", "admin", "dashboard password")
|
rootCmd.PersistentFlags().StringVarP(&dashboardPwd, "dashboard_pwd", "", "admin", "dashboard password")
|
||||||
|
rootCmd.PersistentFlags().BoolVarP(&hashedPwd, "hashed_pwd", "", false, "specify if password is hashed")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&enablePrometheus, "enable_prometheus", "", false, "enable prometheus dashboard")
|
rootCmd.PersistentFlags().BoolVarP(&enablePrometheus, "enable_prometheus", "", false, "enable prometheus dashboard")
|
||||||
rootCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "log file")
|
rootCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "log file")
|
||||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level")
|
rootCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level")
|
||||||
@ -166,6 +168,7 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
|
|||||||
cfg.DashboardPort = dashboardPort
|
cfg.DashboardPort = dashboardPort
|
||||||
cfg.DashboardUser = dashboardUser
|
cfg.DashboardUser = dashboardUser
|
||||||
cfg.DashboardPwd = dashboardPwd
|
cfg.DashboardPwd = dashboardPwd
|
||||||
|
cfg.HashedPwd = hashedPwd
|
||||||
cfg.EnablePrometheus = enablePrometheus
|
cfg.EnablePrometheus = enablePrometheus
|
||||||
cfg.LogFile = logFile
|
cfg.LogFile = logFile
|
||||||
cfg.LogLevel = logLevel
|
cfg.LogLevel = logLevel
|
||||||
|
@ -83,6 +83,8 @@ type ClientCommonConf struct {
|
|||||||
// AdminPwd specifies the password that the admin server will use for
|
// AdminPwd specifies the password that the admin server will use for
|
||||||
// login.
|
// login.
|
||||||
AdminPwd string `ini:"admin_pwd" json:"admin_pwd"`
|
AdminPwd string `ini:"admin_pwd" json:"admin_pwd"`
|
||||||
|
// HashedPwd specifies if the password is hashed using BCrypt or not
|
||||||
|
HashedPwd bool `ini:"hashed_pwd" json:"hashed_pwd"`
|
||||||
// AssetsDir specifies the local directory that the admin server will load
|
// AssetsDir specifies the local directory that the admin server will load
|
||||||
// resources from. If this value is "", assets will be loaded from the
|
// resources from. If this value is "", assets will be loaded from the
|
||||||
// bundled executable using statik. By default, this value is "".
|
// bundled executable using statik. By default, this value is "".
|
||||||
|
@ -160,6 +160,7 @@ type HTTPProxyConf struct {
|
|||||||
Locations []string `ini:"locations" json:"locations"`
|
Locations []string `ini:"locations" json:"locations"`
|
||||||
HTTPUser string `ini:"http_user" json:"http_user"`
|
HTTPUser string `ini:"http_user" json:"http_user"`
|
||||||
HTTPPwd string `ini:"http_pwd" json:"http_pwd"`
|
HTTPPwd string `ini:"http_pwd" json:"http_pwd"`
|
||||||
|
HashedPwd bool `ini:"hashed_pwd" json:"hashed_pwd"`
|
||||||
HostHeaderRewrite string `ini:"host_header_rewrite" json:"host_header_rewrite"`
|
HostHeaderRewrite string `ini:"host_header_rewrite" json:"host_header_rewrite"`
|
||||||
Headers map[string]string `ini:"-" json:"headers"`
|
Headers map[string]string `ini:"-" json:"headers"`
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,8 @@ type ServerCommonConf struct {
|
|||||||
// DashboardPwd specifies the password that the dashboard will use for
|
// DashboardPwd specifies the password that the dashboard will use for
|
||||||
// login.
|
// login.
|
||||||
DashboardPwd string `ini:"dashboard_pwd" json:"dashboard_pwd"`
|
DashboardPwd string `ini:"dashboard_pwd" json:"dashboard_pwd"`
|
||||||
|
// HashedPwd specifies if the password is hashed using BCrypt or not
|
||||||
|
HashedPwd bool `ini:"hashed_pwd" json:"hashed_pwd"`
|
||||||
// EnablePrometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port}
|
// EnablePrometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port}
|
||||||
// in /metrics api.
|
// in /metrics api.
|
||||||
EnablePrometheus bool `ini:"enable_prometheus" json:"enable_prometheus"`
|
EnablePrometheus bool `ini:"enable_prometheus" json:"enable_prometheus"`
|
||||||
@ -193,6 +195,7 @@ func GetDefaultServerConf() ServerCommonConf {
|
|||||||
DashboardPort: 0,
|
DashboardPort: 0,
|
||||||
DashboardUser: "",
|
DashboardUser: "",
|
||||||
DashboardPwd: "",
|
DashboardPwd: "",
|
||||||
|
HashedPwd: false,
|
||||||
EnablePrometheus: false,
|
EnablePrometheus: false,
|
||||||
AssetsDir: "",
|
AssetsDir: "",
|
||||||
LogFile: "console",
|
LogFile: "console",
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
frpNet "github.com/fatedier/frp/pkg/util/net"
|
frpNet "github.com/fatedier/frp/pkg/util/net"
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ type StaticFilePlugin struct {
|
|||||||
stripPrefix string
|
stripPrefix string
|
||||||
httpUser string
|
httpUser string
|
||||||
httpPasswd string
|
httpPasswd string
|
||||||
|
hashedPwd bool
|
||||||
|
|
||||||
l *Listener
|
l *Listener
|
||||||
s *http.Server
|
s *http.Server
|
||||||
@ -45,6 +47,11 @@ func NewStaticFilePlugin(params map[string]string) (Plugin, error) {
|
|||||||
stripPrefix := params["plugin_strip_prefix"]
|
stripPrefix := params["plugin_strip_prefix"]
|
||||||
httpUser := params["plugin_http_user"]
|
httpUser := params["plugin_http_user"]
|
||||||
httpPasswd := params["plugin_http_passwd"]
|
httpPasswd := params["plugin_http_passwd"]
|
||||||
|
hashedPwd, err := strconv.ParseBool(params["plugin_hashed_pwd"])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
hashedPwd = false
|
||||||
|
}
|
||||||
|
|
||||||
listener := NewProxyListener()
|
listener := NewProxyListener()
|
||||||
|
|
||||||
@ -53,6 +60,7 @@ func NewStaticFilePlugin(params map[string]string) (Plugin, error) {
|
|||||||
stripPrefix: stripPrefix,
|
stripPrefix: stripPrefix,
|
||||||
httpUser: httpUser,
|
httpUser: httpUser,
|
||||||
httpPasswd: httpPasswd,
|
httpPasswd: httpPasswd,
|
||||||
|
hashedPwd: hashedPwd,
|
||||||
|
|
||||||
l: listener,
|
l: listener,
|
||||||
}
|
}
|
||||||
@ -64,7 +72,7 @@ func NewStaticFilePlugin(params map[string]string) (Plugin, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.Use(frpNet.NewHTTPAuthMiddleware(httpUser, httpPasswd).Middleware)
|
router.Use(frpNet.NewHTTPAuthMiddleware(httpUser, httpPasswd, hashedPwd).Middleware)
|
||||||
router.PathPrefix(prefix).Handler(frpNet.MakeHTTPGzipHandler(http.StripPrefix(prefix, http.FileServer(http.Dir(localPath))))).Methods("GET")
|
router.PathPrefix(prefix).Handler(frpNet.MakeHTTPGzipHandler(http.StripPrefix(prefix, http.FileServer(http.Dir(localPath))))).Methods("GET")
|
||||||
sp.s = &http.Server{
|
sp.s = &http.Server{
|
||||||
Handler: router,
|
Handler: router,
|
||||||
|
@ -50,12 +50,14 @@ func (aw *HTTPAuthWraper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
type HTTPAuthMiddleware struct {
|
type HTTPAuthMiddleware struct {
|
||||||
user string
|
user string
|
||||||
passwd string
|
passwd string
|
||||||
|
hashed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTPAuthMiddleware(user, passwd string) *HTTPAuthMiddleware {
|
func NewHTTPAuthMiddleware(user, passwd string, hashed bool) *HTTPAuthMiddleware {
|
||||||
return &HTTPAuthMiddleware{
|
return &HTTPAuthMiddleware{
|
||||||
user: user,
|
user: user,
|
||||||
passwd: passwd,
|
passwd: passwd,
|
||||||
|
hashed: hashed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +67,7 @@ func (authMid *HTTPAuthMiddleware) Middleware(next http.Handler) http.Handler {
|
|||||||
if (authMid.user == "" && authMid.passwd == "") ||
|
if (authMid.user == "" && authMid.passwd == "") ||
|
||||||
(hasAuth && reqUser == authMid.user && reqPasswd == authMid.passwd) {
|
(hasAuth && reqUser == authMid.user && reqPasswd == authMid.passwd) {
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
} else if authMid.user == reqUser && authMid.passwd[:4] == "$2a$" || authMid.passwd[:4] == "$2y$" {
|
} else if authMid.user == reqUser && authMid.hashed {
|
||||||
correct := bcrypt.CompareHashAndPassword([]byte(authMid.passwd), []byte(reqPasswd))
|
correct := bcrypt.CompareHashAndPassword([]byte(authMid.passwd), []byte(reqPasswd))
|
||||||
if correct == nil {
|
if correct == nil {
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
|
@ -48,8 +48,8 @@ func (svr *Service) RunDashboardServer(address string) (err error) {
|
|||||||
|
|
||||||
subRouter := router.NewRoute().Subrouter()
|
subRouter := router.NewRoute().Subrouter()
|
||||||
|
|
||||||
user, passwd := svr.cfg.DashboardUser, svr.cfg.DashboardPwd
|
user, passwd, hashed := svr.cfg.DashboardUser, svr.cfg.DashboardPwd, svr.cfg.HashedPwd
|
||||||
subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd).Middleware)
|
subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd, hashed).Middleware)
|
||||||
|
|
||||||
// metrics
|
// metrics
|
||||||
if svr.cfg.EnablePrometheus {
|
if svr.cfg.EnablePrometheus {
|
||||||
|
Loading…
Reference in New Issue
Block a user