]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/account/DomainAddForm.java
Move the "dbObject"s to their own package.
[gigi.git] / src / org / cacert / gigi / pages / account / DomainAddForm.java
index 809425e4048f4e73aeca58df13c8fb4abdc99acf..65e168c4f8ab5ecf671b67a833854418e9f96490 100644 (file)
@@ -1,19 +1,23 @@
 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;
 
-import org.cacert.gigi.Domain;
+import org.cacert.gigi.Gigi;
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.User;
+import org.cacert.gigi.dbObjects.Domain;
+import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.Form;
 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 +30,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 +46,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);
+            }
+            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) {
+                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);
+                    }
+
+                }
+            }
+            Gigi.notifyPinger();
+
             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 +100,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);