2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 11:27:17 +08:00

feat: 修改面板端口前检查占用

This commit is contained in:
耗子
2024-11-13 12:01:47 +08:00
parent 00ea2f40e2
commit 47e114d43e
4 changed files with 18 additions and 4 deletions

View File

@@ -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