dns.go 1.4 KB

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