jinnrry 2 年 前
コミット
eeb22b5ed3

+ 24 - 6
.github/workflows/release.yml

@@ -34,28 +34,46 @@ jobs:
       - name: Setup Go environment
       - name: Setup Go environment
         uses: actions/setup-go@v4.1.0
         uses: actions/setup-go@v4.1.0
         with:
         with:
-          go-version: '1.21'
           check-latest: true
           check-latest: true
       - name: Gen output name
       - name: Gen output name
-        run: echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
+        run: |
+            echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
+            echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
+            echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
+            echo "WEBFILENAME=web_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
       - name: Rename Windows File
       - name: Rename Windows File
         if: matrix.goos == 'windows'
         if: matrix.goos == 'windows'
-        run: echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
+        run: |
+            echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
+            echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
+            echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
+            echo "WEBFILENAME=web_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
       - name: FE Build
       - name: FE Build
         run: cd fe && yarn && yarn build
         run: cd fe && yarn && yarn build
       - name: BE Build
       - name: BE Build
         run: |
         run: |
             cd server && cp -rf ../fe/dist http_server
             cd server && cp -rf ../fe/dist http_server
-            go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o ${{ env.FILENAME }}  main.go
+            go build -ldflags "-s -w -X 'main.version=${{ VERSION }}' -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o ${{ env.FILENAME }}  main.go
+            go build -ldflags "-s -w" -o ${{ env.TGFILENAME }} hooks/telegram_push/telegram_push.go 
+            go build -ldflags "-s -w" -o ${{ env.WEBFILENAME }} hooks/web_push/web_push.go 
+            go build -ldflags "-s -w" -o ${{ env.WCFILENAME }} hooks/wechat_push/wechat_push.go
       - name: Upload files to Artifacts
       - name: Upload files to Artifacts
         uses: actions/upload-artifact@v3
         uses: actions/upload-artifact@v3
         with:
         with:
           name: ${{ env.FILENAME }}
           name: ${{ env.FILENAME }}
-          path: ./server/${{ env.FILENAME }}
+          path: |
+            ./server/${{ env.FILENAME }}
+            ./server/${{ env.TGFILENAME }}
+            ./server/${{ env.WEBFILENAME }}
+            ./server/${{ env.WCFILENAME }}
       - name: Upload binaries to release
       - name: Upload binaries to release
         uses: svenstaro/upload-release-action@v2
         uses: svenstaro/upload-release-action@v2
         with:
         with:
           repo_token: ${{ secrets.GITHUB_TOKEN }}
           repo_token: ${{ secrets.GITHUB_TOKEN }}
-          file: ./server/${{ env.FILENAME }}
+          file: |
+            ./server/${{ env.FILENAME }}
+            ./server/${{ env.TGFILENAME }}
+            ./server/${{ env.WEBFILENAME }}
+            ./server/${{ env.WCFILENAME }}
           tag: ${{ github.ref }}
           tag: ${{ github.ref }}
           file_glob: true
           file_glob: true

+ 6 - 1
Dockerfile

@@ -15,6 +15,9 @@ COPY --from=febuild /work/dist /work/http_server/dist
 
 
 RUN apk update && apk add git
 RUN apk update && apk add git
 RUN go build -ldflags "-X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
 RUN go build -ldflags "-X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
+RUN cd /work/hooks/telegram_push && go build -ldflags "-s -W" -o output/telegram_push main.go
+RUN cd /work/hooks/web_push && go build -ldflags "-s -W" -o output/web_push main.go
+RUN cd /work/hooks/wechat_push && go build -ldflags "-s -W" -o output/wechat_push main.go
 
 
 
 
 FROM alpine
 FROM alpine
@@ -30,6 +33,8 @@ RUN apk add --no-cache tzdata \
 
 
 
 
 COPY --from=serverbuild /work/pmail .
 COPY --from=serverbuild /work/pmail .
-
+COPY --from=serverbuild /work/hooks/telegram_push/output/* ./plugin/
+COPY --from=serverbuild /work/hooks/web_push/output/* ./plugin/
+COPY --from=serverbuild /work/hooks/wechat_push/output/* ./plugin/
 
 
 CMD /work/pmail
 CMD /work/pmail

+ 7 - 2
DockerfileGithubAction

@@ -5,7 +5,10 @@ WORKDIR /work
 COPY server .
 COPY server .
 
 
 RUN apk update && apk add git
 RUN apk update && apk add git
-RUN go build -ldflags "-X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
+RUN go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
+RUN cd /work/hooks/telegram_push && go build -ldflags "-s -W" -o output/telegram_push main.go
+RUN cd /work/hooks/web_push && go build -ldflags "-s -W" -o output/web_push main.go
+RUN cd /work/hooks/wechat_push && go build -ldflags "-s -W" -o output/wechat_push main.go
 
 
 
 
 FROM alpine
 FROM alpine
@@ -21,6 +24,8 @@ RUN apk add --no-cache tzdata \
 
 
 
 
 COPY --from=serverbuild /work/pmail .
 COPY --from=serverbuild /work/pmail .
-
+COPY --from=serverbuild /work/hooks/telegram_push/output/* ./plugin/
+COPY --from=serverbuild /work/hooks/web_push/output/* ./plugin/
+COPY --from=serverbuild /work/hooks/wechat_push/output/* ./plugin/
 
 
 CMD /work/pmail
 CMD /work/pmail

+ 5 - 7
Makefile

@@ -2,9 +2,7 @@ build: build_fe build_server telegram_push web_push wechat_push package
 
 
 clean:
 clean:
 	rm -rf output
 	rm -rf output
-	rm -rf server/hooks/telegram_push/output
-	rm -rf server/hooks/web_push/output
-	rm -rf server/hooks/wechat_push/output
+
 
 
 build_fe:
 build_fe:
 	cd fe && yarn && yarn build
 	cd fe && yarn && yarn build
@@ -41,11 +39,11 @@ package: clean
 	mkdir output
 	mkdir output
 	mv server/pmail* output/
 	mv server/pmail* output/
 	mkdir output/config
 	mkdir output/config
-	mkdir output/plugin
+	mkdir output/plugins
 	cp -r server/config/dkim output/config/
 	cp -r server/config/dkim output/config/
 	cp -r server/config/ssl output/config/
 	cp -r server/config/ssl output/config/
 	cp -r server/config/config.json output/config/
 	cp -r server/config/config.json output/config/
-	mv server/hooks/telegram_push/output/* output/plugin
-	mv server/hooks/web_push/output/* output/plugin
-	mv server/hooks/wechat_push/output/* output/plugin
+	mv server/hooks/telegram_push/output/* output/plugins
+	mv server/hooks/web_push/output/* output/plugins
+	mv server/hooks/wechat_push/output/* output/plugins
 	cp README.md output/
 	cp README.md output/

+ 11 - 21
README.md

@@ -71,19 +71,6 @@ configure.
 Check if your mailbox has completed all the security configuration. It is recommended to
 Check if your mailbox has completed all the security configuration. It is recommended to
 use [https://www.mail-tester.com/](https://www.mail-tester.com/) for checking.
 use [https://www.mail-tester.com/](https://www.mail-tester.com/) for checking.
 
 
-## 5、 WeChat Message Push
-
-Open the `config/config.json` file in the run directory, edit a few configuration items at the beginning of `weChatPush`
-and restart the service.
-
-## 6、Telegram Message Push
-
-Create bot and get token from [BotFather](https://t.me/BotFather)
-Open the `config/config.json` file in the run directory, edit a few configuration items at the beginning of `tg`and restart the service.
-
-## 7、WebHook Push
-
-Open the `config/config.json` file in the running directory, edit the webPushUrl and webPushToken (optional). After receiving an email, the email information will be posted to the hook address, and the token will also be placed in the body for easy verification. After configuring, restart the service.
 
 
 # Configuration file format description
 # Configuration file format description
 
 
@@ -102,14 +89,6 @@ Open the `config/config.json` file in the running directory, edit the webPushUrl
   "httpPort": 80, // http port . default 80
   "httpPort": 80, // http port . default 80
   "httpsPort": 443, // https port . default 443
   "httpsPort": 443, // https port . default 443
   "spamFilterLevel": 0,// Spam filter level, 0: no filter, 1: filtering when `spf` and `dkim` don't pass, 2: filtering when `spf` don't pass
   "spamFilterLevel": 0,// Spam filter level, 0: no filter, 1: filtering when `spf` and `dkim` don't pass, 2: filtering when `spf` don't pass
-  "weChatPushAppId": "", // wechat appid
-  "weChatPushSecret": "", // weChat  Secret
-  "weChatPushTemplateId": "", // weChat TemplateId
-  "weChatPushUserId": "", // weChat UserId
-  "tgChatId": "", // telegram chatid
-  "tgBotToken": "", // telegram  token
-  "webPushUrl": "", // webhook push URL
-  "webPushToken": "", // webhook push token
   "isInit": true // If false, it will enter the bootstrap process.
   "isInit": true // If false, it will enter the bootstrap process.
 }
 }
 ```
 ```
@@ -124,6 +103,16 @@ SMTP Server Address : smtp.[Your Domain]
 
 
 SMTP Port: 25/465(SSL)
 SMTP Port: 25/465(SSL)
 
 
+# Plugin
+
+[WeChat Push](server/hooks/wechat_push/README.md)
+
+[Telegram Push](server/hooks/wechat_push/README.md)
+
+[Web Push](server/hooks/wechat_push/README.md)
+
+
+
 # For Developer
 # For Developer
 
 
 ## Project Framework
 ## Project Framework
@@ -143,3 +132,4 @@ The code is in `server` folder.
 ## Plugin Development
 ## Plugin Development
 
 
 Reference this file. `server/hooks/wechat_push/wechat_push.go`
 Reference this file. `server/hooks/wechat_push/wechat_push.go`
+

+ 9 - 20
README_CN.md

@@ -77,18 +77,6 @@ PMail是一个追求极简部署流程、极致资源占用的个人域名邮箱
 
 
 建议找一下邮箱测试服务(比如[https://www.mail-tester.com/](https://www.mail-tester.com/))进行邮件得分检测,避免自己某些步骤漏配,导致发件进对方垃圾箱。
 建议找一下邮箱测试服务(比如[https://www.mail-tester.com/](https://www.mail-tester.com/))进行邮件得分检测,避免自己某些步骤漏配,导致发件进对方垃圾箱。
 
 
-## 5、微信推送
-
-打开运行目录下的 `config/config.json`文件,编辑 `weChatPush` 开头的几个配置项,重启服务即可。
-
-## 6、Telegram推送
-
-从 [BotFather](https://t.me/BotFather) 创建并获取令牌机器人。 打开运行目录下的 config/config.json 文件,编辑 `tg` 开头的几个配置项,重启服务即可。
-
-## 7、WebHook推送
-
-打开运行目录下的 `config/config.json`文件,编辑 webPushUrl 跟webPushToken (可选),接收到邮件后会往hook地址post发送邮件信息,token也会放在body中,方便需要的进行校验,配置完重启服务即可。
-
 # 配置文件说明
 # 配置文件说明
 
 
 ```json
 ```json
@@ -106,14 +94,6 @@ PMail是一个追求极简部署流程、极致资源占用的个人域名邮箱
   "spamFilterLevel": 0,// 垃圾邮件过滤级别,0不过滤、1 spf dkim 校验均失败时过滤,2 spf校验不通过时过滤
   "spamFilterLevel": 0,// 垃圾邮件过滤级别,0不过滤、1 spf dkim 校验均失败时过滤,2 spf校验不通过时过滤
   "httpPort": 80, // http 端口 . 默认 80
   "httpPort": 80, // http 端口 . 默认 80
   "httpsPort": 443, // https 端口 . 默认 443
   "httpsPort": 443, // https 端口 . 默认 443
-  "weChatPushAppId": "", // 微信推送appid
-  "weChatPushSecret": "", // 微信推送秘钥
-  "weChatPushTemplateId": "", // 微信推送模板id
-  "weChatPushUserId": "", // 微信推送用户id
-  "tgChatId": "", // telegram 推送chatid
-  "tgBotToken": "", // telegram 推送 token
-  "webPushUrl": "", // webhook 推送地址
-  "webPushToken": "", // webhook 推送 token
   "isInit": true // 为false的时候会进入安装引导流程 
   "isInit": true // 为false的时候会进入安装引导流程 
 }
 }
 ```
 ```
@@ -128,6 +108,15 @@ SMTP地址: smtp.[你的域名]
 
 
 SMTP端口: 25/465(SSL)
 SMTP端口: 25/465(SSL)
 
 
+
+# 插件
+
+[微信推送](server/hooks/wechat_push/README.md)
+
+[Telegram推送](server/hooks/wechat_push/README.md)
+
+[WebHook推送](server/hooks/wechat_push/README.md)
+
 # 参与开发
 # 参与开发
 
 
 ## 项目架构
 ## 项目架构

+ 15 - 0
server/hooks/telegram_push/README.md

@@ -0,0 +1,15 @@
+## How To Ues
+
+Create bot and get token from [BotFather](https://t.me/BotFather)
+
+Copy plugin binary file to `/plugins` 
+
+add config.json to `/plugins/config.com` like this:
+
+```json
+{
+  "tgChatId": "", // telegram  chatid
+  "tgBotToken": "", // telegram   token
+}
+
+```

+ 14 - 0
server/hooks/web_push/README.md

@@ -0,0 +1,14 @@
+## How To Ues
+
+
+Copy plugin binary file to `/plugins` 
+
+add config.json to `/plugins/config.com` like this:
+
+```json
+{
+  "webPushUrl": "", // webhook push URL
+  "webPushToken": "", // webhook push token
+}
+
+```

+ 15 - 0
server/hooks/wechat_push/README.md

@@ -0,0 +1,15 @@
+## How To Ues
+
+
+Copy plugin binary file to `/plugins` 
+
+add config.json to `/plugins/config.com` like this:
+
+```json
+{
+  "weChatPushAppId": "", // wechat appid
+  "weChatPushSecret": "", // weChat  Secret
+  "weChatPushTemplateId": "", // weChat TemplateId
+  "weChatPushUserId": "", // weChat UserId
+}
+```

+ 1 - 0
server/hooks/wechat_push/wechat_push.go

@@ -174,6 +174,7 @@ func NewWechatPushHook() *WeChatPushHook {
 
 
 }
 }
 
 
+// 插件将以独立进程运行,因此需要主函数。
 func main() {
 func main() {
 	framework.CreatePlugin(NewWechatPushHook()).Run()
 	framework.CreatePlugin(NewWechatPushHook()).Run()
 }
 }

+ 3 - 4
server/http_server/setup_server.go

@@ -1,11 +1,11 @@
 package http_server
 package http_server
 
 
 import (
 import (
+	"flag"
 	"fmt"
 	"fmt"
 	log "github.com/sirupsen/logrus"
 	log "github.com/sirupsen/logrus"
 	"io/fs"
 	"io/fs"
 	"net/http"
 	"net/http"
-	"pmail/config"
 	"pmail/controllers"
 	"pmail/controllers"
 	"time"
 	"time"
 )
 )
@@ -27,9 +27,8 @@ func SetupStart() {
 	mux.HandleFunc("/.well-known/", controllers.AcmeChallenge)
 	mux.HandleFunc("/.well-known/", controllers.AcmeChallenge)
 
 
 	HttpPort := 80
 	HttpPort := 80
-	if config.Instance != nil && config.Instance.HttpPort > 0 {
-		HttpPort = config.Instance.HttpPort
-	}
+	flag.IntVar(&HttpPort, "p", 80, "初始化阶段Http服务端口")
+	flag.Parse()
 	log.Infof("HttpServer Start On Port :%d", HttpPort)
 	log.Infof("HttpServer Start On Port :%d", HttpPort)
 	setupServer = &http.Server{
 	setupServer = &http.Server{
 		Addr:         fmt.Sprintf(":%d", HttpPort),
 		Addr:         fmt.Sprintf(":%d", HttpPort),

+ 2 - 1
server/main.go

@@ -38,6 +38,7 @@ var (
 	gitHash   string
 	gitHash   string
 	buildTime string
 	buildTime string
 	goVersion string
 	goVersion string
+	version   string
 )
 )
 
 
 func main() {
 func main() {
@@ -74,7 +75,7 @@ func main() {
 	}
 	}
 
 
 	log.Infoln("***************************************************")
 	log.Infoln("***************************************************")
-	log.Infof("***\tServer Start Success Version:%s\n", config.Version)
+	log.Infof("***\tServer Start Success Version:%s\n", version)
 	log.Infof("***\tGit Commit Hash: %s ", gitHash)
 	log.Infof("***\tGit Commit Hash: %s ", gitHash)
 	log.Infof("***\tBuild TimeStamp: %s ", buildTime)
 	log.Infof("***\tBuild TimeStamp: %s ", buildTime)
 	log.Infof("***\tBuild GoLang Version: %s ", goVersion)
 	log.Infof("***\tBuild GoLang Version: %s ", goVersion)