diff --git a/internal/data/setting.go b/internal/data/setting.go index 837da02e..ae2b383c 100644 --- a/internal/data/setting.go +++ b/internal/data/setting.go @@ -316,8 +316,8 @@ func (r *settingRepo) UpdatePanel(req *request.SettingPanel) (bool, error) { fw := firewall.NewFirewall() err = fw.Port(firewall.FireInfo{ Type: firewall.TypeNormal, - PortStart: config.HTTP.Port, - PortEnd: config.HTTP.Port, + PortStart: req.Port, + PortEnd: req.Port, Direction: firewall.DirectionIn, Strategy: firewall.StrategyAccept, }, firewall.OperationAdd) diff --git a/internal/service/cli.go b/internal/service/cli.go index bf883c83..2276f087 100644 --- a/internal/service/cli.go +++ b/internal/service/cli.go @@ -542,16 +542,18 @@ func (s *CliService) Port(ctx context.Context, cmd *cli.Command) error { } // 放行端口 - fw := firewall.NewFirewall() - err = fw.Port(firewall.FireInfo{ - Type: firewall.TypeNormal, - PortStart: config.HTTP.Port, - PortEnd: config.HTTP.Port, - Direction: firewall.DirectionIn, - Strategy: firewall.StrategyAccept, - }, firewall.OperationAdd) - if err != nil { - return err + if ok, _ := systemctl.IsEnabled("firewalld"); ok { + fw := firewall.NewFirewall() + err = fw.Port(firewall.FireInfo{ + Type: firewall.TypeNormal, + PortStart: port, + PortEnd: port, + Direction: firewall.DirectionIn, + Strategy: firewall.StrategyAccept, + }, firewall.OperationAdd) + if err != nil { + return err + } } if err = io.Write("/usr/local/etc/panel/config.yml", string(encoded), 0700); err != nil { @@ -990,8 +992,8 @@ checkPort: fw := firewall.NewFirewall() _ = fw.Port(firewall.FireInfo{ Type: firewall.TypeNormal, - PortStart: config.HTTP.Port, - PortEnd: config.HTTP.Port, + PortStart: port, + PortEnd: port, Direction: firewall.DirectionIn, Strategy: firewall.StrategyAccept, }, firewall.OperationAdd)