added IP ban facility - IP addresses can now be blocked from logging into

Venice, either individually or in blocks
This commit is contained in:
Eric J. Bowersox
2004-05-31 03:38:41 +00:00
parent 55db78c0e9
commit 609d216148
19 changed files with 959 additions and 32 deletions

View File

@@ -8,9 +8,9 @@
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2001-2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
// Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
@@ -35,6 +35,15 @@ if (user.isLoggedIn())
} // end if
// Test to see if the IP address has been banned.
banmsg = rinput.engine.testIPBan(rinput.sourceAddress);
if (banmsg!=null)
{ // this IP address has been banned - you are Not Allowed
vlib.output(new ErrorBox("This IP address has been banned",banmsg,target));
vlib.done();
} // end if
dlg = rinput.getDialog("login");
if ("GET"==rinput.verb)

View File

@@ -8,9 +8,9 @@
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2001-04 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
// Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
@@ -35,6 +35,15 @@ if (user.isLoggedIn())
} // end if
// Test to see if the IP address has been banned.
banmsg = rinput.engine.testIPBan(rinput.sourceAddress);
if (banmsg!=null)
{ // this IP address has been banned - you are Not Allowed
vlib.output(new ErrorBox("This IP address has been banned",banmsg,target));
vlib.done();
} // end if
// Return the text of the User Agreement.
rinput.displayLogin = false;
html = vlib.queryHTMLRendering(rinput);

View File

@@ -8,9 +8,9 @@
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
// Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
@@ -36,6 +36,15 @@ if (user.isLoggedIn())
} // end if
// Test to see if the IP address has been banned.
banmsg = rinput.engine.testIPBan(rinput.sourceAddress);
if (banmsg!=null)
{ // this IP address has been banned - you are Not Allowed
vlib.output(new ErrorBox("This IP address has been banned",banmsg,target));
vlib.done();
} // end if
// create the new account dialog
dlg = rinput.getDialog("newacct");
@@ -145,4 +154,4 @@ else
} // end else
vlib.output(rc);
vlib.output(rc);

View File

@@ -8,9 +8,9 @@
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
// Copyright (C) 2002-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
@@ -32,7 +32,9 @@ if (cctl.isCookiePresent(cookie_name))
logged_in = false;
try
{ // attempt to log the user in with the cookie
logged_in = sess.user.authenticateWithToken(cctl.getCookie(cookie_name));
// but don't do it if they're IP-banned
if (rinput.engine.testIPBan(rinput.sourceAddress)==null)
logged_in = sess.user.authenticateWithToken(cctl.getCookie(cookie_name));
} // end try
catch (e)

View File

@@ -0,0 +1,116 @@
// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
importPackage(java.util);
importPackage(Packages.com.silverwrist.util);
importPackage(Packages.com.silverwrist.venice.core);
importPackage(Packages.com.silverwrist.venice.except);
importPackage(Packages.com.silverwrist.venice.ui);
importPackage(Packages.com.silverwrist.venice.ui.view);
// get the request object
rinput = bsf.lookupBean("request");
if (!(rinput.user.hasAdminAccess()))
{ // you don't have permission to administer the system
vlib.output(new ErrorBox("Access Error","You do not have permission to administer the system.",null));
vlib.done();
} // end if
// create the IP ban add dialog
dlg = rinput.getDialog("ipban.add");
if ("GET"==rinput.verb)
{ // fill in default values and put forth the dialog
dlg.setValue("mask","255.255.255.255");
dlg.setValue("etime","1");
vlib.output(dlg);
vlib.done();
} // end if
// everything that follows is for a POST operation
op = dlg.whichButton(rinput) + "";
if (op=="cancel")
{ // user cancelled create - bounce back to the target
vlib.output(new Redirect("sysadmin/ip_bans.js.vs",LinkTypes.SERVLET));
vlib.done();
} // end if
rc = null;
if (op=="add")
{ // load the dialog
dlg.load(rinput);
try
{ // validate the dialog
dlg.validate();
// load the admin interface
adm = rinput.user.adminInterface;
// determine the expire date
exp_date = null;
if (dlg.getValue("echeck"))
{ // create a GregorianCalendar and use it to figure the expiration date
cal = new java.util.GregorianCalendar();
unit = dlg.getValue("eunit");
if (unit=="D")
cal.add(Calendar.DATE,dlg.getValue("etime"));
else if (unit=="W")
cal.add(Calendar.DATE,dlg.getValue("etime") * 7);
else if (unit=="M")
cal.add(Calendar.MONTH,dlg.getValue("etime"));
else if (unit=="Y")
cal.add(Calendar.YEAR,dlg.getValue("etime"));
exp_date = cal.getTime();
} // end if
msg = dlg.getValue("msg");
if (StringUtil.isStringEmpty(msg))
msg = "This IP address has been banned from logging in by an administrator.";
adm.addIPBan(dlg.getValue("address"),dlg.getValue("mask"),exp_date,msg);
rc = new Redirect("sysadmin/ip_bans.js.vs",LinkTypes.SERVLET);
} // end try
catch (e)
{ // whoops!
etype = vlib.exceptionType(e) + "";
if (etype.match("ValidationException"))
{ // put the dialog back up on a validation error
dlg.setErrorMessage(e.message + " Please try again.");
rc = dlg;
} // end if
else if (etype.match("DataException"))
rc = new ErrorBox("Database Error",e.message);
else
rc = e;
} // end catch
} // end if
else
{ // no dialog present
logger.error("no known button click on POST to ip_ban_add.js");
rc = new ErrorBox("Internal Error","Unknown command button pressed","sysadmin/ip_bans.js.vs");
} // end else
vlib.output(rc);

View File

@@ -0,0 +1,81 @@
// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
importPackage(java.util);
importPackage(Packages.com.silverwrist.venice.core);
importPackage(Packages.com.silverwrist.venice.except);
importPackage(Packages.com.silverwrist.venice.ui);
importPackage(Packages.com.silverwrist.venice.ui.view);
// get the request object
rinput = bsf.lookupBean("request");
if (!(rinput.user.hasAdminAccess()))
{ // you don't have permission to administer the system
vlib.output(new ErrorBox("Access Error","You do not have permission to administer the system.",null));
vlib.done();
} // end if
adm = rinput.user.adminInterface;
// get the list of IP bans
banlist = null;
try
{ // handle enables?
if (rinput.hasParameter("enable"))
{ // enable the identified ban
id = rinput.getParameterInt("enable",-1);
if (id>0)
adm.enableIPBan(id,true);
} // end if
if (rinput.hasParameter("disable"))
{ // disable the identified ban
id = rinput.getParameterInt("disable",-1);
if (id>0)
adm.enableIPBan(id,false);
} // end if
if (rinput.hasParameter("remove"))
{ // disable the identified ban
id = rinput.getParameterInt("remove",-1);
if (id>0)
adm.removeIPBan(id);
} // end if
// get the ban information list
banlist = adm.getIPBanInfo();
} // end try
catch (e)
{ // find the exception type
etype = vlib.exceptionType(e) + "";
if (etype.match("DataException"))
rc = new ErrorBox("Database Error",e.message);
else
rc = e;
vlib.output(rc);
vlib.done();
} // end catch
// display the list of IP bans
rinput.setRequestAttribute("ipbans.list",banlist);
vlib.output(new JSPView("Manage IP Address Bans","sysadmin/list_ip_bans.jsp"));