Metabrik-Repository
view release on metacpan or search on metacpan
lib/Metabrik/Database/Ripe.pm view on Meta::CPAN
#
# $Id$
#
# database::ripe Brik
#
package Metabrik::Database::Ripe;
use strict;
use warnings;
# API RIPE search : http://rest.db.ripe.net/search?query-string=193.6.223.152/24
# https://github.com/RIPE-NCC/whois/wiki/WHOIS-REST-API
use base qw(Metabrik);
sub brik_properties {
return {
revision => '$Revision$',
tags => [ qw(unstable netname country as) ],
author => 'GomoR <GomoR[at]metabrik.org>',
license => 'http://opensource.org/licenses/BSD-3-Clause',
attributes => {
datadir => [ qw(datadir) ],
input => [ qw(ripe.db) ],
_read => [ qw(INTERNAL) ],
},
attributes_default => {
input => 'ripe.db',
},
commands => {
update => [ ],
next_record => [ qw(file.ripe|OPTIONAL) ],
},
require_modules => {
'Metabrik::Client::Www' => [ ],
'Metabrik::File::Compress' => [ ],
'Metabrik::File::Read' => [ ],
'Metabrik::File::Text' => [ ],
},
};
}
sub update {
my $self = shift;
my @urls = qw(
ftp://ftp.apnic.net/apnic/whois/apnic.db.inetnum.gz
ftp://ftp.apnic.net/apnic/whois/apnic.db.inet6num.gz
ftp://ftp.ripe.net/ripe/dbase/ripe.db.gz
ftp://ftp.afrinic.net/dbase/afrinic.db.gz
http://ftp.apnic.net/apnic/dbase/data/jpnic.db.gz
http://ftp.apnic.net/apnic/dbase/data/krnic.db.gz
http://ftp.apnic.net/apnic/dbase/data/twnic.db.gz
ftp://ftp.arin.net/pub/rr/arin.db.gz
);
my $datadir = $self->datadir;
my $cw = Metabrik::Client::Www->new_from_brik_init($self) or return;
my @fetched = ();
for my $url (@urls) {
$self->log->verbose("update: fetching url [$url]");
(my $filename = $url) =~ s/^.*\/(.*?)$/$1/;
(my $unzipped = $filename) =~ s/\.gz$//;
my $output = $datadir."/$filename";
my $r = $cw->mirror($url, $filename, $datadir);
if (! defined($r)) {
$self->log->warning("update: can't fetch url [$url]");
next;
}
elsif (@$r == 0) { # Already up to date
next;
}
my $files = [];
if ($filename =~ m{.gz$}) {
$self->log->verbose("update: uncompressing file to [$unzipped]");
my $fc = Metabrik::File::Compress->new_from_brik_init($self) or return;
$files = $fc->uncompress($output, $unzipped, $datadir);
if (! defined($files)) {
$self->log->warning("update: can't uncompress file [$output]");
next;
}
}
else {
push @fetched, $output;
}
push @fetched, @$files;
}
return \@fetched;
}
sub next_record {
my $self = shift;
my ($input) = @_;
$input ||= $self->datadir.'/'.$self->input;
$self->brik_help_run_file_not_found('next_record', $input) or return;
my $fr = $self->_read;
if (! defined($fr)) {
$fr = Metabrik::File::Read->new_from_brik_init($self) or return;
( run in 0.686 second using v1.01-cache-2.11-cpan-39bf76dae61 )