mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-30 23:17:14 +00:00
d9ccf157c3
* feat: add manual and automatic WARP IP rotation * fix: update generated api and frontend schemas * fix(warp): validate rotation interval, fix auto-update timing, sync editor - Validate the auto-update interval as an integer and store it via setInt; a non-integer value previously broke GetAllSetting for the whole panel. - Seed warpLastUpdate when the interval is saved and when changing IP manually, so auto-update counts from "now" instead of epoch 0 and a manual rotation doesn't trigger an immediate scheduled one. - Guard WarpIpJob: when lastUpdate is unset, establish a baseline and skip instead of rotating on the next tick. - Log WARP license re-apply failures instead of swallowing them. - After a manual "Change IP", sync the in-memory Xray editor with the keys the backend persisted so a later template save can't revert them; only toast success when the interval save actually succeeds. - Add the WARP rotation UI strings to all 13 locales. - Drop trailing whitespace introduced in entity.go and xray_setting.go. --------- Co-authored-by: Rqzbeh <Rqzbeh@example.com> Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package job
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/logger"
|
|
"github.com/mhsanaei/3x-ui/v3/web/service"
|
|
)
|
|
|
|
type WarpIpJob struct {
|
|
settingService service.SettingService
|
|
warpService service.WarpService
|
|
xrayService service.XrayService
|
|
}
|
|
|
|
func NewWarpIpJob() *WarpIpJob {
|
|
return &WarpIpJob{}
|
|
}
|
|
|
|
func (j *WarpIpJob) Run() {
|
|
allSetting, err := j.settingService.GetAllSetting()
|
|
if err != nil {
|
|
return
|
|
}
|
|
interval := allSetting.WarpUpdateInterval
|
|
if interval <= 0 {
|
|
return
|
|
}
|
|
|
|
lastUpdate, _ := j.settingService.GetWarpLastUpdate()
|
|
now := time.Now().Unix()
|
|
|
|
// First run after the feature is enabled (e.g. interval set via direct
|
|
// DB edit): establish a baseline instead of rotating immediately.
|
|
if lastUpdate == 0 {
|
|
_ = j.settingService.SetWarpLastUpdate(now)
|
|
return
|
|
}
|
|
|
|
if now-lastUpdate >= int64(interval*24*3600) {
|
|
logger.Info("Starting scheduled WARP IP update...")
|
|
_, err := j.warpService.ChangeWarpIP()
|
|
if err != nil {
|
|
logger.Warning("Failed to update WARP IP: ", err)
|
|
return
|
|
}
|
|
|
|
_ = j.settingService.SetWarpLastUpdate(now)
|
|
j.xrayService.SetToNeedRestart()
|
|
logger.Info("Successfully updated WARP IP and scheduled Xray restart")
|
|
}
|
|
}
|