Files
i2p.i2p/apps/routerconsole/java/src/net/i2p/router/web/ConfigPeerHandler.java

80 lines
2.9 KiB
Java
Raw Normal View History

2008-07-16 15:05:07 +00:00
package net.i2p.router.web;
import net.i2p.data.Hash;
import net.i2p.data.Base64;
import net.i2p.router.peermanager.PeerProfile;
/**
*
*/
public class ConfigPeerHandler extends FormHandler {
private String _peer;
private String _speed;
private String _capacity;
2009-08-15 16:08:33 +00:00
@Override
2008-07-16 15:05:07 +00:00
protected void processForm() {
if ("Save Configuration".equals(_action)) {
_context.router().saveConfig();
addFormNotice("Settings saved - not really!!!!!");
} else if (_action.equals(_("Ban peer until restart"))) {
2008-07-16 15:05:07 +00:00
Hash h = getHash();
if (h != null) {
2010-11-17 22:26:31 +00:00
_context.shitlist().shitlistRouterForever(h, _("Manually banned via {0}"), "<a href=\"configpeer\">configpeer</a>");
addFormNotice(_("Peer") + " " + _peer + " " + _("banned until restart") );
2008-07-16 15:05:07 +00:00
return;
}
addFormError(_("Invalid peer"));
} else if (_action.equals(_("Unban peer"))) {
2008-07-16 15:05:07 +00:00
Hash h = getHash();
if (h != null) {
if (_context.shitlist().isShitlisted(h)) {
_context.shitlist().unshitlistRouter(h);
addFormNotice(_("Peer") + " " + _peer + " " + _("unbanned") );
2008-07-16 15:05:07 +00:00
} else
addFormNotice(_("Peer") + " " + _peer + " " + _("is not currently banned") );
2008-07-16 15:05:07 +00:00
return;
}
addFormError(_("Invalid peer"));
} else if (_action.equals(_("Adjust peer bonuses"))) {
2008-07-16 15:05:07 +00:00
Hash h = getHash();
if (h != null) {
PeerProfile prof = _context.profileOrganizer().getProfile(h);
if (prof != null) {
try {
prof.setSpeedBonus(Long.parseLong(_speed));
} catch (NumberFormatException nfe) {
addFormError(_("Bad speed value"));
2008-07-16 15:05:07 +00:00
}
try {
prof.setCapacityBonus(Long.parseLong(_capacity));
} catch (NumberFormatException nfe) {
addFormError(_("Bad capacity value"));
2008-07-16 15:05:07 +00:00
}
addFormNotice("Bonuses adjusted for " + _peer);
} else
addFormError("No profile exists for " + _peer);
return;
}
addFormError(_("Invalid peer"));
2008-07-16 15:05:07 +00:00
} else if (_action.startsWith("Check")) {
2010-03-05 15:27:32 +00:00
addFormError(_("Unsupported"));
} else {
addFormError("Unknown action \"" + _action + '"');
2008-07-16 15:05:07 +00:00
}
}
private Hash getHash() {
if (_peer != null && _peer.length() == 44) {
byte[] b = Base64.decode(_peer);
if (b != null)
return new Hash(b);
}
return null;
}
public void setPeer(String peer) { _peer = peer; }
public void setSpeed(String bonus) { _speed = bonus; }
public void setCapacity(String bonus) { _capacity = bonus; }
}