Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"github.com/1Panel-dev/1Panel/agent/app/service"
"github.com/1Panel-dev/1Panel/agent/global"
"github.com/1Panel-dev/1Panel/agent/utils/firewall"
firewallClient "github.com/1Panel-dev/1Panel/agent/utils/firewall/client"
"github.com/1Panel-dev/1Panel/agent/utils/firewall/client/iptables"
)

func Init() {

Check failure on line 14 in agent/init/firewall/firewall.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 33 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=1Panel-dev_1Panel&issues=AZq5p3y6zHd3JlITZZ0N&open=AZq5p3y6zHd3JlITZZ0N&pullRequest=11066
client, err := firewall.NewFirewallClient()
if err != nil {
return
Expand All @@ -29,6 +30,10 @@
global.LOG.Errorf("load postrouting rules from file failed, err: %v", err)
return
}
if err := firewallClient.EnableIptablesForward(); err != nil {
global.LOG.Errorf("enable iptables forward failed, err: %v", err)
return
}
global.LOG.Infof("loaded iptables rules for forward from file successfully")
}
if clientName == "ufw" {
Expand Down
2 changes: 1 addition & 1 deletion agent/utils/firewall/client/iptables/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (

func RunWithStd(tab, rule string) (string, error) {
cmdMgr := cmd.NewCommandMgr(cmd.WithIgnoreExist1(), cmd.WithTimeout(20*time.Second))
stdout, err := cmdMgr.RunWithStdoutBashCf("%s iptables -t %s %s", cmd.SudoHandleCmd(), tab, rule)
stdout, err := cmdMgr.RunWithStdoutBashCf("%s iptables -w -t %s %s", cmd.SudoHandleCmd(), tab, rule)
if err != nil {
global.LOG.Errorf("iptables command failed [table=%s, rule=%s]: %v", tab, rule, err)
return stdout, err
Expand Down
9 changes: 4 additions & 5 deletions agent/utils/firewall/client/iptables/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ func SaveRulesToFile(tab, chain, fileName string) error {
}

func LoadRulesFromFile(tab, chain, fileName string) error {
rulesFile := path.Join(global.Dir.FirewallDir, fileName)
if _, err := os.Stat(rulesFile); os.IsNotExist(err) {
return nil
}

if err := AddChain(tab, chain); err != nil {
global.LOG.Errorf("create chain %s failed: %v", chain, err)
return err
}
rulesFile := path.Join(global.Dir.FirewallDir, fileName)
if _, err := os.Stat(rulesFile); os.IsNotExist(err) {
return nil
}
data, err := os.ReadFile(rulesFile)
if err != nil {
global.LOG.Errorf("read rules from file %s failed, err: %v", rulesFile, err)
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/views/host/firewall/advance/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<template #main>
<div class="app-warn">
<div class="flex flex-col gap-2 items-center justify-center w-full sm:flex-row">
<span>{{ $t('firewall.advancedControlNotAvailable', [firewallName]) }}</span>
<span>{{ $t('firewall.advancedControlNotAvailable', [fireName]) }}</span>
</div>
<div>
<img src="@/assets/images/no_app.svg" />
Expand Down Expand Up @@ -160,7 +160,6 @@ const loading = ref();
const selects = ref<any>([]);
const selectedChain = ref('1PANEL_INPUT');
const defaultStrategy = ref('ACCEPT');
const firewallName = ref('');

const maskShow = ref(true);
const isActive = ref(false);
Expand Down
Loading