From 7a304904824126ecfc9e4cad5bf9bcd91e1b45f7 Mon Sep 17 00:00:00 2001
From: zzz
Date: Wed, 19 May 2010 18:55:53 +0000
Subject: [PATCH] more validation
---
apps/susidns/src/css.css | 24 ++++++++++
.../src/i2p/susi/dns/AddressbookBean.java | 45 +++++++++++++++----
apps/susidns/src/jsp/addressbook.jsp | 5 ++-
apps/susidns/src/jsp/config.jsp | 2 +-
apps/susidns/src/jsp/subscriptions.jsp | 2 +-
history.txt | 4 ++
.../src/net/i2p/router/RouterVersion.java | 2 +-
7 files changed, 71 insertions(+), 13 deletions(-)
diff --git a/apps/susidns/src/css.css b/apps/susidns/src/css.css
index fae4f94a0b..14ab494b23 100644
--- a/apps/susidns/src/css.css
+++ b/apps/susidns/src/css.css
@@ -150,3 +150,27 @@ input[type=submit]:hover {
}
+input[type=reset] {
+ border: 1px outset #999;
+ background: #ddf;
+ color: #001;
+ margin: 5px;
+ font: bold 8pt "Lucida Sans Unicode", "Bitstream Vera Sans", Verdana, Tahoma, Helvetica, sans-serif;
+ padding: 1px 2px;
+ text-decoration: none;
+ min-width: 110px;
+ border-radius: 4px;
+ -moz-border-radius: 4px;
+ -khtml-border-radius: 4px;
+ -moz-box-shadow: inset 0px 2px 8px 0px #fff;
+ color: #006;
+ opacity: 0.9;
+}
+
+input[type=reset]:hover {
+ background: #22a;
+ color: #fff;
+ border: 1px solid #f60;
+ opacity: 1.0;
+ -moz-box-shadow: inset 0px 0px 0px 1px #fff;
+}
diff --git a/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java b/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java
index 443293886f..63c4db85ac 100644
--- a/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java
+++ b/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java
@@ -35,7 +35,9 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.Properties;
+import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper;
+import net.i2p.data.Destination;
public class AddressbookBean
{
@@ -254,15 +256,40 @@ public class AddressbookBean
boolean changed = false;
int deleted = 0;
String name = null;
- if (action.equals(_("Add"))) {
+ if (action.equals(_("Add")) || action.equals(_("Replace"))) {
if( addressbook != null && hostname != null && destination != null ) {
- addressbook.put( hostname, destination );
- changed = true;
- message = _("Destination added.");
- // clear search when adding
- search = null;
+ String oldDest = (String) addressbook.get(hostname);
+ if (destination.equals(oldDest)) {
+ message = _("Host name {0} is already in addressbook, unchanged.", hostname);
+ } else if (oldDest != null && !action.equals(_("Replace"))) {
+ message = _("Host name {0} is already in addressbook with a different destination. Click \"Replace\" to overwrite.", hostname);
+ } else {
+ boolean valid = true;
+ try {
+ Destination dest = new Destination(destination);
+ } catch (DataFormatException dfe) {
+ valid = false;
+ }
+ if (valid) {
+ addressbook.put( hostname, destination );
+ changed = true;
+ if (oldDest == null)
+ message = _("Destination added for {0}.", hostname);
+ else
+ message = _("Destination changed for {0}.", hostname);
+ // clear form
+ hostname = null;
+ destination = null;
+ } else {
+ message = _("Invalid Base 64 destination.");
+ }
+ }
+ } else {
+ message = _("Please enter a host name and destination");
}
- } else if (action.equals(_("Delete"))) {
+ // clear search when adding
+ search = null;
+ } else if (action.equals(_("Delete Selected"))) {
Iterator it = deletionMarks.iterator();
while( it.hasNext() ) {
name = (String)it.next();
@@ -340,7 +367,7 @@ public class AddressbookBean
return destination;
}
public void setDestination(String destination) {
- this.destination = DataHelper.stripHTML(destination); // XSS
+ this.destination = DataHelper.stripHTML(destination).trim(); // XSS
}
public String getHostname() {
return hostname;
@@ -352,7 +379,7 @@ public class AddressbookBean
deletionMarks.addLast( name );
}
public void setHostname(String hostname) {
- this.hostname = DataHelper.stripHTML(hostname); // XSS
+ this.hostname = DataHelper.stripHTML(hostname).trim(); // XSS
}
private int getBeginInt() {
return Math.max(0, Math.min(entries.length - 1, beginIndex));
diff --git a/apps/susidns/src/jsp/addressbook.jsp b/apps/susidns/src/jsp/addressbook.jsp
index ff09b41e02..15c76dfc84 100644
--- a/apps/susidns/src/jsp/addressbook.jsp
+++ b/apps/susidns/src/jsp/addressbook.jsp
@@ -160,7 +160,9 @@
@@ -179,6 +181,7 @@
<%=intl._("Hostname")%>:
<%=intl._("Destination")%>:
+ " >
" >
diff --git a/apps/susidns/src/jsp/config.jsp b/apps/susidns/src/jsp/config.jsp
index f8b47ab003..4ad8b77dbb 100644
--- a/apps/susidns/src/jsp/config.jsp
+++ b/apps/susidns/src/jsp/config.jsp
@@ -69,8 +69,8 @@
- " >
" >
+ " >
diff --git a/apps/susidns/src/jsp/subscriptions.jsp b/apps/susidns/src/jsp/subscriptions.jsp
index 29bad17245..27af719847 100644
--- a/apps/susidns/src/jsp/subscriptions.jsp
+++ b/apps/susidns/src/jsp/subscriptions.jsp
@@ -69,8 +69,8 @@
- " >
" >
+ " >
diff --git a/history.txt b/history.txt
index 40d68dce90..b066471097 100644
--- a/history.txt
+++ b/history.txt
@@ -1,3 +1,7 @@
+2010-05-19 zzz
+ * Data: Remove lots of unnecessary initializers
+ * susidns: More validataion when adding entry
+
2010-05-15 zzz
* Console:
- Tag text in graphs
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index fecba78d69..a6204817e3 100644
--- a/router/java/src/net/i2p/router/RouterVersion.java
+++ b/router/java/src/net/i2p/router/RouterVersion.java
@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
- public final static long BUILD = 7;
+ public final static long BUILD = 8;
/** for example "-test" */
public final static String EXTRA = "";