forked from domainr/epp
/
info.go
94 lines (81 loc) · 2.72 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package epp
import (
"bytes"
"encoding/xml"
"strconv"
"github.com/nbio/xx"
)
// CheckDomain queries the EPP server for the availability status of one or more domains.
func (c *Conn) DomainInfo(domain string) (*DomainInfoResponse, error) {
err := encodeDomainInfo(&c.buf, domain)
if err != nil {
return nil, err
}
err = c.flushDataUnit()
if err != nil {
return nil, err
}
var res response_
err = c.readResponse(&res)
if err != nil {
return nil, err
}
return &res.DomainInfoResponse, nil
}
func encodeDomainInfo(buf *bytes.Buffer, domain string) error {
buf.Reset()
buf.WriteString(xmlCommandPrefix)
buf.WriteString(`<info>`)
buf.WriteString(`<domain:info xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">`)
buf.WriteString(`<domain:name>`)
xml.EscapeText(buf, []byte(domain))
buf.WriteString(`</domain:name>`)
buf.WriteString(`</domain:info>`)
buf.WriteString(`</info>`)
buf.WriteString(xmlCommandSuffix)
return nil
}
type DomainInfoResponse struct {
Nameservers []string
Expiry string
DSRecords []DSRecord
}
func init() {
// Default EPP check data
path := "epp > response > resData > " + ObjDomain + " infData"
scanResponse.MustHandleCharData(path+"> ns > hostObj", func(c *xx.Context) error {
di := &c.Value.(*response_).DomainInfoResponse
di.Nameservers = append(di.Nameservers, string(c.CharData))
return nil
})
scanResponse.MustHandleCharData(path+">exDate", func(c *xx.Context) error {
c.Value.(*response_).DomainInfoResponse.Expiry = string(c.CharData)
return nil
})
path = "epp > response > extension > urn:ietf:params:xml:ns:secDNS-1.1 infData"
scanResponse.MustHandleStartElement(path+">dsData", func(c *xx.Context) error {
dsd := &c.Value.(*response_).DomainInfoResponse
dsd.DSRecords = append(dsd.DSRecords, DSRecord{})
return nil
})
scanResponse.MustHandleCharData(path+">dsData>keyTag", func(c *xx.Context) error {
dsrecords := c.Value.(*response_).DomainInfoResponse.DSRecords
dsrecords[len(dsrecords)-1].KeyTag, _ = strconv.Atoi(string(c.CharData))
return nil
})
scanResponse.MustHandleCharData(path+">dsData>alg", func(c *xx.Context) error {
dsrecords := c.Value.(*response_).DomainInfoResponse.DSRecords
dsrecords[len(dsrecords)-1].Algorithm, _ = strconv.Atoi(string(c.CharData))
return nil
})
scanResponse.MustHandleCharData(path+">dsData>digestType", func(c *xx.Context) error {
dsrecords := c.Value.(*response_).DomainInfoResponse.DSRecords
dsrecords[len(dsrecords)-1].DigestType, _ = strconv.Atoi(string(c.CharData))
return nil
})
scanResponse.MustHandleCharData(path+">dsData>digest", func(c *xx.Context) error {
dsrecords := c.Value.(*response_).DomainInfoResponse.DSRecords
dsrecords[len(dsrecords)-1].Digest = string(c.CharData)
return nil
})
}