支持可配置反代HTTPS端口并统一管理与重置入口
This commit is contained in:
1 parent
b2b8951bcf
commit
54b19a19f8
23 files changed
+268
-50
No files matched your search
@@ -24,9 +24,10 @@ type settingsView struct {
|
||||
}
|
||||
|
||||
type settingsServerView struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
HTTPSMode string `json:"https_mode"`
|
||||
ProxyHTTPSPort int `json:"proxy_https_port"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
HTTPSMode string `json:"https_mode"`
|
||||
}
|
||||
|
||||
type settingsWebView struct {
|
||||
@@ -96,9 +97,10 @@ type settingsRequest struct {
|
||||
}
|
||||
|
||||
type settingsServerRequest struct {
|
||||
Host *string `json:"host"`
|
||||
Port *int `json:"port"`
|
||||
HTTPSMode *string `json:"https_mode"`
|
||||
ProxyHTTPSPort *int `json:"proxy_https_port"`
|
||||
Host *string `json:"host"`
|
||||
Port *int `json:"port"`
|
||||
HTTPSMode *string `json:"https_mode"`
|
||||
}
|
||||
|
||||
type settingsWebRequest struct {
|
||||
@@ -329,7 +331,7 @@ func nonRenewalACMEConfig(cfg config.ACMEConfig) config.ACMEConfig {
|
||||
|
||||
func settingsViewFromConfig(cfg config.Config) settingsView {
|
||||
return settingsView{
|
||||
Server: settingsServerView{Host: cfg.Server.Host, Port: cfg.Server.Port, HTTPSMode: cfg.Server.HTTPSMode},
|
||||
Server: settingsServerView{Host: cfg.Server.Host, Port: cfg.Server.Port, HTTPSMode: cfg.Server.HTTPSMode, ProxyHTTPSPort: cfg.Server.ProxyHTTPSPort},
|
||||
Web: settingsWebView{Enabled: cfg.Web.Enabled, Hostname: cfg.Web.Hostname, PublicIP: cfg.Web.PublicIP},
|
||||
Paths: settingsPathsView{Certificate: cfg.Paths.Certificate},
|
||||
ACME: settingsACMEView{
|
||||
@@ -373,6 +375,9 @@ func applySettingsRequest(cfg *config.Config, request settingsRequest) {
|
||||
if request.Server.HTTPSMode != nil {
|
||||
cfg.Server.HTTPSMode = strings.TrimSpace(*request.Server.HTTPSMode)
|
||||
}
|
||||
if request.Server.ProxyHTTPSPort != nil {
|
||||
cfg.Server.ProxyHTTPSPort = *request.Server.ProxyHTTPSPort
|
||||
}
|
||||
}
|
||||
if request.Web != nil {
|
||||
if request.Web.Enabled != nil {
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestSettingsAPIUpdatesSafeFieldsWithoutReturningSecrets(t *testing.T) {
|
||||
cookie := loginForSettingsTest(t, server)
|
||||
|
||||
request := httptest.NewRequest(http.MethodPut, "/api/v1/settings", strings.NewReader(`{
|
||||
"server": {"port": 5443},
|
||||
"server": {"port": 5443, "proxy_https_port": 8004},
|
||||
"web": {"hostname": "admin.example.test"},
|
||||
"acme": {"renewal_threshold_days": 10}
|
||||
}`))
|
||||
@@ -85,6 +85,9 @@ func TestSettingsAPIUpdatesSafeFieldsWithoutReturningSecrets(t *testing.T) {
|
||||
if saved.Admin.PasswordHash != cfg.Admin.PasswordHash || saved.Database.DSN != cfg.Database.DSN {
|
||||
t.Fatal("更新设置不应覆盖管理员密码或数据库 DSN")
|
||||
}
|
||||
if payload.Settings.Server.ProxyHTTPSPort != 8004 || saved.Server.ProxyHTTPSPort != 8004 {
|
||||
t.Fatal("代理公开端口未保存或未返回")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSettingsAPIWebAddressChangeDoesNotRequireRestart(t *testing.T) {
|
||||
|
||||
@@ -70,6 +70,7 @@ type setupRequest struct {
|
||||
WebPublicIP string `json:"web_public_ip"`
|
||||
WebEnabled *bool `json:"web_enabled"`
|
||||
HTTPSMode string `json:"https_mode"`
|
||||
ProxyHTTPSPort int `json:"proxy_https_port"`
|
||||
}
|
||||
|
||||
type dnsTestRequest struct {
|
||||
@@ -122,6 +123,7 @@ func (s *Server) setupStatus(c *gin.Context) {
|
||||
"server_port": cfg.Server.Port,
|
||||
"reset_url": cfg.ResetURL(),
|
||||
"https_mode": cfg.Server.HTTPSMode,
|
||||
"proxy_https_port": cfg.Server.ProxyHTTPSPort,
|
||||
"web_enabled": cfg.Web.Enabled,
|
||||
"web_hostname": cfg.Web.Hostname,
|
||||
"web_public_ip": cfg.Web.PublicIP,
|
||||
@@ -378,6 +380,7 @@ func (s *Server) applySetup(c *gin.Context) {
|
||||
WebPublicIP: request.WebPublicIP,
|
||||
WebEnabled: webEnabled,
|
||||
HTTPSMode: request.HTTPSMode,
|
||||
ProxyHTTPSPort: request.ProxyHTTPSPort,
|
||||
})
|
||||
if err != nil {
|
||||
s.rollbackSetupCredentialsWithLog(createdCredentialRefs)
|
||||
|
||||
@@ -358,7 +358,7 @@ func TestSetupApplyPersistsConfigurationWithoutPlainPassword(t *testing.T) {
|
||||
if !strings.Contains(response.Body.String(), `"firewall"`) || !strings.Contains(response.Body.String(), `"created":true`) {
|
||||
t.Fatalf("初始化响应应返回本机防火墙结果:%s", response.Body.String())
|
||||
}
|
||||
if !strings.Contains(response.Body.String(), `"reset_url":"https://scert.example.test/reset"`) {
|
||||
if !strings.Contains(response.Body.String(), `"reset_url":"https://scert.example.test:8443/reset"`) {
|
||||
t.Fatalf("初始化响应应返回根据 Web 地址生成的密码重置路径:%s", response.Body.String())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user