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"
|
|
|
|
"github.com/naiba/nezha/service/dao"
|
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,
|
|
|
|
Msg: "此页面需要登录",
|
|
|
|
Btn: "点此登录",
|
|
|
|
Redirect: "/login",
|
|
|
|
}))
|
2019-12-08 10:18:29 -05:00
|
|
|
mr.GET("/server", mp.server)
|
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) {
|
2019-12-09 05:14:31 -05:00
|
|
|
dao.ServerLock.RLock()
|
|
|
|
defer dao.ServerLock.RUnlock()
|
2020-12-09 06:05:40 -05:00
|
|
|
c.HTML(http.StatusOK, "dashboard/server", mygin.CommonEnvironment(c, gin.H{
|
2019-12-08 10:18:29 -05:00
|
|
|
"Title": "服务器管理",
|
2019-12-09 05:14:31 -05:00
|
|
|
"Servers": dao.ServerList,
|
2019-12-08 10:18:29 -05:00
|
|
|
}))
|
2019-12-08 03:59:58 -05:00
|
|
|
}
|
2020-12-09 06:05:40 -05:00
|
|
|
|
2020-12-19 09:14:36 -05:00
|
|
|
func (mp *memberPage) notification(c *gin.Context) {
|
|
|
|
var nf []model.Notification
|
|
|
|
dao.DB.Find(&nf)
|
2020-12-19 10:11:16 -05:00
|
|
|
var ar []model.AlertRule
|
|
|
|
dao.DB.Find(&ar)
|
2020-12-19 09:14:36 -05:00
|
|
|
c.HTML(http.StatusOK, "dashboard/notification", mygin.CommonEnvironment(c, gin.H{
|
|
|
|
"Title": "通知管理",
|
|
|
|
"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{
|
|
|
|
"Title": "系统设置",
|
|
|
|
"Conf": dao.Conf,
|
|
|
|
}))
|
|
|
|
}
|