Skip to content

Commit

Permalink
check fail2ban installed or not
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSanaei committed Sep 1, 2023
1 parent 4b4be5f commit 6765bab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions web/job/check_client_ip_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"log"
"os"
"os/exec"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -41,6 +42,7 @@ func (j *CheckClientIpJob) Run() {

// check for limit ip
if j.hasLimitIp() {
j.checkFail2BanInstalled()
j.processLogFile()
}
}
Expand Down Expand Up @@ -74,6 +76,16 @@ func (j *CheckClientIpJob) hasLimitIp() bool {
return false
}

func (j *CheckClientIpJob) checkFail2BanInstalled() {
cmd := "fail2ban-client"
args := []string{"-h"}

err := exec.Command(cmd, args...).Run()
if err != nil {
logger.Warning("fail2ban is not installed. IP limiting may not work properly.")
}
}

func (j *CheckClientIpJob) processLogFile() {
accessLogPath := xray.GetAccessLogPath()
if accessLogPath == "" {
Expand Down

0 comments on commit 6765bab

Please sign in to comment.