add dashboard url

This commit is contained in:
fatih 2019-09-04 11:57:53 +08:00
parent e62d9a5242
commit 149ea92e8b
5 changed files with 21 additions and 4 deletions

View File

@ -44,6 +44,7 @@ var (
vhostHttpPort int
vhostHttpsPort int
vhostHttpTimeout int64
dashboardUrl string
dashboardAddr string
dashboardPort int
dashboardUser string
@ -73,6 +74,7 @@ func init() {
rootCmd.PersistentFlags().IntVarP(&vhostHttpPort, "vhost_http_port", "", 0, "vhost http 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().StringVarP(&dashboardUrl, "dashboard_url", "", "/", "dasboard root url")
rootCmd.PersistentFlags().StringVarP(&dashboardAddr, "dashboard_addr", "", "0.0.0.0", "dasboard address")
rootCmd.PersistentFlags().IntVarP(&dashboardPort, "dashboard_port", "", 0, "dashboard port")
rootCmd.PersistentFlags().StringVarP(&dashboardUser, "dashboard_user", "", "admin", "dashboard user")
@ -164,6 +166,7 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
cfg.VhostHttpPort = vhostHttpPort
cfg.VhostHttpsPort = vhostHttpsPort
cfg.VhostHttpTimeout = vhostHttpTimeout
cfg.DashboardUrl = dashboardUrl
cfg.DashboardAddr = dashboardAddr
cfg.DashboardPort = dashboardPort
cfg.DashboardUser = dashboardUser

View File

@ -26,6 +26,7 @@ vhost_https_port = 443
# set dashboard_addr and dashboard_port to view dashboard of frps
# dashboard_addr's default value is same with bind_addr
# dashboard is available only if dashboard_port is set
dashboard_url = /
dashboard_addr = 0.0.0.0
dashboard_port = 7500

View File

@ -60,6 +60,10 @@ type ServerCommonConf struct {
// HTTP server, in seconds. By default, this value is 60.
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
// default, this value is "0.0.0.0".
DashboardAddr string `json:"dashboard_addr"`
@ -148,6 +152,7 @@ func GetDefaultServerConf() ServerCommonConf {
VhostHttpPort: 0,
VhostHttpsPort: 0,
VhostHttpTimeout: 60,
DashboardUrl: "/",
DashboardAddr: "0.0.0.0",
DashboardPort: 0,
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 {
cfg.DashboardAddr = tmpStr
} else {

View File

@ -31,9 +31,11 @@ var (
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
router := mux.NewRouter()
r := mux.NewRouter()
r.Host(url)
router := r.PathPrefix(url).Subrouter()
user, passwd := svr.cfg.DashboardUser, svr.cfg.DashboardPwd
router.Use(frpNet.NewHttpAuthMiddleware(user, passwd).Middleware)

View File

@ -231,12 +231,12 @@ func NewService(cfg config.ServerCommonConf) (svr *Service, err error) {
return
}
err = svr.RunDashboardServer(cfg.DashboardAddr, cfg.DashboardPort)
err = svr.RunDashboardServer(cfg.DashboardUrl, cfg.DashboardAddr, cfg.DashboardPort)
if err != nil {
err = fmt.Errorf("Create dashboard web server error, %v", err)
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
}