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