+04Jan23=======================================================================
+1. Fillout DXCIDR, attach checks in PC61 and logins. Login that fail will
+ simply disconnect, like locked out callsigns
+2. Fix qrz.com URL in stock Internet.pm.
+30Dec22=======================================================================
+1. Add more BadWords (regex) checks.
01Dec22=======================================================================
1. Re-add some debugging to see which incoming PC protcol sentences are
being dumped because of any bad content (words or calls) if debugging
my @out;
my @added;
my @in = split /\s+/, $line;
-my @list= DXCIDR::list();
+my $maxlth = 0;
+
+$DB::single = 1;
+
+
+my @list = map {my $s = $_; $s =~ s|/32$||; $maxlth = length $s if length $s > $maxlth; $s =~ /^1$/?undef:$s} DXCIDR::list();
+my @l;
+$maxlth //= 20;
+my $n = int (80/($maxlth+1));
+my $format = "\%-${maxlth}s " x $n;
+chop $format;
+
foreach my $list (@list) {
if (@in) {
for (@in) {
}
}
} else {
- push @out, $list;
- }
+ if (@l > $n) {
+ push @out, sprintf $format, @l;
+ @l = ();
+ }
+ push @l, $list;
+ }
+}
+unless (@in) {
+ push @l, "" while @l < $n;
+ push @out, sprintf $format, @l;
}
+
+push @out, "show/badip: " . scalar @list . " records found";
return (1, @out);
#
# show list of bad dx callsigns
#
-# Copyright (c) 1998 - Dirk Koopman G1TLH
+# Copyright (c) 2023 - Dirk Koopman G1TLH
#
#
#
use DXLog;
use IO::File;
use File::Copy;
+use Socket qw(inet_pton inet_ntop);
our $active = 0;
our $badipfn = "badip";
sub load
{
if ($active) {
- $count4 = _get($ipv4, 4);
- $count6 = _get($ipv6, 6);
+ $count4 = _load($ipv4, 4);
+ $count6 = _load($ipv6, 6);
}
LogDbg('DXProt', "DXCIDR: loaded $count4 IPV4 addresses and $count6 IPV6 addresses");
return $count4 + $count6;
sub _fn
{
- return localdata($badipfn) . "$_[0]";
+ return localdata($badipfn) . ".$_[0]";
}
-sub _get
+sub _load
{
my $list = shift;
my $sort = shift;
while (<$fh>) {
chomp;
next if /^\s*\#/;
- $list->add($_);
+ next unless /[\.:]/;
+ $list->add_any($_);
++$count;
}
$fh->close;
$list->clean if $count;
+ $list->prep_find;
} elsif (-r $fn) {
LogDbg('err', "DXCIDR: $fn not found ($!)");
}
sub add
{
- for (@_) {
+ for my $ip (@_) {
# protect against stupid or malicious
next if /^127\./;
next if /^::1$/;
if (/\./) {
- $ipv4->add($_);
+ if ($ipv4->find($ip)) {
+ LogDbg('DXProt', "DXCIDR: Ignoring existing IPV4 $ip");
+ next;
+ }
+ $ipv4->add_any($ip);
++$count4;
- LogDbg('DXProt', "DXCIDR: Added IPV4 $_ address");
- } else {
- $ipv6->add($_);
+ } elsif (/:/) {
+ if ($ipv6->find($ip)) {
+ LogDbg('DXProt', "DXCIDR: Ignoring existing IPV6 $ip");
+ next;
+ }
+ $ipv6->add_any($ip);
++$count6;
- LogDbg('DXProt', "DXCIDR: Added IPV6 $_ address");
+ LogDbg('DXProt', "DXCIDR: Added IPV6 $ip address");
}
}
if ($ipv4 && $count4) {
sub save
{
return 0 unless $active;
- my $list = $ipv4->list;
- _put($list, 4) if $list;
- $list = $ipv6->list;
- _put($list, 6) if $list;
+ _put($ipv4, 4) if $count4;
+ _put($ipv6, 6) if $count6;
+}
+
+sub _sort
+{
+ my @in;
+ my @out;
+ for (@_) {
+ push @in, [inet_pton($_), split m|/|];
+ }
+ @out = sort {$a->[0] <=> $b->[0]} @in;
+ return map { "$_->[1]/$_->[2]"} @out;
}
sub list
{
my @out;
- push @out, $ipv4->list;
- push @out, $ipv6->list;
- return (1, sort @out);
+ push @out, $ipv4->list if $count4;
+ push @out, $ipv6->list if $count6;
+ return _sort(@out);
}
sub find
{
return 0 unless $active;
return 0 unless $_[0];
-
+
if ($_[0] =~ /\./) {
return $ipv4->find($_[0]) if $count4;
}
$ipv4 = Net::CIDR::Lite->new;
$ipv6 = Net::CIDR::Lite->new;
- load();
$active = 1;
+ load();
}
}
$self->send_ans(@ans);
} else {
- if (@bad = BadWords::check($cmdline)) {
- $self->badcount(($self->badcount||0) + @bad);
- LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with badwords: '" . join(',', @bad) . "'");
- } else {
+# if (@bad = BadWords::check($cmdline)) {
+# $self->badcount(($self->badcount||0) + @bad);
+# LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with badwords: '" . join(',', @bad) . "'");
+# } else {
$self->send_ans(run_cmd($self, $cmdline));
- }
+# }
}
# check for excessive swearing
# move existing file
localdata_mv($name);
- my $s = readfilestr($main::local_data, localdata($name));
+ my $s = readfilestr($main::local_data, $name);
my $self = undef;
$self = eval $s if $s;
dbg("error in reading $name in DXHash $@") if $@;
{
my $pcno = shift;
my $hops = $DXProt::hopcount{$pcno};
- $hops = $DXProt::def_hopcount if !$hops;
+ $hops = $DXProt::def_hopcount unless $hops;
return "H$hops";
}
$ip =~ s/,/:/g;
$ip =~ s/^::ffff://;
if (DXCIDR::find($ip)) {
-
+ dbg("DXProt: Spot ignore $pc->[8] in badip list") if dbg('badip');
+ return;
}
}
# can be changed if necessary.
#
-$qrz_url = 'www.qrz.com'; # used by show/qrz
+$qrz_url = 'xmldata.qrz.com'; # used by show/qrz
$wm7d_url = 'www.wm7d.net'; # used by show/wm7d
$db0sdx_url = 'www.qslinfo.de'; # used by show/db0sdx
$db0sdx_path = '/qslinfo';
}
# now deal with the lock
+ my $host = $conn->peerhost;
if ($lock) {
- my $host = $conn->peerhost;
LogDbg('', "$call on $host is locked out, disconnected");
$conn->disconnect;
return;
}
+ # Is he from a badip?
+ if (DXCIDR::find($host)) {
+ LogDbg('', "$call on $host is from a badip $host, disconnected");
+ $conn->disconnect;
+ return;
+ }
+
# set up the basic channel info for "Normal" Users
# is there one already connected to me - locally?