Make it work with badip system active
[spider.git] / cmd / show / badip.pl
1 #
2 # set list of bad dx nodes
3 #
4 # Copyright (c) 2021 - Dirk Koopman G1TLH
5 #
6 #
7 #
8 my ($self, $line) = @_;
9 return (1, $self->msg('e5')) if $self->remotecmd;
10 # are we permitted?
11 return (1, $self->msg('e5')) if $self->priv < 6;
12 return (1, q{Please install Net::CIDR::Lite or libnet-cidr-lite-perl to use this command}) unless $DXCIDR::active;
13
14 my @out;
15 my @added;
16 my @in = split /\s+/, $line;
17 my $maxlth = 0;
18 my $width = $self->width // 80;
19
20 #$DB::single = 1;
21
22
23 my @list = map {my $s = $_; $s =~ s|/32$||; $maxlth = length $s if length $s > $maxlth; $s =~ /^1$/?undef:$s} DXCIDR::list();
24 my @l;
25 $maxlth //= 20;
26 my $n = int ($width/($maxlth+1));
27 my $format = "\%-${maxlth}s " x $n;
28 chop $format;
29
30 foreach my $list (@list) {
31         if (@in) {
32                 for (@in) {
33                         if ($list =~ /$_/i) {
34                                 push @out, $list;
35                                 last;
36                         }
37                 }
38         } else {
39                 if (@l > $n) {
40                         push @out, sprintf $format, @l;
41                         @l = ();
42                 }
43                 push @l, $list;
44         }
45 }       
46 unless (@in) {
47         push @l, "" while @l < $n;
48         push @out, sprintf $format, @l;
49 }
50
51 push @out, "show/badip: " . scalar @out . " records found";
52 return (1, @out);