This commit is contained in:
1 parent
64caebb5b4
commit
a78f369e23
4 files changed
+53
-4
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -166,15 +167,26 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
response.NewSuccessResponse(map[string]any{
|
||||
"smtp_domain": smtpDomain,
|
||||
"web_domain": webDomain,
|
||||
"domains": domains,
|
||||
"smtp_domain": smtpDomain,
|
||||
"web_domain": webDomain,
|
||||
"domains": domains,
|
||||
"public_https_port": config.ResolvePublicHTTPSPort(config.CurrentHTTPConfig()),
|
||||
}).FPrint(w)
|
||||
return
|
||||
}
|
||||
|
||||
if reqData["step"] == "domain" && reqData["action"] == "set" {
|
||||
err := setup.SetDomainSettings(cast.ToString(reqData["smtp_domain"]), cast.ToString(reqData["web_domain"]), reqData["multi_domain"])
|
||||
var err error
|
||||
if value := strings.TrimSpace(reqData["public_https_port"]); value != "" {
|
||||
port, parseErr := strconv.Atoi(value)
|
||||
if parseErr != nil || port < 1 || port > 65535 {
|
||||
response.NewErrorResponse(response.ParamsError, "公网 HTTPS 端口必须是 1 到 65535 的整数", "").FPrint(w)
|
||||
return
|
||||
}
|
||||
err = setup.SetDomainSettingsWithPublicHTTPSPort(reqData["smtp_domain"], reqData["web_domain"], reqData["multi_domain"], port)
|
||||
} else {
|
||||
err = setup.SetDomainSettings(reqData["smtp_domain"], reqData["web_domain"], reqData["multi_domain"])
|
||||
}
|
||||
if err != nil {
|
||||
writeSetupError(ctx, w, err)
|
||||
return
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.pcux.cn/xuans/Smail/config"
|
||||
"git.pcux.cn/xuans/Smail/utils/array"
|
||||
"git.pcux.cn/xuans/Smail/utils/errors"
|
||||
@@ -17,6 +19,18 @@ func GetDomainSettings() (string, string, []string, error) {
|
||||
}
|
||||
|
||||
func SetDomainSettings(smtpDomain, webDomain, multiDomains string) error {
|
||||
return setDomainSettings(smtpDomain, webDomain, multiDomains, nil)
|
||||
}
|
||||
|
||||
// SetDomainSettingsWithPublicHTTPSPort 同时保存公网入口端口,不改变内部监听端口。
|
||||
func SetDomainSettingsWithPublicHTTPSPort(smtpDomain, webDomain, multiDomains string, publicHTTPSPort int) error {
|
||||
if publicHTTPSPort < 1 || publicHTTPSPort > 65535 {
|
||||
return fmt.Errorf("公网 HTTPS 端口必须是 1 到 65535 的整数")
|
||||
}
|
||||
return setDomainSettings(smtpDomain, webDomain, multiDomains, &publicHTTPSPort)
|
||||
}
|
||||
|
||||
func setDomainSettings(smtpDomain, webDomain, multiDomains string, publicHTTPSPort *int) error {
|
||||
configData, err := config.ReadConfig()
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
@@ -43,6 +57,9 @@ func SetDomainSettings(smtpDomain, webDomain, multiDomains string) error {
|
||||
|
||||
configData.Domain = smtpDomain
|
||||
configData.WebDomain = webDomain
|
||||
if publicHTTPSPort != nil {
|
||||
configData.PublicHTTPSPort = *publicHTTPSPort
|
||||
}
|
||||
|
||||
// 检查域名是否指向本机 todo
|
||||
|
||||
|
||||
Reference in new issue
Block a user