mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-25 20:15:01 +03:00
3cb5bb7187
Panel alerts and the scheduled status report could go to Telegram, Discord or email, but not to a WeCom group robot or a generic webhook. Add a WeChat channel, off by default, with two modes: a WeCom group robot, or a webhook that receives a small signed-free JSON envelope with an optional bearer token. It carries the same events as the other channels (logins, CPU and memory, Xray crash, node and outbound state) and a scheduled text report. Delivery goes through the SSRF-guarded dialer, follows no redirects, and the URL and token are stored and redacted like the other notification secrets.
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package web
|
|
|
|
import "github.com/mhsanaei/3x-ui/v3/internal/web/job"
|
|
|
|
func (s *Server) reloadWechatJobs() {
|
|
s.wechatScheduleMu.Lock()
|
|
defer s.wechatScheduleMu.Unlock()
|
|
if s.cron == nil {
|
|
return
|
|
}
|
|
if s.wechatScheduler != s.cron {
|
|
s.wechatScheduler = s.cron
|
|
s.wechatNotifyEntryID, s.cpuAlarmEntryID, s.memoryAlarmEntryID = 0, 0, 0
|
|
s.wechatReportSpec = ""
|
|
}
|
|
enabled, enableErr := s.settingService.GetWechatEnable()
|
|
reports, reportErr := s.settingService.GetWechatReportEnable()
|
|
spec, specErr := s.settingService.GetWechatRunTime()
|
|
wanted := enableErr == nil && reportErr == nil && specErr == nil && enabled && reports
|
|
if s.wechatNotifyEntryID != 0 && (!wanted || spec != s.wechatReportSpec) {
|
|
s.cron.Remove(s.wechatNotifyEntryID)
|
|
s.wechatNotifyEntryID = 0
|
|
s.wechatReportSpec = ""
|
|
}
|
|
if wanted && s.wechatNotifyEntryID == 0 {
|
|
s.wechatNotifyEntryID = scheduleSettingJob(s.cron, "WeChat notify", spec, "@daily", job.NewWechatNotifyJob(s.wechatService))
|
|
s.wechatReportSpec = spec
|
|
}
|
|
if s.cpuAlarmWanted() {
|
|
if s.cpuAlarmEntryID == 0 {
|
|
s.cpuAlarmEntryID, _ = s.cron.AddJob(cadenceCPUAlarm, job.NewCheckCpuJob())
|
|
}
|
|
} else if s.cpuAlarmEntryID != 0 {
|
|
s.cron.Remove(s.cpuAlarmEntryID)
|
|
s.cpuAlarmEntryID = 0
|
|
}
|
|
if s.memoryAlarmWanted() {
|
|
if s.memoryAlarmEntryID == 0 {
|
|
s.memoryAlarmEntryID, _ = s.cron.AddJob(cadenceMemoryAlarm, job.NewCheckMemJob())
|
|
}
|
|
} else if s.memoryAlarmEntryID != 0 {
|
|
s.cron.Remove(s.memoryAlarmEntryID)
|
|
s.memoryAlarmEntryID = 0
|
|
}
|
|
}
|