staging commt for badword and badip
[spider.git] / perl / DXProtHandle.pm
index 6f4fbd08d92c3bca3513e7189111ede1aa982e8d..8a35bbbf137c47369637619354823928618a9637 100644 (file)
@@ -89,14 +89,6 @@ sub handle_10
                return;
        }
 
-       # will we allow it at all?
-       if ($censorpc) {
-               my @bad;
-               if (@bad = BadWords::check($pc->[3])) {
-                       dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
-                       return;
-               }
-       }
 
        # is it for me or one of mine?
        my ($from, $to, $via, $call, $dxchan);
@@ -110,7 +102,8 @@ sub handle_10
 
        # if this is a 'nodx' node then ignore it
        if ($badnode->in($pc->[6]) || ($via && $badnode->in($via))) {
-               dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: Bad Node, dropped");
                return;
        }
 
@@ -118,7 +111,8 @@ sub handle_10
        my $nossid = $from;
        $nossid =~ s/-\d+$//;
        if ($badspotter->in($nossid)) {
-               dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: Bad Spotter, dropped");
                return;
        }
 
@@ -129,6 +123,17 @@ sub handle_10
                        return;
                }
        }
+       
+       # will we allow it at all?
+       if ($censorpc) {
+               my @bad;
+               if (@bad = BadWords::check($pc->[3])) {
+                       my $bw = join ', ', @bad; 
+                       dbg($line) if isdbg('nologchan');
+                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       return;
+               }
+       }
 
        # convert this to a PC93, coming from mycall with origin set and process it as such
        $main::me->normal(pc93($to, $from, $via, $pc->[3], $pc->[6]));
@@ -163,18 +168,21 @@ sub handle_11
        # is the spotted callsign blank? This should really be trapped earlier but it
        # could break other protocol sentences. Also check for lower case characters.
        if ($pc->[2] =~ /^\s*$/) {
-               dbg("PCPROT: blank callsign, dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: blank callsign, dropped");
                return;
        }
        if ($pc->[2] =~ /[a-z]/) {
-               dbg("PCPROT: lowercase characters, dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: lowercase characters, dropped");
                return;
        }
 
 
        # if this is a 'nodx' node then ignore it
        if ($badnode->in($pc->[7])) {
-               dbg("PCPROT: Bad Node $pc->[7], dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: Bad Node $pc->[7], dropped");
                return;
        }
 
@@ -182,7 +190,8 @@ sub handle_11
        my $nossid = $pc->[6];
        $nossid =~ s/-\d+$//;
        if ($badspotter->in($nossid)) {
-               dbg("PCPROT: Bad Spotter $pc->[6], dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: Bad Spotter $pc->[6], dropped");
                return;
        }
 
@@ -192,7 +201,8 @@ sub handle_11
                $ip =~ s/,/:/g;
                $ip =~ s/^::ffff://;
                if (DXCIDR::find($ip)) {
-                       
+                       dbg("DXProt: Spot ignore $pc->[8] in badip list") if dbg('badip');
+                       return;
                }
        }
 
@@ -200,13 +210,13 @@ sub handle_11
        my $d = cltounix($pc->[3], $pc->[4]);
        # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
        if (!$d || (($pcno == 11 || $pcno == 61) && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
-               dbg("PCPROT: Spot ignored, invalid date or out of range ($pc->[3] $pc->[4])\n") if isdbg('chanerr');
+               dbg("PCPROT: Spot ignored, invalid date or out of range ($pc->[3] $pc->[4])\n");
                return;
        }
 
        # is it 'baddx'
-       if ($baddx->in($pc->[2]) || BadWords::check($pc->[2])) {
-               dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
+       if ($baddx->in($pc->[2])) {
+               dbg("PCPROT: Bad DX spot '$pc->[2]', ignored");
                return;
        }
 
@@ -217,13 +227,6 @@ sub handle_11
                dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
                return;
        }
-       if ($censorpc) {
-               my @bad;
-               if (@bad = BadWords::check($pc->[5])) {
-                       dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
-                       return;
-               }
-       }
        
 
        my @spot = Spot::prepare($pc->[1], $pc->[2], $d, $pc->[5], $nossid, $pc->[7], $pc->[8]);
@@ -322,6 +325,18 @@ sub handle_11
                }
        }
 
+# we until here to do any censorship to try and reduce the amount of noise that repeated copies
+# from other connected nodes cause
+       if ($censorpc) {
+               my @bad;
+               if (@bad = BadWords::check($pc->[5])) {
+                       my $bw = join ', ', @bad;
+                       dbg($line) if isdbg('nologchan');
+                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       return;
+               }
+       }
+
        # If is a new PC11, store it, releasing the one that is there (if any),
        # if a PC61 comes along then dump the stored PC11
        # If there is a different PC11 stored, release that one and store this PC11 instead,
@@ -436,17 +451,10 @@ sub handle_12
        # announce duplicate checking
        $pc->[3] =~ s/^\s+//;                   # remove leading blanks
 
-       if ($censorpc) {
-               my @bad;
-               if (@bad = BadWords::check($pc->[3])) {
-                       dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
-                       return;
-               }
-       }
-
        # if this is a 'nodx' node then ignore it
        if ($badnode->in($pc->[5])) {
-               dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: Bad Node, dropped");
                return;
        }
 
@@ -454,7 +462,8 @@ sub handle_12
        my $nossid = $pc->[1];
        $nossid =~ s/-\d+$//;
        if ($badspotter->in($nossid)) {
-               dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: Bad Spotter, dropped");
                return;
        }
 
@@ -465,6 +474,17 @@ sub handle_12
                return;
        }
 
+       if ($censorpc) {
+               my @bad;
+               if (@bad = BadWords::check($pc->[3])) {
+                       my $bw = join ', ', @bad;
+                       dbg($line) if isdbg('nologchan');
+                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       return;
+               }
+       }
+
+
        my $dxchan;
 
        if ((($dxchan = DXChannel::get($pc->[2])) && $dxchan->is_user) || $pc->[4] =~ /^[\#\w.]+$/){
@@ -1571,19 +1591,23 @@ sub _decode_pc92_call
        my $version = $part[1] || 0;
        my $build = $part[2] || 0;
        my $ip = $part[3] || '';
-       
-       if (is_ipaddr($version)) {
+
+       # remember that, at this stage, IPV6 addresses have : replaced by ,
+       if (length $version > 4 && $version =~ /[,\.][\da-f]{1,4}/i) {
                $ip = $version;
                $version = 0;
        }
        $version =~ s/\D//g;
+       $version = 0 unless $version && $version =~ /^[0-9]+$/;
        $build =~ s/^0\.//;
        $build =~ s/\D//g;
+       $build = 0 unless $build &&  $build =~ /^[0-9]+$/;
        if ($ip) {
         $ip =~ s/,/:/g;
         $ip =~ s/^::ffff://i;
+               $ip = '' unless is_ipaddr($ip);
     }
-       dbg("$icall = '" . join("', '", $call, $is_node, $is_extnode, $here, $version, $build, $ip) . "'") if isdbg('pc92');
+       dbg("'$icall' = '" . join("', '", $call, $is_node, $is_extnode, $here, $version, $build, $ip) . "'") if isdbg('pc92');
        return ($call, $is_node, $is_extnode, $here, $version+0, $build+0, $ip);
 }
 
@@ -1665,9 +1689,9 @@ sub _add_thingy
                                                $user->sort('S');
                                                dbg("PCProt::_add_thingy node $call v: $version b: $build sort ($old) updated to " . $user->sort);
                                        } elsif ($user->is_spider && ($version < 3000 || ($version > 4000 && $version < 5455))) {
-                                               unless ($version == 5000 && $build == 0) {
+                                               unless ($version > 0  && $build == 0) {
                                                        $user->sort('A');
-                                                       $build //= 0;
+                                                       $build ||= 0;
                                                        dbg("PCProt::_add_thingy node $call v: $version b: $build sort ($old) downgraded to " . $user->sort);
                                                }
                                        }
@@ -2248,21 +2272,13 @@ sub handle_93
                my $s = "ANNTALK: $from\@$onode$vs -> $to '$text' route: $origin";
                dbg($s);
        }
-       
-       # will we allow it at all?
-       if ($censorpc) {
-               my @bad;
-               if (@bad = BadWords::check($text)) {
-                       dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
-                       return;
-               }
-       }
 
        # if this is a 'bad spotter' user then ignore it
        my $nossid = $from;
        $nossid =~ s/-\d+$//;
        if ($badspotter->in($nossid)) {
-               dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
+               dbg($line) if isdbg('nologchan');
+               dbg("PCPROT: Bad Spotter, dropped");
                return;
        }
 
@@ -2272,6 +2288,17 @@ sub handle_93
                return;
        }
 
+       # will we allow it at all?
+       if ($censorpc) {
+               my @bad;
+               if (@bad = BadWords::check($text)) {
+                       my $bw = join ', ', @bad;
+                       dbg($line) if isdbg('nologchan');
+                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       return;
+               }
+       }
+
        # if it is routeable then then treat it like a talk
        my $ref = Route::get($to);
        if ($ref) {