blocklistshow 1.0 → 1.2

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: 46d7101d4cdf766ddc1d332f752a4c2982acd54643404cc00483d56a1d05712b
4
- data.tar.gz: 36600a16f4683373926827f8cb8654629dff00ba51281a6a3bdc151cebf2d006
3
+ metadata.gz: d59160b951cd30f78713bb78065b2891114950c9a425f78cd9118c4703c91360
4
+ data.tar.gz: 370a9a88615ff07b03f5742278578bb369ad689a23e6e4f8f464699d3a374d2b
5
5
  SHA512:
6
- metadata.gz: 8823bb78fb271dac8bd7703507221e0f30e3ebdfd2ac4cec1a97dd3cccbece4957509d6c8e9ccf8b2b5ccf1cd3d61578ef3ea71984425541151e2c24c925ca02
7
- data.tar.gz: 9b7152a0d4167660e3d1ae67d6e8e26dce9bc91a6dc0e183175a628b17070b84555493e16ace16036c927956c7e4f23691a21eff38e06eb238663ea9af4b6ff3
6
+ metadata.gz: 5afef2dd7e33c4cc6e1ab5f4b5a5cad207b80a4dbce31b1f940f8477b46ea43d92b083670e2d059af40ec7a5e1e951907a60f9a03f85a7f86ffa1b7e5724a34a
7
+ data.tar.gz: 57100a4f6132e6b0182ef9995a7a712514cd0972ce52b7c0298dd9cfd64f5481fd2790a5b2d3022c15abdf9940dd59dd02a0e135ab94e8404fde0be1c786344d
data/.rubocop.yml CHANGED
@@ -2,6 +2,9 @@ inherit_from: .rubocop_todo.yml
2
2
 
3
3
  # rubocop configuration
4
4
 
5
+ AllCops:
6
+ NewCops: enable
7
+
5
8
  Layout/SpaceInsideArrayLiteralBrackets:
6
9
  EnforcedStyle: space
7
10
  Exclude:
data/bin/blocklist.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'ipaddr'
4
4
  require 'json'
5
- require 'pp'
6
5
 
7
6
  DNS_CACHE_FILE = '/var/db/blacklistd.dns.json'.freeze
8
7
  CC_CACHE_FILE = '/var/db/blacklistd.cc.json'.freeze
data/bin/unblock.rb ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ BDB_FILE = '/var/db/blacklistd.db'.freeze
4
+ LOCAL_BDB_FILE_MODE = 0o0600
5
+ LOCAL_BDB_OPTIONS = { 'set_pagesize' => 1024, 'set_cachesize' => 32 * 1024 }.freeze
6
+
7
+ require 'ipaddr'
8
+ require 'bdb1'
9
+
10
+ # /usr/src/contrib/blacklist/bin/conf.h
11
+ # struct conf {
12
+ # struct sockaddr_storage c_ss;
13
+ # int c_lmask;
14
+ # int c_port;
15
+ # int c_proto;
16
+ # int c_family;
17
+ # int c_uid;
18
+ # int c_nfail;
19
+ # char c_name[128];
20
+ # int c_rmask;
21
+ # int c_duration;
22
+ # };
23
+
24
+ # /usr/src/contrib/blacklist/bin/state.h
25
+ # struct dbinfo {
26
+ # int count;
27
+ # time_t last;
28
+ # char id[64];
29
+ # };
30
+
31
+ # /usr/include/sys/_sockaddr_storage.h
32
+ # struct sockaddr_storage {
33
+ # unsigned char ss_len; /* address length */
34
+ # sa_family_t ss_family; /* address family */
35
+ # char __ss_pad1[_SS_PAD1SIZE];
36
+ # __int64_t __ss_align; /* force desired struct alignment */
37
+ # char __ss_pad2[_SS_PAD2SIZE];
38
+ # };
39
+
40
+ def decode_ip( key, afamily )
41
+ case afamily
42
+ when 2
43
+ off = 4
44
+ key[ off .. ].unpack( 'C4' ).join( '.' )
45
+ when 28
46
+ off = 8
47
+ IPAddr::IN6FORMAT % key[ off .. ].unpack( 'n8' )
48
+ else
49
+ raise IPAddr::AddressFamilyError, 'unsupported address family'
50
+ end
51
+ end
52
+
53
+ def ip_from_key( key )
54
+ # puts "size: #{key.size}"
55
+
56
+ # len = key.unpack1( 'C' )
57
+ # puts "len: #{len}"
58
+
59
+ af = key[ 1 .. 1 ].unpack1( 'C' )
60
+ # puts "af: #{af}"
61
+
62
+ ip = decode_ip( key, af )
63
+ # puts "ip: #{ip}"
64
+
65
+ IPAddr.new( ip )
66
+ end
67
+
68
+ def search_db( dbh, list )
69
+ found = []
70
+ dbh.each_key do |key|
71
+ # pp key, val
72
+ ip2 = ip_from_key( key ).to_s
73
+ next unless list.include?( ip2 )
74
+
75
+ puts "ip2: #{ip2}"
76
+ found.push( key )
77
+ end
78
+ found
79
+ end
80
+
81
+ def remove_db( dbh, found )
82
+ removed = 0
83
+ found.each do |key|
84
+ dbh.delete( key )
85
+ removed += 1
86
+ end
87
+ puts "removed: #{removed}"
88
+ dbh.sync
89
+ dbh.close
90
+ end
91
+
92
+ dbh = BDB1::Hash.open( BDB_FILE,
93
+ BDB1::WRITE | BDB1::CREATE,
94
+ LOCAL_BDB_FILE_MODE,
95
+ LOCAL_BDB_OPTIONS )
96
+ found = search_db( dbh, ARGV )
97
+ remove_db( dbh, found )
98
+
99
+ # 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.0'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dirk Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-06 00:00:00.000000000 Z
11
+ date: 2023-09-30 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
@@ -25,10 +26,10 @@ files:
25
26
  - CHANGELOG.md
26
27
  - Gemfile
27
28
  - LICENSE.txt
28
- - Makefile
29
29
  - README.md
30
30
  - bin/blocklist.rb
31
31
  - bin/geodb-lookup.rb
32
+ - bin/unblock.rb
32
33
  homepage: https://rubygems.org/gems/blocklistshow
33
34
  licenses:
34
35
  - MIT
@@ -41,14 +42,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
42
  requirements:
42
43
  - - ">="
43
44
  - !ruby/object:Gem::Version
44
- version: '2.4'
45
+ version: '2.7'
45
46
  required_rubygems_version: !ruby/object:Gem::Requirement
46
47
  requirements:
47
48
  - - ">="
48
49
  - !ruby/object:Gem::Version
49
50
  version: '0'
50
51
  requirements: []
51
- rubygems_version: 3.0.8
52
+ rubygems_version: 3.4.12
52
53
  signing_key:
53
54
  specification_version: 4
54
55
  summary: show blocklistd data
data/Makefile DELETED
@@ -1,7 +0,0 @@
1
-
2
- cop:
3
- rubocop
4
-
5
- auto::
6
- rubocop --auto-gen-config
7
-