From 1a49c4af0e1adc796041274c726c23a539f1b53c Mon Sep 17 00:00:00 2001 From: dream Date: Sat, 10 Sep 2011 02:18:23 +0000 Subject: [PATCH] Fixing Shortcut to parse URLs correctly when adding an address helper. Also a quick example of how to use rsync over i2p. --- addresspublisher/nbproject/build-impl.xml | 249 ++++++++++++++---- .../nbproject/genfiles.properties | 4 +- .../nbproject/private/private.properties | 2 +- .../src/i2p/dream/lookup/Shortcut.java | 134 +++++++--- rsyncwproxy.sh | 8 + 5 files changed, 302 insertions(+), 95 deletions(-) create mode 100644 rsyncwproxy.sh diff --git a/addresspublisher/nbproject/build-impl.xml b/addresspublisher/nbproject/build-impl.xml index a2ffc77..39fd410 100644 --- a/addresspublisher/nbproject/build-impl.xml +++ b/addresspublisher/nbproject/build-impl.xml @@ -80,7 +80,14 @@ is divided into following sections: - + + + + + + + + @@ -95,8 +102,14 @@ is divided into following sections: + + + + + + @@ -109,40 +122,41 @@ is divided into following sections: - - - - - - - - - - - + + + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + @@ -198,8 +212,17 @@ is divided into following sections: - + + + + + + + + + + @@ -327,7 +350,9 @@ is divided into following sections: - + + + @@ -337,7 +362,8 @@ is divided into following sections: - + + @@ -353,11 +379,56 @@ is divided into following sections: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + @@ -452,6 +523,7 @@ is divided into following sections: + @@ -467,7 +539,7 @@ is divided into following sections: - + @@ -596,10 +668,10 @@ is divided into following sections: - + - + @@ -608,44 +680,53 @@ is divided into following sections: - To run this application from the command line without Ant, try: + To run this application from the command line without Ant, try: - java -cp "${run.classpath.with.dist.jar}" ${main.class} + java -cp "${run.classpath.with.dist.jar}" ${main.class} - + + + + + + + + + + + + + + - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" + + + - - - - - - - To run this application from the command line without Ant, try: + + + To run this application from the command line without Ant, try: - java -jar "${dist.jar.resolved}" + java -jar "${dist.jar.resolved}" + + + + + + - + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + Must select some files in the IDE or set javac.includes diff --git a/addresspublisher/nbproject/genfiles.properties b/addresspublisher/nbproject/genfiles.properties index 529faeb..ccf88a7 100644 --- a/addresspublisher/nbproject/genfiles.properties +++ b/addresspublisher/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.2.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=00fdd0af -nbproject/build-impl.xml.script.CRC32=b5dc77d5 -nbproject/build-impl.xml.stylesheet.CRC32=229523de@1.38.3.45 +nbproject/build-impl.xml.script.CRC32=b8efd1b3 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/addresspublisher/nbproject/private/private.properties b/addresspublisher/nbproject/private/private.properties index 8994e0a..ce75207 100644 --- a/addresspublisher/nbproject/private/private.properties +++ b/addresspublisher/nbproject/private/private.properties @@ -5,4 +5,4 @@ file.reference.i2p.jar=/mnt/bb/dream/packages/mtn/i2p.scripts/addresspublisher/l file.reference.javax.servlet.jar=/mnt/bb/dream/packages/mtn/i2p.scripts/addresspublisher/lib/javax.servlet.jar javac.debug=true javadoc.preview=true -user.properties.file=/mnt/bb/dream/.netbeans/6.9/build.properties +user.properties.file=/mnt/bb/dream/.netbeans/7.0/build.properties diff --git a/lookup/shortcut/src/i2p/dream/lookup/Shortcut.java b/lookup/shortcut/src/i2p/dream/lookup/Shortcut.java index fa2e147..76f988e 100644 --- a/lookup/shortcut/src/i2p/dream/lookup/Shortcut.java +++ b/lookup/shortcut/src/i2p/dream/lookup/Shortcut.java @@ -1,24 +1,28 @@ package i2p.dream.lookup; -import java.util.logging.Level; -import java.util.logging.Logger; +import net.i2p.I2PAppContext; +import net.i2p.data.Base32; +import net.i2p.data.Base64; +import net.i2p.data.DataFormatException; +import net.i2p.data.Destination; +import net.i2p.data.Hash; +import net.i2p.data.Base64; + import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -import net.i2p.data.Base32; -import net.i2p.data.DataFormatException; -import net.i2p.data.Destination; - +import java.util.logging.Level; +import java.util.logging.Logger; import java.io.PrintWriter; - -import net.i2p.data.Hash; - -import net.i2p.I2PAppContext; -import net.i2p.data.Base64; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLEncoder; +import java.net.URLDecoder; +import java.net.MalformedURLException; public class Shortcut extends HttpServlet { @@ -31,18 +35,18 @@ public class Shortcut extends HttpServlet { HttpServletResponse response) throws ServletException, IOException { - String name = request.getParameter("name"); - boolean quick = request.getParameter("q") != null; - if (name == null) { + String bleh = request.getParameter("url"); + URL url = null; + String name = null; + if(bleh!=null) { + url = new URL(URLDecoder.decode(bleh,"utf-8")); + name = url.getHost(); + } + + final boolean quick = request.getParameter("q") != null; + if (url == null) { askForName(response); } else { - if (name.startsWith("http://")) { - name = name.substring(7); - } - int i = name.indexOf('/'); - if (i > 0) { - name = name.substring(0, i); - } boolean isb32 = false; Destination address = null; int length = name.length(); @@ -61,18 +65,17 @@ public class Shortcut extends HttpServlet { final String b64 = request.getParameter("b64"); if (b64 == null) { // lookup works for both b32 and addressbook names. - System.err.println("nameboo " + name); address = I2PAppContext.getGlobalContext().namingService().lookup(name); - // we still want to give it a name though. + // we still want to give it a name though, even though b32 if(isb32) { - name = null; + name = request.getParameter("name"); } - showShortcut(response, name, address, quick); + showShortcut(response, name, url, address, quick); return; } else { if (isb32) { // don't be adding any b32 names to our addressbook now. - name = null; + name = request.getParameter("name"); } address = new Destination(); try { @@ -87,7 +90,7 @@ public class Shortcut extends HttpServlet { }); return; } - showShortcut(response, name, address, quick); + showShortcut(response, name, url, address, quick); } } } @@ -117,14 +120,52 @@ public class Shortcut extends HttpServlet { public void respond(PrintWriter out) { out.println("Shortcut Finder"); out.println("

Enter a name in your addressbook, or a base64 hash to find the shortcut base32 address for the eepsite.

"); - out.println("

"); + out.println("

"); out.println(""); } }); } + URL addAddressHelper(final URL url, final Destination address, boolean useb32) { + final String scheme = url.getProtocol(); + final String host = url.getHost(); + final int port = url.getPort(); + final String authority = url.getAuthority(); + final String userInfo = url.getUserInfo(); + final String path = url.getPath(); + String query = url.getQuery(); + final String fragment = url.getRef(); + /* the contextual URL constructor parses + "http://a.b/c/d" + "?i2paddresshelper=..." wrong + into "http://a.b/c/?i2paddresshelper=..." (discarding d) + so we'll just do it instead. + */ + + final String param; + if(useb32) + param = "i2paddresshelper="+Base32.encode(address.getHash().getData()) + +".b32.i2p"; + else + param = "i2paddresshelper="+address.toBase64(); + + if(query==null) + query = param; + else + query = query + "&" + param; + try { + return (new URI(scheme,userInfo,host,port,path,query,fragment)).toURL(); + // these exceptions should never happen since we started + // with a valid URL + } catch(URISyntaxException ex) { + throw new RuntimeException("The URL wasn't a URI?",ex); + } catch(MalformedURLException ex) { + throw new RuntimeException("The URL wasn't a URL???",ex); + } + } + void showShortcut(HttpServletResponse response, final String name, + final URL url, final Destination address, boolean quick) throws IOException { @@ -154,8 +195,9 @@ public class Shortcut extends HttpServlet { out.println("

Name needed

"); out.println("

Please enter a name for " + b32 + ":"); out.println(""); + out.println(""); out.println(""); - out.println(""); + out.println(""); out.println("

"); } }); @@ -163,19 +205,29 @@ public class Shortcut extends HttpServlet { } if(quick) { response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); - response.setHeader("Location", "http://" + name + "/?i2paddresshelper=" + address.toBase64()); + response.setHeader("Location", addAddressHelper(url,address,false).toExternalForm()); } else { respond(response, new Responder() { public void respond(PrintWriter out) { - String b32 = Base32.encode(address.getHash().getData()); - out.println("Jump for "+name+"|"+b32+""); - out.println(""); - out.println("

"+name+" ready.

"); - out.println("
    "); - out.println("
  • To add this to your addressbook, go here.
  • "); - out.println("
  • For a shortcut to skip this page go here.
  • "); - out.println("
  • To just use the base32 of "+name+" go here.
  • "); - out.println("
"); + try { + String b32 = Base32.encode(address.getHash().getData()); + out.println("Jump for "+name+"|"+b32+""); + out.println(""); + out.println("

"+name+" ready.

"); + out.println("
    "); + out.println("
  • To add this to your addressbook, go here.
  • "); + out.println("
  • To copy this into IRC, go here.
  • "); + try { + out.println("
  • For a shortcut to skip this page go here.
  • "); + } catch(java.io.UnsupportedEncodingException ex) { + throw new RuntimeException("Uh...what no utf-8 support?",ex); + } + out.println("
  • To just use the base32 of "+name+" go here.
  • "); + out.println("
"); + } catch(MalformedURLException ex) { + out.println("

error!

"+ex+"

"); + } } }); } diff --git a/rsyncwproxy.sh b/rsyncwproxy.sh new file mode 100644 index 0000000..a69465d --- /dev/null +++ b/rsyncwproxy.sh @@ -0,0 +1,8 @@ +PORT=7665 +# Note, you need the openbsd-netcat to do this: +export RSYNC_CONNECT_PROG="nc -X 5 -x 127.0.0.1:$PORT %H 873" + +exec rsync $@ + +# example: +# sh rsyncwproxy.sh bswwika32z7eym55zziv3nath4kqvtzkrtcjtihm6plcxjg6qsnq.b32.i2p::code/ \ No newline at end of file