Parcourir la source

check fail2ban installed or not

MHSanaei il y a 1 an
Parent
commit
6765babe7b
1 fichiers modifiés avec 12 ajouts et 0 suppressions
  1. 12 0
      web/job/check_client_ip_job.go

+ 12 - 0
web/job/check_client_ip_job.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"log"
 	"os"
+	"os/exec"
 	"regexp"
 	"sort"
 	"strings"
@@ -41,6 +42,7 @@ func (j *CheckClientIpJob) Run() {
 
 	// check for limit ip
 	if j.hasLimitIp() {
+		j.checkFail2BanInstalled()
 		j.processLogFile()
 	}
 }
@@ -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 == "" {