]> WPIA git - gigi.git/commitdiff
ADD: store pingconfig into the database.
authorFelix Dörre <felix@dogcraft.de>
Sun, 24 Aug 2014 00:59:42 +0000 (02:59 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sun, 24 Aug 2014 02:14:22 +0000 (04:14 +0200)
doc/tableStructure.sql
src/org/cacert/gigi/Domain.java
src/org/cacert/gigi/pages/account/DomainAddForm.java
src/org/cacert/gigi/pages/account/DomainAddForm.templ
src/org/cacert/gigi/ping/SSLPinger.java

index b2972841bd2e63a97f8dc370056a10390433b870..2e4e5c0485cd5c35d22e6509ad60d88bee46b352 100644 (file)
@@ -62,11 +62,31 @@ CREATE TABLE `emails` (
   KEY `email` (`email`)
 ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;
 
-DROP TABLE IF EXISTS `pinglog`;
-CREATE TABLE `pinglog` (
+DROP TABLE IF EXISTS `emailPinglog`;
+CREATE TABLE `emailPinglog` (
   `when` datetime NOT NULL,
   `uid` int(11) NOT NULL,
-  `email` varchar(255) NOT NULL,
+  `emailid` int(11) NOT NULL,
+  `type` enum('fast', 'active') NOT NULL,
+  `status` enum('open', 'success', 'failed') NOT NULL,
+  `result` varchar(255) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+DROP TABLE IF EXISTS `pingconfig`;
+CREATE TABLE `pingconfig` (
+  `domainid` int(11) NOT NULL,
+  `type` enum('email', 'ssl', 'http', 'dns') NOT NULL,
+  `info` varchar(255) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+
+DROP TABLE IF EXISTS `domainPinglog`;
+CREATE TABLE `domainPinglog` (
+  `when` datetime NOT NULL,
+  `uid` int(11) NOT NULL,
+  `domainid` int(11) NOT NULL,
+  `type` enum('email', 'ssl', 'http', 'dns') NOT NULL,
+  `status` enum('open', 'success', 'failed') NOT NULL,
   `result` varchar(255) NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
index 538081d8d37143f3e924c2579d57162894d9996c..89a3d2b6a021c6cd2e38865184aa5950ee3d8112 100644 (file)
@@ -104,4 +104,15 @@ 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);
+        }
+    }
 }
index 809425e4048f4e73aeca58df13c8fb4abdc99acf..edf729e57e54923dbf4b6f299a0c8c6b3f511b6b 100644 (file)
@@ -1,6 +1,8 @@
 package org.cacert.gigi.pages.account;
 
 import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
@@ -14,6 +16,7 @@ import org.cacert.gigi.output.template.IterableDataset;
 import org.cacert.gigi.output.template.OutputableArrayIterable;
 import org.cacert.gigi.output.template.Template;
 import org.cacert.gigi.pages.Page;
+import org.cacert.gigi.ping.SSLPinger;
 import org.cacert.gigi.util.RandomToken;
 
 public class DomainAddForm extends Form {
@@ -26,6 +29,8 @@ public class DomainAddForm extends Form {
 
     private String tokenValue = RandomToken.generateToken(16);
 
+    private static final int MAX_SSL_TESTS = 4;
+
     public DomainAddForm(HttpServletRequest hsr, User target) {
         super(hsr);
         this.target = target;
@@ -40,7 +45,39 @@ public class DomainAddForm extends Form {
             }
             Domain d = new Domain(target, parameter);
             d.insert();
+            if (req.getParameter("emailType") != null) {
+                String mail = AUTHORATIVE_EMAILS[Integer.parseInt(req.getParameter("email"))];
+                d.addPing("email", mail + "@" + d.getSuffix());
+            }
+            if (req.getParameter("DNSType") != null) {
+                d.addPing("dns", tokenName + ":" + tokenValue);
+            }
+            if (req.getParameter("HTTPType") != null) {
+                d.addPing("http", tokenName + ":" + tokenValue);
+            }
+            if (req.getParameter("SSLType") != null) {
+                System.out.println("ssl");
+                List<String> types = Arrays.asList(SSLPinger.TYPES);
+                for (int i = 0; i < MAX_SSL_TESTS; i++) {
+                    String type = req.getParameter("ssl-type-" + i);
+                    String port = req.getParameter("ssl-port-" + i);
+                    if (type == null || port == null || port.equals("")) {
+                        continue;
+                    }
+                    int portInt = Integer.parseInt(port);
+                    if ("direct".equals(type)) {
+                        d.addPing("ssl", port);
+                    } else if (types.contains(type)) {
+                        d.addPing("ssl", portInt + ":" + type);
+                    }
+
+                }
+            }
+
             return true;
+        } catch (NumberFormatException e) {
+            new GigiApiException("A number could not be parsed").format(out, Page.getLanguage(req));
+            return false;
         } catch (GigiApiException e) {
             e.format(out, Page.getLanguage(req));
             return false;
@@ -62,7 +99,7 @@ public class DomainAddForm extends Form {
 
             @Override
             public boolean next(Language l, Map<String, Object> vars) {
-                if (counter >= 4) {
+                if (counter >= MAX_SSL_TESTS) {
                     return false;
                 }
                 vars.put("i", counter);
index 4a6177f66aac70c771e22dee32645c33b3ffeaa0..1f83ea1302b37e22dfc755f63a33000c627b3742 100644 (file)
@@ -35,7 +35,7 @@
     <td>
         Please insert the following DNS TXT entry into the SOA-file of your domain:<br/>
         <pre>
-        cacert-<?=$tokenName?> IN      TXT     "<?=$tokenValue?>"
+        cacert-<?=$tokenName?> IN      TXT     <?=$tokenValue?>
         </pre>
     </td>
   </tr>
index d6ebe71c2a3b3f3dd60f8463f82a6f51097202fe..32434079a3e477c7a7d8f8e138c01a8088f67156 100644 (file)
@@ -22,6 +22,10 @@ import javax.security.cert.X509Certificate;
 
 public class SSLPinger extends DomainPinger {
 
+    public static final String[] TYPES = new String[] {
+            "xmpp", "server-xmpp", "smtp", "imap"
+    };
+
     @Override
     public void ping(String domain, String configuration, String expToken) {
         try {