dns.go 1.5 KB

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