forked from I2P_Developers/i2p.i2p
Proxy: Move error page resources to jar
This commit is contained in:
@@ -86,7 +86,12 @@
|
||||
<target name="jar" depends="builddep, compile, bundle-proxy, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
|
||||
<!-- set if unset -->
|
||||
<property name="workspace.changes.j.tr" value="" />
|
||||
<jar destfile="./build/i2ptunnel.jar" basedir="./build/obj" includes="**/*.class" excludes="**/ui/*.class **/web/*.class" >
|
||||
<mkdir dir="./build/obj/net/i2p/i2ptunnel/resources"/>
|
||||
<copy todir="./build/obj/net/i2p/i2ptunnel/resources">
|
||||
<fileset dir="../../routerconsole/jsp/" includes="themes/console/*/*.css themes/console/images/i2plogo.png themes/console/images/favicon.ico themes/console/images/itoopie_sm.png" />
|
||||
<fileset dir="../resources" includes="**/*.ht" />
|
||||
</copy>
|
||||
<jar destfile="./build/i2ptunnel.jar" basedir="./build/obj" excludes="**/ui/*.class **/web/*.class" >
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="net.i2p.i2ptunnel.I2PTunnel" />
|
||||
<attribute name="${manifest.classpath.name}" value="i2p.jar mstreaming.jar" />
|
||||
|
@@ -7,6 +7,7 @@ import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
@@ -40,6 +41,7 @@ import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.i2cp.MessageStatusMessage;
|
||||
import net.i2p.i2ptunnel.localServer.LocalHTTPServer;
|
||||
import net.i2p.util.EepGet;
|
||||
import net.i2p.util.EventDispatcher;
|
||||
import net.i2p.util.InternalSocket;
|
||||
@@ -670,8 +672,7 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
* @since 0.9.4 moved from I2PTunnelHTTPClient
|
||||
*/
|
||||
protected static String getErrorPage(I2PAppContext ctx, String base, String backup) {
|
||||
File errorDir = new File(ctx.getBaseDir(), "docs");
|
||||
File file = new File(errorDir, base + "-header.ht");
|
||||
String file = "proxy/" + base + "-header.ht";
|
||||
try {
|
||||
return readFile(ctx, file);
|
||||
} catch(IOException ioe) {
|
||||
@@ -683,20 +684,24 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
private static final String BUNDLE_NAME = "net.i2p.i2ptunnel.proxy.messages";
|
||||
|
||||
/**
|
||||
* As of 0.9.49, loads the error pages from the jar, not the file system.
|
||||
* @since 0.9.4 moved from I2PTunnelHTTPClient
|
||||
*/
|
||||
private static String readFile(I2PAppContext ctx, File file) throws IOException {
|
||||
private static String readFile(I2PAppContext ctx, String file) throws IOException {
|
||||
Reader reader = null;
|
||||
char[] buf = new char[512];
|
||||
StringBuilder out = new StringBuilder(2048);
|
||||
InputStream in = LocalHTTPServer.getResource(file);
|
||||
if (in == null)
|
||||
throw new IOException();
|
||||
try {
|
||||
boolean hasSusiDNS = ctx.portMapper().isRegistered(PortMapper.SVC_SUSIDNS);
|
||||
boolean hasI2PTunnel = ctx.portMapper().isRegistered(PortMapper.SVC_I2PTUNNEL);
|
||||
if (hasSusiDNS && hasI2PTunnel) {
|
||||
reader = new TranslateReader(ctx, BUNDLE_NAME, new FileInputStream(file));
|
||||
reader = new TranslateReader(ctx, BUNDLE_NAME, in);
|
||||
} else {
|
||||
// strip out the addressbook links
|
||||
reader = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
||||
reader = new InputStreamReader(in, "UTF-8");
|
||||
int len;
|
||||
while((len = reader.read(buf)) > 0) {
|
||||
out.append(buf, 0, len);
|
||||
@@ -734,6 +739,7 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
String rv = out.toString();
|
||||
return rv;
|
||||
} finally {
|
||||
try { in.close(); } catch (IOException ioe) {}
|
||||
try {
|
||||
if(reader != null)
|
||||
reader.close();
|
||||
|
@@ -5,6 +5,7 @@ package net.i2p.i2ptunnel.localServer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -124,32 +125,30 @@ public abstract class LocalHTTPServer {
|
||||
if ((method.equals("GET") || method.equals("HEAD")) &&
|
||||
targetRequest.startsWith("/themes/") &&
|
||||
!targetRequest.contains("..")) {
|
||||
String filename = null;
|
||||
try {
|
||||
filename = targetRequest.substring(8); // "/themes/".length
|
||||
} catch (IndexOutOfBoundsException ioobe) {
|
||||
return;
|
||||
}
|
||||
String filename = targetRequest.substring(1);
|
||||
// theme hack
|
||||
if (filename.startsWith("console/default/"))
|
||||
if (filename.startsWith("themes/console/default/"))
|
||||
filename = filename.replaceFirst("default", context.getProperty("routerconsole.theme", "light"));
|
||||
File themesDir = new File(context.getBaseDir(), "docs/themes");
|
||||
File file = new File(themesDir, filename);
|
||||
if (file.exists() && !file.isDirectory()) {
|
||||
String type;
|
||||
if (filename.endsWith(".css"))
|
||||
type = "text/css";
|
||||
else if (filename.endsWith(".ico"))
|
||||
type = "image/x-icon";
|
||||
else if (filename.endsWith(".png"))
|
||||
type = "image/png";
|
||||
else if (filename.endsWith(".jpg"))
|
||||
type = "image/jpeg";
|
||||
else type = "text/html";
|
||||
out.write("HTTP/1.1 200 OK\r\nContent-Type: ".getBytes("UTF-8"));
|
||||
out.write(type.getBytes("UTF-8"));
|
||||
out.write("\r\nCache-Control: max-age=86400\r\nConnection: close\r\nProxy-Connection: close\r\n\r\n".getBytes("UTF-8"));
|
||||
FileUtil.readFile(filename, themesDir.getAbsolutePath(), out);
|
||||
InputStream in = getResource(filename);
|
||||
if (in != null) {
|
||||
try {
|
||||
String type;
|
||||
if (filename.endsWith(".css"))
|
||||
type = "text/css";
|
||||
else if (filename.endsWith(".ico"))
|
||||
type = "image/x-icon";
|
||||
else if (filename.endsWith(".png"))
|
||||
type = "image/png";
|
||||
else if (filename.endsWith(".jpg"))
|
||||
type = "image/jpeg";
|
||||
else type = "text/html";
|
||||
out.write("HTTP/1.1 200 OK\r\nContent-Type: ".getBytes("UTF-8"));
|
||||
out.write(type.getBytes("UTF-8"));
|
||||
out.write("\r\nCache-Control: max-age=86400\r\nConnection: close\r\nProxy-Connection: close\r\n\r\n".getBytes("UTF-8"));
|
||||
DataHelper.copy(in, out);
|
||||
} finally {
|
||||
try { in.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -483,6 +482,15 @@ public abstract class LocalHTTPServer {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource relative path
|
||||
* @return stream or null if not found
|
||||
* @since 0.9.49
|
||||
*/
|
||||
public static InputStream getResource(String resource) {
|
||||
return LocalHTTPServer.class.getResourceAsStream("/net/i2p/i2ptunnel/resources/" + resource);
|
||||
}
|
||||
|
||||
/** these strings go in the jar, not the war */
|
||||
private static final String BUNDLE_NAME = "net.i2p.i2ptunnel.proxy.messages";
|
||||
|
||||
|
@@ -1659,11 +1659,10 @@
|
||||
<fixcrlf srcdir="pkg-temp/docs" includes="*.ht" encoding="utf8" eol="crlf" />
|
||||
</target>
|
||||
|
||||
<!-- readme and proxy error page files -->
|
||||
<!-- readme files -->
|
||||
<target name="prepConsoleDocUpdates">
|
||||
<copy todir="pkg-temp/docs/" >
|
||||
<fileset dir="installer/resources/readme/" includes="readme*.html" />
|
||||
<fileset dir="installer/resources/proxy/" includes="*.ht" />
|
||||
<!--
|
||||
As of 0.9.36:
|
||||
All new and changed flags must go in the flags16x11/ dir,
|
||||
@@ -3101,9 +3100,6 @@
|
||||
<copy file="installer/resources/console.ico" todir="pkg-temp/docs/" />
|
||||
<!-- HTTP Header files, english only,
|
||||
if you need a different lang do it in a seperate target -->
|
||||
<copy todir="pkg-temp/docs/" >
|
||||
<fileset dir="installer/resources/proxy/" includes="**-header.ht" />
|
||||
</copy>
|
||||
<!-- Theme light only -->
|
||||
<copy todir="pkg-temp/docs/themes/console/light/" overwrite="true" >
|
||||
<fileset dir="installer/resources/themes/console/light/" includes="**.css" />
|
||||
|
Reference in New Issue
Block a user