2023-03-24 23:19:17 +08:00
|
|
|
package firewall
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/firewall/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FirewallClient interface {
|
|
|
|
Start() error
|
|
|
|
Stop() error
|
|
|
|
Reload() error
|
|
|
|
Status() (string, error)
|
|
|
|
ListPort() ([]client.FireInfo, error)
|
2023-03-27 19:02:36 +08:00
|
|
|
ListAddress() ([]client.FireInfo, error)
|
2023-03-24 23:19:17 +08:00
|
|
|
|
|
|
|
Port(port client.FireInfo, operation string) error
|
|
|
|
RichRules(rule client.FireInfo, operation string) error
|
|
|
|
PortForward(info client.Forward, operation string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFirewallClient() (FirewallClient, error) {
|
2023-03-27 19:02:36 +08:00
|
|
|
// if _, err := os.Stat("/usr/sbin/firewalld"); err == nil {
|
|
|
|
return client.NewFirewalld()
|
|
|
|
// }
|
2023-03-24 23:19:17 +08:00
|
|
|
// if _, err := os.Stat("/usr/sbin/ufw"); err == nil {
|
|
|
|
// return client.NewUfw()
|
|
|
|
// }
|
2023-03-27 19:02:36 +08:00
|
|
|
// return nil, errors.New("no such type")
|
2023-03-24 23:19:17 +08:00
|
|
|
}
|