mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
add notify model, add send notify method
This commit is contained in:
parent
9d6efbc806
commit
ccbdf4e31d
10
settings.go
10
settings.go
@ -12,6 +12,15 @@ type Domain struct {
|
||||
SubDomains []string `json:"sub_domains"`
|
||||
}
|
||||
|
||||
type Notify struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
SMTPServer string `json:"smtp_server"`
|
||||
SendTo string `json:"send_to"`
|
||||
Port int `json:"port"`
|
||||
Account string `json:"account"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// Settings struct
|
||||
type Settings struct {
|
||||
Provider string `json:"provider"`
|
||||
@ -22,6 +31,7 @@ type Settings struct {
|
||||
IPUrl string `json:"ip_url"`
|
||||
LogPath string `json:"log_path"`
|
||||
Socks5Proxy string `json:"socks5_proxy"`
|
||||
Notify Notify `json:"notify"`
|
||||
}
|
||||
|
||||
// LoadSettings -- Load settings from config file
|
||||
|
19
utils.go
19
utils.go
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
"gopkg.in/gomail.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -102,3 +103,21 @@ func LoadCurrentIP() string {
|
||||
|
||||
return strings.Replace(string(content), "\n", "", -1)
|
||||
}
|
||||
|
||||
// SendNotify sends mail notify if IP is changed
|
||||
func SendNotify(configuration *Settings, currentIP string) error {
|
||||
m := gomail.NewMessage()
|
||||
|
||||
m.SetHeader("From", configuration.Notify.Account)
|
||||
m.SetHeader("To", configuration.Notify.SendTo)
|
||||
m.SetHeader("Subject", "GoDNS Notification")
|
||||
m.SetBody("text/html", "")
|
||||
|
||||
d := gomail.NewPlainDialer(configuration.Notify.SMTPServer, configuration.Notify.Port, configuration.Notify.Account, configuration.Notify.Password)
|
||||
|
||||
// Send the email config by sendlist .
|
||||
if err := d.DialAndSend(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user