fix: Fail2ban 配置文件区分系统 (#3202)

This commit is contained in:
ssongliu
2023-12-06 09:22:11 +00:00
committed by GitHub
parent a74ed6a317
commit 8a24342b85
+11 -1
View File
@@ -134,7 +134,7 @@ func initLocalFile() error {
bantime = 600
findtime = 300
maxretry = 5
banaction = firewallcmd-ipset
banaction = $banaction
action = %(action_mwl)s
#DEFAULT-END
@@ -148,6 +148,16 @@ findtime = 300
bantime = 600
action = %(action_mwl)s
logpath = /var/log/secure`
banaction := ""
if active, _ := systemctl.IsActive("firewalld"); active {
banaction = "firewallcmd-ipset"
} else if active, _ := systemctl.IsActive("ufw"); active {
banaction = "ufw"
} else {
banaction = "iptables-allports"
}
initFile = strings.ReplaceAll(initFile, "$banaction", banaction)
if err := os.WriteFile(defaultPath, []byte(initFile), 0640); err != nil {
return err
}