]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
isbanned.pl: add support for trailing characters in CIDR bans
authormniip <redacted>
Mon, 14 Sep 2015 11:11:01 +0000 (14:11 +0300)
committermniip <redacted>
Tue, 15 Sep 2015 16:59:17 +0000 (19:59 +0300)
_data/scripts.yaml
scripts/isbanned.pl

index a2408883305c489ea472304430118e45a51f95a8..1f0b11514270d83c93d7b8fe53c0f06ab2f5dd4e 100644 (file)
   description: 'freenode-specific script that checks whether someone is banned on some channel'
   filename: isbanned.pl
   license: 'Public domain'
-  modified: '2015-06-12 21:43:19'
+  modified: '2015-09-14 14:11:01'
   name: isbanned
-  version: 0.6.4
+  version: 0.7.0
 -
   authors: 'Uli Baumann'
   contact: f-zappa@irc-muenster.de
index 0dc1755e599f350b2531fc8f8bfd54568b049211..aa3304cdcf690416348dc80eada6d3157c4df335 100644 (file)
@@ -13,9 +13,9 @@ use vars qw($VERSION %IRSSI);
        authors => "mniip",
        contact => "mniip \@ freenode",
        license => "Public domain",
-       modified => "2015-01-16"
+       modified => "2015-09-14"
 );
-$VERSION = "0.6.4";
+$VERSION = "0.7.0";
 
 #      Commands:
 #              /isbanned <channel> <user>
@@ -60,6 +60,9 @@ $VERSION = "0.6.4";
 #
 #              0.6.4 (2015.03.22)
 #                      Fix translation from python: fix bans containing the letter Z not matching
+#
+#              0.7.0 (2015.09.14)
+#                      Support trailing characters in CIDR bans.
 
 my $active = 0;
 my $user;
@@ -277,24 +280,31 @@ sub analyze
                                if(!$found)
                                {
                                        my ($ip, $width) = split /\//, $bhost, 2;
-                                       if(defined $width && $width =~ /^[0-9]+$/)
+                                       if(defined $width)
                                        {
-                                               my $is_v4 = !($ip =~ /:/);
-                                               $width = ($is_v4 ? 32 : 128) - $width;
-                                               $width = 0 if $width < 0;
-                                               $ip = parse_ip($ip);
-                                               for my $h(@$host)
+                                               $width =~ s/^([0-9]*).*/$1/g;
+                                               $width = int("0" . $width);
+                                               if($width > 0)
                                                {
-                                                       if(!($h =~ /:/) == $is_v4)
+                                                       my $is_v4 = !($ip =~ /:/);
+                                                       $width = ($is_v4 ? 32 : 128) - $width;
+                                                       $width = 0 if $width < 0;
+                                                       $ip = parse_ip($ip);
+                                                       for my $h(@$host)
                                                        {
-                                                               eval
+                                                               if(!($h =~ /:/) == $is_v4)
                                                                {
-                                                                       my $h = parse_ip($h, 1);
-                                                                       if(($ip >> $width) == ($h >> $width))
+                                                                       my $last;
+                                                                       eval
                                                                        {
-                                                                               add_ban(@$b);
-                                                                               last;
-                                                                       }
+                                                                               my $h = parse_ip($h, 1);
+                                                                               if(($ip >> $width) == ($h >> $width))
+                                                                               {
+                                                                                       add_ban(@$b);
+                                                                                       $last = 1;
+                                                                               }
+                                                                       };
+                                                                       last if $last;
                                                                }
                                                        }
                                                }
git clone https://git.99rst.org/PROJECT