staging commt for badword and badip
[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 my @out;
13 my @added;
14 my @in = split /\s+/, $line;
15 my $maxlth = 0;
16
17 $DB::single = 1;
18
19
20 my @list = map {my $s = $_; $s =~ s|/32$||; $maxlth = length $s if length $s > $maxlth; $s =~ /^1$/?undef:$s} DXCIDR::list();
21 my @l;
22 $maxlth //= 20;
23 my $n = int (80/($maxlth+1));
24 my $format = "\%-${maxlth}s " x $n;
25 chop $format;
26
27 foreach my $list (@list) {
28         if (@in) {
29                 for (@in) {
30                         if ($list =~ /$_/i) {
31                                 push @out, $list;
32                                 last;
33                         }
34                 }
35         } else {
36                 if (@l > $n) {
37                         push @out, sprintf $format, @l;
38                         @l = ();
39                 }
40                 push @l, $list;
41         }
42 }       
43 unless (@in) {
44         push @l, "" while @l < $n;
45         push @out, sprintf $format, @l;
46 }
47
48 push @out, "show/badip: " . scalar @list . " records found";
49 return (1, @out);