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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d59160b951cd30f78713bb78065b2891114950c9a425f78cd9118c4703c91360
4
- data.tar.gz: 370a9a88615ff07b03f5742278578bb369ad689a23e6e4f8f464699d3a374d2b
3
+ metadata.gz: 34b39ec980acfb4429c4db89284e00377f0b87d6fc55b0809bc510b77c6ec0c6
4
+ data.tar.gz: 60867006da7dc29205e0cfae0b8dd2211bac5246f45aad9dac35d1bb16863a4d
5
5
  SHA512:
6
- metadata.gz: 5afef2dd7e33c4cc6e1ab5f4b5a5cad207b80a4dbce31b1f940f8477b46ea43d92b083670e2d059af40ec7a5e1e951907a60f9a03f85a7f86ffa1b7e5724a34a
7
- data.tar.gz: 57100a4f6132e6b0182ef9995a7a712514cd0972ce52b7c0298dd9cfd64f5481fd2790a5b2d3022c15abdf9940dd59dd02a0e135ab94e8404fde0be1c786344d
6
+ metadata.gz: f12d7b7c0f3f8b7163af7cb6dab53f0e6b24c01b694fe9650a67479693eb2c78f2179fd18bb6745545b6c8a1bf2a53116fa6eb5e92b60f4c1986f92deef5865a
7
+ data.tar.gz: 47ae8bddda24ffd0238d45d83a5515a67289f8689aa7a7c677705310151f5bef03cfaf75332a622b345809b1d277f29ab7ef155b9cd894c682affa99d099418d
data/.rubocop.yml CHANGED
@@ -24,7 +24,8 @@ Layout/SpaceInsideReferenceBrackets:
24
24
  Exclude:
25
25
  - 'blocklistshow.gemspec'
26
26
 
27
- Metrics/LineLength:
27
+ #Metrics/LineLength:
28
+ Layout/LineLength:
28
29
  Exclude:
29
30
  - 'blocklistshow.gemspec'
30
31
 
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
@@ -0,0 +1,10 @@
1
+
2
+ cop:
3
+ rubocop
4
+
5
+ auto::
6
+ rubocop --auto-gen-config
7
+
8
+ gem::
9
+ gem build blocklistshow.gemspec
10
+
data/README.md CHANGED
@@ -8,7 +8,7 @@ The reverse DNS and the country codes are cached.
8
8
  Install it on the server running blocklistd by:
9
9
 
10
10
  $ pkg install databases/ruby-bdb net/webalizer-geodb
11
- $ gem install blocklist
11
+ $ gem install blocklistshow
12
12
 
13
13
  ## Usage
14
14
 
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+
2
+ Diagnostic tools for blocklistd
3
+
data/bin/blocklist.rb CHANGED
@@ -3,8 +3,35 @@
3
3
  require 'ipaddr'
4
4
  require 'json'
5
5
 
6
- DNS_CACHE_FILE = '/var/db/blacklistd.dns.json'.freeze
7
- CC_CACHE_FILE = '/var/db/blacklistd.cc.json'.freeze
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 = `blacklistctl dump -b -n -w`
181
+ raw = `#{BLOCKLISTCTL} dump -b -n -w`
143
182
  # pp raw
144
183
  raw.split( "\n" ).each do |line|
145
- address_port, state, _nfail, access = line.split( "\t", 4 )
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
- BDB_FILE = '/var/db/blacklistd.db'.freeze
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.2'
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: 2023-09-30 00:00:00.000000000 Z
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
- post_install_message:
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: 3.4.12
53
- signing_key:
52
+ rubygems_version: 4.0.7
54
53
  specification_version: 4
55
54
  summary: show blocklistd data
56
55
  test_files: []