Skip to content

Commit 5576426

Browse files
committed
fix: 修复防火墙端口放行
1 parent d81ed39 commit 5576426

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

internal/data/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ func (r *settingRepo) UpdatePanel(req *request.SettingPanel) (bool, error) {
316316
fw := firewall.NewFirewall()
317317
err = fw.Port(firewall.FireInfo{
318318
Type: firewall.TypeNormal,
319-
PortStart: config.HTTP.Port,
320-
PortEnd: config.HTTP.Port,
319+
PortStart: req.Port,
320+
PortEnd: req.Port,
321321
Direction: firewall.DirectionIn,
322322
Strategy: firewall.StrategyAccept,
323323
}, firewall.OperationAdd)

internal/service/cli.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,18 @@ func (s *CliService) Port(ctx context.Context, cmd *cli.Command) error {
542542
}
543543

544544
// 放行端口
545-
fw := firewall.NewFirewall()
546-
err = fw.Port(firewall.FireInfo{
547-
Type: firewall.TypeNormal,
548-
PortStart: config.HTTP.Port,
549-
PortEnd: config.HTTP.Port,
550-
Direction: firewall.DirectionIn,
551-
Strategy: firewall.StrategyAccept,
552-
}, firewall.OperationAdd)
553-
if err != nil {
554-
return err
545+
if ok, _ := systemctl.IsEnabled("firewalld"); ok {
546+
fw := firewall.NewFirewall()
547+
err = fw.Port(firewall.FireInfo{
548+
Type: firewall.TypeNormal,
549+
PortStart: port,
550+
PortEnd: port,
551+
Direction: firewall.DirectionIn,
552+
Strategy: firewall.StrategyAccept,
553+
}, firewall.OperationAdd)
554+
if err != nil {
555+
return err
556+
}
555557
}
556558

557559
if err = io.Write("/usr/local/etc/panel/config.yml", string(encoded), 0700); err != nil {
@@ -990,8 +992,8 @@ checkPort:
990992
fw := firewall.NewFirewall()
991993
_ = fw.Port(firewall.FireInfo{
992994
Type: firewall.TypeNormal,
993-
PortStart: config.HTTP.Port,
994-
PortEnd: config.HTTP.Port,
995+
PortStart: port,
996+
PortEnd: port,
995997
Direction: firewall.DirectionIn,
996998
Strategy: firewall.StrategyAccept,
997999
}, firewall.OperationAdd)

0 commit comments

Comments
 (0)