2019-12-08 03:59:58 -05:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
2019-12-08 10:18:29 -05:00
|
|
|
"net/http"
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
"github.com/gin-gonic/gin"
|
2020-12-19 09:14:36 -05:00
|
|
|
"github.com/naiba/nezha/model"
|
2020-11-10 21:07:45 -05:00
|
|
|
"github.com/naiba/nezha/pkg/mygin"
|
2022-01-08 22:54:14 -05:00
|
|
|
"github.com/naiba/nezha/service/singleton"
|
2022-04-29 21:32:57 -04:00
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
2019-12-08 03:59:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type memberPage struct {
|
|
|
|
r *gin.Engine
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mp *memberPage) serve() {
|
|
|
|
mr := mp.r.Group("")
|
|
|
|
mr.Use(mygin.Authorize(mygin.AuthorizeOption{
|
|
|
|
Member: true,
|
|
|
|
IsPage: true,
|
2022-04-29 21:32:57 -04:00
|
|
|
Msg: singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "YouAreNotAuthorized"}),
|
|
|
|
Btn: singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Login"}),
|
2019-12-08 03:59:58 -05:00
|
|
|
Redirect: "/login",
|
|
|
|
}))
|
2019-12-08 10:18:29 -05:00
|
|
|
mr.GET("/server", mp.server)
|
2021-01-15 11:45:49 -05:00
|
|
|
mr.GET("/monitor", mp.monitor)
|
2021-01-18 20:59:04 -05:00
|
|
|
mr.GET("/cron", mp.cron)
|
2020-12-19 09:14:36 -05:00
|
|
|
mr.GET("/notification", mp.notification)
|
2020-12-09 06:05:40 -05:00
|
|
|
mr.GET("/setting", mp.setting)
|
2019-12-08 10:18:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mp *memberPage) server(c *gin.Context) {
|
2022-01-08 22:54:14 -05:00
|
|
|
singleton.SortedServerLock.RLock()
|
|
|
|
defer singleton.SortedServerLock.RUnlock()
|
2020-12-09 06:05:40 -05:00
|
|
|
c.HTML(http.StatusOK, "dashboard/server", mygin.CommonEnvironment(c, gin.H{
|
2022-04-29 21:32:57 -04:00
|
|
|
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "ServersManagement"}),
|
2022-01-08 22:54:14 -05:00
|
|
|
"Servers": singleton.SortedServerList,
|
2019-12-08 10:18:29 -05:00
|
|
|
}))
|
2019-12-08 03:59:58 -05:00
|
|
|
}
|
2020-12-09 06:05:40 -05:00
|
|
|
|
2021-01-15 11:45:49 -05:00
|
|
|
func (mp *memberPage) monitor(c *gin.Context) {
|
|
|
|
c.HTML(http.StatusOK, "dashboard/monitor", mygin.CommonEnvironment(c, gin.H{
|
2022-04-29 21:32:57 -04:00
|
|
|
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "ServicesManagement"}),
|
2022-01-08 22:54:14 -05:00
|
|
|
"Monitors": singleton.ServiceSentinelShared.Monitors(),
|
2021-01-15 11:45:49 -05:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-01-18 20:59:04 -05:00
|
|
|
func (mp *memberPage) cron(c *gin.Context) {
|
|
|
|
var crons []model.Cron
|
2022-01-08 22:54:14 -05:00
|
|
|
singleton.DB.Find(&crons)
|
2021-01-18 20:59:04 -05:00
|
|
|
c.HTML(http.StatusOK, "dashboard/cron", mygin.CommonEnvironment(c, gin.H{
|
2022-04-29 21:32:57 -04:00
|
|
|
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "ScheduledTasks"}),
|
2021-01-18 20:59:04 -05:00
|
|
|
"Crons": crons,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2020-12-19 09:14:36 -05:00
|
|
|
func (mp *memberPage) notification(c *gin.Context) {
|
|
|
|
var nf []model.Notification
|
2022-01-08 22:54:14 -05:00
|
|
|
singleton.DB.Find(&nf)
|
2020-12-19 10:11:16 -05:00
|
|
|
var ar []model.AlertRule
|
2022-01-08 22:54:14 -05:00
|
|
|
singleton.DB.Find(&ar)
|
2020-12-19 09:14:36 -05:00
|
|
|
c.HTML(http.StatusOK, "dashboard/notification", mygin.CommonEnvironment(c, gin.H{
|
2022-04-29 21:32:57 -04:00
|
|
|
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Notification"}),
|
2020-12-19 09:14:36 -05:00
|
|
|
"Notifications": nf,
|
2020-12-19 10:11:16 -05:00
|
|
|
"AlertRules": ar,
|
2020-12-19 09:14:36 -05:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2020-12-09 06:05:40 -05:00
|
|
|
func (mp *memberPage) setting(c *gin.Context) {
|
|
|
|
c.HTML(http.StatusOK, "dashboard/setting", mygin.CommonEnvironment(c, gin.H{
|
2022-04-30 11:02:40 -04:00
|
|
|
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Settings"}),
|
|
|
|
"Languages": model.Languages,
|
|
|
|
"Themes": model.Themes,
|
2020-12-09 06:05:40 -05:00
|
|
|
}))
|
|
|
|
}
|