Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/web/job
diff options
context:
space:
mode:
authorHamidreza <70919649+hamid-gh98@users.noreply.github.com>2024-03-13 10:54:41 +0300
committerGitHub <noreply@github.com>2024-03-13 10:54:41 +0300
commit569c9428fb7924fb693605385f745e4bf524dc20 (patch)
treedba6587b61f2f845c422d7a4fe29d3c8b59da2e0 /web/job
parent97489e743abe004a3d4865746c4c7f261aca4e10 (diff)
[iplimit] fix access log path in settings service (#2044)
* [iplimit] fix access log path in settings service better to avoid hardcoding the access log path to enhance flexibility. not all users prefer the default './access.log' * [iplimit] fix iplimit
Diffstat (limited to 'web/job')
-rw-r--r--web/job/check_client_ip_job.go35
1 files changed, 22 insertions, 13 deletions
diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go
index 4b799ab1..c5e8fc0d 100644
--- a/web/job/check_client_ip_job.go
+++ b/web/job/check_client_ip_job.go
@@ -44,7 +44,7 @@ func (j *CheckClientIpJob) Run() {
shouldClearAccessLog = j.processLogFile()
} else {
if !f2bInstalled {
- logger.Warning("fail2ban is not installed. IP limiting may not work properly.")
+ logger.Warning("[iplimit] fail2ban is not installed. IP limiting may not work properly.")
}
}
}
@@ -58,8 +58,11 @@ func (j *CheckClientIpJob) clearAccessLog() {
logAccessP, err := os.OpenFile(xray.GetAccessPersistentLogPath(), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
j.checkError(err)
+ // get access log path to open it
+ accessLogPath, err := xray.GetAccessLogPath()
+ j.checkError(err)
+
// reopen the access log file for reading
- accessLogPath := xray.GetAccessLogPath()
file, err := os.Open(accessLogPath)
j.checkError(err)
@@ -106,15 +109,9 @@ func (j *CheckClientIpJob) hasLimitIp() bool {
return false
}
-func (j *CheckClientIpJob) checkFail2BanInstalled() bool {
- cmd := "fail2ban-client"
- args := []string{"-h"}
- err := exec.Command(cmd, args...).Run()
- return err == nil
-}
-
func (j *CheckClientIpJob) processLogFile() bool {
- accessLogPath := xray.GetAccessLogPath()
+ accessLogPath, err := xray.GetAccessLogPath()
+ j.checkError(err)
file, err := os.Open(accessLogPath)
j.checkError(err)
@@ -170,10 +167,21 @@ func (j *CheckClientIpJob) processLogFile() bool {
return shouldCleanLog
}
-func (j *CheckClientIpJob) checkAccessLogAvailable(doWarning bool) bool {
- accessLogPath := xray.GetAccessLogPath()
+func (j *CheckClientIpJob) checkFail2BanInstalled() bool {
+ cmd := "fail2ban-client"
+ args := []string{"-h"}
+ err := exec.Command(cmd, args...).Run()
+ return err == nil
+}
+
+func (j *CheckClientIpJob) checkAccessLogAvailable(handleWarning bool) bool {
isAvailable := true
warningMsg := ""
+ accessLogPath, err := xray.GetAccessLogPath()
+ if err != nil {
+ return false
+ }
+
// access log is not available if it is set to 'none' or an empty string
switch accessLogPath {
case "none":
@@ -183,7 +191,8 @@ func (j *CheckClientIpJob) checkAccessLogAvailable(doWarning bool) bool {
warningMsg = "Access log doesn't exist in your Xray Configs"
isAvailable = false
}
- if doWarning && warningMsg != "" {
+
+ if handleWarning && warningMsg != "" {
logger.Warning(warningMsg)
}
return isAvailable