fix set/badip so that it appends to the existing file
authorDirk Koopman <djk@tobit.co.uk>
Wed, 11 Jan 2023 19:37:51 +0000 (19:37 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Wed, 11 Jan 2023 19:37:51 +0000 (19:37 +0000)
Because of some excess zeal on my part, I was overwriting, rather
than appending to the existing file.

Face Palm!

Changes
cmd/set/badip.pl
perl/DXCIDR.pm

diff --git a/Changes b/Changes
index 59ba86d60aa432acfe9aaf9b9e56f79b0a49a7bc..7a2067f121d6d9fe333bddd16b84fed60cbe22fa 100644 (file)
--- a/Changes
+++ b/Changes
@@ -21,6 +21,7 @@
    23 or 24 to get your own local copies. 
 
    A 'set/debug badip' will show you what is being blocked. 
+3. Fix set/badip so that it appends new IP addresses correctly.
 10Jan23=======================================================================
 1. Add baddx on incoming callsign in RBN.
 2. Search for all /spider/local_data/badip.* files to allow more control on
index 3c4578ba444caf8c59796c36ef253691a61e6006..b33261b7faa473233bda582d38f5e890710afdc7 100644 (file)
@@ -31,6 +31,7 @@ for my $ip (@in) {
 my $count = @added;
 my $list = join ' ', @in;
 DXCIDR::clean_prep();
+#$DB::single = 1;
 DXCIDR::append($suffix, @added);
 push @out, "set/badip: added $count entries to badip.$suffix : $list" if $count;
 return (1, @out);
index fdade7fc8989bae6d17fad741ff636604c0d2938..5a6272aa4747e0c813b96431b5932b5df22f1516 100644 (file)
@@ -88,14 +88,13 @@ sub append
        
        if ($suffix) {
                my $fn = _fn() . ".$suffix";
-               my $r = rand;
-               my $fh = IO::File->new (">>$fn.$r");
-               if ($fh) {
+               my $fh = IO::File->new;
+               if ($fh->open("$fn", "a+")) {
+                       $fh->seek(0, 2);        # belt and braces !!
                        print $fh "$_\n" for @in;
                        $fh->close;
-                       move "$fn.$r", $fn;
                } else {
-                       LogDbg('err', "DXCIDR::append error appending to $fn.$r $!");
+                       LogDbg('err', "DXCIDR::append error appending to $fn $!");
                }
        } else {
                LogDbg('err', "DXCIDR::append require badip suffix");