fix set/badip so that it appends to the existing file
[spider.git] / cmd / set / 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 $suffix = 'local';
16 if ($in[0] =~ /^[_\d\w]+$/) {
17         $suffix = shift @in;
18 }
19 return (1, "set/badip: need [suffix (def: local])] IP, IP-IP or IP/24") unless @in;
20 for my $ip (@in) {
21         my $r;
22         eval{ $r = DXCIDR::find($ip); };
23         return (1, "set/badip: $ip $@") if $@;
24         if ($r) {
25                 push @out, "set/badip: $ip exists, not added";
26                 next;
27         }
28         DXCIDR::add($suffix, $ip);
29         push @added, $ip;
30 }
31 my $count = @added;
32 my $list = join ' ', @in;
33 DXCIDR::clean_prep();
34 #$DB::single = 1;
35 DXCIDR::append($suffix, @added);
36 push @out, "set/badip: added $count entries to badip.$suffix : $list" if $count;
37 return (1, @out);