* Implemented a Syndie auto-updater.
This commit is contained in:
@ -3,6 +3,7 @@ package net.i2p.syndie;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.naming.PetName;
|
import net.i2p.client.naming.PetName;
|
||||||
import net.i2p.client.naming.PetNameDB;
|
import net.i2p.client.naming.PetNameDB;
|
||||||
@ -277,6 +278,8 @@ public class BlogManager {
|
|||||||
|
|
||||||
public String getDefaultProxyHost() { return _context.getProperty("syndie.defaultProxyHost", ""); }
|
public String getDefaultProxyHost() { return _context.getProperty("syndie.defaultProxyHost", ""); }
|
||||||
public String getDefaultProxyPort() { return _context.getProperty("syndie.defaultProxyPort", ""); }
|
public String getDefaultProxyPort() { return _context.getProperty("syndie.defaultProxyPort", ""); }
|
||||||
|
public int getUpdateDelay() { return Integer.parseInt(_context.getProperty("syndie.updateDelay", "1")); }
|
||||||
|
public String[] getUpdateArchives() { return _context.getProperty("syndie.updateArchives", "").split(","); }
|
||||||
|
|
||||||
public boolean authorizeAdmin(String pass) {
|
public boolean authorizeAdmin(String pass) {
|
||||||
if (isSingleUser()) return true;
|
if (isSingleUser()) return true;
|
||||||
|
65
apps/syndie/java/src/net/i2p/syndie/Updater.java
Normal file
65
apps/syndie/java/src/net/i2p/syndie/Updater.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package net.i2p.syndie;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.util.Log;
|
||||||
|
import net.i2p.syndie.web.RemoteArchiveBean;
|
||||||
|
|
||||||
|
public class Updater {
|
||||||
|
public static final String VERSION = "1.0";
|
||||||
|
private static final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(Updater.class);
|
||||||
|
private static final Updater _instance = new Updater();
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
_log.debug("Update started.");
|
||||||
|
BlogManager bm = BlogManager.instance();
|
||||||
|
User user = new User();
|
||||||
|
RemoteArchiveBean rab = new RemoteArchiveBean();
|
||||||
|
String[] archives = bm.getUpdateArchives();
|
||||||
|
for (int i = 0; i < archives.length; i++) {
|
||||||
|
_log.debug("Fetching " + archives[i]);
|
||||||
|
rab.fetchIndex(user, "web", archives[i], bm.getDefaultProxyHost(), bm.getDefaultProxyPort());
|
||||||
|
if (rab.getRemoteIndex() != null) {
|
||||||
|
_log.debug("Index fetched, getting new entries.");
|
||||||
|
HashMap parameters = new HashMap();
|
||||||
|
parameters.put("action", "Fetch all new entries");
|
||||||
|
//rab.fetchSelectedBulk(user, parameters);
|
||||||
|
rab.fetchAllEntries(user, parameters);
|
||||||
|
_log.debug("Update finished.");
|
||||||
|
} else {
|
||||||
|
_log.debug("Index fetch failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main() {
|
||||||
|
_instance.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
// wait
|
||||||
|
try {
|
||||||
|
Thread.currentThread().sleep(5*60*1000);
|
||||||
|
} catch (InterruptedException ie) {}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
int delay = BlogManager.instance().getUpdateDelay();
|
||||||
|
update();
|
||||||
|
try {
|
||||||
|
synchronized (this) {
|
||||||
|
wait(delay * 60 * 60 * 1000);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException exp) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void wakeup() {
|
||||||
|
synchronized (_instance) {
|
||||||
|
_instance.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
apps/syndie/java/src/net/i2p/syndie/UpdaterServlet.java
Normal file
37
apps/syndie/java/src/net/i2p/syndie/UpdaterServlet.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package net.i2p.syndie;
|
||||||
|
|
||||||
|
import javax.servlet.GenericServlet;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.ServletConfig;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper for syndie updater to allow it to be started as a web application.
|
||||||
|
*
|
||||||
|
* @author Ragnarok
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class UpdaterServlet extends GenericServlet {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see javax.servlet.Servlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
|
||||||
|
*/
|
||||||
|
public void service(ServletRequest request, ServletResponse response) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
|
||||||
|
*/
|
||||||
|
public void init(ServletConfig config) {
|
||||||
|
try {
|
||||||
|
super.init(config);
|
||||||
|
} catch (ServletException exp) {
|
||||||
|
}
|
||||||
|
UpdaterThread thread = new UpdaterThread();
|
||||||
|
thread.setDaemon(true);
|
||||||
|
thread.start();
|
||||||
|
System.out.println("INFO: Starting Syndie Updater " + Updater.VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
apps/syndie/java/src/net/i2p/syndie/UpdaterThread.java
Normal file
27
apps/syndie/java/src/net/i2p/syndie/UpdaterThread.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package net.i2p.syndie;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A thread that runs the updater.
|
||||||
|
*
|
||||||
|
* @author Ragnarok
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class UpdaterThread extends Thread {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an UpdaterThread.
|
||||||
|
*/
|
||||||
|
public UpdaterThread() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
|
public void run() {
|
||||||
|
//try {
|
||||||
|
// Thread.sleep(5 * 60 * 1000);
|
||||||
|
//} catch (InterruptedException exp) {
|
||||||
|
//}
|
||||||
|
Updater.main();
|
||||||
|
}
|
||||||
|
}
|
@ -297,18 +297,24 @@ public class RemoteArchiveBean {
|
|||||||
|
|
||||||
_statusMessages.add("Fetching index from " + HTMLRenderer.sanitizeString(_remoteLocation) +
|
_statusMessages.add("Fetching index from " + HTMLRenderer.sanitizeString(_remoteLocation) +
|
||||||
(_proxyHost != null ? " via " + HTMLRenderer.sanitizeString(_proxyHost) + ":" + _proxyPort : ""));
|
(_proxyHost != null ? " via " + HTMLRenderer.sanitizeString(_proxyHost) + ":" + _proxyPort : ""));
|
||||||
File archiveFile = new File(BlogManager.instance().getTempDir(), user.getBlog().toBase64() + "_remoteArchive.txt");
|
|
||||||
|
File archiveFile;
|
||||||
|
if (user.getBlog() != null) {
|
||||||
|
archiveFile = new File(BlogManager.instance().getTempDir(), user.getBlog().toBase64() + "_remoteArchive.txt");
|
||||||
|
} else {
|
||||||
|
archiveFile = new File(BlogManager.instance().getTempDir(), "remoteArchive.txt");
|
||||||
|
}
|
||||||
archiveFile.delete();
|
archiveFile.delete();
|
||||||
|
|
||||||
Properties etags = new Properties();
|
Properties etags = new Properties();
|
||||||
try {
|
try {
|
||||||
etags.load(new FileInputStream(new File(BlogManager.instance().getRootDir(), "etags")));
|
DataHelper.loadProps(etags, new File(BlogManager.instance().getRootDir(), "etags"));
|
||||||
} catch (Exception exp) {
|
} catch (IOException ioe) {
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
EepGet eep = new EepGet(I2PAppContext.getGlobalContext(), ((_proxyHost != null) && (_proxyPort > 0)),
|
EepGet eep = new EepGet(I2PAppContext.getGlobalContext(), ((_proxyHost != null) && (_proxyPort > 0)),
|
||||||
_proxyHost, _proxyPort, 0, archiveFile.getAbsolutePath(), location, etags.getProperty(location));
|
_proxyHost, _proxyPort, 0, archiveFile.getAbsolutePath(), location, true, etags.getProperty(location));
|
||||||
eep.addStatusListener(new IndexFetcherStatusListener(archiveFile));
|
eep.addStatusListener(new IndexFetcherStatusListener(archiveFile));
|
||||||
eep.fetch();
|
eep.fetch();
|
||||||
|
|
||||||
@ -316,8 +322,8 @@ public class RemoteArchiveBean {
|
|||||||
etags.setProperty(location, eep.getETag());
|
etags.setProperty(location, eep.getETag());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
etags.store(new FileOutputStream(new File(BlogManager.instance().getRootDir(), "etags")), "etags");
|
DataHelper.storeProps(etags, new File(BlogManager.instance().getRootDir(), "etags"));
|
||||||
} catch (Exception exp) {
|
} catch (IOException ioe) {
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,12 @@
|
|||||||
<servlet-class>net.i2p.syndie.web.RSSServlet</servlet-class>
|
<servlet-class>net.i2p.syndie.web.RSSServlet</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>net.i2p.syndie.UpdaterServlet</servlet-name>
|
||||||
|
<servlet-class>net.i2p.syndie.UpdaterServlet</servlet-class>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
<!-- precompiled servlets -->
|
<!-- precompiled servlets -->
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
|
11
history.txt
11
history.txt
@ -1,4 +1,13 @@
|
|||||||
$Id: history.txt,v 1.276 2005/09/30 19:57:34 ragnarok Exp $
|
$Id: history.txt,v 1.277 2005/10/01 14:20:10 jrandom Exp $
|
||||||
|
|
||||||
|
2005-10-03 ragnarok
|
||||||
|
* Implemented a Syndie auto-updater. It will automatically pull new posts
|
||||||
|
from selected syndie archives. To try it out, add
|
||||||
|
syndie.updateArchives=<comma seperated list of syndie archives> to your
|
||||||
|
syndie.config. Archives must be specified as the full url to archive.txt
|
||||||
|
(e.g. http://syndiemedia.i2p/archive/archive.txt). By default, it checks
|
||||||
|
for new posts every hour. This can be modified by setting
|
||||||
|
syndie.updateDelay=<delay in hours> also in syndie.config.
|
||||||
|
|
||||||
* 2005-10-01 0.6.1.1 released
|
* 2005-10-01 0.6.1.1 released
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user