mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-05 05:00:05 +00:00
✨ 任意时间区间(月流量)统计,无视重启~
This commit is contained in:
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
"github.com/naiba/nezha/service/dao"
|
||||
)
|
||||
|
||||
func ServeWeb(port uint) {
|
||||
func ServeWeb(port uint) *http.Server {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
r := gin.Default()
|
||||
if dao.Conf.Debug {
|
||||
@@ -112,7 +113,11 @@ func ServeWeb(port uint) {
|
||||
r.Static("/static", "resource/static")
|
||||
r.LoadHTMLGlob("resource/template/**/*")
|
||||
routers(r)
|
||||
r.Run(fmt.Sprintf(":%d", port))
|
||||
srv := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", port),
|
||||
Handler: r,
|
||||
}
|
||||
return srv
|
||||
}
|
||||
|
||||
func routers(r *gin.Engine) {
|
||||
|
||||
@@ -57,7 +57,7 @@ func (ma *memberAPI) delete(c *gin.Context) {
|
||||
var err error
|
||||
switch c.Param("model") {
|
||||
case "server":
|
||||
err = dao.DB.Delete(&model.Server{}, "id = ?", id).Error
|
||||
err = dao.DB.Unscoped().Delete(&model.Server{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
dao.ServerLock.Lock()
|
||||
delete(dao.SecretToID, dao.ServerList[id].Secret)
|
||||
@@ -66,18 +66,18 @@ func (ma *memberAPI) delete(c *gin.Context) {
|
||||
dao.ReSortServer()
|
||||
}
|
||||
case "notification":
|
||||
err = dao.DB.Delete(&model.Notification{}, "id = ?", id).Error
|
||||
err = dao.DB.Unscoped().Delete(&model.Notification{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
dao.OnDeleteNotification(id)
|
||||
}
|
||||
case "monitor":
|
||||
err = dao.DB.Delete(&model.Monitor{}, "id = ?", id).Error
|
||||
err = dao.DB.Unscoped().Delete(&model.Monitor{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
dao.ServiceSentinelShared.OnMonitorDelete(id)
|
||||
err = dao.DB.Delete(&model.MonitorHistory{}, "monitor_id = ?", id).Error
|
||||
err = dao.DB.Unscoped().Delete(&model.MonitorHistory{}, "monitor_id = ?", id).Error
|
||||
}
|
||||
case "cron":
|
||||
err = dao.DB.Delete(&model.Cron{}, "id = ?", id).Error
|
||||
err = dao.DB.Unscoped().Delete(&model.Cron{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
dao.CronLock.RLock()
|
||||
defer dao.CronLock.RUnlock()
|
||||
@@ -88,7 +88,7 @@ func (ma *memberAPI) delete(c *gin.Context) {
|
||||
delete(dao.Crons, id)
|
||||
}
|
||||
case "alert-rule":
|
||||
err = dao.DB.Delete(&model.AlertRule{}, "id = ?", id).Error
|
||||
err = dao.DB.Unscoped().Delete(&model.AlertRule{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
dao.OnDeleteAlert(id)
|
||||
}
|
||||
@@ -378,8 +378,8 @@ func (ma *memberAPI) addOrEditAlertRule(c *gin.Context) {
|
||||
err = errors.New("至少定义一条规则")
|
||||
} else {
|
||||
for i := 0; i < len(r.Rules); i++ {
|
||||
if r.Rules[i].Duration < 3 {
|
||||
err = errors.New("Duration 至少为 3")
|
||||
if !r.Rules[i].IsTransferDurationRule() && r.Rules[i].Duration < 3 {
|
||||
err = errors.New("错误:Duration 至少为 3")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,22 +29,24 @@ func (oa *oauth2controller) serve() {
|
||||
}
|
||||
|
||||
func (oa *oauth2controller) getCommonOauth2Config(c *gin.Context) *oauth2.Config {
|
||||
var endPoint oauth2.Endpoint
|
||||
if dao.Conf.Oauth2.Type == model.ConfigTypeGitee {
|
||||
endPoint = oauth2.Endpoint{
|
||||
AuthURL: "https://gitee.com/oauth/authorize",
|
||||
TokenURL: "https://gitee.com/oauth/token",
|
||||
return &oauth2.Config{
|
||||
ClientID: dao.Conf.Oauth2.ClientID,
|
||||
ClientSecret: dao.Conf.Oauth2.ClientSecret,
|
||||
Scopes: []string{},
|
||||
Endpoint: oauth2.Endpoint{
|
||||
AuthURL: "https://gitee.com/oauth/authorize",
|
||||
TokenURL: "https://gitee.com/oauth/token",
|
||||
},
|
||||
RedirectURL: oa.getRedirectURL(c),
|
||||
}
|
||||
} else {
|
||||
endPoint = GitHubOauth2.Endpoint
|
||||
}
|
||||
|
||||
return &oauth2.Config{
|
||||
ClientID: dao.Conf.Oauth2.ClientID,
|
||||
ClientSecret: dao.Conf.Oauth2.ClientSecret,
|
||||
Scopes: []string{},
|
||||
Endpoint: endPoint,
|
||||
RedirectURL: oa.getRedirectURL(c),
|
||||
return &oauth2.Config{
|
||||
ClientID: dao.Conf.Oauth2.ClientID,
|
||||
ClientSecret: dao.Conf.Oauth2.ClientSecret,
|
||||
Scopes: []string{},
|
||||
Endpoint: GitHubOauth2.Endpoint,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user