]> 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 246dbc145ff8152b13e0021b30b8b1a09074ec59..bcc66beb7ea826d31a7fd1ffb86437cba395b474 100644 (file)
@@ -8,14 +8,14 @@ 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 `domain` WHERE id=? AND deleted IS NULL");
+        PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT memid, domain FROM `domains` WHERE id=? AND deleted IS NULL");
         ps.setInt(1, id);
 
         ResultSet rs = ps.executeQuery();
@@ -36,7 +36,7 @@ public class Domain {
 
     private static void checkInsert(String suffix) throws GigiApiException {
         try {
-            PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT 1 FROM `domain` WHERE (domain=RIGHT(?,LENGTH(domain))  OR RIGHT(domain,LENGTH(?))=?) AND deleted IS NULL");
+            PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT 1 FROM `domains` WHERE (domain=RIGHT(?,LENGTH(domain))  OR RIGHT(domain,LENGTH(?))=?) AND deleted IS NULL");
             ps.setString(1, suffix);
             ps.setString(2, suffix);
             ps.setString(3, suffix);
@@ -58,7 +58,7 @@ public class Domain {
         synchronized (Domain.class) {
             checkInsert(suffix);
             try {
-                PreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domain` SET memid=?, domain=?");
+                PreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?");
                 ps.setInt(1, owner.getId());
                 ps.setString(2, suffix);
                 ps.execute();
@@ -74,7 +74,7 @@ public class Domain {
             throw new GigiApiException("not inserted.");
         }
         try {
-            PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `domain` SET deleted=CURRENT_TIMESTAMP WHERE id=?");
+            PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `domains` SET deleted=CURRENT_TIMESTAMP WHERE id=?");
             ps.setInt(1, id);
             ps.execute();
         } catch (SQLException e) {
@@ -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;
+    }
 }