X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCIDR.pm;h=5a6272aa4747e0c813b96431b5932b5df22f1516;hb=bb3889c1d4930e2ca96b47aea10ce5e803737043;hp=88a26d5c552631e4b66c173eb0c3262400e17d0d;hpb=996fed89967a1fd4d8665a10fd73b9612aeb1606;p=spider.git diff --git a/perl/DXCIDR.pm b/perl/DXCIDR.pm index 88a26d5c..5a6272aa 100644 --- a/perl/DXCIDR.pm +++ b/perl/DXCIDR.pm @@ -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"); @@ -202,10 +201,23 @@ sub reload { new(); - my $count = _load('base'); - $count += _load('local'); - - LogDbg('DXProt', "DXCIDR::reload $count ip addresses found (IPV4: $count4 IPV6: $count6)" ); + my $count = 0; + my $files = 0; + + LogDbg('DXProt', "DXCIDR::reload reload database" ); + + my $dir; + opendir($dir, $main::local_data); + while (my $fn = readdir $dir) { + next unless my ($suffix) = $fn =~ /^badip\.(\w+)$/; + my $c = _load($suffix); + LogDbg('DXProt', "DXCIDR::reload: $fn read containing $c ip addresses" ); + $count += $c; + $files++; + } + closedir $dir; + + LogDbg('DXProt', "DXCIDR::reload $count ip addresses found (IPV4: $count4 IPV6: $count6) in $files badip files" ); return $count; }