mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-03-01 01:20:49 +03:00

* Reduce outage time on Xray errors * Improved logs clearing, added previous logs File name change: 3xipl-access-persistent.log -> 3xipl-ap.log All previous logs have .prev suffix * Preparations for tgbot additions * [tgbot] Improvements, Additions and Fixes * Changed interaction with Expire Date for Clients * Added more info and interactions with Online Clients * Added a way to get Ban Logs (also added them to backup) * Few fixes and optimizations in code * Fixed RU translation * [tgbot] More updates and fixes * [tgbot] Quick Fix * [tgbot] Quick Fix 2 * [tgbot] Big Updates Added Notifications for Clients throught Tgbot (when Expire) Added compability for Usernames both w/wo @ Added more buttons overall for admins * [tgbot] Fixes * [tbot] Fixes 2 * [tgbot] Removed usernames support for Notifications to work * [tgbot] Fix * [tgbot] Fix Notify * [tgbot] small fixes * [tgbot] replyMarkup only for last message on big messages * [tgbot] Fixed last message is empty * [tgbot] Fix messages split
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package job
|
|
|
|
import (
|
|
"os"
|
|
"x-ui/logger"
|
|
"x-ui/xray"
|
|
)
|
|
|
|
type ClearLogsJob struct{}
|
|
|
|
func NewClearLogsJob() *ClearLogsJob {
|
|
return new(ClearLogsJob)
|
|
}
|
|
|
|
// Here Run is an interface method of the Job interface
|
|
func (j *ClearLogsJob) Run() {
|
|
logFiles := []string{xray.GetIPLimitLogPath(), xray.GetIPLimitBannedLogPath(), xray.GetAccessPersistentLogPath()}
|
|
logFilesPrev := []string{xray.GetIPLimitPrevLogPath(), xray.GetIPLimitBannedPrevLogPath(), xray.GetAccessPersistentPrevLogPath()}
|
|
|
|
// clear old previous logs
|
|
for i := 0; i < len(logFilesPrev); i++ {
|
|
if err := os.Truncate(logFilesPrev[i], 0); err != nil {
|
|
logger.Warning("clear logs job err:", err)
|
|
}
|
|
}
|
|
|
|
// clear log files and copy to previous logs
|
|
for i := 0; i < len(logFiles); i++ {
|
|
|
|
// copy to previous logs
|
|
logFilePrev, err := os.OpenFile(logFilesPrev[i], os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
|
|
if err != nil {
|
|
logger.Warning("clear logs job err:", err)
|
|
}
|
|
|
|
logFile, err := os.ReadFile(logFiles[i])
|
|
if err != nil {
|
|
logger.Warning("clear logs job err:", err)
|
|
}
|
|
|
|
_, err = logFilePrev.Write(logFile)
|
|
if err != nil {
|
|
logger.Warning("clear logs job err:", err)
|
|
}
|
|
defer logFilePrev.Close()
|
|
|
|
err = os.Truncate(logFiles[i], 0)
|
|
if err != nil {
|
|
logger.Warning("clear logs job err:", err)
|
|
}
|
|
}
|
|
}
|