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>
|
<a-tooltip>
|
||||||
<template slot="title">
|
<template slot="title">
|
||||||
<span>{{ i18n "pages.inbounds.periodicTrafficResetDesc" }}</span>
|
<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>
|
</template>
|
||||||
{{ i18n "pages.inbounds.periodicTrafficResetTitle" }}
|
{{ i18n "pages.inbounds.periodicTrafficResetTitle" }}
|
||||||
<a-icon type="question-circle"></a-icon>
|
<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) {
|
func (s *InboundService) GetInboundsByTrafficReset(period string) ([]*model.Inbound, error) {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
var inbounds []*model.Inbound
|
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
|
err := db.Model(model.Inbound{}).Where("traffic_reset = ?", period).Find(&inbounds).Error
|
||||||
if err != nil && err != gorm.ErrRecordNotFound {
|
if err != nil && err != gorm.ErrRecordNotFound {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
logger.Infof("Found %d inbounds with traffic reset period: %s", len(inbounds), period)
|
||||||
return inbounds, nil
|
return inbounds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1844,20 +1846,39 @@ func (s *InboundService) ResetClientTraffic(id int, clientEmail string) (bool, e
|
||||||
|
|
||||||
func (s *InboundService) ResetAllClientTraffics(id int) error {
|
func (s *InboundService) ResetAllClientTraffics(id int) error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
|
now := time.Now().Unix() * 1000
|
||||||
|
|
||||||
whereText := "inbound_id "
|
return db.Transaction(func(tx *gorm.DB) error {
|
||||||
if id == -1 {
|
whereText := "inbound_id "
|
||||||
whereText += " > ?"
|
if id == -1 {
|
||||||
} else {
|
whereText += " > ?"
|
||||||
whereText += " = ?"
|
} else {
|
||||||
}
|
whereText += " = ?"
|
||||||
|
}
|
||||||
|
|
||||||
result := db.Model(xray.ClientTraffic{}).
|
// Reset client traffics
|
||||||
Where(whereText, id).
|
result := tx.Model(xray.ClientTraffic{}).
|
||||||
Updates(map[string]any{"enable": true, "up": 0, "down": 0})
|
Where(whereText, id).
|
||||||
|
Updates(map[string]any{"enable": true, "up": 0, "down": 0})
|
||||||
|
|
||||||
err := result.Error
|
if result.Error != nil {
|
||||||
return err
|
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 {
|
func (s *InboundService) ResetAllTraffics() error {
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "تصدير الإدخال"
|
"exportInbound" = "تصدير الإدخال"
|
||||||
"import" = "استيراد"
|
"import" = "استيراد"
|
||||||
"importInbound" = "استيراد إدخال"
|
"importInbound" = "استيراد إدخال"
|
||||||
|
"lastReset" = "آخر إعادة تعيين"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "أضف عميل"
|
"add" = "أضف عميل"
|
||||||
|
|
|
||||||
|
|
@ -232,6 +232,7 @@
|
||||||
"importInbound" = "Import an Inbound"
|
"importInbound" = "Import an Inbound"
|
||||||
"periodicTrafficResetTitle" = "Traffic Reset"
|
"periodicTrafficResetTitle" = "Traffic Reset"
|
||||||
"periodicTrafficResetDesc" = "Automatically reset traffic counter at specified intervals"
|
"periodicTrafficResetDesc" = "Automatically reset traffic counter at specified intervals"
|
||||||
|
"lastReset" = "Last Reset"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "Add Client"
|
"add" = "Add Client"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "Exportación entrante"
|
"exportInbound" = "Exportación entrante"
|
||||||
"import" = "Importar"
|
"import" = "Importar"
|
||||||
"importInbound" = "Importar un entrante"
|
"importInbound" = "Importar un entrante"
|
||||||
|
"lastReset" = "Último reinicio"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "Agregar Cliente"
|
"add" = "Agregar Cliente"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "استخراج ورودی"
|
"exportInbound" = "استخراج ورودی"
|
||||||
"import" = "افزودن"
|
"import" = "افزودن"
|
||||||
"importInbound" = "افزودن یک ورودی"
|
"importInbound" = "افزودن یک ورودی"
|
||||||
|
"lastReset" = "آخرین بازنشانی"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "کاربر جدید"
|
"add" = "کاربر جدید"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "Ekspor Masuk"
|
"exportInbound" = "Ekspor Masuk"
|
||||||
"import" = "Impor"
|
"import" = "Impor"
|
||||||
"importInbound" = "Impor Masuk"
|
"importInbound" = "Impor Masuk"
|
||||||
|
"lastReset" = "Reset Terakhir"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "Tambah Klien"
|
"add" = "Tambah Klien"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "インバウンドルールをエクスポート"
|
"exportInbound" = "インバウンドルールをエクスポート"
|
||||||
"import" = "インポート"
|
"import" = "インポート"
|
||||||
"importInbound" = "インバウンドルールをインポート"
|
"importInbound" = "インバウンドルールをインポート"
|
||||||
|
"lastReset" = "最後のリセット"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "クライアント追加"
|
"add" = "クライアント追加"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "Exportar Inbound"
|
"exportInbound" = "Exportar Inbound"
|
||||||
"import" = "Importar"
|
"import" = "Importar"
|
||||||
"importInbound" = "Importar um Inbound"
|
"importInbound" = "Importar um Inbound"
|
||||||
|
"lastReset" = "Último Reset"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "Adicionar Cliente"
|
"add" = "Adicionar Cliente"
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,7 @@
|
||||||
"renewDesc" = "Автопродление после истечения срока действия. (0 = отключить)(единица: день)"
|
"renewDesc" = "Автопродление после истечения срока действия. (0 = отключить)(единица: день)"
|
||||||
"periodicTrafficResetTitle" = "Сброс трафика"
|
"periodicTrafficResetTitle" = "Сброс трафика"
|
||||||
"periodicTrafficResetDesc" = "Автоматический сброс счетчика трафика через указанные интервалы"
|
"periodicTrafficResetDesc" = "Автоматический сброс счетчика трафика через указанные интервалы"
|
||||||
|
"lastReset" = "Последний сброс"
|
||||||
|
|
||||||
[pages.inbounds.periodicTrafficReset]
|
[pages.inbounds.periodicTrafficReset]
|
||||||
"never" = "Никогда"
|
"never" = "Никогда"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "Geleni Dışa Aktar"
|
"exportInbound" = "Geleni Dışa Aktar"
|
||||||
"import" = "İçe Aktar"
|
"import" = "İçe Aktar"
|
||||||
"importInbound" = "Bir Gelen İçe Aktar"
|
"importInbound" = "Bir Gelen İçe Aktar"
|
||||||
|
"lastReset" = "Son Sıfırlama"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "Müşteri Ekle"
|
"add" = "Müşteri Ekle"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "Експортувати вхідні"
|
"exportInbound" = "Експортувати вхідні"
|
||||||
"import" = "Імпорт"
|
"import" = "Імпорт"
|
||||||
"importInbound" = "Імпортувати вхідний"
|
"importInbound" = "Імпортувати вхідний"
|
||||||
|
"lastReset" = "Останнє скидання"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "Додати клієнта"
|
"add" = "Додати клієнта"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "Xuất nhập khẩu"
|
"exportInbound" = "Xuất nhập khẩu"
|
||||||
"import" = "Nhập"
|
"import" = "Nhập"
|
||||||
"importInbound" = "Nhập inbound"
|
"importInbound" = "Nhập inbound"
|
||||||
|
"lastReset" = "Đặt lại lần cuối"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "Thêm người dùng"
|
"add" = "Thêm người dùng"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "导出入站规则"
|
"exportInbound" = "导出入站规则"
|
||||||
"import"="导入"
|
"import"="导入"
|
||||||
"importInbound" = "导入入站规则"
|
"importInbound" = "导入入站规则"
|
||||||
|
"lastReset" = "上次重置"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "添加客户端"
|
"add" = "添加客户端"
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@
|
||||||
"exportInbound" = "匯出入站規則"
|
"exportInbound" = "匯出入站規則"
|
||||||
"import"="匯入"
|
"import"="匯入"
|
||||||
"importInbound" = "匯入入站規則"
|
"importInbound" = "匯入入站規則"
|
||||||
|
"lastReset" = "上次重置"
|
||||||
|
|
||||||
[pages.client]
|
[pages.client]
|
||||||
"add" = "新增客戶端"
|
"add" = "新增客戶端"
|
||||||
|
|
|
||||||
10
web/web.go
10
web/web.go
|
|
@ -273,22 +273,22 @@ func (s *Server) startTask() {
|
||||||
// Run once a day, midnight
|
// Run once a day, midnight
|
||||||
// TODO: for testing, run every minute, change back to daily later
|
// TODO: for testing, run every minute, change back to daily later
|
||||||
// s.cron.AddJob("@daily", job.NewPeriodicTrafficResetJob("daily"))
|
// 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
|
// Run once a week, midnight between Sat/Sun
|
||||||
s.cron.AddJob("@weekly", job.NewPeriodicTrafficResetJob("weekly"))
|
s.cron.AddJob("@weekly", job.NewPeriodicTrafficResetJob("weekly"))
|
||||||
// Run once a month, midnight, first of month
|
// Run once a month, midnight, first of month
|
||||||
s.cron.AddJob("@monthly", job.NewPeriodicTrafficResetJob("monthly"))
|
s.cron.AddJob("@monthly", job.NewPeriodicTrafficResetJob("monthly"))
|
||||||
|
|
||||||
// Client traffic reset jobs
|
// 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
|
// Run once a day, midnight
|
||||||
// TODO: for testing, run every minute, change back to daily later
|
// TODO: for testing, run every minute, change back to daily later
|
||||||
// s.cron.AddJob("@daily", job.NewPeriodicClientTrafficResetJob("daily"))
|
// 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
|
// 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
|
// 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
|
// Make a traffic condition every day, 8:30
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue