Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
cbe1188e51 | |||
1bcad97ed2 | |||
c2a9618f27 |
@@ -23,6 +23,18 @@ func offlineMonitoring() {
|
|||||||
// 遍历客户端数据,并渲染数据信息
|
// 遍历客户端数据,并渲染数据信息
|
||||||
for _, d := range devices {
|
for _, d := range devices {
|
||||||
for _, p := range d.Peers {
|
for _, p := range d.Peers {
|
||||||
|
var ipAllocation string
|
||||||
|
for _, iaip := range p.AllowedIPs {
|
||||||
|
ipAllocation += iaip.String() + ","
|
||||||
|
}
|
||||||
|
ipAllocation = strings.TrimRight(ipAllocation, ",")
|
||||||
|
isOnline := time.Since(p.LastHandshakeTime).Minutes() < 3
|
||||||
|
|
||||||
|
// 未离线
|
||||||
|
if isOnline {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
clientInfo, err := repository.Client().GetByPublicKey(p.PublicKey.String())
|
clientInfo, err := repository.Client().GetByPublicKey(p.PublicKey.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@@ -33,25 +45,13 @@ func offlineMonitoring() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var ipAllocation string
|
|
||||||
for _, iaip := range p.AllowedIPs {
|
|
||||||
ipAllocation += iaip.String() + ","
|
|
||||||
}
|
|
||||||
ipAllocation = strings.TrimRight(ipAllocation, ",")
|
|
||||||
isOnline := time.Since(p.LastHandshakeTime).Minutes() < 3
|
|
||||||
|
|
||||||
// 未离线
|
|
||||||
if !isOnline {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
content := fmt.Sprintf("客户端:%s\r\n", clientInfo.Name)
|
content := fmt.Sprintf("客户端:%s\r\n", clientInfo.Name)
|
||||||
content += fmt.Sprintf("客户端IP:%s\r\n", ipAllocation)
|
content += fmt.Sprintf("客户端IP:%s\r\n", ipAllocation)
|
||||||
content += fmt.Sprintf("端点IP:%s\r\n", p.Endpoint.String())
|
content += fmt.Sprintf("端点IP:%s\r\n", p.Endpoint.String())
|
||||||
content += fmt.Sprintf("最后握手时间:%s\r\n", p.LastHandshakeTime.Format("2006-01-02 15:04:05"))
|
content += fmt.Sprintf("最后握手时间:%s\r\n", p.LastHandshakeTime.Format("2006-01-02 15:04:05"))
|
||||||
|
|
||||||
// 离线并且配置了邮箱,准备发送邮件
|
// 离线并且配置了邮箱,准备发送邮件
|
||||||
err = utils.Mail().SendMail(clientInfo.Email, fmt.Sprintf("客户端离线通知"), content, "")
|
err = utils.Mail().SendMail(clientInfo.Email, fmt.Sprintf("客户端[%s]离线通知", clientInfo.Name), content, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("发送离线通知邮件失败: %v", err.Error())
|
log.Errorf("发送离线通知邮件失败: %v", err.Error())
|
||||||
continue
|
continue
|
||||||
|
@@ -72,9 +72,9 @@ func initDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logLevel := gl.Info
|
logLevel := gl.Info
|
||||||
if os.Getenv("GIN_MODE") == "release" {
|
//if os.Getenv("GIN_MODE") == "release" {
|
||||||
logLevel = gl.Error
|
// logLevel = gl.Error
|
||||||
}
|
//}
|
||||||
|
|
||||||
db, err := gorm.Open(dbDialector, &gorm.Config{
|
db, err := gorm.Open(dbDialector, &gorm.Config{
|
||||||
Logger: logger.NewGormLoggerWithConfig(gl.Config{
|
Logger: logger.NewGormLoggerWithConfig(gl.Config{
|
||||||
|
5
main.go
5
main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
"wireguard-dashboard/config"
|
"wireguard-dashboard/config"
|
||||||
|
"wireguard-dashboard/cron_task"
|
||||||
"wireguard-dashboard/initialize"
|
"wireguard-dashboard/initialize"
|
||||||
"wireguard-dashboard/queues"
|
"wireguard-dashboard/queues"
|
||||||
"wireguard-dashboard/route"
|
"wireguard-dashboard/route"
|
||||||
@@ -18,8 +19,8 @@ func init() {
|
|||||||
if err := script.NewScript().Do(); err != nil {
|
if err := script.NewScript().Do(); err != nil {
|
||||||
log.Errorf("执行脚本失败: %v", err.Error())
|
log.Errorf("执行脚本失败: %v", err.Error())
|
||||||
}
|
}
|
||||||
go queues.StartConsumer() // 启动队列
|
go queues.StartConsumer() // 启动队列
|
||||||
//go cron_task.StartCronTask() // 启动定时任务
|
go cron_task.StartCronTask() // 启动定时任务
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Reference in New Issue
Block a user