more cleanup

This commit is contained in:
jrandom
2005-11-15 06:24:17 +00:00
committed by zzz
parent dceac73951
commit b031de5404
12 changed files with 182 additions and 94 deletions

View File

@@ -267,10 +267,34 @@ class HTTPResponseOutputStream extends FilterOutputStream {
public InternalGZIPInputStream(InputStream in) throws IOException { public InternalGZIPInputStream(InputStream in) throws IOException {
super(in); super(in);
} }
public long getTotalRead() { return super.inf.getTotalIn(); } public long getTotalRead() {
public long getTotalExpanded() { return super.inf.getTotalOut(); } try {
public long getRemaining() { return super.inf.getRemaining(); } return super.inf.getTotalIn();
public boolean getFinished() { return super.inf.finished(); } } catch (Exception e) {
return 0;
}
}
public long getTotalExpanded() {
try {
return super.inf.getTotalOut();
} catch (Exception e) {
return 0;
}
}
public long getRemaining() {
try {
return super.inf.getRemaining();
} catch (Exception e) {
return 0;
}
}
public boolean getFinished() {
try {
return super.inf.finished();
} catch (Exception e) {
return true;
}
}
public String toString() { public String toString() {
return "Read: " + getTotalRead() + " expanded: " + getTotalExpanded() + " remaining: " + getRemaining() + " finished: " + getFinished(); return "Read: " + getTotalRead() + " expanded: " + getTotalExpanded() + " remaining: " + getRemaining() + " finished: " + getFinished();
} }

View File

@@ -10,6 +10,7 @@ import java.net.SocketException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import java.util.zip.Deflater;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.I2PException; import net.i2p.I2PException;
@@ -230,8 +231,22 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
public InternalGZIPOutputStream(OutputStream target) throws IOException { public InternalGZIPOutputStream(OutputStream target) throws IOException {
super(target); super(target);
} }
public long getTotalRead() { return super.def.getTotalIn(); } public long getTotalRead() {
public long getTotalCompressed() { return super.def.getTotalOut(); } try {
return def.getTotalIn();
} catch (Exception e) {
// j2se 1.4.2_08 on linux is sometimes throwing an NPE in the getTotalIn() implementation
return 0;
}
}
public long getTotalCompressed() {
try {
return def.getTotalOut();
} catch (Exception e) {
// j2se 1.4.2_08 on linux is sometimes throwing an NPE in the getTotalOut() implementation
return 0;
}
}
} }
private String formatHeaders(Properties headers, StringBuffer command) { private String formatHeaders(Properties headers, StringBuffer command) {

View File

@@ -314,12 +314,19 @@ public class BlogManager {
try { try {
Properties props = loadUserProps(userFile); Properties props = loadUserProps(userFile);
if (props == null) throw new IOException("Error reading " + userFile); if (props == null) throw new IOException("Error reading " + userFile);
return user.login(login, pass, props); String rv = user.login(login, pass, props);
if (User.LOGIN_OK.equals(rv))
_log.info("Login successful");
else
_log.info("Login failed: [" + rv + "]");
return rv;
} catch (IOException ioe) { } catch (IOException ioe) {
_log.error("Error logging in", ioe); _log.error("Error logging in", ioe);
return "<span class=\"b_loginMsgErr\">Error logging in - corrupt userfile</span>"; return "<span class=\"b_loginMsgErr\">Error logging in - corrupt userfile</span>";
} }
} else { } else {
if (_log.shouldLog(Log.INFO))
_log.info("User does not exist");
return "<span class=\"b_loginMsgErr\">User does not exist</span>"; return "<span class=\"b_loginMsgErr\">User does not exist</span>";
} }
} }

View File

@@ -41,6 +41,7 @@ public class User {
private int _torProxyPort; private int _torProxyPort;
private PetNameDB _petnames; private PetNameDB _petnames;
private boolean _importAddresses; private boolean _importAddresses;
private boolean _dataImported;
static final String PROP_USERHASH = "__userHash"; static final String PROP_USERHASH = "__userHash";
@@ -87,6 +88,7 @@ public class User {
_lastMetaEntry = 0; _lastMetaEntry = 0;
_petnames = new PetNameDB(); _petnames = new PetNameDB();
_importAddresses = false; _importAddresses = false;
_dataImported = false;
} }
public boolean getAuthenticated() { return _authenticated; } public boolean getAuthenticated() { return _authenticated; }
@@ -127,6 +129,13 @@ public class User {
init(); init();
} }
public void dataImported() { _dataImported = true; }
public boolean resetDataImported() {
boolean rv = _dataImported;
_dataImported = false;
return rv;
}
public boolean changePassword(String oldPass, String pass0, String pass1) { public boolean changePassword(String oldPass, String pass0, String pass1) {
String curPass = _hashedPassword; String curPass = _hashedPassword;
Hash curPassHash = _context.sha().calculateHash(DataHelper.getUTF8(oldPass)); Hash curPassHash = _context.sha().calculateHash(DataHelper.getUTF8(oldPass));

View File

@@ -112,13 +112,13 @@ public class HTMLPreviewRenderer extends HTMLRenderer {
} else { } else {
_postBodyBuffer.append(" <a ").append(getClass("summDetailAddrLink")).append(" href=\"addresses.jsp?"); _postBodyBuffer.append(" <a ").append(getClass("summDetailAddrLink")).append(" href=\"addresses.jsp?");
if (a.schema != null) if (a.schema != null)
_postBodyBuffer.append("network=").append(sanitizeTagParam(a.schema)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_NET).append("=").append(sanitizeTagParam(a.schema)).append('&');
if (a.location != null) if (a.location != null)
_postBodyBuffer.append("location=").append(sanitizeTagParam(a.location)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_LOC).append("=").append(sanitizeTagParam(a.location)).append('&');
if (a.name != null) if (a.name != null)
_postBodyBuffer.append("name=").append(sanitizeTagParam(a.name)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_NAME).append("=").append(sanitizeTagParam(a.name)).append('&');
if (a.protocol != null) if (a.protocol != null)
_postBodyBuffer.append("protocol=").append(sanitizeTagParam(a.protocol)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_PROTO).append("=").append(sanitizeTagParam(a.protocol)).append('&');
_postBodyBuffer.append("\">").append(sanitizeString(a.name)).append("</a>"); _postBodyBuffer.append("\">").append(sanitizeString(a.name)).append("</a>");
} }
} }

View File

@@ -408,7 +408,7 @@ public class HTMLRenderer extends EventReceiverImpl {
} }
if (_user.getAuthenticated()) { if (_user.getAuthenticated()) {
_bodyBuffer.append(" <a ").append(getClass("archiveBookmarkLink")).append(" href=\""); _bodyBuffer.append(" <a ").append(getClass("archiveBookmarkLink")).append(" href=\"");
_bodyBuffer.append(getBookmarkURL(sanitizeString(name), surl.getLocation(), surl.getSchema(), "syndiearchive")); _bodyBuffer.append(getBookmarkURL(sanitizeString(name), surl.getLocation(), surl.getSchema(), AddressesServlet.PROTO_ARCHIVE));
_bodyBuffer.append("\">bookmark it</a>"); _bodyBuffer.append("\">bookmark it</a>");
} }
} }
@@ -496,13 +496,13 @@ public class HTMLRenderer extends EventReceiverImpl {
_log.debug("Receiving address [" + location + "]"); _log.debug("Receiving address [" + location + "]");
_bodyBuffer.append("<a ").append(getClass("addrAdd")).append(" href=\"addresses.jsp?"); _bodyBuffer.append("<a ").append(getClass("addrAdd")).append(" href=\"addresses.jsp?");
if (schema != null) if (schema != null)
_bodyBuffer.append("network=").append(sanitizeTagParam(schema)).append('&'); _bodyBuffer.append(AddressesServlet.PARAM_NET).append('=').append(sanitizeTagParam(schema)).append('&');
if (name != null) if (name != null)
_bodyBuffer.append("name=").append(sanitizeTagParam(name)).append('&'); _bodyBuffer.append(AddressesServlet.PARAM_NAME).append('=').append(sanitizeTagParam(name)).append('&');
if (protocol != null) if (protocol != null)
_bodyBuffer.append("protocol=").append(sanitizeTagParam(protocol)).append('&'); _bodyBuffer.append(AddressesServlet.PARAM_PROTO).append('=').append(sanitizeTagParam(protocol)).append('&');
if (location != null) if (location != null)
_bodyBuffer.append("location=").append(sanitizeTagParam(location)); _bodyBuffer.append(AddressesServlet.PARAM_LOC).append('=').append(sanitizeTagParam(location));
_bodyBuffer.append("\">").append(sanitizeString(anchorText)).append("</a>"); _bodyBuffer.append("\">").append(sanitizeString(anchorText)).append("</a>");
} }
} }
@@ -659,13 +659,13 @@ public class HTMLRenderer extends EventReceiverImpl {
} else { } else {
_postBodyBuffer.append(" <a ").append(getClass("summDetailAddrLink")).append(" href=\"addresses.jsp?"); _postBodyBuffer.append(" <a ").append(getClass("summDetailAddrLink")).append(" href=\"addresses.jsp?");
if (a.schema != null) if (a.schema != null)
_postBodyBuffer.append("network=").append(sanitizeTagParam(a.schema)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_NET).append('=').append(sanitizeTagParam(a.schema)).append('&');
if (a.location != null) if (a.location != null)
_postBodyBuffer.append("location=").append(sanitizeTagParam(a.location)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_LOC).append('=').append(sanitizeTagParam(a.location)).append('&');
if (a.name != null) if (a.name != null)
_postBodyBuffer.append("name=").append(sanitizeTagParam(a.name)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_NAME).append('=').append(sanitizeTagParam(a.name)).append('&');
if (a.protocol != null) if (a.protocol != null)
_postBodyBuffer.append("protocol=").append(sanitizeTagParam(a.protocol)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_PROTO).append('=').append(sanitizeTagParam(a.protocol)).append('&');
_postBodyBuffer.append("\">").append(sanitizeString(a.name)).append("</a>"); _postBodyBuffer.append("\">").append(sanitizeString(a.name)).append("</a>");
} }
} }
@@ -682,7 +682,7 @@ public class HTMLRenderer extends EventReceiverImpl {
_postBodyBuffer.append(": ").append(getSpan("summDetailArchiveDesc")).append(sanitizeString(a.description)).append("</span>"); _postBodyBuffer.append(": ").append(getSpan("summDetailArchiveDesc")).append(sanitizeString(a.description)).append("</span>");
if (null == _user.getPetNameDB().getByLocation(a.location)) { if (null == _user.getPetNameDB().getByLocation(a.location)) {
_postBodyBuffer.append(" <a ").append(getClass("summDetailArchiveBookmark")).append(" href=\""); _postBodyBuffer.append(" <a ").append(getClass("summDetailArchiveBookmark")).append(" href=\"");
_postBodyBuffer.append(getBookmarkURL(a.name, a.location, a.locationSchema, "syndiearchive")); _postBodyBuffer.append(getBookmarkURL(a.name, a.location, a.locationSchema, AddressesServlet.PROTO_ARCHIVE));
_postBodyBuffer.append("\">bookmark it</a>"); _postBodyBuffer.append("\">bookmark it</a>");
} }
} }
@@ -1069,15 +1069,15 @@ public class HTMLRenderer extends EventReceiverImpl {
return buf.toString(); return buf.toString();
} }
public String getArchiveURL(Hash blog, SafeURL archiveLocation) { public String getArchiveURL(Hash blog, SafeURL archiveLocation) {
return "remote.jsp?" return "syndicate.jsp?"
//+ "action=Continue..." // should this be the case? //+ "action=Continue..." // should this be the case?
+ "&schema=" + sanitizeTagParam(archiveLocation.getSchema()) + "&" + SyndicateServlet.PARAM_SCHEMA + "=" + sanitizeTagParam(archiveLocation.getSchema())
+ "&location=" + sanitizeTagParam(archiveLocation.getLocation()); + "&" + SyndicateServlet.PARAM_LOCATION + "=" + sanitizeTagParam(archiveLocation.getLocation());
} }
public String getBookmarkURL(String name, String location, String schema, String protocol) { public String getBookmarkURL(String name, String location, String schema, String protocol) {
return "addresses.jsp?name=" + sanitizeTagParam(name) return "addresses.jsp?" + AddressesServlet.PARAM_NAME + '=' + sanitizeTagParam(name)
+ "&network=" + sanitizeTagParam(schema) + "&" + AddressesServlet.PARAM_NET + '=' + sanitizeTagParam(schema)
+ "&protocol=" + sanitizeTagParam(protocol) + "&" + AddressesServlet.PARAM_PROTO + '=' + sanitizeTagParam(protocol)
+ "&location=" + sanitizeTagParam(location); + "&" + AddressesServlet.PARAM_LOC + '=' + sanitizeTagParam(location);
} }
} }

View File

@@ -8,6 +8,7 @@ import net.i2p.client.naming.PetName;
import net.i2p.data.*; import net.i2p.data.*;
import net.i2p.syndie.*; import net.i2p.syndie.*;
import net.i2p.syndie.data.*; import net.i2p.syndie.data.*;
import net.i2p.syndie.web.AddressesServlet;
/** /**
* *
@@ -261,10 +262,10 @@ public class RSSRenderer extends HTMLRenderer {
pn = _user.getPetNameDB().getByLocation(a.location); pn = _user.getPetNameDB().getByLocation(a.location);
if (pn == null) { if (pn == null) {
StringBuffer url = new StringBuffer(128); StringBuffer url = new StringBuffer(128);
url.append("addresses.jsp?network="); url.append("addresses.jsp?").append(AddressesServlet.PARAM_NAME).append('=');
url.append(sanitizeTagParam(a.schema)).append("&location="); url.append(sanitizeTagParam(a.schema)).append("&").append(AddressesServlet.PARAM_LOC).append("=");
url.append(sanitizeTagParam(a.location)).append("&name="); url.append(sanitizeTagParam(a.location)).append("&").append(AddressesServlet.PARAM_NAME).append("=");
url.append(sanitizeTagParam(a.name)).append("&protocol="); url.append(sanitizeTagParam(a.name)).append("&").append(AddressesServlet.PARAM_PROTO).append("=");
url.append(sanitizeTagParam(a.protocol)); url.append(sanitizeTagParam(a.protocol));
out.write(" <enclosure url=\"" + urlPrefix + sanitizeXML(url) + "\" length=\"1\" type=\"text/html\" syndietype=\"address\" />\n"); out.write(" <enclosure url=\"" + urlPrefix + sanitizeXML(url) + "\" length=\"1\" type=\"text/html\" syndietype=\"address\" />\n");
} }

View File

@@ -45,8 +45,6 @@ public class ThreadedHTMLRenderer extends HTMLRenderer {
public static final String PARAM_PROFILE_DESC = "profileDesc"; public static final String PARAM_PROFILE_DESC = "profileDesc";
public static final String PARAM_PROFILE_URL = "profileURL"; public static final String PARAM_PROFILE_URL = "profileURL";
public static final String PARAM_PROFILE_OTHER = "profileOther"; public static final String PARAM_PROFILE_OTHER = "profileOther";
public static final String PARAM_ARCHIVE = "archiveLocation";
public static String getFilterByTagLink(String uri, ThreadNode node, User user, String tag, String author) { public static String getFilterByTagLink(String uri, ThreadNode node, User user, String tag, String author) {
StringBuffer buf = new StringBuffer(64); StringBuffer buf = new StringBuffer(64);
@@ -368,13 +366,13 @@ public class ThreadedHTMLRenderer extends HTMLRenderer {
} else { } else {
_postBodyBuffer.append(" <a ").append(getClass("summDetailAddrLink")).append(" href=\"addresses.jsp?"); _postBodyBuffer.append(" <a ").append(getClass("summDetailAddrLink")).append(" href=\"addresses.jsp?");
if (a.schema != null) if (a.schema != null)
_postBodyBuffer.append("network=").append(sanitizeTagParam(a.schema)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_NET).append("=").append(sanitizeTagParam(a.schema)).append('&');
if (a.location != null) if (a.location != null)
_postBodyBuffer.append("location=").append(sanitizeTagParam(a.location)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_LOC).append("=").append(sanitizeTagParam(a.location)).append('&');
if (a.name != null) if (a.name != null)
_postBodyBuffer.append("name=").append(sanitizeTagParam(a.name)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_NAME).append("=").append(sanitizeTagParam(a.name)).append('&');
if (a.protocol != null) if (a.protocol != null)
_postBodyBuffer.append("protocol=").append(sanitizeTagParam(a.protocol)).append('&'); _postBodyBuffer.append(AddressesServlet.PARAM_PROTO).append("=").append(sanitizeTagParam(a.protocol)).append('&');
_postBodyBuffer.append("\">").append(sanitizeString(a.name)).append("</a>"); _postBodyBuffer.append("\">").append(sanitizeString(a.name)).append("</a>");
} }
} }
@@ -391,7 +389,7 @@ public class ThreadedHTMLRenderer extends HTMLRenderer {
_postBodyBuffer.append(": ").append(getSpan("summDetailArchiveDesc")).append(sanitizeString(a.description)).append("</span>"); _postBodyBuffer.append(": ").append(getSpan("summDetailArchiveDesc")).append(sanitizeString(a.description)).append("</span>");
if (null == _user.getPetNameDB().getByLocation(a.location)) { if (null == _user.getPetNameDB().getByLocation(a.location)) {
_postBodyBuffer.append(" <a ").append(getClass("summDetailArchiveBookmark")).append(" href=\""); _postBodyBuffer.append(" <a ").append(getClass("summDetailArchiveBookmark")).append(" href=\"");
_postBodyBuffer.append(getBookmarkURL(a.name, a.location, a.locationSchema, "syndiearchive")); _postBodyBuffer.append(getBookmarkURL(sanitizeTagParam(a.name), sanitizeTagParam(a.location), sanitizeTagParam(a.locationSchema), AddressesServlet.PROTO_ARCHIVE));
_postBodyBuffer.append("\">bookmark it</a>"); _postBodyBuffer.append("\">bookmark it</a>");
} }
} }
@@ -475,17 +473,4 @@ public class ThreadedHTMLRenderer extends HTMLRenderer {
buf.append(PARAM_TAGS).append('=').append(sanitizeTagParam(tag)).append('&'); buf.append(PARAM_TAGS).append('=').append(sanitizeTagParam(tag)).append('&');
return buf.toString(); return buf.toString();
} }
public String getArchiveURL(Hash blog, SafeURL archiveLocation) {
return "remote.jsp?"
//+ "action=Continue..." // should this be the case?
+ "&schema=" + sanitizeTagParam(archiveLocation.getSchema())
+ "&location=" + sanitizeTagParam(archiveLocation.getLocation());
}
public String getBookmarkURL(String name, String location, String schema, String protocol) {
return "addresses.jsp?name=" + sanitizeTagParam(name)
+ "&network=" + sanitizeTagParam(schema)
+ "&protocol=" + sanitizeTagParam(protocol)
+ "&location=" + sanitizeTagParam(location);
}
} }

View File

@@ -70,14 +70,19 @@ public class AddressesServlet extends BaseServlet {
String uri = req.getRequestURI(); String uri = req.getRequestURI();
PetName pn = buildNewName(req, PROTO_BLOG); PetName pn = buildNewName(req, PROTO_BLOG);
_log.debug("pn for protoBlog [" + req.getParameter(PARAM_PROTO) + "]: " + pn);
renderBlogs(user, db, uri, pn, out); renderBlogs(user, db, uri, pn, out);
pn = buildNewName(req, PROTO_ARCHIVE); pn = buildNewName(req, PROTO_ARCHIVE);
_log.debug("pn for protoArchive [" + req.getParameter(PARAM_PROTO) + "]: " + pn);
renderArchives(user, db, uri, pn, out); renderArchives(user, db, uri, pn, out);
pn = buildNewName(req, PROTO_I2PHEX); pn = buildNewName(req, PROTO_I2PHEX);
_log.debug("pn for protoPhex [" + req.getParameter(PARAM_PROTO) + "]: " + pn);
renderI2Phex(user, db, uri, pn, out); renderI2Phex(user, db, uri, pn, out);
pn = buildNewName(req, PROTO_EEPSITE); pn = buildNewName(req, PROTO_EEPSITE);
_log.debug("pn for protoEep [" + req.getParameter(PARAM_PROTO) + "]: " + pn);
renderEepsites(user, db, uri, pn, out); renderEepsites(user, db, uri, pn, out);
pn = buildNewName(req); pn = buildNewName(req);
_log.debug("pn for proto other [" + req.getParameter(PARAM_PROTO) + "]: " + pn);
renderOther(user, db, uri, pn, out); renderOther(user, db, uri, pn, out);
} }
} }
@@ -165,14 +170,16 @@ public class AddressesServlet extends BaseServlet {
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (pn.getIsPublic() ? " checked=\"true\" " : "") + " />\n"); out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (pn.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"hidden\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + pn.getName() + "\" />" + pn.getName() + " "); out.write("Name: <input type=\"hidden\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + pn.getName() + "\" />" + pn.getName() + " ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"20\" value=\"" + pn.getLocation() + "\" /> "); out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"20\" value=\"" + pn.getLocation() + "\" /> ");
if (BlogManager.instance().syndicationScheduled(pn.getLocation())) if (BlogManager.instance().authorizeRemote(user)) {
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" checked=\"true\" value=\"true\" />");
else if (BlogManager.instance().syndicationScheduled(pn.getLocation()))
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" value=\"true\" />"); out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" checked=\"true\" value=\"true\" />");
else
out.write("<a href=\"" + getSyndicateLink(user, pn.getName()) out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" value=\"true\" />");
+ "\" title=\"Synchronize manually with the peer\">Sync manually</a> ");
out.write("<a href=\"" + getSyndicateLink(user, pn.getLocation())
+ "\" title=\"Synchronize manually with the peer\">Sync manually</a> ");
}
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_DELETE_ARCHIVE + "\" /> "); out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_DELETE_ARCHIVE + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_UPDATE_ARCHIVE + "\" /> "); out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_UPDATE_ARCHIVE + "\" /> ");
out.write("</td></tr>\n"); out.write("</td></tr>\n");
@@ -187,10 +194,12 @@ public class AddressesServlet extends BaseServlet {
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (newName.getIsPublic() ? " checked=\"true\" " : "") + " />\n"); out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (newName.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"text\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + newName.getName() + "\" /> "); out.write("Name: <input type=\"text\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + newName.getName() + "\" /> ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"20\" value=\"" + newName.getLocation() + "\" /> "); out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"20\" value=\"" + newName.getLocation() + "\" /> ");
if (BlogManager.instance().syndicationScheduled(newName.getLocation())) if (BlogManager.instance().authorizeRemote(user)) {
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" checked=\"true\" value=\"true\" />"); if (BlogManager.instance().syndicationScheduled(newName.getLocation()))
else out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" checked=\"true\" value=\"true\" />");
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" value=\"true\" />"); else
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" value=\"true\" />");
}
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_ADD_ARCHIVE + "\" /> "); out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_ADD_ARCHIVE + "\" /> ");
out.write("</td></tr>\n"); out.write("</td></tr>\n");
@@ -344,7 +353,6 @@ public class AddressesServlet extends BaseServlet {
return pn; return pn;
} else { } else {
pn = buildNewAddress(req); pn = buildNewAddress(req);
pn.setProtocol(protocol);
} }
return pn; return pn;
} }

View File

@@ -14,6 +14,7 @@ import net.i2p.data.*;
import net.i2p.syndie.*; import net.i2p.syndie.*;
import net.i2p.syndie.data.*; import net.i2p.syndie.data.*;
import net.i2p.syndie.sml.*; import net.i2p.syndie.sml.*;
import net.i2p.util.Log;
/** /**
* Base servlet for handling request and rendering the templates * Base servlet for handling request and rendering the templates
@@ -22,10 +23,14 @@ import net.i2p.syndie.sml.*;
public abstract class BaseServlet extends HttpServlet { public abstract class BaseServlet extends HttpServlet {
protected static final String PARAM_AUTH_ACTION = "syndie.auth"; protected static final String PARAM_AUTH_ACTION = "syndie.auth";
private static long _authNonce; private static long _authNonce;
private I2PAppContext _context;
protected Log _log;
public void init() throws ServletException { public void init() throws ServletException {
super.init(); super.init();
_authNonce = I2PAppContext.getGlobalContext().random().nextLong(); _context = I2PAppContext.getGlobalContext();
_log = _context.logManager().getLog(getClass());
_authNonce = _context.random().nextLong();
} }
protected boolean authAction(HttpServletRequest req) { protected boolean authAction(HttpServletRequest req) {
@@ -92,18 +97,34 @@ public abstract class BaseServlet extends HttpServlet {
if (user == null) { if (user == null) {
if ("Login".equals(action)) { if ("Login".equals(action)) {
user = BlogManager.instance().login(login, pass); // ignore failures - user will just be unauthorized user = BlogManager.instance().login(login, pass); // ignore failures - user will just be unauthorized
if (!user.getAuthenticated()) if (!user.getAuthenticated()) {
user = BlogManager.instance().getDefaultUser(); user = BlogManager.instance().getDefaultUser();
if (_log.shouldLog(Log.INFO))
_log.info("Explicit login failed for [" + login + "], using default login");
} else {
if (_log.shouldLog(Log.INFO))
_log.info("Explicit login successful for [" + login + "]");
}
} else { } else {
user = BlogManager.instance().getDefaultUser(); user = BlogManager.instance().getDefaultUser();
if (_log.shouldLog(Log.INFO))
_log.info("Implicit login for the default user");
} }
forceNewIndex = true; forceNewIndex = true;
} else if (authAction && "Login".equals(action)) { } else if (authAction && "Login".equals(action)) {
user = BlogManager.instance().login(login, pass); // ignore failures - user will just be unauthorized user = BlogManager.instance().login(login, pass); // ignore failures - user will just be unauthorized
if (!user.getAuthenticated()) if (!user.getAuthenticated()) {
if (_log.shouldLog(Log.INFO))
_log.info("Explicit relogin failed for [" + login + "] from [" + user.getUsername() + "], using default user");
user = BlogManager.instance().getDefaultUser(); user = BlogManager.instance().getDefaultUser();
} else {
if (_log.shouldLog(Log.INFO))
_log.info("Explicit relogin successful for [" + login + "] from [" + user.getUsername() + "]");
}
forceNewIndex = true; forceNewIndex = true;
} else if (authAction && "Logout".equals(action)) { } else if (authAction && "Logout".equals(action)) {
if (_log.shouldLog(Log.INFO))
_log.info("Explicit logout successful for [" + user.getUsername() + "], using default login");
user = BlogManager.instance().getDefaultUser(); user = BlogManager.instance().getDefaultUser();
forceNewIndex = true; forceNewIndex = true;
} }
@@ -118,6 +139,13 @@ public abstract class BaseServlet extends HttpServlet {
handleUpdateProfile(user, req); handleUpdateProfile(user, req);
} }
// the 'dataImported' flag is set by successful fetches in the SyndicateServlet/RemoteArchiveBean
if (user.resetDataImported()) {
forceNewIndex = true;
if (_log.shouldLog(Log.INFO))
_log.info("Data imported, force regenerate");
}
FilteredThreadIndex index = (FilteredThreadIndex)req.getSession().getAttribute("threadIndex"); FilteredThreadIndex index = (FilteredThreadIndex)req.getSession().getAttribute("threadIndex");
Collection tags = getFilteredTags(req); Collection tags = getFilteredTags(req);
@@ -125,6 +153,8 @@ public abstract class BaseServlet extends HttpServlet {
if (forceNewIndex || (index == null) || (!index.getFilteredTags().equals(tags)) || (!index.getFilteredAuthors().equals(filteredAuthors))) { if (forceNewIndex || (index == null) || (!index.getFilteredTags().equals(tags)) || (!index.getFilteredAuthors().equals(filteredAuthors))) {
index = new FilteredThreadIndex(user, BlogManager.instance().getArchive(), getFilteredTags(req), filteredAuthors); index = new FilteredThreadIndex(user, BlogManager.instance().getArchive(), getFilteredTags(req), filteredAuthors);
req.getSession().setAttribute("threadIndex", index); req.getSession().setAttribute("threadIndex", index);
if (_log.shouldLog(Log.INFO))
_log.info("New filtered index created (forced? " + forceNewIndex + ")");
} }
render(user, req, resp.getWriter(), index); render(user, req, resp.getWriter(), index);
@@ -468,7 +498,8 @@ public abstract class BaseServlet extends HttpServlet {
out.write("<a href=\"" + getPostURI() + "\" title=\"Post a new thread\">Post a new thread</a>\n"); out.write("<a href=\"" + getPostURI() + "\" title=\"Post a new thread\">Post a new thread</a>\n");
out.write("<a href=\"addresses.jsp\" title=\"View your addressbook\">Addressbook</a>\n"); out.write("<a href=\"addresses.jsp\" title=\"View your addressbook\">Addressbook</a>\n");
} else { } else {
out.write("<form action=\"" + req.getRequestURI() + "\" method=\"GET\">\n"); out.write("<form action=\"" + req.getRequestURI() + "\" method=\"POST\">\n");
writeAuthActionFields(out);
out.write("Login: <input type=\"text\" name=\"login\" />\n"); out.write("Login: <input type=\"text\" name=\"login\" />\n");
out.write("Password: <input type=\"password\" name=\"password\" />\n"); out.write("Password: <input type=\"password\" name=\"password\" />\n");
out.write("<input type=\"submit\" name=\"action\" value=\"Login\" /></form>\n"); out.write("<input type=\"submit\" name=\"action\" value=\"Login\" /></form>\n");
@@ -483,12 +514,9 @@ public abstract class BaseServlet extends HttpServlet {
out.write("</span><!-- nav bar end -->\n</td></tr>\n"); out.write("</span><!-- nav bar end -->\n</td></tr>\n");
} }
protected String getSyndicateLink(User user, String archiveName) { protected String getSyndicateLink(User user, String location) {
if ( (user != null) && (archiveName != null) ) { if (location != null)
PetName pn = user.getPetNameDB().getByName(archiveName); return "syndicate.jsp?" + SyndicateServlet.PARAM_LOCATION + "=" + location;
if (pn != null)
return "syndicate.jsp?" + ThreadedHTMLRenderer.PARAM_ARCHIVE + "=" + pn.getLocation();
}
return "syndicate.jsp"; return "syndicate.jsp";
} }

View File

@@ -131,7 +131,7 @@ public class RemoteArchiveBean {
for (int i = 0; i < urls.size(); i++) for (int i = 0; i < urls.size(); i++)
_statusMessages.add("Scheduling blog post fetching for " + HTMLRenderer.sanitizeString(entries[i])); _statusMessages.add("Scheduling blog post fetching for " + HTMLRenderer.sanitizeString(entries[i]));
fetch(urls, tmpFiles, user, new BlogStatusListener()); fetch(urls, tmpFiles, user, new BlogStatusListener(user));
} }
public void fetchSelectedBulk(User user, Map parameters) { public void fetchSelectedBulk(User user, Map parameters) {
@@ -186,7 +186,7 @@ public class RemoteArchiveBean {
boolean shouldProxy = (_proxyHost != null) && (_proxyPort > 0); boolean shouldProxy = (_proxyHost != null) && (_proxyPort > 0);
final EepGet get = new EepGet(_context, shouldProxy, _proxyHost, _proxyPort, 0, tmp.getAbsolutePath(), url.toString(), postData.toString()); final EepGet get = new EepGet(_context, shouldProxy, _proxyHost, _proxyPort, 0, tmp.getAbsolutePath(), url.toString(), postData.toString());
get.addStatusListener(new BulkFetchListener(tmp)); get.addStatusListener(new BulkFetchListener(user, tmp));
if (shouldBlock) { if (shouldBlock) {
get.fetch(); get.fetch();
@@ -218,7 +218,7 @@ public class RemoteArchiveBean {
File t = File.createTempFile("fetchBulk", ".dat", BlogManager.instance().getTempDir()); File t = File.createTempFile("fetchBulk", ".dat", BlogManager.instance().getTempDir());
tmpFiles.add(t); tmpFiles.add(t);
} }
fetch(urls, tmpFiles, user, new BlogStatusListener(), shouldBlock); fetch(urls, tmpFiles, user, new BlogStatusListener(user), shouldBlock);
} catch (IOException ioe) { } catch (IOException ioe) {
_statusMessages.add("Internal error creating temporary file to fetch posts: " + HTMLRenderer.sanitizeString(urls.toString())); _statusMessages.add("Internal error creating temporary file to fetch posts: " + HTMLRenderer.sanitizeString(urls.toString()));
} }
@@ -266,7 +266,7 @@ public class RemoteArchiveBean {
for (int i = 0; i < urls.size(); i++) for (int i = 0; i < urls.size(); i++)
_statusMessages.add("Fetch all entries: " + HTMLRenderer.sanitizeString((String)urls.get(i))); _statusMessages.add("Fetch all entries: " + HTMLRenderer.sanitizeString((String)urls.get(i)));
fetch(urls, tmpFiles, user, new BlogStatusListener()); fetch(urls, tmpFiles, user, new BlogStatusListener(user));
} }
private void fetch(List urls, List tmpFiles, User user, EepGet.StatusListener lsnr) { private void fetch(List urls, List tmpFiles, User user, EepGet.StatusListener lsnr) {
@@ -352,7 +352,7 @@ public class RemoteArchiveBean {
_archiveFile = file; _archiveFile = file;
} }
public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) { public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) {
_statusMessages.add("Attempt " + currentAttempt + " failed after " + bytesTransferred + (cause != null ? cause.getMessage() : "")); _statusMessages.add("Attempt " + currentAttempt + " failed after " + bytesTransferred + (cause != null ? " " + cause.getMessage() : ""));
} }
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {} public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {}
@@ -390,7 +390,7 @@ public class RemoteArchiveBean {
private class MetadataStatusListener implements EepGet.StatusListener { private class MetadataStatusListener implements EepGet.StatusListener {
public MetadataStatusListener() {} public MetadataStatusListener() {}
public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) { public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) {
_statusMessages.add("Attempt " + currentAttempt + " failed after " + bytesTransferred + (cause != null ? cause.getMessage() : "")); _statusMessages.add("Attempt " + currentAttempt + " failed after " + bytesTransferred + (cause != null ? " " + cause.getMessage() : ""));
} }
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {} public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {}
@@ -428,9 +428,12 @@ public class RemoteArchiveBean {
} }
private class BlogStatusListener implements EepGet.StatusListener { private class BlogStatusListener implements EepGet.StatusListener {
public BlogStatusListener() {} private User _user;
public BlogStatusListener(User user) {
_user = user;
}
public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) { public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) {
_statusMessages.add("Attempt " + currentAttempt + " failed after " + bytesTransferred + (cause != null ? cause.getMessage() : "")); _statusMessages.add("Attempt " + currentAttempt + " failed after " + bytesTransferred + (cause != null ? " " + cause.getMessage() : ""));
} }
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {} public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {}
@@ -464,6 +467,7 @@ public class RemoteArchiveBean {
} else { } else {
_statusMessages.add("Blog post " + uri.toString() + " imported"); _statusMessages.add("Blog post " + uri.toString() + " imported");
BlogManager.instance().getArchive().regenerateIndex(); BlogManager.instance().getArchive().regenerateIndex();
_user.dataImported();
} }
} catch (IOException ioe) { } catch (IOException ioe) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
@@ -485,11 +489,13 @@ public class RemoteArchiveBean {
*/ */
private class BulkFetchListener implements EepGet.StatusListener { private class BulkFetchListener implements EepGet.StatusListener {
private File _tmp; private File _tmp;
public BulkFetchListener(File tmp) { private User _user;
public BulkFetchListener(User user, File tmp) {
_user = user;
_tmp = tmp; _tmp = tmp;
} }
public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) { public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) {
_statusMessages.add("Attempt " + currentAttempt + " failed after " + bytesTransferred + (cause != null ? cause.getMessage() : "")); _statusMessages.add("Attempt " + currentAttempt + " failed after " + bytesTransferred + (cause != null ? " " + cause.getMessage() : ""));
} }
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {} public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {}
@@ -499,7 +505,7 @@ public class RemoteArchiveBean {
ZipInputStream zi = null; ZipInputStream zi = null;
try { try {
zi = new ZipInputStream(new FileInputStream(file)); zi = new ZipInputStream(new FileInputStream(file));
boolean postImported = false;
while (true) { while (true) {
ZipEntry entry = zi.getNextEntry(); ZipEntry entry = zi.getNextEntry();
if (entry == null) if (entry == null)
@@ -540,11 +546,14 @@ public class RemoteArchiveBean {
continue; continue;
} else { } else {
_statusMessages.add("Blog post " + uri.toString() + " imported"); _statusMessages.add("Blog post " + uri.toString() + " imported");
postImported = true;
} }
} }
} }
BlogManager.instance().getArchive().regenerateIndex(); BlogManager.instance().getArchive().regenerateIndex();
if (postImported)
_user.dataImported();
} catch (IOException ioe) { } catch (IOException ioe) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.debug("Error importing", ioe); _log.debug("Error importing", ioe);

View File

@@ -23,6 +23,8 @@ public class SyndicateServlet extends BaseServlet {
protected String getTitle() { return "Syndie :: Syndicate"; } protected String getTitle() { return "Syndie :: Syndicate"; }
public static final String PARAM_SCHEMA = "schema"; public static final String PARAM_SCHEMA = "schema";
public static final String PARAM_LOCATION = "location";
public static final String PARAM_PETNAME = "petname";
protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index, protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index,
int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException { int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException {
@@ -40,14 +42,14 @@ public class SyndicateServlet extends BaseServlet {
RemoteArchiveBean remote = getRemote(req); RemoteArchiveBean remote = getRemote(req);
String action = req.getParameter("action"); String action = req.getParameter("action");
if ("Continue...".equals(action)) { if ("Continue...".equals(action)) {
String location = req.getParameter("location"); String location = req.getParameter(PARAM_LOCATION);
String pn = req.getParameter("archivepetname"); String pn = req.getParameter(PARAM_PETNAME);
if ( (pn != null) && (pn.trim().length() > 0) ) { if ( (pn != null) && (pn.trim().length() > 0) ) {
PetName pnval = user.getPetNameDB().getByName(pn); PetName pnval = user.getPetNameDB().getByName(pn);
if (pnval != null) location = pnval.getLocation(); if (pnval != null) location = pnval.getLocation();
} }
remote.fetchIndex(user, req.getParameter("schema"), location, remote.fetchIndex(user, req.getParameter(PARAM_SCHEMA), location,
req.getParameter("proxyhost"), req.getParameter("proxyhost"),
req.getParameter("proxyport")); req.getParameter("proxyport"));
} else if ("Fetch metadata".equals(action)) { } else if ("Fetch metadata".equals(action)) {
@@ -82,7 +84,7 @@ public class SyndicateServlet extends BaseServlet {
out.write("</span>"); out.write("</span>");
out.write("<a class=\"b_remoteRefetch\" href=\""); out.write("<a class=\"b_remoteRefetch\" href=\"");
out.write(req.getRequestURI()); out.write(req.getRequestURI());
out.write("?schema=" + remote.getRemoteSchema() + "&location=" + remote.getRemoteLocation()); out.write("?" + PARAM_SCHEMA + "=" + remote.getRemoteSchema() + "&" + PARAM_LOCATION + "=" + remote.getRemoteLocation());
if (remote.getProxyHost() != null && remote.getProxyPort() > 0) { if (remote.getProxyHost() != null && remote.getProxyPort() > 0) {
out.write("&proxyhost=" + remote.getProxyHost() + "&proxyport=" + remote.getProxyPort()); out.write("&proxyhost=" + remote.getProxyHost() + "&proxyport=" + remote.getProxyPort());
} }
@@ -100,12 +102,12 @@ public class SyndicateServlet extends BaseServlet {
writeAuthActionFields(out); writeAuthActionFields(out);
out.write("<tr><td colspan=\"3\">"); out.write("<tr><td colspan=\"3\">");
out.write("<span class=\"b_remoteChooser\"><span class=\"b_remoteChooserField\">Import from:</span>\n"); out.write("<span class=\"b_remoteChooser\"><span class=\"b_remoteChooserField\">Import from:</span>\n");
out.write("<select class=\"b_remoteChooserNet\" name=\"schema\">\n"); out.write("<select class=\"b_remoteChooserNet\" name=\"" + PARAM_SCHEMA + "\">\n");
String schema = req.getParameter(PARAM_SCHEMA); String schema = req.getParameter(PARAM_SCHEMA);
out.write("<option value=\"web\" "); out.write("<option value=\"web\" ");
if ("web".equals(schema)) if ("web".equals(schema))
out.write("selected=\"true\" "); out.write("selected=\"true\" ");
out.write(">I2P/Tor/Freenet</option>\n"); out.write(">I2P/Web/Tor/Freenet</option>\n");
out.write("</select>\n"); out.write("</select>\n");
out.write("<span class=\"b_remoteChooserField\">Proxy</span>\n"); out.write("<span class=\"b_remoteChooserField\">Proxy</span>\n");
@@ -116,7 +118,7 @@ public class SyndicateServlet extends BaseServlet {
out.write(BlogManager.instance().getDefaultProxyPort()); out.write(BlogManager.instance().getDefaultProxyPort());
out.write("\" /><br />\n"); out.write("\" /><br />\n");
out.write("<span class=\"b_remoteChooserField\">Bookmarked archives:</span>\n"); out.write("<span class=\"b_remoteChooserField\">Bookmarked archives:</span>\n");
out.write("<select class=\"b_remoteChooserPN\" name=\"archivepetname\">"); out.write("<select class=\"b_remoteChooserPN\" name=\"" + PARAM_PETNAME + "\">");
out.write("<option value=\"\">Custom location</option>"); out.write("<option value=\"\">Custom location</option>");
for (Iterator iter = user.getPetNameDB().iterator(); iter.hasNext(); ) { for (Iterator iter = user.getPetNameDB().iterator(); iter.hasNext(); ) {
@@ -130,7 +132,7 @@ public class SyndicateServlet extends BaseServlet {
} }
} }
out.write("</select> or "); out.write("</select> or ");
out.write("<input type=\"text\" class=\"b_remoteChooserLocation\" name=\"location\" size=\"30\" value=\""); out.write("<input type=\"text\" class=\"b_remoteChooserLocation\" name=\"" + PARAM_LOCATION + "\" size=\"30\" value=\"");
String reqLoc = req.getParameter("location"); String reqLoc = req.getParameter("location");
if (reqLoc != null) if (reqLoc != null)
out.write(reqLoc); out.write(reqLoc);