mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-10-27 02:24:40 +00:00
feat: add last traffic reset time display and update logic in inbound service
This commit is contained in:
parent
52196c014d
commit
6fce769c27
16 changed files with 56 additions and 16 deletions
|
|
@ -49,6 +49,12 @@
|
|||
<a-tooltip>
|
||||
<template slot="title">
|
||||
<span>{{ i18n "pages.inbounds.periodicTrafficResetDesc" }}</span>
|
||||
<br v-if="dbInbound.lastTrafficResetTime && dbInbound.lastTrafficResetTime > 0">
|
||||
<span v-if="dbInbound.lastTrafficResetTime && dbInbound.lastTrafficResetTime > 0">
|
||||
<strong>{{ i18n "pages.inbounds.lastReset" }}:</strong>
|
||||
<span v-if="datepicker == 'gregorian'">[[ moment(dbInbound.lastTrafficResetTime).format('YYYY-MM-DD HH:mm:ss') ]]</span>
|
||||
<span v-else>[[ DateUtil.convertToJalalian(moment(dbInbound.lastTrafficResetTime)) ]]</span>
|
||||
</span>
|
||||
</template>
|
||||
{{ i18n "pages.inbounds.periodicTrafficResetTitle" }}
|
||||
<a-icon type="question-circle"></a-icon>
|
||||
|
|
|
|||
|
|
@ -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,7 +1846,9 @@ 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
|
||||
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
whereText := "inbound_id "
|
||||
if id == -1 {
|
||||
whereText += " > ?"
|
||||
|
|
@ -1852,12 +1856,29 @@ func (s *InboundService) ResetAllClientTraffics(id int) error {
|
|||
whereText += " = ?"
|
||||
}
|
||||
|
||||
result := db.Model(xray.ClientTraffic{}).
|
||||
// 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 {
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "تصدير الإدخال"
|
||||
"import" = "استيراد"
|
||||
"importInbound" = "استيراد إدخال"
|
||||
"lastReset" = "آخر إعادة تعيين"
|
||||
|
||||
[pages.client]
|
||||
"add" = "أضف عميل"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "Exportación entrante"
|
||||
"import" = "Importar"
|
||||
"importInbound" = "Importar un entrante"
|
||||
"lastReset" = "Último reinicio"
|
||||
|
||||
[pages.client]
|
||||
"add" = "Agregar Cliente"
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "استخراج ورودی"
|
||||
"import" = "افزودن"
|
||||
"importInbound" = "افزودن یک ورودی"
|
||||
"lastReset" = "آخرین بازنشانی"
|
||||
|
||||
[pages.client]
|
||||
"add" = "کاربر جدید"
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "Ekspor Masuk"
|
||||
"import" = "Impor"
|
||||
"importInbound" = "Impor Masuk"
|
||||
"lastReset" = "Reset Terakhir"
|
||||
|
||||
[pages.client]
|
||||
"add" = "Tambah Klien"
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "インバウンドルールをエクスポート"
|
||||
"import" = "インポート"
|
||||
"importInbound" = "インバウンドルールをインポート"
|
||||
"lastReset" = "最後のリセット"
|
||||
|
||||
[pages.client]
|
||||
"add" = "クライアント追加"
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "Exportar Inbound"
|
||||
"import" = "Importar"
|
||||
"importInbound" = "Importar um Inbound"
|
||||
"lastReset" = "Último Reset"
|
||||
|
||||
[pages.client]
|
||||
"add" = "Adicionar Cliente"
|
||||
|
|
|
|||
|
|
@ -250,6 +250,7 @@
|
|||
"renewDesc" = "Автопродление после истечения срока действия. (0 = отключить)(единица: день)"
|
||||
"periodicTrafficResetTitle" = "Сброс трафика"
|
||||
"periodicTrafficResetDesc" = "Автоматический сброс счетчика трафика через указанные интервалы"
|
||||
"lastReset" = "Последний сброс"
|
||||
|
||||
[pages.inbounds.periodicTrafficReset]
|
||||
"never" = "Никогда"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "Експортувати вхідні"
|
||||
"import" = "Імпорт"
|
||||
"importInbound" = "Імпортувати вхідний"
|
||||
"lastReset" = "Останнє скидання"
|
||||
|
||||
[pages.client]
|
||||
"add" = "Додати клієнта"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "导出入站规则"
|
||||
"import"="导入"
|
||||
"importInbound" = "导入入站规则"
|
||||
"lastReset" = "上次重置"
|
||||
|
||||
[pages.client]
|
||||
"add" = "添加客户端"
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@
|
|||
"exportInbound" = "匯出入站規則"
|
||||
"import"="匯入"
|
||||
"importInbound" = "匯入入站規則"
|
||||
"lastReset" = "上次重置"
|
||||
|
||||
[pages.client]
|
||||
"add" = "新增客戶端"
|
||||
|
|
|
|||
10
web/web.go
10
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue