mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-23 16:00:52 +00:00
* refactor(firewall): rebuild rule management foundation * refactor(firewall): streamline rule checks and inventory * feat(firewall): improve native rule inventory * refactor(firewall): refine rule management * feat: add Docker port guard * feat(firewall): support native nftables * feat(firewall): add configurable firewall selection * feat(firewall): support nftables docker port guard * refactor(firewall): complete v2 rule management and migration * refactor(firewall): align state and API contracts * refactor(firewall): unify rule management operations * feat: refine firewall v2 rules and forwarding * fix(firewall): harden dual-stack rule management * refactor(firewall): consolidate rule validation and persistence
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package providers
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
|
)
|
|
|
|
type Iptables struct{ executable string }
|
|
|
|
func NewIptables(executable string) (*Iptables, error) {
|
|
if executable == "" {
|
|
executable = "iptables"
|
|
}
|
|
return &Iptables{executable: executable}, nil
|
|
}
|
|
|
|
func (i *Iptables) Name() string {
|
|
return "iptables"
|
|
}
|
|
|
|
func (i *Iptables) Status() (bool, error) {
|
|
stdout, err := cmd.NewCommandMgr(cmd.WithTimeout(20*time.Second)).RunWithStdout(i.executable, "-L", "-n")
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
firstLine := strings.Split(strings.TrimSpace(stdout), "\n")[0]
|
|
return strings.Contains(firstLine, "Chain"), nil
|
|
}
|
|
|
|
func (i *Iptables) Start() error {
|
|
return nil
|
|
}
|
|
|
|
func (i *Iptables) Stop() error {
|
|
return nil
|
|
}
|
|
|
|
func (i *Iptables) Restart() error {
|
|
return nil
|
|
}
|
|
|
|
func (i *Iptables) Version() (string, error) {
|
|
stdout, err := cmd.NewCommandMgr(cmd.WithTimeout(20*time.Second)).RunWithStdout(i.executable, "--version")
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to get iptables version: %w", err)
|
|
}
|
|
parts := strings.Fields(stdout)
|
|
if len(parts) >= 2 {
|
|
return strings.TrimPrefix(parts[1], "v"), nil
|
|
}
|
|
return strings.TrimSpace(stdout), nil
|
|
}
|