mirror of
https://github.com/nezhahq/nezha.git
synced 2025-03-10 07:48:14 -04:00
🐛 修复修改服务器导致 Agent 离线
This commit is contained in:
parent
bcb95ba718
commit
e24121bdf7
@ -1,7 +1,7 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
<img width="500" style="max-width:100%" src="resource/static/brand.png" title="哪吒监控">
|
<img width="500" style="max-width:100%" src="resource/static/brand.png" title="哪吒监控">
|
||||||
<br><br>
|
<br><br>
|
||||||
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.10&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.6.4-brightgreen?style=for-the-badge&logo=linux">
|
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.11&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.6.4-brightgreen?style=for-the-badge&logo=linux">
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>
|
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>
|
||||||
|
@ -154,7 +154,7 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
|
|||||||
s.ID = sf.ID
|
s.ID = sf.ID
|
||||||
s.Tag = sf.Tag
|
s.Tag = sf.Tag
|
||||||
s.Note = sf.Note
|
s.Note = sf.Note
|
||||||
if sf.ID == 0 {
|
if s.ID == 0 {
|
||||||
s.Secret = utils.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, admin.ID))
|
s.Secret = utils.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, admin.ID))
|
||||||
s.Secret = s.Secret[:18]
|
s.Secret = s.Secret[:18]
|
||||||
err = dao.DB.Create(&s).Error
|
err = dao.DB.Create(&s).Error
|
||||||
@ -171,13 +171,17 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if isEdit {
|
if isEdit {
|
||||||
dao.ServerLock.RLock()
|
dao.ServerLock.Lock()
|
||||||
s.Host = dao.ServerList[s.ID].Host
|
s.CopyFromRunningServer(dao.ServerList[s.ID])
|
||||||
s.State = dao.ServerList[s.ID].State
|
// 如果修改了 Secret
|
||||||
dao.SecretToID[s.Secret] = s.ID
|
if s.Secret != dao.ServerList[s.ID].Secret {
|
||||||
delete(dao.SecretToID, dao.ServerList[s.ID].Secret)
|
// 删除旧 Secret-ID 绑定关系
|
||||||
|
dao.SecretToID[s.Secret] = s.ID
|
||||||
|
// 设置新的 Secret-ID 绑定关系
|
||||||
|
delete(dao.SecretToID, dao.ServerList[s.ID].Secret)
|
||||||
|
}
|
||||||
dao.ServerList[s.ID] = &s
|
dao.ServerList[s.ID] = &s
|
||||||
dao.ServerLock.RUnlock()
|
dao.ServerLock.Unlock()
|
||||||
} else {
|
} else {
|
||||||
s.Host = &model.Host{}
|
s.Host = &model.Host{}
|
||||||
s.State = &model.HostState{}
|
s.State = &model.HostState{}
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/go-github/github"
|
|
||||||
GitHubAPI "github.com/google/go-github/github"
|
GitHubAPI "github.com/google/go-github/github"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
GitHubOauth2 "golang.org/x/oauth2/github"
|
GitHubOauth2 "golang.org/x/oauth2/github"
|
||||||
@ -87,7 +86,7 @@ func (oa *oauth2controller) callback(c *gin.Context) {
|
|||||||
client = GitHubAPI.NewClient(oc)
|
client = GitHubAPI.NewClient(oc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var gu *github.User
|
var gu *GitHubAPI.User
|
||||||
if err == nil {
|
if err == nil {
|
||||||
gu, _, err = client.Users.Get(ctx, "")
|
gu, _, err = client.Users.Get(ctx, "")
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,16 @@ type Server struct {
|
|||||||
PrevHourlyTransferOut int64 `gorm:"-" json:"-"` // 上次数据点时的出站使用量
|
PrevHourlyTransferOut int64 `gorm:"-" json:"-"` // 上次数据点时的出站使用量
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) CopyFromRunningServer(old *Server) {
|
||||||
|
s.Host = old.Host
|
||||||
|
s.State = old.State
|
||||||
|
s.LastActive = old.LastActive
|
||||||
|
s.TaskClose = old.TaskClose
|
||||||
|
s.TaskStream = old.TaskStream
|
||||||
|
s.PrevHourlyTransferIn = old.PrevHourlyTransferIn
|
||||||
|
s.PrevHourlyTransferOut = old.PrevHourlyTransferOut
|
||||||
|
}
|
||||||
|
|
||||||
func (s Server) Marshal() template.JS {
|
func (s Server) Marshal() template.JS {
|
||||||
name, _ := json.Marshal(s.Name)
|
name, _ := json.Marshal(s.Name)
|
||||||
tag, _ := json.Marshal(s.Tag)
|
tag, _ := json.Marshal(s.Tag)
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
pb "github.com/naiba/nezha/proto"
|
pb "github.com/naiba/nezha/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "v0.9.10" // !!记得修改 README 中的 badge 版本!!
|
var Version = "v0.9.11" // !!记得修改 README 中的 badge 版本!!
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Conf *model.Config
|
Conf *model.Config
|
||||||
|
@ -35,8 +35,11 @@ func (a *AuthHandler) Check(ctx context.Context) (uint64, error) {
|
|||||||
dao.ServerLock.RLock()
|
dao.ServerLock.RLock()
|
||||||
defer dao.ServerLock.RUnlock()
|
defer dao.ServerLock.RUnlock()
|
||||||
clientID, hasID := dao.SecretToID[clientSecret]
|
clientID, hasID := dao.SecretToID[clientSecret]
|
||||||
|
if !hasID {
|
||||||
|
return 0, status.Errorf(codes.Unauthenticated, "客户端认证失败")
|
||||||
|
}
|
||||||
_, hasServer := dao.ServerList[clientID]
|
_, hasServer := dao.ServerList[clientID]
|
||||||
if !hasID || !hasServer {
|
if !hasServer {
|
||||||
return 0, status.Errorf(codes.Unauthenticated, "客户端认证失败")
|
return 0, status.Errorf(codes.Unauthenticated, "客户端认证失败")
|
||||||
}
|
}
|
||||||
return clientID, nil
|
return clientID, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user