fix: 解决 UFW 防火墙规则为空时插入规则失败的问题 (#2816)

Refs #2794
This commit is contained in:
ssongliu
2023-11-06 02:54:39 +00:00
committed by GitHub
parent cd5658adab
commit 262ddb5f12
+7
View File
@@ -183,6 +183,13 @@ func (f *Ufw) RichRules(rule FireInfo, operation string) error {
stdout, err := cmd.Exec(ruleStr)
if err != nil {
if strings.Contains(stdout, "ERROR: Invalid position") {
stdout, err := cmd.Exec(strings.ReplaceAll(ruleStr, "insert 1 ", ""))
if err != nil {
return fmt.Errorf("%s rich rules (%s), failed, err: %s", operation, ruleStr, stdout)
}
return nil
}
return fmt.Errorf("%s rich rules (%s), failed, err: %s", operation, ruleStr, stdout)
}
return nil