From: Felix Dörre Date: Sun, 24 Aug 2014 00:59:42 +0000 (+0200) Subject: ADD: store pingconfig into the database. X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=12064eb9e794b40506ef94e27b7aa2f55ebd9ced ADD: store pingconfig into the database. --- diff --git a/doc/tableStructure.sql b/doc/tableStructure.sql index b2972841..2e4e5c04 100644 --- a/doc/tableStructure.sql +++ b/doc/tableStructure.sql @@ -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; diff --git a/src/org/cacert/gigi/Domain.java b/src/org/cacert/gigi/Domain.java index 538081d8..89a3d2b6 100644 --- a/src/org/cacert/gigi/Domain.java +++ b/src/org/cacert/gigi/Domain.java @@ -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); + } + } } diff --git a/src/org/cacert/gigi/pages/account/DomainAddForm.java b/src/org/cacert/gigi/pages/account/DomainAddForm.java index 809425e4..edf729e5 100644 --- a/src/org/cacert/gigi/pages/account/DomainAddForm.java +++ b/src/org/cacert/gigi/pages/account/DomainAddForm.java @@ -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 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 vars) { - if (counter >= 4) { + if (counter >= MAX_SSL_TESTS) { return false; } vars.put("i", counter); diff --git a/src/org/cacert/gigi/pages/account/DomainAddForm.templ b/src/org/cacert/gigi/pages/account/DomainAddForm.templ index 4a6177f6..1f83ea13 100644 --- a/src/org/cacert/gigi/pages/account/DomainAddForm.templ +++ b/src/org/cacert/gigi/pages/account/DomainAddForm.templ @@ -35,7 +35,7 @@ Please insert the following DNS TXT entry into the SOA-file of your domain:
-        cacert-	IN	TXT	""
+        cacert-	IN	TXT	
         
diff --git a/src/org/cacert/gigi/ping/SSLPinger.java b/src/org/cacert/gigi/ping/SSLPinger.java index d6ebe71c..32434079 100644 --- a/src/org/cacert/gigi/ping/SSLPinger.java +++ b/src/org/cacert/gigi/ping/SSLPinger.java @@ -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 {