diff --git a/README_CN.md b/README_CN.md index 0ad0d91..a59a898 100644 --- a/README_CN.md +++ b/README_CN.md @@ -30,7 +30,10 @@ PMail是一个追求极简部署流程、极致资源占用的个人域名邮箱 ### 4、自动SSL证书 -实现了ACME协议,程序将自动获取并更新Let’s Encrypt证书。 +实现了ACME协议,程序将自动获取并更新Let’s +Encrypt证书。默认情况下,会为web后台也生成ssl证书,让后台使用https访问,如果你有自己的网关层,不需要https的话,在配置文件中将`httpsEnabled` +设置为`2`,这样管理后台就不会使用https协议。( +注意:即使你不需要https,也请保证ssl证书文件路径正确,http协议虽然不使用证书了,但是smtp协议还需要证书) ## 其他 diff --git a/server/config/config.go b/server/config/config.go index 2f496b9..621a74a 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -11,7 +11,7 @@ import ( var IsInit bool type Config struct { - LogLevel string `json:"logLevel"` + LogLevel string `json:"logLevel"` // 日志级别 Domain string `json:"domain"` WebDomain string `json:"webDomain"` DkimPrivateKeyPath string `json:"dkimPrivateKeyPath"` @@ -25,6 +25,7 @@ type Config struct { WeChatPushTemplateId string `json:"weChatPushTemplateId"` WeChatPushUserId string `json:"weChatPushUserId"` IsInit bool `json:"isInit"` + HttpsEnabled int `json:"httpsEnabled"` //后台页面是否启用https,0默认(启用),1启用,2不启用 Tables map[string]string `json:"-"` TablesInitData map[string]string `json:"-"` } @@ -32,7 +33,7 @@ type Config struct { //go:embed tables/* var tableConfig embed.FS -const Version = "2.0.0" +const Version = "2.0.1" const DBTypeMySQL = "mysql" const DBTypeSQLite = "sqlite" diff --git a/server/config/config.json b/server/config/config.json index 540a6ef..61ec6db 100644 --- a/server/config/config.json +++ b/server/config/config.json @@ -12,5 +12,6 @@ "weChatPushSecret": "", "weChatPushTemplateId": "", "weChatPushUserId": "", - "isInit": false + "isInit": false, + "httpsEnabled": 0 } \ No newline at end of file diff --git a/server/http_server/http_server.go b/server/http_server/http_server.go index a83139e..f592621 100644 --- a/server/http_server/http_server.go +++ b/server/http_server/http_server.go @@ -2,8 +2,11 @@ package http_server import ( "fmt" + "io/fs" "net/http" + "pmail/config" "pmail/controllers" + "pmail/controllers/email" "time" ) @@ -20,7 +23,26 @@ func HttpStop() { func HttpStart() { mux := http.NewServeMux() - mux.HandleFunc("/", controllers.Interceptor) + + if config.Instance.HttpsEnabled != 2 { + mux.HandleFunc("/", controllers.Interceptor) + } else { + fe, err := fs.Sub(local, "dist") + if err != nil { + panic(err) + } + mux.Handle("/", http.FileServer(http.FS(fe))) + mux.HandleFunc("/api/ping", contextIterceptor(controllers.Ping)) + mux.HandleFunc("/api/login", contextIterceptor(controllers.Login)) + mux.HandleFunc("/api/group", contextIterceptor(controllers.GetUserGroup)) + mux.HandleFunc("/api/email/list", contextIterceptor(email.EmailList)) + mux.HandleFunc("/api/email/detail", contextIterceptor(email.EmailDetail)) + mux.HandleFunc("/api/email/send", contextIterceptor(email.Send)) + mux.HandleFunc("/api/settings/modify_password", contextIterceptor(controllers.ModifyPassword)) + mux.HandleFunc("/attachments/", contextIterceptor(controllers.GetAttachments)) + mux.HandleFunc("/attachments/download/", contextIterceptor(controllers.Download)) + } + httpServer = &http.Server{ Addr: fmt.Sprintf(":%d", HttpPort), Handler: mux, diff --git a/server/http_server/https_server.go b/server/http_server/https_server.go index f8130f4..5da0c39 100644 --- a/server/http_server/https_server.go +++ b/server/http_server/https_server.go @@ -62,17 +62,18 @@ func HttpsStart() { // go http server会打一堆没用的日志,写一个空的日志处理器,屏蔽掉日志输出 nullLog := olog.New(&nullWrite{}, "", olog.Ldate) - httpsServer = &http.Server{ - Addr: fmt.Sprintf(":%d", HttpsPort), - Handler: session.Instance.LoadAndSave(mux), - ReadTimeout: time.Second * 60, - WriteTimeout: time.Second * 60, - ErrorLog: nullLog, - } - - err = httpsServer.ListenAndServeTLS("config/ssl/public.crt", "config/ssl/private.key") - if err != nil { - panic(err) + if config.Instance.HttpsEnabled != 2 { + httpsServer = &http.Server{ + Addr: fmt.Sprintf(":%d", HttpsPort), + Handler: session.Instance.LoadAndSave(mux), + ReadTimeout: time.Second * 60, + WriteTimeout: time.Second * 60, + ErrorLog: nullLog, + } + err = httpsServer.ListenAndServeTLS("config/ssl/public.crt", "config/ssl/private.key") + if err != nil { + panic(err) + } } }