2006-03-25 jrandom

* Added a simple purge and ban of syndie authors, shown as the
      "Purge and ban" button on the addressbook for authors that are already
      on the ignore list.  All of their entries and metadata are deleted from
      the archive, and the are transparently filtered from any remote
      syndication (so no user on the syndie instance will pull any new posts
      from them)
    * More strict tunnel join throtting when congested
This commit is contained in:
jrandom
2006-03-25 23:50:48 +00:00
committed by zzz
parent d489caa88c
commit b5c0d77c69
9 changed files with 116 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ import java.text.*;
import net.i2p.I2PAppContext;
import net.i2p.data.*;
import net.i2p.syndie.data.*;
import net.i2p.util.FileUtil;
import net.i2p.util.Log;
/**
@@ -332,6 +333,15 @@ public class Archive {
return rv;
}
public synchronized void delete(Hash blog) {
if (blog == null) return;
File blogDir = new File(_rootDir, blog.toBase64());
boolean deleted = FileUtil.rmdir(blogDir, false);
File cacheDir = new File(_cacheDir, blog.toBase64());
deleted = FileUtil.rmdir(cacheDir, false) && deleted;
_log.info("Deleted blog " + blog.toBase64() + " completely? " + deleted);
}
public boolean storeEntry(EntryContainer container) {
if (container == null) return false;
BlogURI uri = container.getURI();

View File

@@ -1060,4 +1060,49 @@ public class BlogManager {
return true;
return false;
}
public boolean isBanned(Hash blog) {
if (blog == null) return false;
String str = blog.toBase64();
String banned = System.getProperty("syndie.bannedBlogs", "");
return (banned.indexOf(str) >= 0);
}
public String[] getBannedBlogs() {
List blogs = new ArrayList();
String str = System.getProperty("syndie.bannedBlogs", "");
StringTokenizer tok = new StringTokenizer(str, ",");
while (tok.hasMoreTokens()) {
String blog = tok.nextToken();
try {
Hash h = new Hash();
h.fromBase64(blog);
blogs.add(blog); // the base64 string, but verified
} catch (DataFormatException dfe) {
// ignored
}
}
String rv[] = new String[blogs.size()];
for (int i = 0; i < blogs.size(); i++)
rv[i] = (String)blogs.get(i);
return rv;
}
/**
* Delete the blog from the archive completely, and ban them from ever being added again
*/
public void purgeAndBan(Hash blog) {
String banned[] = getBannedBlogs();
StringBuffer buf = new StringBuffer();
String str = blog.toBase64();
buf.append(str);
for (int i = 0; banned != null && i < banned.length; i++) {
if (!banned[i].equals(str))
buf.append(",").append(banned[i]);
}
System.setProperty("syndie.bannedBlogs", buf.toString());
writeConfig();
_archive.delete(blog);
_archive.regenerateIndex();
}
}

View File

@@ -46,6 +46,7 @@ public class AddressesServlet extends BaseServlet {
public static final String ACTION_DELETE_BLOG = "Delete author";
public static final String ACTION_UPDATE_BLOG = "Update author";
public static final String ACTION_ADD_BLOG = "Add author";
public static final String ACTION_PURGE_AND_BAN_BLOG = "Purge and ban author";
public static final String ACTION_DELETE_ARCHIVE = "Delete archive";
public static final String ACTION_UPDATE_ARCHIVE = "Update archive";
@@ -128,6 +129,8 @@ public class AddressesServlet extends BaseServlet {
if (pn.isMember(FilteredThreadIndex.GROUP_IGNORE)) {
out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE
+ "\" checked=\"true\" value=\"true\" title=\"If true, their threads are hidden\" /> ");
if (BlogManager.instance().authorizeRemote(user))
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_PURGE_AND_BAN_BLOG + "\" /> ");
} else {
out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE
+ "\" value=\"true\" title=\"If true, their threads are hidden\" /> ");

View File

@@ -329,6 +329,34 @@ public abstract class BaseServlet extends HttpServlet {
(AddressesServlet.ACTION_UPDATE_OTHER.equals(action)) ||
(AddressesServlet.ACTION_UPDATE_PEER.equals(action)) ) {
return updateAddress(user, req);
} else if (AddressesServlet.ACTION_PURGE_AND_BAN_BLOG.equals(action)) {
String name = req.getParameter(AddressesServlet.PARAM_NAME);
PetName pn = user.getPetNameDB().getByName(name);
if (pn != null) {
boolean purged = false;
if (BlogManager.instance().authorizeRemote(user)) {
Hash h = null;
BlogURI uri = new BlogURI(pn.getLocation());
if (uri.getKeyHash() != null) {
h = uri.getKeyHash();
}
if (h == null) {
byte b[] = Base64.decode(pn.getLocation());
if ( (b != null) && (b.length == Hash.HASH_LENGTH) )
h = new Hash(b);
}
if (h != null) {
BlogManager.instance().purgeAndBan(h);
purged = true;
}
}
if (purged) // force a new thread index
return true;
else
return false;
} else {
return false;
}
} else if ( (AddressesServlet.ACTION_DELETE_ARCHIVE.equals(action)) ||
(AddressesServlet.ACTION_DELETE_BLOG.equals(action)) ||
(AddressesServlet.ACTION_DELETE_EEPSITE.equals(action)) ||

View File

@@ -62,6 +62,8 @@ public class RemoteArchiveBean {
}
private boolean ignoreBlog(User user, Hash blog) {
if (BlogManager.instance().isBanned(blog))
return true;
PetNameDB db = user.getPetNameDB();
PetName pn = db.getByLocation(blog.toBase64());
return ( (pn!= null) && (pn.isMember("Ignore")) );