add dashboard url
This commit is contained in:
parent
e62d9a5242
commit
149ea92e8b
@ -44,6 +44,7 @@ var (
|
|||||||
vhostHttpPort int
|
vhostHttpPort int
|
||||||
vhostHttpsPort int
|
vhostHttpsPort int
|
||||||
vhostHttpTimeout int64
|
vhostHttpTimeout int64
|
||||||
|
dashboardUrl string
|
||||||
dashboardAddr string
|
dashboardAddr string
|
||||||
dashboardPort int
|
dashboardPort int
|
||||||
dashboardUser string
|
dashboardUser string
|
||||||
@ -73,6 +74,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().IntVarP(&vhostHttpPort, "vhost_http_port", "", 0, "vhost http port")
|
rootCmd.PersistentFlags().IntVarP(&vhostHttpPort, "vhost_http_port", "", 0, "vhost http port")
|
||||||
rootCmd.PersistentFlags().IntVarP(&vhostHttpsPort, "vhost_https_port", "", 0, "vhost https port")
|
rootCmd.PersistentFlags().IntVarP(&vhostHttpsPort, "vhost_https_port", "", 0, "vhost https port")
|
||||||
rootCmd.PersistentFlags().Int64VarP(&vhostHttpTimeout, "vhost_http_timeout", "", 60, "vhost http response header timeout")
|
rootCmd.PersistentFlags().Int64VarP(&vhostHttpTimeout, "vhost_http_timeout", "", 60, "vhost http response header timeout")
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&dashboardUrl, "dashboard_url", "", "/", "dasboard root url")
|
||||||
rootCmd.PersistentFlags().StringVarP(&dashboardAddr, "dashboard_addr", "", "0.0.0.0", "dasboard address")
|
rootCmd.PersistentFlags().StringVarP(&dashboardAddr, "dashboard_addr", "", "0.0.0.0", "dasboard address")
|
||||||
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")
|
||||||
@ -164,6 +166,7 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
|
|||||||
cfg.VhostHttpPort = vhostHttpPort
|
cfg.VhostHttpPort = vhostHttpPort
|
||||||
cfg.VhostHttpsPort = vhostHttpsPort
|
cfg.VhostHttpsPort = vhostHttpsPort
|
||||||
cfg.VhostHttpTimeout = vhostHttpTimeout
|
cfg.VhostHttpTimeout = vhostHttpTimeout
|
||||||
|
cfg.DashboardUrl = dashboardUrl
|
||||||
cfg.DashboardAddr = dashboardAddr
|
cfg.DashboardAddr = dashboardAddr
|
||||||
cfg.DashboardPort = dashboardPort
|
cfg.DashboardPort = dashboardPort
|
||||||
cfg.DashboardUser = dashboardUser
|
cfg.DashboardUser = dashboardUser
|
||||||
|
@ -26,6 +26,7 @@ vhost_https_port = 443
|
|||||||
# set dashboard_addr and dashboard_port to view dashboard of frps
|
# set dashboard_addr and dashboard_port to view dashboard of frps
|
||||||
# dashboard_addr's default value is same with bind_addr
|
# dashboard_addr's default value is same with bind_addr
|
||||||
# dashboard is available only if dashboard_port is set
|
# dashboard is available only if dashboard_port is set
|
||||||
|
dashboard_url = /
|
||||||
dashboard_addr = 0.0.0.0
|
dashboard_addr = 0.0.0.0
|
||||||
dashboard_port = 7500
|
dashboard_port = 7500
|
||||||
|
|
||||||
|
@ -60,6 +60,10 @@ type ServerCommonConf struct {
|
|||||||
// HTTP server, in seconds. By default, this value is 60.
|
// HTTP server, in seconds. By default, this value is 60.
|
||||||
VhostHttpTimeout int64 `json:"vhost_http_timeout"`
|
VhostHttpTimeout int64 `json:"vhost_http_timeout"`
|
||||||
|
|
||||||
|
// DashboardUrl specifies the root path of the dashboard url. By
|
||||||
|
// default, this value is "/".
|
||||||
|
DashboardUrl string `json:"dashboard_url"`
|
||||||
|
|
||||||
// DashboardAddr specifies the address that the dashboard binds to. By
|
// DashboardAddr specifies the address that the dashboard binds to. By
|
||||||
// default, this value is "0.0.0.0".
|
// default, this value is "0.0.0.0".
|
||||||
DashboardAddr string `json:"dashboard_addr"`
|
DashboardAddr string `json:"dashboard_addr"`
|
||||||
@ -148,6 +152,7 @@ func GetDefaultServerConf() ServerCommonConf {
|
|||||||
VhostHttpPort: 0,
|
VhostHttpPort: 0,
|
||||||
VhostHttpsPort: 0,
|
VhostHttpsPort: 0,
|
||||||
VhostHttpTimeout: 60,
|
VhostHttpTimeout: 60,
|
||||||
|
DashboardUrl: "/",
|
||||||
DashboardAddr: "0.0.0.0",
|
DashboardAddr: "0.0.0.0",
|
||||||
DashboardPort: 0,
|
DashboardPort: 0,
|
||||||
DashboardUser: "admin",
|
DashboardUser: "admin",
|
||||||
@ -255,6 +260,12 @@ func UnmarshalServerConfFromIni(content string) (cfg ServerCommonConf, err error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tmpStr, ok = conf.Get("common", "dashboard_url"); ok {
|
||||||
|
cfg.DashboardUrl = tmpStr
|
||||||
|
} else {
|
||||||
|
cfg.DashboardUrl = "/"
|
||||||
|
}
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "dashboard_addr"); ok {
|
if tmpStr, ok = conf.Get("common", "dashboard_addr"); ok {
|
||||||
cfg.DashboardAddr = tmpStr
|
cfg.DashboardAddr = tmpStr
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,9 +31,11 @@ var (
|
|||||||
httpServerWriteTimeout = 10 * time.Second
|
httpServerWriteTimeout = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func (svr *Service) RunDashboardServer(addr string, port int) (err error) {
|
func (svr *Service) RunDashboardServer(url string, addr string, port int) (err error) {
|
||||||
// url router
|
// url router
|
||||||
router := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
|
r.Host(url)
|
||||||
|
router := r.PathPrefix(url).Subrouter()
|
||||||
|
|
||||||
user, passwd := svr.cfg.DashboardUser, svr.cfg.DashboardPwd
|
user, passwd := svr.cfg.DashboardUser, svr.cfg.DashboardPwd
|
||||||
router.Use(frpNet.NewHttpAuthMiddleware(user, passwd).Middleware)
|
router.Use(frpNet.NewHttpAuthMiddleware(user, passwd).Middleware)
|
||||||
|
@ -231,12 +231,12 @@ func NewService(cfg config.ServerCommonConf) (svr *Service, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = svr.RunDashboardServer(cfg.DashboardAddr, cfg.DashboardPort)
|
err = svr.RunDashboardServer(cfg.DashboardUrl, cfg.DashboardAddr, cfg.DashboardPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Create dashboard web server error, %v", err)
|
err = fmt.Errorf("Create dashboard web server error, %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("Dashboard listen on %s:%d", cfg.DashboardAddr, cfg.DashboardPort)
|
log.Info("Dashboard listen on %s:%d%s", cfg.DashboardAddr, cfg.DashboardPort, cfg.DashboardUrl)
|
||||||
statsEnable = true
|
statsEnable = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user