dns.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package setup
  2. import (
  3. "fmt"
  4. "github.com/Jinnrry/pmail/i18n"
  5. "github.com/Jinnrry/pmail/services/auth"
  6. "github.com/Jinnrry/pmail/utils/context"
  7. "github.com/Jinnrry/pmail/utils/errors"
  8. "github.com/Jinnrry/pmail/utils/ip"
  9. )
  10. type DNSItem struct {
  11. Type string `json:"type"`
  12. Host string `json:"host"`
  13. Value string `json:"value"`
  14. TTL int `json:"ttl"`
  15. Tips string `json:"tips"`
  16. }
  17. func GetDNSSettings(ctx *context.Context) (map[string][]*DNSItem, error) {
  18. configData, err := ReadConfig()
  19. if err != nil {
  20. return nil, errors.Wrap(err)
  21. }
  22. ret := make(map[string][]*DNSItem)
  23. for _, domain := range configData.Domains {
  24. ret[domain] = []*DNSItem{
  25. {Type: "A", Host: "smtp", Value: ip.GetIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
  26. {Type: "A", Host: "pop", Value: ip.GetIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
  27. {Type: "A", Host: "@", Value: ip.GetIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
  28. {Type: "MX", Host: "@", Value: fmt.Sprintf("smtp.%s", domain), TTL: 3600},
  29. {Type: "TXT", Host: "@", Value: "v=spf1 a mx ~all", TTL: 3600},
  30. {Type: "TXT", Host: "default._domainkey", Value: auth.DkimGen(), TTL: 3600},
  31. }
  32. }
  33. return ret, nil
  34. }