blocklistshow 1.2 → 1.4
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/.rubocop.yml +2 -1
- data/CHANGELOG.md +24 -0
- data/Makefile +10 -0
- data/README.md +1 -1
- data/TODO +3 -0
- data/bin/blocklist.rb +47 -4
- data/bin/unblock.rb +82 -2
- metadata +7 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34b39ec980acfb4429c4db89284e00377f0b87d6fc55b0809bc510b77c6ec0c6
|
|
4
|
+
data.tar.gz: 60867006da7dc29205e0cfae0b8dd2211bac5246f45aad9dac35d1bb16863a4d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f12d7b7c0f3f8b7163af7cb6dab53f0e6b24c01b694fe9650a67479693eb2c78f2179fd18bb6745545b6c8a1bf2a53116fa6eb5e92b60f4c1986f92deef5865a
|
|
7
|
+
data.tar.gz: 47ae8bddda24ffd0238d45d83a5515a67289f8689aa7a7c677705310151f5bef03cfaf75332a622b345809b1d277f29ab7ef155b9cd894c682affa99d099418d
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## 1.4 (2026-03-29)
|
|
2
|
+
- Gem release
|
|
3
|
+
- Support database format 2025
|
|
4
|
+
|
|
5
|
+
## 1.3 (2024-12-01)
|
|
6
|
+
|
|
7
|
+
- Gem release
|
|
8
|
+
- call helper to unblock
|
|
9
|
+
- support new filenames
|
|
10
|
+
|
|
11
|
+
## 1.2 (2023-09-30)
|
|
12
|
+
|
|
13
|
+
- Gem release
|
|
14
|
+
- add unblock.rb
|
|
15
|
+
|
|
16
|
+
## 1.1 (2023-09-27)
|
|
17
|
+
|
|
18
|
+
- Gem release
|
|
19
|
+
- rubocop cleanups
|
|
20
|
+
|
|
21
|
+
## 1.0 (2021-05-02)
|
|
22
|
+
|
|
23
|
+
- Gem release
|
|
24
|
+
|
|
1
25
|
## 1.0 (2020-11-06)
|
|
2
26
|
|
|
3
27
|
- Initial Release.
|
data/Makefile
ADDED
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
|
+
].freeze
|
|
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
|
|
@@ -137,12 +164,28 @@ until ARGV.empty?
|
|
|
137
164
|
end
|
|
138
165
|
end
|
|
139
166
|
|
|
167
|
+
#
|
|
168
|
+
# Format 2024:
|
|
169
|
+
# blocklistctl dump
|
|
170
|
+
# address/ma:port id nfail last access
|
|
171
|
+
# XX.XXX.XX.XX/32:22 OK 3/3 2026/03/28 04:24:51
|
|
172
|
+
#
|
|
173
|
+
# Format 2025:
|
|
174
|
+
# blocklistctl dump
|
|
175
|
+
# rulename address/ma:port id nfail last access
|
|
176
|
+
# blocklistd XXX.XX.XXX.XX/32:25 3/3 2026/03/28 20:40:06
|
|
177
|
+
#
|
|
178
|
+
|
|
140
179
|
load_cache
|
|
141
180
|
list = []
|
|
142
|
-
raw =
|
|
181
|
+
raw = `#{BLOCKLISTCTL} dump -b -n -w`
|
|
143
182
|
# pp raw
|
|
144
183
|
raw.split( "\n" ).each do |line|
|
|
145
|
-
|
|
184
|
+
if line[ 0 ] == ' ' # Format 2024
|
|
185
|
+
address_port, state, _nfail, access = line.split( "\t", 4 )
|
|
186
|
+
else
|
|
187
|
+
_rulename, address_port, state, _nfail, access = line.split( "\t", 5 )
|
|
188
|
+
end
|
|
146
189
|
list.push( [ access, address_port, state ] )
|
|
147
190
|
end
|
|
148
191
|
list.sort.each do |row|
|
data/bin/unblock.rb
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
#!/usr/local/bin/ruby
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
|
|
4
27
|
LOCAL_BDB_FILE_MODE = 0o0600
|
|
5
28
|
LOCAL_BDB_OPTIONS = { 'set_pagesize' => 1024, 'set_cachesize' => 32 * 1024 }.freeze
|
|
6
29
|
|
|
@@ -9,6 +32,8 @@ require 'bdb1'
|
|
|
9
32
|
|
|
10
33
|
# /usr/src/contrib/blacklist/bin/conf.h
|
|
11
34
|
# struct conf {
|
|
35
|
+
# size_t c_lineno; # Fromat 2025
|
|
36
|
+
# struct sockaddr_storage c_ss;
|
|
12
37
|
# struct sockaddr_storage c_ss;
|
|
13
38
|
# int c_lmask;
|
|
14
39
|
# int c_port;
|
|
@@ -37,6 +62,15 @@ require 'bdb1'
|
|
|
37
62
|
# char __ss_pad2[_SS_PAD2SIZE];
|
|
38
63
|
# };
|
|
39
64
|
|
|
65
|
+
def fix_key( key )
|
|
66
|
+
case key.size
|
|
67
|
+
when 296 # Format 2025
|
|
68
|
+
return key[ 8 .. ]
|
|
69
|
+
end
|
|
70
|
+
# Format 2024
|
|
71
|
+
key
|
|
72
|
+
end
|
|
73
|
+
|
|
40
74
|
def decode_ip( key, afamily )
|
|
41
75
|
case afamily
|
|
42
76
|
when 2
|
|
@@ -69,7 +103,7 @@ def search_db( dbh, list )
|
|
|
69
103
|
found = []
|
|
70
104
|
dbh.each_key do |key|
|
|
71
105
|
# pp key, val
|
|
72
|
-
ip2 = ip_from_key( key ).to_s
|
|
106
|
+
ip2 = ip_from_key( fix_key( key ) ).to_s
|
|
73
107
|
next unless list.include?( ip2 )
|
|
74
108
|
|
|
75
109
|
puts "ip2: #{ip2}"
|
|
@@ -78,10 +112,51 @@ def search_db( dbh, list )
|
|
|
78
112
|
found
|
|
79
113
|
end
|
|
80
114
|
|
|
115
|
+
PROTOCOLS = {
|
|
116
|
+
6 => 'tcp',
|
|
117
|
+
17 => 'udp',
|
|
118
|
+
132 => 'sctp'
|
|
119
|
+
}.freeze
|
|
120
|
+
|
|
121
|
+
def decode_key( key )
|
|
122
|
+
af = key[ 1 .. 1 ].unpack1( 'C' )
|
|
123
|
+
{
|
|
124
|
+
af: af,
|
|
125
|
+
ip: decode_ip( key, af ),
|
|
126
|
+
mask: key[ 128 .. 131 ].unpack1( 'L' ),
|
|
127
|
+
port: key[ 132 .. 135 ].unpack1( 'L' ),
|
|
128
|
+
proto: PROTOCOLS[ key[ 136 .. 139 ].unpack1( 'L' ) ],
|
|
129
|
+
family: key[ 140 .. 143 ].unpack1( 'L' ),
|
|
130
|
+
uid: key[ 144 .. 147 ].unpack1( 'L' ),
|
|
131
|
+
nfail: key[ 148 .. 151 ].unpack1( 'L' ),
|
|
132
|
+
name: key[ 152 .. 279 ].delete( "\0" ),
|
|
133
|
+
rmask: key[ 280 .. 283 ].unpack1( 'L' ),
|
|
134
|
+
duration: key[ 284 .. 287 ].unpack1( 'L' )
|
|
135
|
+
}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def decode_data( buffer )
|
|
139
|
+
{
|
|
140
|
+
count: buffer[ 0 .. 3 ].unpack1( 'L' ),
|
|
141
|
+
pad1: buffer[ 4 .. 7 ].unpack1( 'L' ),
|
|
142
|
+
time1: Time.at( buffer[ 8 .. 11 ].unpack1( 'L' ) ),
|
|
143
|
+
time2: buffer[ 12 .. 15 ].unpack1( 'L' ),
|
|
144
|
+
text: buffer[ 16 .. 79 ].delete( "\0" )
|
|
145
|
+
}
|
|
146
|
+
end
|
|
147
|
+
|
|
81
148
|
def remove_db( dbh, found )
|
|
82
149
|
removed = 0
|
|
83
150
|
found.each do |key|
|
|
151
|
+
# pp key
|
|
152
|
+
h = decode_key( fix_key( key ) )
|
|
153
|
+
# buffer = dbh[ key ]
|
|
154
|
+
# pp decode_data( buffer )
|
|
84
155
|
dbh.delete( key )
|
|
156
|
+
# pp h
|
|
157
|
+
line = "#{HELPER_FILE} 'rem' '#{h[ :name ]}' '#{h[ :proto ]}' '#{h[ :ip ]}' '#{h[ :mask ]}' '#{h[ :port ]}' '#{h[ :uid ]}'"
|
|
158
|
+
puts line
|
|
159
|
+
`#{line}`
|
|
85
160
|
removed += 1
|
|
86
161
|
end
|
|
87
162
|
puts "removed: #{removed}"
|
|
@@ -89,6 +164,11 @@ def remove_db( dbh, found )
|
|
|
89
164
|
dbh.close
|
|
90
165
|
end
|
|
91
166
|
|
|
167
|
+
if ARGV.empty?
|
|
168
|
+
warn "#{$0} IP-Addresss [ IP-Addresss ] [ ... ]"
|
|
169
|
+
exit 64
|
|
170
|
+
end
|
|
171
|
+
|
|
92
172
|
dbh = BDB1::Hash.open( BDB_FILE,
|
|
93
173
|
BDB1::WRITE | BDB1::CREATE,
|
|
94
174
|
LOCAL_BDB_FILE_MODE,
|
metadata
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: blocklistshow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.4'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dirk Meyer
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Display of data from blocklistd on FreeBSD with country codes and reverse
|
|
14
13
|
DNS.
|
|
15
|
-
email:
|
|
16
14
|
executables:
|
|
17
15
|
- blocklist.rb
|
|
18
16
|
- geodb-lookup.rb
|
|
@@ -26,15 +24,17 @@ files:
|
|
|
26
24
|
- CHANGELOG.md
|
|
27
25
|
- Gemfile
|
|
28
26
|
- LICENSE.txt
|
|
27
|
+
- Makefile
|
|
29
28
|
- README.md
|
|
29
|
+
- TODO
|
|
30
30
|
- bin/blocklist.rb
|
|
31
31
|
- bin/geodb-lookup.rb
|
|
32
32
|
- bin/unblock.rb
|
|
33
33
|
homepage: https://rubygems.org/gems/blocklistshow
|
|
34
34
|
licenses:
|
|
35
35
|
- MIT
|
|
36
|
-
metadata:
|
|
37
|
-
|
|
36
|
+
metadata:
|
|
37
|
+
rubygems_mfa_required: 'true'
|
|
38
38
|
rdoc_options: []
|
|
39
39
|
require_paths:
|
|
40
40
|
- lib
|
|
@@ -49,8 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
49
49
|
- !ruby/object:Gem::Version
|
|
50
50
|
version: '0'
|
|
51
51
|
requirements: []
|
|
52
|
-
rubygems_version:
|
|
53
|
-
signing_key:
|
|
52
|
+
rubygems_version: 4.0.7
|
|
54
53
|
specification_version: 4
|
|
55
54
|
summary: show blocklistd data
|
|
56
55
|
test_files: []
|