line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# database::ripe Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Database::Ripe; |
7
|
1
|
|
|
1
|
|
697
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
8
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# API RIPE search : http://rest.db.ripe.net/search?query-string=193.6.223.152/24 |
11
|
|
|
|
|
|
|
# https://github.com/RIPE-NCC/whois/wiki/WHOIS-REST-API |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
7
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
989
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub brik_properties { |
16
|
|
|
|
|
|
|
return { |
17
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
18
|
|
|
|
|
|
|
tags => [ qw(unstable netname country as) ], |
19
|
|
|
|
|
|
|
author => 'GomoR ', |
20
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
21
|
|
|
|
|
|
|
attributes => { |
22
|
|
|
|
|
|
|
datadir => [ qw(datadir) ], |
23
|
|
|
|
|
|
|
input => [ qw(ripe.db) ], |
24
|
|
|
|
|
|
|
_read => [ qw(INTERNAL) ], |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
attributes_default => { |
27
|
|
|
|
|
|
|
input => 'ripe.db', |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
commands => { |
30
|
|
|
|
|
|
|
update => [ ], |
31
|
|
|
|
|
|
|
next_record => [ qw(file.ripe|OPTIONAL) ], |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
require_modules => { |
34
|
|
|
|
|
|
|
'Metabrik::Client::Www' => [ ], |
35
|
|
|
|
|
|
|
'Metabrik::File::Compress' => [ ], |
36
|
|
|
|
|
|
|
'Metabrik::File::Read' => [ ], |
37
|
|
|
|
|
|
|
'Metabrik::File::Text' => [ ], |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub update { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my @urls = qw( |
46
|
|
|
|
|
|
|
ftp://ftp.apnic.net/apnic/whois/apnic.db.inetnum.gz |
47
|
|
|
|
|
|
|
ftp://ftp.apnic.net/apnic/whois/apnic.db.inet6num.gz |
48
|
|
|
|
|
|
|
ftp://ftp.ripe.net/ripe/dbase/ripe.db.gz |
49
|
|
|
|
|
|
|
ftp://ftp.afrinic.net/dbase/afrinic.db.gz |
50
|
|
|
|
|
|
|
http://ftp.apnic.net/apnic/dbase/data/jpnic.db.gz |
51
|
|
|
|
|
|
|
http://ftp.apnic.net/apnic/dbase/data/krnic.db.gz |
52
|
|
|
|
|
|
|
http://ftp.apnic.net/apnic/dbase/data/twnic.db.gz |
53
|
|
|
|
|
|
|
ftp://ftp.arin.net/pub/rr/arin.db.gz |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
my $cw = Metabrik::Client::Www->new_from_brik_init($self) or return; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my @fetched = (); |
61
|
0
|
|
|
|
|
|
for my $url (@urls) { |
62
|
0
|
|
|
|
|
|
$self->log->verbose("update: fetching url [$url]"); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
(my $filename = $url) =~ s/^.*\/(.*?)$/$1/; |
65
|
0
|
|
|
|
|
|
(my $unzipped = $filename) =~ s/\.gz$//; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $output = $datadir."/$filename"; |
68
|
0
|
|
|
|
|
|
my $r = $cw->mirror($url, $filename, $datadir); |
69
|
0
|
0
|
|
|
|
|
if (! defined($r)) { |
|
|
0
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$self->log->warning("update: can't fetch url [$url]"); |
71
|
0
|
|
|
|
|
|
next; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
elsif (@$r == 0) { # Already up to date |
74
|
0
|
|
|
|
|
|
next; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $files = []; |
78
|
0
|
0
|
|
|
|
|
if ($filename =~ m{.gz$}) { |
79
|
0
|
|
|
|
|
|
$self->log->verbose("update: uncompressing file to [$unzipped]"); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
my $fc = Metabrik::File::Compress->new_from_brik_init($self) or return; |
82
|
0
|
|
|
|
|
|
$files = $fc->uncompress($output, $unzipped, $datadir); |
83
|
0
|
0
|
|
|
|
|
if (! defined($files)) { |
84
|
0
|
|
|
|
|
|
$self->log->warning("update: can't uncompress file [$output]"); |
85
|
0
|
|
|
|
|
|
next; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
0
|
|
|
|
|
|
push @fetched, $output; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
push @fetched, @$files; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return \@fetched; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub next_record { |
99
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
100
|
0
|
|
|
|
|
|
my ($input) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
0
|
|
|
|
$input ||= $self->datadir.'/'.$self->input; |
103
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('next_record', $input) or return; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $fr = $self->_read; |
106
|
0
|
0
|
|
|
|
|
if (! defined($fr)) { |
107
|
0
|
0
|
|
|
|
|
$fr = Metabrik::File::Read->new_from_brik_init($self) or return; |
108
|
0
|
|
|
|
|
|
$fr->encoding('ascii'); |
109
|
0
|
|
|
|
|
|
$fr->input($input); |
110
|
0
|
|
|
|
|
|
$fr->as_array(1); |
111
|
0
|
0
|
|
|
|
|
$fr->open |
112
|
|
|
|
|
|
|
or return $self->log->error("next_record: file::read open failed"); |
113
|
0
|
|
|
|
|
|
$self->_read($fr); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $lines = $fr->read_until_blank_line; |
117
|
0
|
0
|
|
|
|
|
if (@$lines == 0) { |
118
|
|
|
|
|
|
|
# If nothing has been read and eof reached, we return undef. |
119
|
|
|
|
|
|
|
# Otherwise, we return an empty object. |
120
|
0
|
0
|
|
|
|
|
if ($fr->eof) { |
121
|
0
|
|
|
|
|
|
$fr->close; |
122
|
0
|
|
|
|
|
|
$self->_read(undef); |
123
|
0
|
|
|
|
|
|
return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
0
|
|
|
|
|
|
return {}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my %record = (); |
131
|
0
|
|
|
|
|
|
for my $line (@$lines) { |
132
|
0
|
0
|
|
|
|
|
next if ($line =~ /^\s*#/); |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$line =~ s/^\s*//; |
135
|
0
|
|
|
|
|
|
$line =~ s/\s*$//; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my ($key, $val); |
138
|
0
|
0
|
|
|
|
|
if ($line =~ /^(.*?)\s*:\s*(.*)$/) { |
139
|
0
|
|
|
|
|
|
$key = $1; |
140
|
0
|
|
|
|
|
|
$val = $2; |
141
|
|
|
|
|
|
|
} |
142
|
0
|
0
|
|
|
|
|
next unless defined($val); |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
push @{$record{raw}}, $line; |
|
0
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
$self->log->debug("next_record: key [$key] val[$val]"); |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
if (! exists($record{$key})) { |
149
|
0
|
|
|
|
|
|
$record{$key} = $val; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
else { |
152
|
0
|
|
|
|
|
|
$record{$key} .= "\n$val"; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Remove DUMMY data, it is kept in {raw} anyway |
156
|
0
|
|
|
|
|
|
delete $record{'remarks'}; |
157
|
0
|
|
|
|
|
|
delete $record{'admin-c'}; |
158
|
0
|
|
|
|
|
|
delete $record{'tech-c'}; |
159
|
0
|
|
|
|
|
|
delete $record{'changed'}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
return \%record; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |