]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/Domain.java
UPD: show the "verified"-status primitive-like for domains.
[gigi.git] / src / org / cacert / gigi / Domain.java
index 538081d8d37143f3e924c2579d57162894d9996c..bcc66beb7ea826d31a7fd1ffb86437cba395b474 100644 (file)
@@ -104,4 +104,38 @@ public class Domain {
         }
     }
 
+    public void addPing(String type, String config) throws GigiApiException {
+        try {
+            PreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO pingconfig SET domainid=?, type=?, info=?");
+            ps.setInt(1, id);
+            ps.setString(2, type);
+            ps.setString(3, config);
+            ps.execute();
+        } catch (SQLException e) {
+            throw new GigiApiException(e);
+        }
+    }
+
+    public void verify(String hash) throws GigiApiException {
+        try {
+            PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE domainPinglog SET state='success' WHERE challenge=? AND configId IN (SELECT id FROM pingconfig WHERE domainId=?)");
+            ps.setString(1, hash);
+            ps.setInt(2, id);
+            ps.executeUpdate();
+        } catch (SQLException e) {
+            throw new GigiApiException(e);
+        }
+    }
+
+    public boolean isVerified() {
+        try {
+            PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT 1 FROM domainPinglog INNER JOIN pingconfig ON pingconfig.id=domainPinglog.configId WHERE domainid=? AND state='success'");
+            ps.setInt(1, id);
+            ResultSet rs = ps.executeQuery();
+            return rs.next();
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
 }