diff --git a/web/html/form/inbound.html b/web/html/form/inbound.html
index 9dd76dcf..ca4dc66a 100644
--- a/web/html/form/inbound.html
+++ b/web/html/form/inbound.html
@@ -49,6 +49,12 @@
{{ i18n "pages.inbounds.periodicTrafficResetDesc" }}
+
+
+ {{ i18n "pages.inbounds.lastReset" }}:
+ [[ moment(dbInbound.lastTrafficResetTime).format('YYYY-MM-DD HH:mm:ss') ]]
+ [[ DateUtil.convertToJalalian(moment(dbInbound.lastTrafficResetTime)) ]]
+
{{ i18n "pages.inbounds.periodicTrafficResetTitle" }}
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 6a2f7bbc..410291fc 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -44,10 +44,12 @@ func (s *InboundService) GetAllInbounds() ([]*model.Inbound, error) {
func (s *InboundService) GetInboundsByTrafficReset(period string) ([]*model.Inbound, error) {
db := database.GetDB()
var inbounds []*model.Inbound
+ logger.Info("Fetching inbounds with traffic reset period:", period)
err := db.Model(model.Inbound{}).Where("traffic_reset = ?", period).Find(&inbounds).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
+ logger.Infof("Found %d inbounds with traffic reset period: %s", len(inbounds), period)
return inbounds, nil
}
@@ -1844,20 +1846,39 @@ func (s *InboundService) ResetClientTraffic(id int, clientEmail string) (bool, e
func (s *InboundService) ResetAllClientTraffics(id int) error {
db := database.GetDB()
+ now := time.Now().Unix() * 1000
- whereText := "inbound_id "
- if id == -1 {
- whereText += " > ?"
- } else {
- whereText += " = ?"
- }
+ return db.Transaction(func(tx *gorm.DB) error {
+ whereText := "inbound_id "
+ if id == -1 {
+ whereText += " > ?"
+ } else {
+ whereText += " = ?"
+ }
- result := db.Model(xray.ClientTraffic{}).
- Where(whereText, id).
- Updates(map[string]any{"enable": true, "up": 0, "down": 0})
+ // Reset client traffics
+ result := tx.Model(xray.ClientTraffic{}).
+ Where(whereText, id).
+ Updates(map[string]any{"enable": true, "up": 0, "down": 0})
- err := result.Error
- return err
+ if result.Error != nil {
+ return result.Error
+ }
+
+ // Update lastTrafficResetTime for the inbound(s)
+ inboundWhereText := "id "
+ if id == -1 {
+ inboundWhereText += " > ?"
+ } else {
+ inboundWhereText += " = ?"
+ }
+
+ result = tx.Model(model.Inbound{}).
+ Where(inboundWhereText, id).
+ Update("last_traffic_reset_time", now)
+
+ return result.Error
+ })
}
func (s *InboundService) ResetAllTraffics() error {
diff --git a/web/translation/translate.ar_EG.toml b/web/translation/translate.ar_EG.toml
index 488da92c..e14caa89 100644
--- a/web/translation/translate.ar_EG.toml
+++ b/web/translation/translate.ar_EG.toml
@@ -230,6 +230,7 @@
"exportInbound" = "تصدير الإدخال"
"import" = "استيراد"
"importInbound" = "استيراد إدخال"
+"lastReset" = "آخر إعادة تعيين"
[pages.client]
"add" = "أضف عميل"
diff --git a/web/translation/translate.en_US.toml b/web/translation/translate.en_US.toml
index f7791860..87701313 100644
--- a/web/translation/translate.en_US.toml
+++ b/web/translation/translate.en_US.toml
@@ -232,6 +232,7 @@
"importInbound" = "Import an Inbound"
"periodicTrafficResetTitle" = "Traffic Reset"
"periodicTrafficResetDesc" = "Automatically reset traffic counter at specified intervals"
+"lastReset" = "Last Reset"
[pages.client]
"add" = "Add Client"
diff --git a/web/translation/translate.es_ES.toml b/web/translation/translate.es_ES.toml
index 813597e4..8fdeb1bd 100644
--- a/web/translation/translate.es_ES.toml
+++ b/web/translation/translate.es_ES.toml
@@ -230,6 +230,7 @@
"exportInbound" = "Exportación entrante"
"import" = "Importar"
"importInbound" = "Importar un entrante"
+"lastReset" = "Último reinicio"
[pages.client]
"add" = "Agregar Cliente"
diff --git a/web/translation/translate.fa_IR.toml b/web/translation/translate.fa_IR.toml
index b77e753c..f6b3fdae 100644
--- a/web/translation/translate.fa_IR.toml
+++ b/web/translation/translate.fa_IR.toml
@@ -230,6 +230,7 @@
"exportInbound" = "استخراج ورودی"
"import" = "افزودن"
"importInbound" = "افزودن یک ورودی"
+"lastReset" = "آخرین بازنشانی"
[pages.client]
"add" = "کاربر جدید"
diff --git a/web/translation/translate.id_ID.toml b/web/translation/translate.id_ID.toml
index 441debd5..77b09236 100644
--- a/web/translation/translate.id_ID.toml
+++ b/web/translation/translate.id_ID.toml
@@ -230,6 +230,7 @@
"exportInbound" = "Ekspor Masuk"
"import" = "Impor"
"importInbound" = "Impor Masuk"
+"lastReset" = "Reset Terakhir"
[pages.client]
"add" = "Tambah Klien"
diff --git a/web/translation/translate.ja_JP.toml b/web/translation/translate.ja_JP.toml
index e9d75bde..fd7e6c94 100644
--- a/web/translation/translate.ja_JP.toml
+++ b/web/translation/translate.ja_JP.toml
@@ -230,6 +230,7 @@
"exportInbound" = "インバウンドルールをエクスポート"
"import" = "インポート"
"importInbound" = "インバウンドルールをインポート"
+"lastReset" = "最後のリセット"
[pages.client]
"add" = "クライアント追加"
diff --git a/web/translation/translate.pt_BR.toml b/web/translation/translate.pt_BR.toml
index 9cc16826..7cac67b8 100644
--- a/web/translation/translate.pt_BR.toml
+++ b/web/translation/translate.pt_BR.toml
@@ -230,6 +230,7 @@
"exportInbound" = "Exportar Inbound"
"import" = "Importar"
"importInbound" = "Importar um Inbound"
+"lastReset" = "Último Reset"
[pages.client]
"add" = "Adicionar Cliente"
diff --git a/web/translation/translate.ru_RU.toml b/web/translation/translate.ru_RU.toml
index bbaaaf3a..00774b72 100644
--- a/web/translation/translate.ru_RU.toml
+++ b/web/translation/translate.ru_RU.toml
@@ -250,6 +250,7 @@
"renewDesc" = "Автопродление после истечения срока действия. (0 = отключить)(единица: день)"
"periodicTrafficResetTitle" = "Сброс трафика"
"periodicTrafficResetDesc" = "Автоматический сброс счетчика трафика через указанные интервалы"
+"lastReset" = "Последний сброс"
[pages.inbounds.periodicTrafficReset]
"never" = "Никогда"
diff --git a/web/translation/translate.tr_TR.toml b/web/translation/translate.tr_TR.toml
index 286ea1c2..1e986404 100644
--- a/web/translation/translate.tr_TR.toml
+++ b/web/translation/translate.tr_TR.toml
@@ -230,6 +230,7 @@
"exportInbound" = "Geleni Dışa Aktar"
"import" = "İçe Aktar"
"importInbound" = "Bir Gelen İçe Aktar"
+"lastReset" = "Son Sıfırlama"
[pages.client]
"add" = "Müşteri Ekle"
diff --git a/web/translation/translate.uk_UA.toml b/web/translation/translate.uk_UA.toml
index 06634ef4..53067860 100644
--- a/web/translation/translate.uk_UA.toml
+++ b/web/translation/translate.uk_UA.toml
@@ -230,6 +230,7 @@
"exportInbound" = "Експортувати вхідні"
"import" = "Імпорт"
"importInbound" = "Імпортувати вхідний"
+"lastReset" = "Останнє скидання"
[pages.client]
"add" = "Додати клієнта"
diff --git a/web/translation/translate.vi_VN.toml b/web/translation/translate.vi_VN.toml
index b601b263..1811e2d4 100644
--- a/web/translation/translate.vi_VN.toml
+++ b/web/translation/translate.vi_VN.toml
@@ -230,6 +230,7 @@
"exportInbound" = "Xuất nhập khẩu"
"import" = "Nhập"
"importInbound" = "Nhập inbound"
+"lastReset" = "Đặt lại lần cuối"
[pages.client]
"add" = "Thêm người dùng"
diff --git a/web/translation/translate.zh_CN.toml b/web/translation/translate.zh_CN.toml
index e0f2c222..95c74f57 100644
--- a/web/translation/translate.zh_CN.toml
+++ b/web/translation/translate.zh_CN.toml
@@ -230,6 +230,7 @@
"exportInbound" = "导出入站规则"
"import"="导入"
"importInbound" = "导入入站规则"
+"lastReset" = "上次重置"
[pages.client]
"add" = "添加客户端"
diff --git a/web/translation/translate.zh_TW.toml b/web/translation/translate.zh_TW.toml
index 66b2bd33..1b0d12d1 100644
--- a/web/translation/translate.zh_TW.toml
+++ b/web/translation/translate.zh_TW.toml
@@ -230,6 +230,7 @@
"exportInbound" = "匯出入站規則"
"import"="匯入"
"importInbound" = "匯入入站規則"
+"lastReset" = "上次重置"
[pages.client]
"add" = "新增客戶端"
diff --git a/web/web.go b/web/web.go
index 81b62952..c75d0b18 100644
--- a/web/web.go
+++ b/web/web.go
@@ -273,22 +273,22 @@ func (s *Server) startTask() {
// Run once a day, midnight
// TODO: for testing, run every minute, change back to daily later
// s.cron.AddJob("@daily", job.NewPeriodicTrafficResetJob("daily"))
- s.cron.AddJob("* * * * *", job.NewPeriodicTrafficResetJob("daily"))
+ s.cron.AddJob("@every 10s", job.NewPeriodicTrafficResetJob("daily"))
// Run once a week, midnight between Sat/Sun
s.cron.AddJob("@weekly", job.NewPeriodicTrafficResetJob("weekly"))
// Run once a month, midnight, first of month
s.cron.AddJob("@monthly", job.NewPeriodicTrafficResetJob("monthly"))
// Client traffic reset jobs
- logger.Info("Scheduling periodic client traffic reset jobs")
+ // logger.Info("Scheduling periodic client traffic reset jobs")
// Run once a day, midnight
// TODO: for testing, run every minute, change back to daily later
// s.cron.AddJob("@daily", job.NewPeriodicClientTrafficResetJob("daily"))
- s.cron.AddJob("* * * * *", job.NewPeriodicClientTrafficResetJob("daily"))
+ // s.cron.AddJob("* * * * *", job.NewPeriodicClientTrafficResetJob("daily"))
// Run once a week, midnight between Sat/Sun
- s.cron.AddJob("@weekly", job.NewPeriodicClientTrafficResetJob("weekly"))
+ // s.cron.AddJob("@weekly", job.NewPeriodicClientTrafficResetJob("weekly"))
// Run once a month, midnight, first of month
- s.cron.AddJob("@monthly", job.NewPeriodicClientTrafficResetJob("monthly"))
+ // s.cron.AddJob("@monthly", job.NewPeriodicClientTrafficResetJob("monthly"))
}
// Make a traffic condition every day, 8:30