feat(signal): 触发密钥验证
This commit is contained in:
@@ -1,3 +1,41 @@
|
||||
# goodBaby
|
||||
|
||||
摇篮系统
|
||||
|
||||
## 他会做什么
|
||||
|
||||
1. 接受 singnal 请求
|
||||
2. 当定时器超时(过长时间没有收到请求)时,触发 `trigger` 函数
|
||||
3. 发送消息到QQ
|
||||
4. 发送邮件
|
||||
5. 将 Github 上的遗言仓库设置为 public
|
||||
|
||||
## 配置
|
||||
|
||||
参照 config.example.json 修改 config.json
|
||||
|
||||
```json
|
||||
{
|
||||
"signal_secret": "", // 发送 signal请求时需要的密钥
|
||||
"debug": false, // debug 模式
|
||||
"disconnect_duration": 5, // 失连时间,超出后会触发系统
|
||||
"cat_bot_url": "", // CatBot 的 webhook地址(https://github.com/ssdomei232/CatBot)
|
||||
"cat_bot_key": "", // CatBot 的 key
|
||||
"qq_send_group": [], // 要发送QQ消息的群号
|
||||
"qq_msg": "", // 要附加的QQ消息
|
||||
"mail_list": [], // 要发送的邮箱
|
||||
"mail_title": "摇篮系统已触发", // 邮件标题
|
||||
"smtp_config": { // 邮件服务器配置
|
||||
"host": "",
|
||||
"port": 465,
|
||||
"user": "",
|
||||
"pass": ""
|
||||
},
|
||||
"mail_content": "", // 要附加的邮件内容
|
||||
"github_config": { // Github 配置
|
||||
"owner": "",
|
||||
"repos": [""],
|
||||
"token": "ghp_xxxx"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
+7
-1
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"signal_secret": "",
|
||||
"debug": false,
|
||||
"disconnect_duration": 5,
|
||||
"cat_bot_url": "",
|
||||
@@ -13,5 +14,10 @@
|
||||
"user": "",
|
||||
"pass": ""
|
||||
},
|
||||
"mail_content": ""
|
||||
"mail_content": "",
|
||||
"github_config": {
|
||||
"owner": "",
|
||||
"repos": [""],
|
||||
"token": "ghp_xxxx"
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
SignalSecret string `json:"signal_secret"`
|
||||
Debug bool `json:"debug"`
|
||||
DisconnectDuration int `json:"disconnect_duration"` // Hours
|
||||
CatBotUrl string `json:"cat_bot_url"`
|
||||
|
||||
@@ -15,7 +15,6 @@ func Github() {
|
||||
}
|
||||
|
||||
for _, repo := range config.GithubConfig.Repos {
|
||||
// 添加重试机制
|
||||
maxRetries := 10
|
||||
for attempt := range maxRetries {
|
||||
err := pkg.MakeRepositoryPublic(config.GithubConfig.Owner, repo, config.GithubConfig.Token)
|
||||
|
||||
@@ -38,13 +38,27 @@ func trigger() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
config, err := configs.GetConfig()
|
||||
if err != nil {
|
||||
log.Printf("获取配置文件失败: %v", err)
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
r.GET("/signal", func(c *gin.Context) {
|
||||
secret := c.Query("secret")
|
||||
if secret != config.SignalSecret {
|
||||
c.JSON(403, gin.H{
|
||||
"code": 403,
|
||||
"message": "secret error",
|
||||
})
|
||||
return
|
||||
}
|
||||
timer.Reset(duration)
|
||||
c.JSON(200, gin.H{
|
||||
"code": 200,
|
||||
"message": "ok",
|
||||
})
|
||||
log.Println("触发信号")
|
||||
})
|
||||
r.Run(":8088")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user