This commit is contained in:
jinnrry 2023-08-13 14:00:06 +08:00
parent 09cdf3e697
commit f2a943f9df
5 changed files with 44 additions and 16 deletions

View File

@ -30,7 +30,10 @@ PMail是一个追求极简部署流程、极致资源占用的个人域名邮箱
### 4、自动SSL证书 ### 4、自动SSL证书
实现了ACME协议,程序将自动获取并更新Let’s Encrypt证书。 实现了ACME协议,程序将自动获取并更新Let’s
Encrypt证书。默认情况下,会为web后台也生成ssl证书,让后台使用https访问,如果你有自己的网关层,不需要https的话,在配置文件中将`httpsEnabled`
设置为`2`,这样管理后台就不会使用https协议。(
注意:即使你不需要https,也请保证ssl证书文件路径正确,http协议虽然不使用证书了,但是smtp协议还需要证书)
## 其他 ## 其他

View File

@ -11,7 +11,7 @@ import (
var IsInit bool var IsInit bool
type Config struct { type Config struct {
LogLevel string `json:"logLevel"` LogLevel string `json:"logLevel"` // 日志级别
Domain string `json:"domain"` Domain string `json:"domain"`
WebDomain string `json:"webDomain"` WebDomain string `json:"webDomain"`
DkimPrivateKeyPath string `json:"dkimPrivateKeyPath"` DkimPrivateKeyPath string `json:"dkimPrivateKeyPath"`
@ -25,6 +25,7 @@ type Config struct {
WeChatPushTemplateId string `json:"weChatPushTemplateId"` WeChatPushTemplateId string `json:"weChatPushTemplateId"`
WeChatPushUserId string `json:"weChatPushUserId"` WeChatPushUserId string `json:"weChatPushUserId"`
IsInit bool `json:"isInit"` IsInit bool `json:"isInit"`
HttpsEnabled int `json:"httpsEnabled"` //后台页面是否启用https,0默认(启用),1启用,2不启用
Tables map[string]string `json:"-"` Tables map[string]string `json:"-"`
TablesInitData map[string]string `json:"-"` TablesInitData map[string]string `json:"-"`
} }
@ -32,7 +33,7 @@ type Config struct {
//go:embed tables/* //go:embed tables/*
var tableConfig embed.FS var tableConfig embed.FS
const Version = "2.0.0" const Version = "2.0.1"
const DBTypeMySQL = "mysql" const DBTypeMySQL = "mysql"
const DBTypeSQLite = "sqlite" const DBTypeSQLite = "sqlite"

View File

@ -12,5 +12,6 @@
"weChatPushSecret": "", "weChatPushSecret": "",
"weChatPushTemplateId": "", "weChatPushTemplateId": "",
"weChatPushUserId": "", "weChatPushUserId": "",
"isInit": false "isInit": false,
"httpsEnabled": 0
} }

View File

@ -2,8 +2,11 @@ package http_server
import ( import (
"fmt" "fmt"
"io/fs"
"net/http" "net/http"
"pmail/config"
"pmail/controllers" "pmail/controllers"
"pmail/controllers/email"
"time" "time"
) )
@ -20,7 +23,26 @@ func HttpStop() {
func HttpStart() { func HttpStart() {
mux := http.NewServeMux() 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{ httpServer = &http.Server{
Addr: fmt.Sprintf(":%d", HttpPort), Addr: fmt.Sprintf(":%d", HttpPort),
Handler: mux, Handler: mux,

View File

@ -62,17 +62,18 @@ func HttpsStart() {
// go http server会打一堆没用的日志,写一个空的日志处理器,屏蔽掉日志输出 // go http server会打一堆没用的日志,写一个空的日志处理器,屏蔽掉日志输出
nullLog := olog.New(&nullWrite{}, "", olog.Ldate) nullLog := olog.New(&nullWrite{}, "", olog.Ldate)
httpsServer = &http.Server{ if config.Instance.HttpsEnabled != 2 {
Addr: fmt.Sprintf(":%d", HttpsPort), httpsServer = &http.Server{
Handler: session.Instance.LoadAndSave(mux), Addr: fmt.Sprintf(":%d", HttpsPort),
ReadTimeout: time.Second * 60, Handler: session.Instance.LoadAndSave(mux),
WriteTimeout: time.Second * 60, ReadTimeout: time.Second * 60,
ErrorLog: nullLog, WriteTimeout: time.Second * 60,
} ErrorLog: nullLog,
}
err = httpsServer.ListenAndServeTLS("config/ssl/public.crt", "config/ssl/private.key") err = httpsServer.ListenAndServeTLS("config/ssl/public.crt", "config/ssl/private.key")
if err != nil { if err != nil {
panic(err) panic(err)
}
} }
} }