* move over the rssimport, and default it to the proxy @ localhost:4444
This commit is contained in:
@ -364,8 +364,8 @@ public class BlogManager {
|
||||
return ( (isSingle != null) && (Boolean.valueOf(isSingle).booleanValue()) );
|
||||
}
|
||||
|
||||
public String getDefaultProxyHost() { return _context.getProperty("syndie.defaultProxyHost", ""); }
|
||||
public String getDefaultProxyPort() { return _context.getProperty("syndie.defaultProxyPort", ""); }
|
||||
public String getDefaultProxyHost() { return _context.getProperty("syndie.defaultProxyHost", "localhost"); }
|
||||
public String getDefaultProxyPort() { return _context.getProperty("syndie.defaultProxyPort", "4444"); }
|
||||
public String[] getUpdateArchives() { return _context.getProperty("syndie.updateArchives", "").split(","); }
|
||||
public boolean getImportAddresses() { return _context.getProperty("syndie.importAddresses", "false").equals("true"); }
|
||||
public int getUpdateDelay() {
|
||||
|
@ -78,8 +78,8 @@ public class Sucker {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
proxyPort="4444";
|
||||
proxyHost="localhost";
|
||||
proxyPort = BlogManager.instance().getDefaultProxyPort();
|
||||
proxyHost = BlogManager.instance().getDefaultProxyHost();
|
||||
|
||||
bm = BlogManager.instance();
|
||||
Hash blogHash = new Hash();
|
||||
@ -171,6 +171,8 @@ public class Sucker {
|
||||
messageNumber=bm.getNextBlogEntry(user);
|
||||
}
|
||||
|
||||
_log.debug("message number: " + messageNumber);
|
||||
|
||||
// Create historyFile if missing
|
||||
historyFile = new File(historyPath);
|
||||
if (!historyFile.exists())
|
||||
@ -195,13 +197,19 @@ public class Sucker {
|
||||
numRetries, fetched.getAbsolutePath(), urlToLoad);
|
||||
SuckerFetchListener lsnr = new SuckerFetchListener();
|
||||
get.addStatusListener(lsnr);
|
||||
|
||||
_log.debug("fetching [" + urlToLoad + "] / " + shouldProxy + "/" + proxyHost + "/" + proxyHost);
|
||||
|
||||
get.fetch();
|
||||
_log.debug("fetched: " + get.getNotModified() + "/" + get.getETag());
|
||||
boolean ok = lsnr.waitForSuccess();
|
||||
if (!ok) {
|
||||
_log.debug("success? " + ok);
|
||||
System.err.println("Unable to retrieve the url after " + numRetries + " tries.");
|
||||
fetched.delete();
|
||||
return;
|
||||
}
|
||||
_log.debug("fetched successfully? " + ok);
|
||||
if(get.getNotModified()) {
|
||||
debugLog("not modified, saving network bytes from useless fetch");
|
||||
fetched.delete();
|
||||
@ -214,6 +222,8 @@ public class Sucker {
|
||||
|
||||
List entries = feed.getEntries();
|
||||
|
||||
_log.debug("entries: " + entries.size());
|
||||
|
||||
FileOutputStream hos = new FileOutputStream(historyFile, true);
|
||||
|
||||
// Process list backwards to get syndie to display the
|
||||
@ -223,6 +233,9 @@ public class Sucker {
|
||||
|
||||
attachmentCounter=0;
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Syndicate entry: " + e.getLink());
|
||||
|
||||
String messageId = convertToSml(e);
|
||||
if (messageId!=null) {
|
||||
hos.write(messageId.getBytes());
|
||||
@ -234,6 +247,8 @@ public class Sucker {
|
||||
FileOutputStream fos = new FileOutputStream(lastIdFile);
|
||||
fos.write(("" + messageNumber).getBytes());
|
||||
}
|
||||
|
||||
_log.debug("done fetching");
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
158
apps/syndie/java/src/net/i2p/syndie/web/ImportFeedServlet.java
Normal file
158
apps/syndie/java/src/net/i2p/syndie/web/ImportFeedServlet.java
Normal file
@ -0,0 +1,158 @@
|
||||
package net.i2p.syndie.web;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.naming.*;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.syndie.*;
|
||||
import net.i2p.syndie.data.*;
|
||||
import net.i2p.syndie.sml.*;
|
||||
|
||||
/**
|
||||
* Schedule the import of atom/rss feeds
|
||||
*
|
||||
* <p><h3>todo:</h3>
|
||||
* <p>caching (eepget should do it)
|
||||
* <p>enclosures support (requires cvs rome)
|
||||
* <p>syndie.sucker.minHistory/maxHistory used to roll over the history file?
|
||||
* <p>configurable update period
|
||||
*
|
||||
*/
|
||||
public class ImportFeedServlet extends BaseServlet {
|
||||
protected String getTitle() { return "Syndie :: Import feed"; }
|
||||
|
||||
protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index,
|
||||
int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException {
|
||||
|
||||
if (!BlogManager.instance().authorizeRemote(user)) {
|
||||
out.write("<tr><td colspan=\"3\"><span class=\"b_rssMsgErr\">You are not authorized for remote access.</span></td></tr>\n");
|
||||
} else {
|
||||
out.write("<tr><td colspan=\"3\">");
|
||||
|
||||
String url=req.getParameter("url");
|
||||
if (url != null)
|
||||
url = url.trim();
|
||||
String blog=req.getParameter("blog");
|
||||
if (blog != null)
|
||||
blog=blog.trim();
|
||||
String tagPrefix = req.getParameter("tagprefix");
|
||||
if (tagPrefix != null)
|
||||
tagPrefix=tagPrefix.trim();
|
||||
String action = req.getParameter("action");
|
||||
if ( (action != null) && ("Add".equals(action)) ) {
|
||||
if(url==null || blog==null || tagPrefix==null) {
|
||||
out.write("<span class=\"b_rssImportMsgErr\">Please fill in all fields</span><br />\n");
|
||||
} else {
|
||||
boolean ret = BlogManager.instance().addRssFeed(url, blog, tagPrefix);
|
||||
if (!ret) {
|
||||
out.write("<span class=\"b_rssImportMsgErr\">addRssFeed failure.</span>");
|
||||
} else {
|
||||
out.write("<span class=\"b_rssImportMsgOk\">RSS feed added.</span>");
|
||||
}
|
||||
}
|
||||
} else if ( (action != null) && ("Change".equals(action)) ) {
|
||||
String lastUrl=req.getParameter("lasturl");
|
||||
String lastBlog=req.getParameter("lastblog");
|
||||
String lastTagPrefix=req.getParameter("lasttagprefix");
|
||||
|
||||
if (url == null || blog == null || tagPrefix == null ||
|
||||
lastUrl == null || lastBlog == null || lastTagPrefix == null) {
|
||||
out.write("<span class=\"b_rssImportMsgErr\">error, some fields were empty.</span><br />");
|
||||
} else {
|
||||
boolean ret = BlogManager.instance().deleteRssFeed(lastUrl,lastBlog,lastTagPrefix);
|
||||
if (!ret) {
|
||||
out.write("<span class=\"b_rssImportMsgErr\">Could not delete while attempting to change.</span>");
|
||||
} else {
|
||||
ret = BlogManager.instance().addRssFeed(url,blog,tagPrefix);
|
||||
if (!ret) {
|
||||
out.write("<span class=\"b_rssImportMsgErr\">Could not add while attempting to change.</span>");
|
||||
} else {
|
||||
out.write("<span class=\"b_rssImportMsgOk\">Ok, changed successfully.</span>");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ( (action != null) && ("Delete".equals(action)) ) {
|
||||
out.write("<span class=\"b_rssImportMsgErr\">Delete some thing</span><br />");
|
||||
if (url == null || blog == null || tagPrefix == null) {
|
||||
out.write("<span class=\"b_rssImportMsgErr\">error, some fields were empty.</span><br />");
|
||||
} else {
|
||||
boolean ret = BlogManager.instance().deleteRssFeed(url,blog,tagPrefix);
|
||||
if (!ret) {
|
||||
out.write("<span class=\"b_rssImportMsgErr\">error, could not delete.</span>");
|
||||
} else {
|
||||
out.write("<span class=\"b_rssImportMsgOk\">ok, deleted successfully.</span>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String blogStr = user.getBlogStr();
|
||||
if (blogStr == null)
|
||||
blogStr="";
|
||||
|
||||
out.write("<p>Here you can add RSS feeds that will be periodically polled and added to your syndie. </p>");
|
||||
out.write("<form action=\"" + req.getRequestURI() + "\" method=\"POST\">");
|
||||
writeAuthActionFields(out);
|
||||
out.write("RSS URL. (e.g. http://tracker.postman.i2p/rss.php)<br />\n");
|
||||
out.write("<em><span class=\"b_rssImportField\">url:</span></em> <input class=\"b_rssImportField\" type=\"text\" size=\"50\" name=\"url\" /><br />\n");
|
||||
out.write("Blog hash to which the RSS entries will get posted, defaults to the one you're logged in to.<br />\n");
|
||||
out.write("<em><span class=\"b_rssImportField\">blog:</span></em> <input class=\"b_rssImportField\" type=\"text\" value=\"");
|
||||
out.write(blogStr);
|
||||
out.write("\" size=\"20\" name=\"blog\" /><br />\n");
|
||||
out.write("This will be prepended to any tags that the RSS feed contains. (e.g. feed.tracker)<br />\n");
|
||||
out.write("<em><span class=\"b_rssImportField\">tagprefix:</span></em>\n");
|
||||
out.write("<input class=\"b_rssImportField\" type=\"text\" value=\"feed\" size=\"20\" name=\"tagprefix\" /><br />\n");
|
||||
out.write("<input class=\"b_rssImportSubmit\" type=\"submit\" name=\"action\" value=\"Add\" />\n");
|
||||
out.write("<input class=\"b_rssImportCancel\" type=\"reset\" value=\"Cancel\" />\n");
|
||||
out.write("</form>\n");
|
||||
|
||||
List feedList = BlogManager.instance().getRssFeeds();
|
||||
if (feedList.size()>0) {
|
||||
out.write("<hr /><h3>Subscriptions:</h3><br />\n");
|
||||
out.write("<table border=\"0\" width=\"100%\" class=\"b_rss\">\n");
|
||||
out.write("<tr class=\"b_rssHeader\">\n");
|
||||
out.write("<td class=\"b_rssHeader\"><em class=\"b_rssHeader\">Url</em></td>\n");
|
||||
out.write("<td class=\"b_rssHeader\"><em class=\"b_rssHeader\">Blog</em></td>\n");
|
||||
out.write("<td class=\"b_rssHeader\"><em class=\"b_rssHeader\">TagPrefix</em></td>\n");
|
||||
out.write("<td class=\"b_rssHeader\"> </td></tr>\n");
|
||||
|
||||
Iterator iter = feedList.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String fields[] = (String[])iter.next();
|
||||
url = fields[0];
|
||||
blog = fields[1];
|
||||
tagPrefix = fields[2];
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
|
||||
buf.append("<tr class=\"b_rssDetail\"><form action=\"" + req.getRequestURI() + "\" method=\"POST\">");
|
||||
writeAuthActionFields(out);
|
||||
buf.append("<input type=\"hidden\" name=\"lasturl\" value=\"").append(url).append("\" />");
|
||||
buf.append("<input type=\"hidden\" name=\"lastblog\" value=\"").append(blog).append("\" />");
|
||||
buf.append("<input type=\"hidden\" name=\"lasttagprefix\" value=\"").append(tagPrefix).append("\" />");
|
||||
|
||||
buf.append("<td class=\"b_rssUrl\"><input class=\"b_rssUrl\" type=\"text\" size=\"50\" name=\"url\" value=\"").append(url).append("\" /></td>");
|
||||
buf.append("<td class=\"b_rssBlog\"><input class=\"b_rssBlog\" type=\"text\" size=\"20\" name=\"blog\" value=\"").append(blog).append("\" /></td>");
|
||||
buf.append("<td class=\"b_rssPrefix\"><input class=\"b_rssPrefix\" type=\"text\" size=\"20\" name=\"tagprefix\" value=\"").append(tagPrefix).append("\" /></td>");
|
||||
buf.append("<td class=\"b_rssDetail\" nowrap=\"nowrap\">");
|
||||
|
||||
buf.append("<input class=\"b_rssChange\" type=\"submit\" name=\"action\" value=\"Change\" />");
|
||||
buf.append("<input class=\"b_rssDelete\" type=\"submit\" name=\"action\" value=\"Delete\" />");
|
||||
|
||||
buf.append("</td></form></tr>");
|
||||
out.write(buf.toString());
|
||||
buf.setLength(0);
|
||||
}
|
||||
|
||||
out.write("</table>\n");
|
||||
} // end iterating over feeds
|
||||
|
||||
out.write("</td></tr>\n");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.data.Base64, net.i2p.syndie.web.*, net.i2p.syndie.sml.*, net.i2p.syndie.data.*, net.i2p.syndie.*, org.mortbay.servlet.MultiPartRequest, java.util.*, java.io.*" %><%
|
||||
request.setCharacterEncoding("UTF-8"); %><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user"
|
||||
/><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>SyndieMedia rss import configuration</title>
|
||||
<link href="style.jsp" rel="stylesheet" type="text/css" >
|
||||
</head>
|
||||
<body>
|
||||
<table border="1" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr class="b_toplogo"><td colspan="5" valign="top" align="left" class="b_toplogo"><jsp:include page="_toplogo.jsp" /></td></tr>
|
||||
<tr><td valign="top" align="left" rowspan="2" class="b_leftnav"><jsp:include page="_leftnav.jsp" /></td>
|
||||
<jsp:include page="_topnav.jsp" />
|
||||
<td valign="top" align="left" rowspan="2" class="b_rightnav"><jsp:include page="_rightnav.jsp" /></td></tr>
|
||||
<tr class="b_content"><td valign="top" align="left" colspan="3" class="b_content"><%
|
||||
|
||||
BlogManager bm = BlogManager.instance();
|
||||
if (!user.getAuthenticated()) {
|
||||
%><span class="b_rssMsgErr">Please log in.</span><%
|
||||
}
|
||||
else if(!bm.authorizeRemote(user)) {
|
||||
%><span class="b_rssMsgErr">You are not authorized for remote access.</span><%
|
||||
} else {
|
||||
String url=request.getParameter("url");
|
||||
if(url!=null) url=url.trim();
|
||||
String blog=request.getParameter("blog");
|
||||
if(blog!=null) blog=blog.trim();
|
||||
String tagPrefix=request.getParameter("tagprefix");
|
||||
if(tagPrefix!=null) tagPrefix=tagPrefix.trim();
|
||||
String action = request.getParameter("action");
|
||||
if ( (action != null) && ("Add".equals(action)) ) {
|
||||
if(url==null || blog==null || tagPrefix==null) {
|
||||
%><span class="b_rssImportMsgErr">Please fill in all fields</span><br /><%
|
||||
} else {
|
||||
boolean ret=bm.addRssFeed(url,blog,tagPrefix);
|
||||
if(!ret) {
|
||||
%><span class="b_rssImportMsgErr">addRssFeed failure.</span><%
|
||||
} else {
|
||||
%><span class="b_rssImportMsgOk">RSS feed added.</span><%
|
||||
}
|
||||
}
|
||||
} else if ( (action != null) && ("Change".equals(action)) ) {
|
||||
String lastUrl=request.getParameter("lasturl");
|
||||
String lastBlog=request.getParameter("lastblog");
|
||||
String lastTagPrefix=request.getParameter("lasttagprefix");
|
||||
if(url==null || blog==null || tagPrefix==null || lastUrl==null || lastBlog==null || lastTagPrefix==null) {
|
||||
%><span class="b_rssImportMsgErr">error, some fields were empty.</span><br /><%
|
||||
} else {
|
||||
boolean ret=bm.deleteRssFeed(lastUrl,lastBlog,lastTagPrefix);
|
||||
if(!ret) {
|
||||
%><span class="b_rssImportMsgErr">Could not delete while attempting to change.</span><%
|
||||
} else {
|
||||
ret=bm.addRssFeed(url,blog,tagPrefix);
|
||||
if(!ret) {
|
||||
%><span class="b_rssImportMsgErr">Could not add while attempting to change.</span><%
|
||||
} else {
|
||||
%><span class="b_rssImportMsgOk">Ok, changed successfully.</span><%
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ( (action != null) && ("Delete".equals(action)) ) {
|
||||
%><span class="b_rssImportMsgErr">Delete some thing</span><br /><%
|
||||
if(url==null || blog==null || tagPrefix==null) {
|
||||
%><span class="b_rssImportMsgErr">error, some fields were empty.</span><br /><%
|
||||
} else {
|
||||
boolean ret=bm.instance().deleteRssFeed(url,blog,tagPrefix);
|
||||
if(!ret) {
|
||||
%><span class="b_rssImportMsgErr">error, could not delete.</span><%
|
||||
} else {
|
||||
%><span class="b_rssImportMsgOk">ok, deleted successfully.</span><%
|
||||
}
|
||||
}
|
||||
}
|
||||
String blogStr=user.getBlogStr();
|
||||
if(blogStr==null)
|
||||
blogStr="";
|
||||
|
||||
///////////////////////////////////////////////
|
||||
%>
|
||||
<p>Here you can add RSS feeds that will be periodically polled and added to your syndie. </p>
|
||||
<form action="rssimport.jsp" method="POST">
|
||||
RSS URL. (e.g. http://tracker.postman.i2p/rss.php)<br />
|
||||
<em><span class="b_rssImportField">url:</span></em> <input class="b_rssImportField" type="text" size="50" name="url" /><br />
|
||||
Blog hash to which the RSS entries will get posted, defaults to the one you're logged in to.<br />
|
||||
<em><span class="b_rssImportField">blog:</span></em> <input class="b_rssImportField" type="text" <%="value=\""+blogStr+"\""%> size="20" name="blog" /><br />
|
||||
This will be prepended to any tags that the RSS feed contains. (e.g. feed.tracker)<br />
|
||||
<em><span class="b_rssImportField">tagprefix:</span></em> <input class="b_rssImportField" type="text" value="feed" size="20" name="tagprefix" /><br />
|
||||
<input class="b_rssImportSubmit" type="submit" name="action" value="Add" /> <input class="b_rssImportCancel" type="reset" value="Cancel" /></form>
|
||||
<%
|
||||
///////////////////////////////////////////////
|
||||
List feedList = bm.getRssFeeds();
|
||||
if(feedList.size()>0) {
|
||||
%>
|
||||
<hr /><h3>Subscriptions:</h3><br />
|
||||
<table border="0" width="100%" class="b_rss">
|
||||
<tr class="b_rssHeader">
|
||||
<td class="b_rssHeader"><em class="b_rssHeader">Url</em></td>
|
||||
<td class="b_rssHeader"><em class="b_rssHeader">Blog</em></td>
|
||||
<td class="b_rssHeader"><em class="b_rssHeader">TagPrefix</em></td>
|
||||
<td class="b_rssHeader"> </td></tr>
|
||||
<%
|
||||
Iterator iter = feedList.iterator();
|
||||
while(iter.hasNext()) {
|
||||
String fields[]=(String[])iter.next();
|
||||
url=fields[0];
|
||||
blog=fields[1];
|
||||
tagPrefix=fields[2];
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
|
||||
buf.append("<tr class=\"b_rssDetail\"><form action=\"rssimport.jsp\" method=\"POST\">");
|
||||
buf.append("<input type=\"hidden\" name=\"lasturl\" value=\"").append(url).append("\" />");
|
||||
buf.append("<input type=\"hidden\" name=\"lastblog\" value=\"").append(blog).append("\" />");
|
||||
buf.append("<input type=\"hidden\" name=\"lasttagprefix\" value=\"").append(tagPrefix).append("\" />");
|
||||
|
||||
buf.append("<td class=\"b_rssUrl\"><input class=\"b_rssUrl\" type=\"text\" size=\"50\" name=\"url\" value=\"").append(url).append("\" /></td>");
|
||||
buf.append("<td class=\"b_rssBlog\"><input class=\"b_rssBlog\" type=\"text\" size=\"20\" name=\"blog\" value=\"").append(blog).append("\" /></td>");
|
||||
buf.append("<td class=\"b_rssPrefix\"><input class=\"b_rssPrefix\" type=\"text\" size=\"20\" name=\"tagprefix\" value=\"").append(tagPrefix).append("\" /></td>");
|
||||
buf.append("<td class=\"b_rssDetail\" nowrap=\"nowrap\">");
|
||||
|
||||
buf.append("<input class=\"b_rssChange\" type=\"submit\" name=\"action\" value=\"Change\" />");
|
||||
buf.append("<input class=\"b_rssDelete\" type=\"submit\" name=\"action\" value=\"Delete\" />");
|
||||
|
||||
buf.append("</td></form></tr>");
|
||||
out.write(buf.toString());
|
||||
buf.setLength(0);
|
||||
}
|
||||
}
|
||||
/*
|
||||
<p><h3>todo:</h3>
|
||||
<p>caching (eepget should do it)
|
||||
<p>enclosures support (requires cvs rome)
|
||||
<p>syndie.sucker.minHistory/maxHistory used to roll over the history file?
|
||||
<p>configurable update period
|
||||
*/
|
||||
%>
|
||||
</table>
|
||||
<hr />
|
||||
<%
|
||||
}
|
||||
%>
|
||||
</td></tr>
|
||||
</table>
|
||||
</body>
|
@ -49,6 +49,11 @@
|
||||
<servlet-class>net.i2p.syndie.web.SyndicateServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>net.i2p.syndie.web.ImportFeedServlet</servlet-name>
|
||||
<servlet-class>net.i2p.syndie.web.ImportFeedServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>net.i2p.syndie.UpdaterServlet</servlet-name>
|
||||
<servlet-class>net.i2p.syndie.UpdaterServlet</servlet-class>
|
||||
@ -99,6 +104,10 @@
|
||||
<servlet-name>net.i2p.syndie.web.SyndicateServlet</servlet-name>
|
||||
<url-pattern>/syndicate.jsp</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>net.i2p.syndie.web.ImportFeedServlet</servlet-name>
|
||||
<url-pattern>/importfeed.jsp</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<session-config>
|
||||
<session-timeout>
|
||||
|
Reference in New Issue
Block a user