MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / UpdatePort

Function UpdatePort

core/utils/firewall/firewall.go:10–30  ·  view source on GitHub ↗
(oldPort, newPort string)

Source from the content-addressed store, hash-verified

8)
9
10func UpdatePort(oldPort, newPort string) error {
11 firewalld := cmd.Which("firewalld")
12 if firewalld {
13 status, _ := cmd.NewCommandMgr(cmd.WithEnv("LANGUAGE=en_US:en")).RunWithStdout("firewall-cmd", "--state")
14 isRunning := status == "running\n"
15 if isRunning {
16 return firewallUpdatePort(oldPort, newPort)
17 }
18 }
19
20 ufw := cmd.Which("ufw")
21 if !ufw {
22 return nil
23 }
24 status, _ := cmd.NewCommandMgr(cmd.WithEnv("LANGUAGE=en_US:en")).RunWithStdout("ufw", "status")
25 isRuning := strings.Contains(status, "Status: active")
26 if isRuning {
27 return ufwUpdatePort(oldPort, newPort)
28 }
29 return nil
30}
31
32func firewallUpdatePort(oldPort, newPort string) error {
33 stdout, err := cmd.NewCommandMgr().RunWithStdout("firewall-cmd", "--zone=public", "--add-port="+newPort+"/tcp", "--permanent")

Callers

nothing calls this directly

Calls 3

firewallUpdatePortFunction · 0.85
ufwUpdatePortFunction · 0.85
RunWithStdoutMethod · 0.45

Tested by

no test coverage detected