|
From: Sam S. <sa...@us...> - 2002-01-23 22:28:32
|
On Tue, 22 Jan 2002, Jonathan Stowe wrote:
> On Tue, 22 Jan 2002, Sam Smith wrote:
> > On Tue, 22 Jan 2002, Jonathan Stowe wrote:
> > > On Tue, 22 Jan 2002, Sam Smith wrote:
> > > > The below patch will allow you to put CIDR IP/bitmasks into @referers
> > > > and have it work for the entirity of 10.10.2.0/24 if that's what you
> > > > want.
> > > >
> > >
> > > Nice idea, however if it has 'issues' with 5.005 I am certain it won't
> > > work on 5.004 either :( I think we should hold on the patch until we can
> > > test it on all the supported platforms ..
> >
> > It appears to be the %b formatting in the sprintf statements.
> >
> > Is there a 5.004 compatible equivalent?
> >
>
> I think that one used to do something funky with unpack :)
Something like the below?
--- FormMail.pl Tue Jan 22 00:13:43 2002
+++ FormMail-sams.pl Wed Jan 23 22:26:21 2002
@@ -277,6 +277,19 @@
if ($referer =~ m|https?://([^/]*)\Q$test_ref\E|i) {
$check_referer = 1;
last;
+ }
+ elsif ( $secure && $test_ref =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/\d{1,2}/ ) {
+ my $cidr=$5;
+ my $test_bits= unpack "N", pack "CCCC", $1, $2, $3, $4;
+ my $test_bit_mask= unpack "N", pack "B*", "1" x $cidr . "0" x (32 - $cidr );
+
+ $referer =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $ip_bits= unpack "N", pack "CCCC", $1, $2, $3, $4;
+
+ if (($test_bits & $test_bit_mask) == ($ip_bits & $test_bit_mask)) {
+ $check_referer = 1;
+ last;
+ }
}
elsif ( $secure && $test_ref =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ ) {
if ( $referer =~ m|https?://([^/]+)| ) {
|