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