Compare commits

..

5 Commits

Author SHA1 Message Date
db065073e2 修复一下页面配置更改时无法修改配置描述 2024-10-16 14:37:16 +08:00
befaa17426 📝更新readme 2024-10-15 17:26:10 +08:00
fae96eccf5 📝更新readme 2024-10-15 17:22:39 +08:00
4a0ec7bdc9 📝更新readme 2024-10-15 17:21:02 +08:00
331849522f 🎨将邮箱smtp配置改为系统当中配置 2024-10-15 17:16:22 +08:00
16 changed files with 58 additions and 37 deletions

View File

@@ -34,14 +34,6 @@ file:
accessSecret: # oss必填 accessSecret: # oss必填
bucketName: # oss必填 bucketName: # oss必填
# 邮件设置
mail:
host:
port:
user:
password:
skipTls:
# 一些系统配置 # 一些系统配置
wireguard: wireguard:
restartMode: DELAY restartMode: DELAY
@@ -78,14 +70,25 @@ services:
账户: admin 账户: admin
密码: admin123 密码: admin123
``` ```
## 配置示例
```text
1. 邮箱配置如下:
code: EMAIL_SMTP
配置项:
1. host: "xxxx.xxx"
2. port: "123"
3. user: "haha"
4. password: "haha123"
5. skipTls: "false"
```
## 示 ## 页面展
![img.png](img.png) ![img.png](document/img.png)
![img_1.png](img_1.png) ![img_1.png](document/img_1.png)
![img_7.png](img_7.png) ![img_7.png](document/img_7.png)
![img_8.png](img_8.png) ![img_8.png](document/img_8.png)
![img_2.png](img_2.png) ![img_2.png](document/img_2.png)
![img_3.png](img_3.png) ![img_3.png](document/img_3.png)
![img_4.png](img_4.png) ![img_4.png](document/img_4.png)
![img_5.png](img_5.png) ![img_5.png](document/img_5.png)
![img_6.png](img_6.png) ![img_6.png](document/img_6.png)

View File

@@ -7,6 +7,5 @@ type config struct {
Database *database `yaml:"database"` Database *database `yaml:"database"`
Cache *cache `yaml:"redis"` Cache *cache `yaml:"redis"`
File *file `yaml:"file"` File *file `yaml:"file"`
Mail *mail `yaml:"email"`
Wireguard *wireguard `yaml:"wireguard"` Wireguard *wireguard `yaml:"wireguard"`
} }

View File

@@ -1,9 +0,0 @@
package config
type mail struct {
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
User string `json:"user" yaml:"user"`
Password string `json:"password" yaml:"password"`
SkipTls bool `json:"skipTls" yaml:"skipTls"`
}

View File

Before

Width:  |  Height:  |  Size: 209 KiB

After

Width:  |  Height:  |  Size: 209 KiB

View File

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View File

@@ -243,7 +243,14 @@ func (ClientApi) Download(c *gin.Context) {
return return
} }
err = utils.Mail().SendMail(data.Email, fmt.Sprintf("客户端: %s", data.Name), "请查收附件", outPath) // 获取邮箱配置
emailConf, err := service.Setting().GetByCode("EMAIL_SMTP")
if err != nil {
response.R(c).FailedWithError("获取邮箱配置失败请先到设置页面的【其他】里面添加code为【EMAIL_SMTP】的具体配置")
return
}
err = utils.Mail(emailConf).SendMail(data.Email, fmt.Sprintf("客户端: %s", data.Name), "请查收附件", outPath)
if err != nil { if err != nil {
response.R(c).FailedWithError("发送邮件失败") response.R(c).FailedWithError("发送邮件失败")
return return

View File

@@ -90,6 +90,17 @@ func (s setting) GetAllSetting(blackList []string) (data []vo.SettingItem, err e
return return
} }
// GetByCode
// @description: 获取指定code的配置
// @receiver s
// @param code
// @return data
// @return err
func (s setting) GetByCode(code string) (data *model.Setting, err error) {
err = s.Model(&model.Setting{}).Where("code = ?", code).Take(&data).Error
return
}
// Export // Export
// @description: 导出 // @description: 导出
// @receiver s // @receiver s

View File

@@ -2,28 +2,35 @@ package utils
import ( import (
"crypto/tls" "crypto/tls"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/jordan-wright/email" "github.com/jordan-wright/email"
"github.com/spf13/cast"
"mime" "mime"
"net/smtp" "net/smtp"
"net/textproto" "net/textproto"
"path/filepath" "path/filepath"
"wireguard-ui/config" "wireguard-ui/model"
) )
type mail struct { type mail struct {
*email.Email *email.Email
addr string addr string
auth smtp.Auth auth smtp.Auth
conf map[string]string
} }
func Mail() *mail { func Mail(conf *model.Setting) *mail {
// 解析配置文件
var mailConf = make(map[string]string)
_ = json.Unmarshal([]byte(conf.Data), &mailConf)
var m mail var m mail
em := email.NewEmail() em := email.NewEmail()
m.Email = em m.Email = em
m.auth = smtp.PlainAuth("", config.Config.Mail.User, config.Config.Mail.Password, config.Config.Mail.Host) m.auth = smtp.PlainAuth("", mailConf["user"], mailConf["password"], mailConf["host"])
m.addr = fmt.Sprintf("%s:%d", config.Config.Mail.Host, config.Config.Mail.Port) m.addr = fmt.Sprintf("%s:%s", mailConf["host"], mailConf["port"])
m.conf = mailConf
return &m return &m
} }
@@ -47,7 +54,7 @@ func (m *mail) VerifyConfig() (err error) {
// @param attacheFilePath // @param attacheFilePath
// @return err // @return err
func (m *mail) SendMail(to, subject, content, attacheFilePath string) (err error) { func (m *mail) SendMail(to, subject, content, attacheFilePath string) (err error) {
m.From = fmt.Sprintf("wg-dashboard <%s>", config.Config.Mail.User) m.From = fmt.Sprintf("wg-dashboard <%s>", m.conf["user"])
m.To = []string{to} m.To = []string{to}
m.Subject = subject m.Subject = subject
m.Text = []byte(content) m.Text = []byte(content)
@@ -61,13 +68,13 @@ func (m *mail) SendMail(to, subject, content, attacheFilePath string) (err error
atch.Header = emHeader atch.Header = emHeader
} }
if config.Config.Mail.SkipTls { if cast.ToBool(m.conf["skipTls"]) {
return m.Send(m.addr, m.auth) return m.Send(m.addr, m.auth)
} }
tlsConfig := &tls.Config{} tlsConfig := &tls.Config{}
tlsConfig.InsecureSkipVerify = config.Config.Mail.SkipTls tlsConfig.InsecureSkipVerify = cast.ToBool(m.conf["skipTls"])
tlsConfig.ServerName = config.Config.Mail.Host tlsConfig.ServerName = m.conf["host"]
return m.SendWithTLS(m.addr, m.auth, tlsConfig) return m.SendWithTLS(m.addr, m.auth, tlsConfig)
} }

View File

@@ -174,6 +174,9 @@
<n-radio :value="false" :checked="editFormModel.data[index] === false" @change="editFormModel.data[index] = false"></n-radio> <n-radio :value="false" :checked="editFormModel.data[index] === false" @change="editFormModel.data[index] = false"></n-radio>
</n-radio-group> </n-radio-group>
</n-form-item> </n-form-item>
<n-form-item label="配置描述">
<n-input v-model:value="editFormModel.describe" />
</n-form-item>
<n-form-item> <n-form-item>
<n-button type="info" @click="updateSetting">确认</n-button> <n-button type="info" @click="updateSetting">确认</n-button>
</n-form-item> </n-form-item>