Make it work with badip system active
authorDirk Koopman <djk@tobit.co.uk>
Fri, 20 Jan 2023 16:53:59 +0000 (16:53 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Fri, 20 Jan 2023 16:53:59 +0000 (16:53 +0000)
Changes
cmd/load/badip.pl
cmd/set/badip.pl
cmd/show/badip.pl
perl/DXCIDR.pm

diff --git a/Changes b/Changes
index ec464699adda8aca071078cd52e9a61ddb00e2d9..2d21b309d5ad0b37dd55d0f019f23f4d9ff01e68 100644 (file)
--- a/Changes
+++ b/Changes
@@ -17,6 +17,8 @@
    than just the normal definitions of localhost. So for 'normal' nodes with
    one external interface, you DO NOT NEED TO DO ANY OF THIS. 
 2. Added CTY-3304 prefix data
+3. Fix Bad IP address system so that one can carry on as normal without
+   Net::CIDR::Lite (or libnet-cidr-lite-perl on debian based systems)
 19Jan23=======================================================================
 1. Introduce aliasing for localhost in DX Spots and outgoing PC92 A records
    on login. There are two variables which can be set with the alias to use:
index 3cf4212d6eb0935036f57801430020a096699770..bb0e55f8f0309b235542e7ef9eda6488aa47bc8a 100644 (file)
@@ -8,6 +8,7 @@ my ($self, $line) = @_;
 return (1, $self->msg('e5')) if $self->remotecmd;
 # are we permitted?
 return (1, $self->msg('e5')) if $self->priv < 6;
+return (1, q{Please install Net::CIDR::Lite or libnet-cidr-lite-perl to use this command}) unless $DXCIDR::active;
 
 my @out;
 
index b33261b7faa473233bda582d38f5e890710afdc7..1ed8225adb050de98ac87e7d388860c8785125e6 100644 (file)
@@ -9,6 +9,8 @@ my ($self, $line) = @_;
 return (1, $self->msg('e5')) if $self->remotecmd;
 # are we permitted?
 return (1, $self->msg('e5')) if $self->priv < 6;
+return (1, q{Please install Net::CIDR::Lite or libnet-cidr-lite-perl to use this command}) unless $DXCIDR::active;
+
 my @out;
 my @added;
 my @in = split /\s+/, $line;
index b378abde47e08a89f63a0e20e2376460fa4af5c8..c7b2122d472a92927d30f8aa0a10e337d7fd77b9 100644 (file)
@@ -9,10 +9,13 @@ my ($self, $line) = @_;
 return (1, $self->msg('e5')) if $self->remotecmd;
 # are we permitted?
 return (1, $self->msg('e5')) if $self->priv < 6;
+return (1, q{Please install Net::CIDR::Lite or libnet-cidr-lite-perl to use this command}) unless $DXCIDR::active;
+
 my @out;
 my @added;
 my @in = split /\s+/, $line;
 my $maxlth = 0;
+my $width = $self->width // 80;
 
 #$DB::single = 1;
 
@@ -20,7 +23,7 @@ my $maxlth = 0;
 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 $n = int ($width/($maxlth+1));
 my $format = "\%-${maxlth}s " x $n;
 chop $format;
 
@@ -45,5 +48,5 @@ unless (@in) {
        push @out, sprintf $format, @l;
 }
 
-push @out, "show/badip: " . scalar @list . " records found";
+push @out, "show/badip: " . scalar @out . " records found";
 return (1, @out);
index 5a6272aa4747e0c813b96431b5932b5df22f1516..a91d13967cf7c3db845e6e49df1c954c9fd1ba53 100644 (file)
@@ -82,6 +82,8 @@ sub _put
 
 sub append
 {
+       return 0 unless $active;
+       
        my $suffix = shift;
        my @in = @_;
        my @out;
@@ -104,6 +106,7 @@ sub append
 
 sub add
 {
+       return 0 unless $active;
        my $count = 0;
        
        for my $ip (@_) {
@@ -127,6 +130,8 @@ sub add
 
 sub clean_prep
 {
+       return unless $active;
+
        if ($ipv4 && $count4) {
                $ipv4->clean;
                $ipv4->prep_find;
@@ -150,6 +155,7 @@ sub _sort
 
 sub list
 {
+       return () unless $active;
        my @out;
        push @out, $ipv4->list if $count4;
        push @out, $ipv6->list if $count6;
@@ -199,6 +205,8 @@ sub _touch
 
 sub reload
 {
+       return 0 unless $active;
+
        new();
 
        my $count = 0;
@@ -224,6 +232,8 @@ sub reload
 
 sub new
 {
+       return 0 unless $active;
+
        $ipv4 = Net::CIDR::Lite->new;
        $ipv6 = Net::CIDR::Lite->new;
        $count4 = $count6 = 0;