blocklistshow 1.1 → 1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +1 -1
- data/bin/blocklist.rb +30 -3
- data/bin/unblock.rb +168 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d12abe9119afea6df652e56becb1cd8589a7cc877c6d02906924c9a4c1fc55de
|
4
|
+
data.tar.gz: 04ccb9bd6eb05003552941e5e7f97ee69962e88600549ef1b4f61f763776bcd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e00f66b08006f8027d4dfca7a5cec2b20246426e5b4f4d0774eff69dcc049cc2f58555a1a6903bfe9710badbe97d87ea2ec912109040a5c42ccc80fef715914
|
7
|
+
data.tar.gz: a789c14563f452b07f127c4eef4e8b95c1cfde14936a6b9671a734bd102bece3c879c1357315acae4848fba6d425256268e194c11136bc5c5c28f9c158152219
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 1.3 (2024-12-01)
|
2
|
+
|
3
|
+
- Gem release
|
4
|
+
- call helper to unblock
|
5
|
+
- support new filenames
|
6
|
+
|
7
|
+
## 1.2 (2023-09-30)
|
8
|
+
|
9
|
+
- Gem release
|
10
|
+
- add unblock.rb
|
11
|
+
|
12
|
+
## 1.1 (2023-09-27)
|
13
|
+
|
14
|
+
- Gem release
|
15
|
+
- rubocop cleanups
|
16
|
+
|
17
|
+
## 1.0 (2021-05-02)
|
18
|
+
|
19
|
+
- Gem release
|
20
|
+
|
1
21
|
## 1.0 (2020-11-06)
|
2
22
|
|
3
23
|
- Initial Release.
|
data/README.md
CHANGED
data/bin/blocklist.rb
CHANGED
@@ -3,8 +3,35 @@
|
|
3
3
|
require 'ipaddr'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# find matching filenames
|
7
|
+
def find_files( list )
|
8
|
+
list.each do |filename|
|
9
|
+
next if filename == ''
|
10
|
+
|
11
|
+
return filename if File.exist?( filename )
|
12
|
+
end
|
13
|
+
|
14
|
+
list.first
|
15
|
+
end
|
16
|
+
|
17
|
+
CC_CACHE_FILES = [
|
18
|
+
'/var/db/blocklistd.cc.json',
|
19
|
+
'/var/db/blacklistd.cc.json'
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
DNS_CACHE_FILES = [
|
23
|
+
'/var/db/blocklistd.dns.json',
|
24
|
+
'/var/db/blacklistd.dns.json'
|
25
|
+
].freeze
|
26
|
+
|
27
|
+
BLOCKLISTCTL_FILES = [
|
28
|
+
`which blocklistctl`.delete( "\n" ),
|
29
|
+
`which blacklistctl`.delete( "\n" )
|
30
|
+
]
|
31
|
+
|
32
|
+
CC_CACHE_FILE = find_files( CC_CACHE_FILES )
|
33
|
+
DNS_CACHE_FILE = find_files( DNS_CACHE_FILES )
|
34
|
+
BLOCKLISTCTL = find_files( BLOCKLISTCTL_FILES )
|
8
35
|
|
9
36
|
# pkg install databases/ruby-bdb net/webalizer-geodb
|
10
37
|
GEODB_FILE = '/usr/local/share/geolizer/GeoDB.dat'.freeze
|
@@ -139,7 +166,7 @@ end
|
|
139
166
|
|
140
167
|
load_cache
|
141
168
|
list = []
|
142
|
-
raw =
|
169
|
+
raw = `#{BLOCKLISTCTL} dump -b -n -w`
|
143
170
|
# pp raw
|
144
171
|
raw.split( "\n" ).each do |line|
|
145
172
|
address_port, state, _nfail, access = line.split( "\t", 4 )
|
data/bin/unblock.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
def find_files( list )
|
4
|
+
list.each do |filename|
|
5
|
+
next if filename == ''
|
6
|
+
|
7
|
+
return filename if File.exist?( filename )
|
8
|
+
end
|
9
|
+
|
10
|
+
list.first
|
11
|
+
end
|
12
|
+
|
13
|
+
BDB_FILES = [
|
14
|
+
'/var/db/blocklistd.db',
|
15
|
+
'/var/db/blacklistd.db'
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
HELPER_FILES = [
|
19
|
+
'/usr/local/libexec/blocklistd-helper',
|
20
|
+
'/usr/libexec/blacklistd-helper',
|
21
|
+
'/libexec/blocklistd-helper'
|
22
|
+
].freeze
|
23
|
+
|
24
|
+
BDB_FILE = find_files( BDB_FILES ).freeze
|
25
|
+
HELPER_FILE = find_files( HELPER_FILES ).freeze
|
26
|
+
|
27
|
+
LOCAL_BDB_FILE_MODE = 0o0600
|
28
|
+
LOCAL_BDB_OPTIONS = { 'set_pagesize' => 1024, 'set_cachesize' => 32 * 1024 }.freeze
|
29
|
+
|
30
|
+
require 'ipaddr'
|
31
|
+
require 'bdb1'
|
32
|
+
|
33
|
+
# /usr/src/contrib/blacklist/bin/conf.h
|
34
|
+
# struct conf {
|
35
|
+
# struct sockaddr_storage c_ss;
|
36
|
+
# int c_lmask;
|
37
|
+
# int c_port;
|
38
|
+
# int c_proto;
|
39
|
+
# int c_family;
|
40
|
+
# int c_uid;
|
41
|
+
# int c_nfail;
|
42
|
+
# char c_name[128];
|
43
|
+
# int c_rmask;
|
44
|
+
# int c_duration;
|
45
|
+
# };
|
46
|
+
|
47
|
+
# /usr/src/contrib/blacklist/bin/state.h
|
48
|
+
# struct dbinfo {
|
49
|
+
# int count;
|
50
|
+
# time_t last;
|
51
|
+
# char id[64];
|
52
|
+
# };
|
53
|
+
|
54
|
+
# /usr/include/sys/_sockaddr_storage.h
|
55
|
+
# struct sockaddr_storage {
|
56
|
+
# unsigned char ss_len; /* address length */
|
57
|
+
# sa_family_t ss_family; /* address family */
|
58
|
+
# char __ss_pad1[_SS_PAD1SIZE];
|
59
|
+
# __int64_t __ss_align; /* force desired struct alignment */
|
60
|
+
# char __ss_pad2[_SS_PAD2SIZE];
|
61
|
+
# };
|
62
|
+
|
63
|
+
def decode_ip( key, afamily )
|
64
|
+
case afamily
|
65
|
+
when 2
|
66
|
+
off = 4
|
67
|
+
key[ off .. ].unpack( 'C4' ).join( '.' )
|
68
|
+
when 28
|
69
|
+
off = 8
|
70
|
+
IPAddr::IN6FORMAT % key[ off .. ].unpack( 'n8' )
|
71
|
+
else
|
72
|
+
raise IPAddr::AddressFamilyError, 'unsupported address family'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def ip_from_key( key )
|
77
|
+
# puts "size: #{key.size}"
|
78
|
+
|
79
|
+
# len = key.unpack1( 'C' )
|
80
|
+
# puts "len: #{len}"
|
81
|
+
|
82
|
+
af = key[ 1 .. 1 ].unpack1( 'C' )
|
83
|
+
# puts "af: #{af}"
|
84
|
+
|
85
|
+
ip = decode_ip( key, af )
|
86
|
+
# puts "ip: #{ip}"
|
87
|
+
|
88
|
+
IPAddr.new( ip )
|
89
|
+
end
|
90
|
+
|
91
|
+
def search_db( dbh, list )
|
92
|
+
found = []
|
93
|
+
dbh.each_key do |key|
|
94
|
+
# pp key, val
|
95
|
+
ip2 = ip_from_key( key ).to_s
|
96
|
+
next unless list.include?( ip2 )
|
97
|
+
|
98
|
+
puts "ip2: #{ip2}"
|
99
|
+
found.push( key )
|
100
|
+
end
|
101
|
+
found
|
102
|
+
end
|
103
|
+
|
104
|
+
PROTOCOLS = {
|
105
|
+
6 => 'tcp',
|
106
|
+
17 => 'udp',
|
107
|
+
132 => 'sctp'
|
108
|
+
}.freeze
|
109
|
+
|
110
|
+
def decode_key( key )
|
111
|
+
af = key[ 1 .. 1 ].unpack1( 'C' )
|
112
|
+
{
|
113
|
+
af: af,
|
114
|
+
ip: decode_ip( key, af ),
|
115
|
+
mask: key[ 128 .. 131 ].unpack1( 'L' ),
|
116
|
+
port: key[ 132 .. 135 ].unpack1( 'L' ),
|
117
|
+
proto: PROTOCOLS[ key[ 136 .. 139 ].unpack1( 'L' ) ],
|
118
|
+
family: key[ 140 .. 143 ].unpack1( 'L' ),
|
119
|
+
uid: key[ 144 .. 147 ].unpack1( 'L' ),
|
120
|
+
nfail: key[ 148 .. 151 ].unpack1( 'L' ),
|
121
|
+
name: key[ 152 .. 279 ].delete( "\0" ),
|
122
|
+
rmask: key[ 280 .. 283 ].unpack1( 'L' ),
|
123
|
+
duration: key[ 284 .. 287 ].unpack1( 'L' )
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
def decode_data( key )
|
128
|
+
{
|
129
|
+
count: key[ 0 .. 3 ].unpack1( 'L' ),
|
130
|
+
pad1: key[ 4 .. 7 ].unpack1( 'L' ),
|
131
|
+
time1: Time.at( key[ 8 .. 11 ].unpack1( 'L' ) ),
|
132
|
+
time2: key[ 12 .. 15 ].unpack1( 'L' ),
|
133
|
+
text: key[ 16 .. 79 ].delete( "\0" )
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
def remove_db( dbh, found )
|
138
|
+
removed = 0
|
139
|
+
found.each do |key|
|
140
|
+
# pp key
|
141
|
+
h = decode_key( key )
|
142
|
+
# data = dbh[ key ]
|
143
|
+
# pp decode_data( data )
|
144
|
+
dbh.delete( key )
|
145
|
+
# pp h
|
146
|
+
line = "#{HELPER_FILE} 'rem' '#{h[ :name ]}' '#{h[ :proto ]}' '#{h[ :ip ]}' '#{h[ :mask ]}' '#{h[ :port ]}' '#{h[ :uid ]}'"
|
147
|
+
puts line
|
148
|
+
`#{line}`
|
149
|
+
removed += 1
|
150
|
+
end
|
151
|
+
puts "removed: #{removed}"
|
152
|
+
dbh.sync
|
153
|
+
dbh.close
|
154
|
+
end
|
155
|
+
|
156
|
+
if ARGV.empty?
|
157
|
+
warn "#{$0} IP-Addresss [ IP-Addresss ] [ ... ]"
|
158
|
+
exit 64
|
159
|
+
end
|
160
|
+
|
161
|
+
dbh = BDB1::Hash.open( BDB_FILE,
|
162
|
+
BDB1::WRITE | BDB1::CREATE,
|
163
|
+
LOCAL_BDB_FILE_MODE,
|
164
|
+
LOCAL_BDB_OPTIONS )
|
165
|
+
found = search_db( dbh, ARGV )
|
166
|
+
remove_db( dbh, found )
|
167
|
+
|
168
|
+
# eof
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blocklistshow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dirk Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Display of data from blocklistd on FreeBSD with country codes and reverse
|
14
14
|
DNS.
|
@@ -16,6 +16,7 @@ email:
|
|
16
16
|
executables:
|
17
17
|
- blocklist.rb
|
18
18
|
- geodb-lookup.rb
|
19
|
+
- unblock.rb
|
19
20
|
extensions: []
|
20
21
|
extra_rdoc_files:
|
21
22
|
- LICENSE.txt
|
@@ -28,6 +29,7 @@ files:
|
|
28
29
|
- README.md
|
29
30
|
- bin/blocklist.rb
|
30
31
|
- bin/geodb-lookup.rb
|
32
|
+
- bin/unblock.rb
|
31
33
|
homepage: https://rubygems.org/gems/blocklistshow
|
32
34
|
licenses:
|
33
35
|
- MIT
|
@@ -47,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
49
|
- !ruby/object:Gem::Version
|
48
50
|
version: '0'
|
49
51
|
requirements: []
|
50
|
-
rubygems_version: 3.
|
52
|
+
rubygems_version: 3.5.22
|
51
53
|
signing_key:
|
52
54
|
specification_version: 4
|
53
55
|
summary: show blocklistd data
|