mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-02 03:40:27 +08:00
31 lines
803 B
Go
31 lines
803 B
Go
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
|
|
|
|
package utils
|
|
|
|
import (
|
|
"os/exec"
|
|
"runtime"
|
|
|
|
executils "github.com/TeaOSLab/EdgeAdmin/internal/utils/exec"
|
|
"github.com/iwind/TeaGo/logs"
|
|
"github.com/iwind/TeaGo/types"
|
|
)
|
|
|
|
func AddPortsToFirewall(ports []int) {
|
|
for _, port := range ports {
|
|
// Linux
|
|
if runtime.GOOS == "linux" {
|
|
// firewalld
|
|
firewallCmd, _ := executils.LookPath("firewall-cmd")
|
|
if len(firewallCmd) > 0 {
|
|
err := exec.Command(firewallCmd, "--add-port="+types.String(port)+"/tcp").Run()
|
|
if err == nil {
|
|
logs.Println("ADMIN_NODE", "add port '"+types.String(port)+"' to firewalld")
|
|
|
|
_ = exec.Command(firewallCmd, "--add-port="+types.String(port)+"/tcp", "--permanent").Run()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|