]> 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 0adf6a4c2d31683f3b3da15a4299d7c0f48ff299..bcc66beb7ea826d31a7fd1ffb86437cba395b474 100644 (file)
@@ -8,11 +8,11 @@ import org.cacert.gigi.database.DatabaseConnection;
 
 public class Domain {
 
-    User owner;
+    private User owner;
 
-    String suffix;
+    private String suffix;
 
-    int id;
+    private int id;
 
     public Domain(int id) throws SQLException {
         PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT memid, domain FROM `domains` WHERE id=? AND deleted IS NULL");
@@ -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;
+    }
 }