mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 09:13:49 +08:00
feat: 修改面板端口前检查占用
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/TheTNB/panel/pkg/cert"
|
||||
"github.com/TheTNB/panel/pkg/firewall"
|
||||
"github.com/TheTNB/panel/pkg/io"
|
||||
"github.com/TheTNB/panel/pkg/os"
|
||||
"github.com/TheTNB/panel/pkg/shell"
|
||||
"github.com/TheTNB/panel/pkg/tools"
|
||||
"github.com/TheTNB/panel/pkg/types"
|
||||
@@ -127,7 +128,7 @@ func (r *settingRepo) GetPanelSetting(ctx context.Context) (*request.PanelSettin
|
||||
BackupPath: backupPath,
|
||||
Username: user.Username,
|
||||
Email: user.Email,
|
||||
Port: app.Conf.Int("http.port"),
|
||||
Port: uint(app.Conf.Int("http.port")),
|
||||
HTTPS: app.Conf.Bool("http.tls"),
|
||||
Cert: crt,
|
||||
Key: key,
|
||||
@@ -202,6 +203,12 @@ func (r *settingRepo) UpdatePanelSetting(ctx context.Context, setting *request.P
|
||||
return false, err
|
||||
}
|
||||
|
||||
if setting.Port != config.HTTP.Port {
|
||||
if os.TCPPortInUse(setting.Port) {
|
||||
return false, errors.New("端口已被占用")
|
||||
}
|
||||
}
|
||||
|
||||
config.App.Locale = setting.Locale
|
||||
config.HTTP.Port = setting.Port
|
||||
config.HTTP.Entrance = setting.Entrance
|
||||
|
||||
@@ -10,7 +10,7 @@ type PanelSetting struct {
|
||||
Username string `json:"username" validate:"required"`
|
||||
Password string `json:"password" validate:"password"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
Port int `json:"port" validate:"required,number,gte=1,lte=65535"`
|
||||
Port uint `json:"port" validate:"required,number,gte=1,lte=65535"`
|
||||
HTTPS bool `json:"https"`
|
||||
Cert string `json:"cert" validate:"required"`
|
||||
Key string `json:"key" validate:"required"`
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/TheTNB/panel/pkg/firewall"
|
||||
"github.com/TheTNB/panel/pkg/io"
|
||||
"github.com/TheTNB/panel/pkg/ntp"
|
||||
"github.com/TheTNB/panel/pkg/os"
|
||||
"github.com/TheTNB/panel/pkg/systemctl"
|
||||
"github.com/TheTNB/panel/pkg/tools"
|
||||
"github.com/TheTNB/panel/pkg/types"
|
||||
@@ -370,7 +371,7 @@ func (s *CliService) EntranceOff(ctx context.Context, cmd *cli.Command) error {
|
||||
}
|
||||
|
||||
func (s *CliService) Port(ctx context.Context, cmd *cli.Command) error {
|
||||
port := cast.ToInt(cmd.Args().First())
|
||||
port := cast.ToUint(cmd.Args().First())
|
||||
if port < 1 || port > 65535 {
|
||||
return fmt.Errorf("端口范围错误")
|
||||
}
|
||||
@@ -384,6 +385,12 @@ func (s *CliService) Port(ctx context.Context, cmd *cli.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if port != config.HTTP.Port {
|
||||
if os.TCPPortInUse(port) {
|
||||
return errors.New("端口已被占用")
|
||||
}
|
||||
}
|
||||
|
||||
config.HTTP.Port = port
|
||||
|
||||
encoded, err := yaml.Marshal(config)
|
||||
|
||||
@@ -17,7 +17,7 @@ type PanelAppConfig struct {
|
||||
|
||||
type PanelHTTPConfig struct {
|
||||
Debug bool `yaml:"debug"`
|
||||
Port int `yaml:"port"`
|
||||
Port uint `yaml:"port"`
|
||||
Entrance string `yaml:"entrance"`
|
||||
TLS bool `yaml:"tls"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user