From ddff2f5f3a201c45af437b2b235bb4cd0ca76b85 Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Mon, 8 Aug 2005 12:45:52 +0000 Subject: [PATCH] new, from meatball --- modules/open-proxy.pl | 75 +++++++++++++++++++++++++++++++++++++++++++ modules/self-ban.pl | 35 ++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 modules/open-proxy.pl create mode 100644 modules/self-ban.pl diff --git a/modules/open-proxy.pl b/modules/open-proxy.pl new file mode 100644 index 00000000..a5d90930 --- /dev/null +++ b/modules/open-proxy.pl @@ -0,0 +1,75 @@ +# Copyright (C) 2005 Sunir Shah +# Copyright (C) 2005 Alex Schroeder +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc. +# 59 Temple Place, Suite 330 +# Boston, MA 02111-1307 USA + +$ModulesDescription .= '

$Id: open-proxy.pl,v 1.1 2005/08/08 12:46:50 as Exp $

'; + +*OpenProxyOldDoEdit = *DoEdit; +*DoEdit = *OpenProxyNewDoEdit; + +sub OpenProxyNewDoEdit { + BanOpenProxy(); + OpenProxyOldDoEdit(@_); +} + +sub BanOpenProxy { + my ($force) = @_; + + my $ip = $ENV{REMOTE_ADDR}; + + # Only check each IP address once a month + my $checked = ReadFile("$DataDir/openproxy"); + my $checkCount = 0; + my $appendChecked; + while( $checked =~ s/^$ip (\d+)\n//mg ) { + if( $Now - $1 < 60*60*24*30 ) { + $checkCount++; + $appendChecked.= "$ip $Now\n"; + } + } + $checked .= $appendChecked; + return if $checkCount >= 3; + + $checked .= "$ip $Now\n"; + + return if !$force && fork; + + require LWP::UserAgent; + my @ports = qw/23 80 81 1080 3128 8080 8081 scx-proxy dproxy sdproxy + funkproxy dpi-proxy proxy-gateway ace-proxy plgproxy + csvr-proxy flamenco-proxy awg-proxy trnsprntproxy + castorproxy ttlpriceproxy privoxy ezproxy ezproxy-2/; + + my $browser = LWP::UserAgent->new( + timeout =>10, + max_size =>2048, + requests_redirectable => [] + ); + + foreach my $port (@ports) + { + $browser->proxy("http","http://$ip:".$port); + my $response = $browser->head("$SiteBase$ScriptName?action=$SelfBan"); + last unless defined $response; + last unless $response->is_error; + } + + WriteStringToFile("$DataDir/openproxy", $checked); + + exit unless $force; +} diff --git a/modules/self-ban.pl b/modules/self-ban.pl new file mode 100644 index 00000000..87a32740 --- /dev/null +++ b/modules/self-ban.pl @@ -0,0 +1,35 @@ +# Copyright (C) 2005 Sunir Shah +# Copyright (C) 2005 Alex Schroeder +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc. +# 59 Temple Place, Suite 330 +# Boston, MA 02111-1307 USA + +$ModulesDescription .= '

$Id: self-ban.pl,v 1.1 2005/08/08 12:45:52 as Exp $

'; + +use vars qw($SelfBan); + +$SelfBan = "xyzzy"; # change this from time to time in your config file + +$Action{$SelfBan} = \&DoSelfBan; + +sub DoSelfBan { + my $date = &TimeToText($Now); + my $str = '^' . quotemeta($ENV{REMOTE_ADDR}); + OpenPage($BannedHosts); + Save ($BannedHosts, $Page{text} . "\n\nself-ban on $date\n $str", + Ts("Self-ban by %s", $ENV{REMOTE_ADDR}), 1); # minor edit + ReportError(T("You have banned your own IP.")); +}