]> WPIA git - gigi.git/blob - src/club/wpia/gigi/ping/DNSPinger.java
upd: rename package name and all references to it
[gigi.git] / src / club / wpia / gigi / ping / DNSPinger.java
1 package club.wpia.gigi.ping;
2
3 import java.util.Arrays;
4 import java.util.List;
5
6 import javax.naming.NamingException;
7
8 import club.wpia.gigi.dbObjects.CertificateOwner;
9 import club.wpia.gigi.dbObjects.Domain;
10 import club.wpia.gigi.util.DNSUtil;
11 import club.wpia.gigi.util.SystemKeywords;
12
13 public class DNSPinger extends DomainPinger {
14
15     @Override
16     public void ping(Domain domain, String expToken, CertificateOwner u, int confId) {
17         String[] tokenParts = expToken.split(":", 2);
18         List<String> nameservers;
19         try {
20             nameservers = Arrays.asList(DNSUtil.getNSNames(domain.getSuffix()));
21         } catch (NamingException e) {
22             enterPingResult(confId, "error", "No authorative nameserver found.", null);
23             return;
24         }
25         StringBuffer result = new StringBuffer();
26         result.append("failed: ");
27         boolean failed = nameservers.isEmpty();
28         nameservers:
29         for (String NS : nameservers) {
30             boolean found = false;
31             try {
32                 for (String token : DNSUtil.getTXTEntries(tokenParts[0] + "." + SystemKeywords.DNS_PREFIX + "._auth." + domain.getSuffix(), NS)) {
33                     if (token.isEmpty()) {
34                         continue;
35                     }
36                     found = true;
37                     if (token.equals(tokenParts[1])) {
38                         continue nameservers;
39                     }
40                 }
41             } catch (NamingException e) {
42                 found = false;
43             }
44             result.append(NS);
45             if (found) {
46                 result.append(" DIFFER;");
47             } else {
48                 result.append(" EMPTY;");
49             }
50             failed = true;
51
52         }
53         if ( !failed) {
54             enterPingResult(confId, PING_SUCCEDED, "", null);
55         } else {
56             enterPingResult(confId, "error", result.toString(), null);
57         }
58     }
59 }