unspam 0.1.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: c3af9375e8a756b3389903f1fa2c8c8108fd8e10
4
- data.tar.gz: 61e660aa192baa1a9bf338371ad063d4586c0517
2
+ SHA256:
3
+ metadata.gz: 3eb8f90cba62104b3f57787682072b5e57f04cd771aec4c2ca7d8e363e305ef4
4
+ data.tar.gz: 856c2c2c307ab974779c60573fb8e0bf8eb7d0ac87465265e4b505b355faa0ed
5
5
  SHA512:
6
- metadata.gz: 749981ed9fc33f20ca341b9f8034f96b901f9f83e42ee8fd71db85b50d7b42d4c6acc676e054ebfcdf88a69e919781759aeb1eac0da0c1cb78d189a86801e079
7
- data.tar.gz: 4aed52af696f1e2a153128f2db90a9a7f490695d373241bb7a22d5e922732b64ca611f138219faba914d97636fcb51d0218ddd5d91d6bcb1f0a3e328b332f6a4
6
+ metadata.gz: 464b5979676cfadba7b0da09ef7b2fd12fa76492875042a3e163e23eae640c907128555bba2ed4ff19c5ae63409006c483faab76926df29103162b603e36395b
7
+ data.tar.gz: 77e61961de1a79e3c34b352f12aac6cb9a5b355903f30d843e60aae4fa53b8899255c1c7f0b3db46b4f31eb27f41699b1b15df5be42f65e86ccf9cdf769c56df
@@ -0,0 +1,25 @@
1
+ name: ci
2
+ permissions:
3
+ contents: read
4
+ on:
5
+ push:
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest]
15
+ ruby: ['3.2', '3.3', '3.4', '4.0']
16
+ include:
17
+ - os: macos-latest
18
+ ruby: '4.0'
19
+ steps:
20
+ - uses: actions/checkout@v6
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - run: bundle exec rake test
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -20,3 +19,9 @@ tmp
20
19
  *.o
21
20
  *.a
22
21
  mkmf.log
22
+
23
+ # local design notes and plans
24
+ docs/
25
+
26
+ # subagent workspace: ledgers, briefs, reports
27
+ .superpowers/
data/AGENTS.md ADDED
@@ -0,0 +1,65 @@
1
+ # AGENTS.md
2
+
3
+ ## What this does
4
+
5
+ `unspam` turns an AS number or an IP address into a Postfix-style blocklist of
6
+ every prefix that network announces. It asks RIPE Stat twice:
7
+
8
+ 1. `searchcomplete` (`data/searchcomplete/data.json?resource=<ip>`) to find the
9
+ ASNs responsible for an IP address. AS input skips this call.
10
+ 2. `announced-prefixes`
11
+ (`data/announced-prefixes/data.json?resource=<asn>&min_peers_seeing=2`) once
12
+ per ASN. `min_peers_seeing=2` is deliberate: prefixes seen by a lone
13
+ collector are noisy and only add false positives to a blocklist, so keep it.
14
+
15
+ A failure on either call is reported on stderr with exit status 1; a run must
16
+ never end in a backtrace.
17
+
18
+ ## Development
19
+
20
+ bundle install
21
+ bundle exec rake test
22
+
23
+ The suite is minitest and stubs HTTP in `test/test_helper.rb`, so it runs
24
+ offline. Run the whole suite before committing; CI runs the same `rake test` on
25
+ Ruby 3.2, 3.3, 3.4 and 4.0 on Linux, plus 4.0 on macOS.
26
+
27
+ ## Ruby support
28
+
29
+ The gem requires Ruby >= 3.2 (`required_ruby_version` in the gemspec, and the CI
30
+ matrix). Do not drop the explicit `csv` and `bigdecimal` dependencies: Ruby 4 no
31
+ longer ships them as default gems and httparty's dependency chain needs both.
32
+
33
+ ## Output format
34
+
35
+ `print_prefixes` pads the prefix to 25 columns and the optional message to 5, and
36
+ the merger emits IPv4 before IPv6. That layout is a contract, not cosmetics:
37
+ users paste the output straight into a Postfix `client_checks` file, so changing
38
+ column widths or ordering is a breaking change. The tests pin both.
39
+
40
+ ## Releases
41
+
42
+ `lib/unspam/version.rb` holds `MAJOR.MINOR.PATCH`. Every release gets a
43
+ `CHANGELOG.md` entry, written before tagging and committed in the release
44
+ commit — release notes that live only in a tag or on the forge get lost. Bump
45
+ the version, run the suite, `gem build unspam.gemspec`, tag annotated
46
+ (`git tag -a vX.Y.Z -m 'vX.Y.Z'`) and push with `--follow-tags`.
47
+
48
+ ## Commits
49
+
50
+ Commit messages say why the change was made, not just what moved. Keep one
51
+ logical change per commit and add no `Co-Authored-By` trailers.
52
+
53
+ ## Branch
54
+
55
+ `main` is the default branch; `master` is gone. Push directly to `main` and let
56
+ CI run on every push.
57
+
58
+ ## Publishing
59
+
60
+ `gem push unspam-X.Y.Z.gem` is manual and needs the RubyGems credentials. Do it
61
+ after the tag is visible and CI on the release commit is green.
62
+
63
+ ## Licence
64
+
65
+ MIT, see `LICENSE`; anything vendored or copied in must be MIT compatible.
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ - Support Ruby 3.2 through 4.0; the previous lockfile pinned bundler 1.17,
6
+ which dies on the removed `String#untaint`.
7
+ - Port prefix merging to netaddr 2 (`parse_net` / `summ_IPv4Net` /
8
+ `summ_IPv6Net`); `NetAddr::CIDR` and `NetAddr.merge` are gone.
9
+ - Merge once across all ASNs matched by an IP, so shared prefixes print once.
10
+ - Report RIPE failures (non-2xx, error status, invalid JSON) on stderr with
11
+ exit 1 instead of raising `NoMethodError`.
12
+ - Route `AS…` numbers, bare AS numbers and IP addresses explicitly; junk input
13
+ now fails with one line.
14
+ - Declare `csv` and `bigdecimal`, which Ruby 4 no longer ships as default gems.
15
+ - Add a minitest suite and CI on Ruby 3.2 → 4.0.
16
+ - Default branch renamed `master` → `main`.
17
+ - `LICENSE` is now MIT only; the stray GPL-2.0 file is gone (`LICENSE.txt`
18
+ was already MIT).
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unspam (0.3.0)
5
+ bigdecimal
6
+ csv
7
+ httparty (~> 0.25)
8
+ netaddr (~> 2.0)
9
+ thor (~> 1.5)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ bigdecimal (4.1.3)
15
+ csv (3.3.7)
16
+ drb (2.2.3)
17
+ httparty (0.25.1)
18
+ csv
19
+ mini_mime (>= 1.0.0)
20
+ multi_xml (>= 0.5.2)
21
+ mini_mime (1.1.5)
22
+ minitest (6.1.0)
23
+ drb (~> 2.0)
24
+ prism (>= 1.5, < 3)
25
+ multi_xml (0.9.1)
26
+ bigdecimal (>= 3.1, < 5)
27
+ netaddr (2.0.6)
28
+ prism (2.1.0)
29
+ prism (2.1.0-aarch64-linux-gnu)
30
+ prism (2.1.0-aarch64-linux-musl)
31
+ prism (2.1.0-arm-linux-gnu)
32
+ prism (2.1.0-arm-linux-musl)
33
+ prism (2.1.0-arm64-darwin)
34
+ prism (2.1.0-x86_64-darwin)
35
+ prism (2.1.0-x86_64-linux-gnu)
36
+ prism (2.1.0-x86_64-linux-musl)
37
+ rake (13.4.2)
38
+ thor (1.5.0)
39
+
40
+ PLATFORMS
41
+ aarch64-linux-gnu
42
+ aarch64-linux-musl
43
+ arm-linux-gnu
44
+ arm-linux-musl
45
+ arm64-darwin
46
+ ruby
47
+ x86_64-darwin
48
+ x86_64-linux-gnu
49
+ x86_64-linux-musl
50
+
51
+ DEPENDENCIES
52
+ bundler (>= 2.4)
53
+ minitest
54
+ rake
55
+ unspam!
56
+
57
+ CHECKSUMS
58
+ bigdecimal (4.1.3) sha256=61ebe1e5e559bdc3cc6f2c0ee7f427321fc838f59611c294356eb04d6e21cf66
59
+ bundler (4.1.0) sha256=d7b7a797b988e544a0677a9c6ed78146f2f63d05ae1af8bc7d9426cf88b46377
60
+ csv (3.3.7) sha256=15a3f16f6628da8664d455eb634e7f22031bcf53044923caf56975109e71b9f8
61
+ drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
62
+ httparty (0.25.1) sha256=354f84b766f9a3e077d64fc8b61a71c88e7c8a890eac4178d30d3269458c1dc5
63
+ mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef
64
+ minitest (6.1.0) sha256=ff373595aa8888631e8a5463986a76b3845346ae6d7fa46e139c1633d418076e
65
+ multi_xml (0.9.1) sha256=7ce766b59c17241ed62976caeae1fae9b2431b263398c35396239a68c4a64e57
66
+ netaddr (2.0.6) sha256=e7c3970ec2c2665aa25c4cbf268011d01f5d98c33182e600759a49961e63f1b4
67
+ prism (2.1.0) sha256=1c0a7c6dea0e93183390fb123f007564dbe663198e2f86ad87204151147601f3
68
+ prism (2.1.0-aarch64-linux-gnu) sha256=808dddc72def68e1a0463689414c97e0ba211938eddbab05387a4844aa2b3ec2
69
+ prism (2.1.0-aarch64-linux-musl) sha256=dd1a0732620c1e575dabb07a297a62911fabd72f8e20ce850b522a866f877930
70
+ prism (2.1.0-arm-linux-gnu) sha256=96b2426b9dbab05448c4add735619929042be3cd7e871ff186468121b62bcfa8
71
+ prism (2.1.0-arm-linux-musl) sha256=00ef918e42a3dc98f11a461bf473586a3424b0f78bee8a4e43b5a65a5f5e2cd0
72
+ prism (2.1.0-arm64-darwin) sha256=2d0c2e3e011cfd89c041940907d3ff3def379d7b0f2ba158d1d42238e8ad8afc
73
+ prism (2.1.0-x86_64-darwin) sha256=6c645d8e6afc742956c7518220ce5106367727c4d9980ac9ab386d55004ddab4
74
+ prism (2.1.0-x86_64-linux-gnu) sha256=b2b647afce09551e650b8bb3e2fc91d7d73d392a09534ca307ec0d619c33bfd4
75
+ prism (2.1.0-x86_64-linux-musl) sha256=249f45981726923e259b927902246219fa25ad10a76f43849c9aee1a3d3ec5b8
76
+ rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
77
+ thor (1.5.0) sha256=e3a9e55fe857e44859ce104a84675ab6e8cd59c650a49106a05f55f136425e73
78
+ unspam (0.3.0)
79
+
80
+ BUNDLED WITH
81
+ 4.1.0
data/LICENSE CHANGED
@@ -1,339 +1,22 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 2, June 1991
3
-
4
- Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
- Everyone is permitted to copy and distribute verbatim copies
7
- of this license document, but changing it is not allowed.
8
-
9
- Preamble
10
-
11
- The licenses for most software are designed to take away your
12
- freedom to share and change it. By contrast, the GNU General Public
13
- License is intended to guarantee your freedom to share and change free
14
- software--to make sure the software is free for all its users. This
15
- General Public License applies to most of the Free Software
16
- Foundation's software and to any other program whose authors commit to
17
- using it. (Some other Free Software Foundation software is covered by
18
- the GNU Lesser General Public License instead.) You can apply it to
19
- your programs, too.
20
-
21
- When we speak of free software, we are referring to freedom, not
22
- price. Our General Public Licenses are designed to make sure that you
23
- have the freedom to distribute copies of free software (and charge for
24
- this service if you wish), that you receive source code or can get it
25
- if you want it, that you can change the software or use pieces of it
26
- in new free programs; and that you know you can do these things.
27
-
28
- To protect your rights, we need to make restrictions that forbid
29
- anyone to deny you these rights or to ask you to surrender the rights.
30
- These restrictions translate to certain responsibilities for you if you
31
- distribute copies of the software, or if you modify it.
32
-
33
- For example, if you distribute copies of such a program, whether
34
- gratis or for a fee, you must give the recipients all the rights that
35
- you have. You must make sure that they, too, receive or can get the
36
- source code. And you must show them these terms so they know their
37
- rights.
38
-
39
- We protect your rights with two steps: (1) copyright the software, and
40
- (2) offer you this license which gives you legal permission to copy,
41
- distribute and/or modify the software.
42
-
43
- Also, for each author's protection and ours, we want to make certain
44
- that everyone understands that there is no warranty for this free
45
- software. If the software is modified by someone else and passed on, we
46
- want its recipients to know that what they have is not the original, so
47
- that any problems introduced by others will not reflect on the original
48
- authors' reputations.
49
-
50
- Finally, any free program is threatened constantly by software
51
- patents. We wish to avoid the danger that redistributors of a free
52
- program will individually obtain patent licenses, in effect making the
53
- program proprietary. To prevent this, we have made it clear that any
54
- patent must be licensed for everyone's free use or not licensed at all.
55
-
56
- The precise terms and conditions for copying, distribution and
57
- modification follow.
58
-
59
- GNU GENERAL PUBLIC LICENSE
60
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
-
62
- 0. This License applies to any program or other work which contains
63
- a notice placed by the copyright holder saying it may be distributed
64
- under the terms of this General Public License. The "Program", below,
65
- refers to any such program or work, and a "work based on the Program"
66
- means either the Program or any derivative work under copyright law:
67
- that is to say, a work containing the Program or a portion of it,
68
- either verbatim or with modifications and/or translated into another
69
- language. (Hereinafter, translation is included without limitation in
70
- the term "modification".) Each licensee is addressed as "you".
71
-
72
- Activities other than copying, distribution and modification are not
73
- covered by this License; they are outside its scope. The act of
74
- running the Program is not restricted, and the output from the Program
75
- is covered only if its contents constitute a work based on the
76
- Program (independent of having been made by running the Program).
77
- Whether that is true depends on what the Program does.
78
-
79
- 1. You may copy and distribute verbatim copies of the Program's
80
- source code as you receive it, in any medium, provided that you
81
- conspicuously and appropriately publish on each copy an appropriate
82
- copyright notice and disclaimer of warranty; keep intact all the
83
- notices that refer to this License and to the absence of any warranty;
84
- and give any other recipients of the Program a copy of this License
85
- along with the Program.
86
-
87
- You may charge a fee for the physical act of transferring a copy, and
88
- you may at your option offer warranty protection in exchange for a fee.
89
-
90
- 2. You may modify your copy or copies of the Program or any portion
91
- of it, thus forming a work based on the Program, and copy and
92
- distribute such modifications or work under the terms of Section 1
93
- above, provided that you also meet all of these conditions:
94
-
95
- a) You must cause the modified files to carry prominent notices
96
- stating that you changed the files and the date of any change.
97
-
98
- b) You must cause any work that you distribute or publish, that in
99
- whole or in part contains or is derived from the Program or any
100
- part thereof, to be licensed as a whole at no charge to all third
101
- parties under the terms of this License.
102
-
103
- c) If the modified program normally reads commands interactively
104
- when run, you must cause it, when started running for such
105
- interactive use in the most ordinary way, to print or display an
106
- announcement including an appropriate copyright notice and a
107
- notice that there is no warranty (or else, saying that you provide
108
- a warranty) and that users may redistribute the program under
109
- these conditions, and telling the user how to view a copy of this
110
- License. (Exception: if the Program itself is interactive but
111
- does not normally print such an announcement, your work based on
112
- the Program is not required to print an announcement.)
113
-
114
- These requirements apply to the modified work as a whole. If
115
- identifiable sections of that work are not derived from the Program,
116
- and can be reasonably considered independent and separate works in
117
- themselves, then this License, and its terms, do not apply to those
118
- sections when you distribute them as separate works. But when you
119
- distribute the same sections as part of a whole which is a work based
120
- on the Program, the distribution of the whole must be on the terms of
121
- this License, whose permissions for other licensees extend to the
122
- entire whole, and thus to each and every part regardless of who wrote it.
123
-
124
- Thus, it is not the intent of this section to claim rights or contest
125
- your rights to work written entirely by you; rather, the intent is to
126
- exercise the right to control the distribution of derivative or
127
- collective works based on the Program.
128
-
129
- In addition, mere aggregation of another work not based on the Program
130
- with the Program (or with a work based on the Program) on a volume of
131
- a storage or distribution medium does not bring the other work under
132
- the scope of this License.
133
-
134
- 3. You may copy and distribute the Program (or a work based on it,
135
- under Section 2) in object code or executable form under the terms of
136
- Sections 1 and 2 above provided that you also do one of the following:
137
-
138
- a) Accompany it with the complete corresponding machine-readable
139
- source code, which must be distributed under the terms of Sections
140
- 1 and 2 above on a medium customarily used for software interchange; or,
141
-
142
- b) Accompany it with a written offer, valid for at least three
143
- years, to give any third party, for a charge no more than your
144
- cost of physically performing source distribution, a complete
145
- machine-readable copy of the corresponding source code, to be
146
- distributed under the terms of Sections 1 and 2 above on a medium
147
- customarily used for software interchange; or,
148
-
149
- c) Accompany it with the information you received as to the offer
150
- to distribute corresponding source code. (This alternative is
151
- allowed only for noncommercial distribution and only if you
152
- received the program in object code or executable form with such
153
- an offer, in accord with Subsection b above.)
154
-
155
- The source code for a work means the preferred form of the work for
156
- making modifications to it. For an executable work, complete source
157
- code means all the source code for all modules it contains, plus any
158
- associated interface definition files, plus the scripts used to
159
- control compilation and installation of the executable. However, as a
160
- special exception, the source code distributed need not include
161
- anything that is normally distributed (in either source or binary
162
- form) with the major components (compiler, kernel, and so on) of the
163
- operating system on which the executable runs, unless that component
164
- itself accompanies the executable.
165
-
166
- If distribution of executable or object code is made by offering
167
- access to copy from a designated place, then offering equivalent
168
- access to copy the source code from the same place counts as
169
- distribution of the source code, even though third parties are not
170
- compelled to copy the source along with the object code.
171
-
172
- 4. You may not copy, modify, sublicense, or distribute the Program
173
- except as expressly provided under this License. Any attempt
174
- otherwise to copy, modify, sublicense or distribute the Program is
175
- void, and will automatically terminate your rights under this License.
176
- However, parties who have received copies, or rights, from you under
177
- this License will not have their licenses terminated so long as such
178
- parties remain in full compliance.
179
-
180
- 5. You are not required to accept this License, since you have not
181
- signed it. However, nothing else grants you permission to modify or
182
- distribute the Program or its derivative works. These actions are
183
- prohibited by law if you do not accept this License. Therefore, by
184
- modifying or distributing the Program (or any work based on the
185
- Program), you indicate your acceptance of this License to do so, and
186
- all its terms and conditions for copying, distributing or modifying
187
- the Program or works based on it.
188
-
189
- 6. Each time you redistribute the Program (or any work based on the
190
- Program), the recipient automatically receives a license from the
191
- original licensor to copy, distribute or modify the Program subject to
192
- these terms and conditions. You may not impose any further
193
- restrictions on the recipients' exercise of the rights granted herein.
194
- You are not responsible for enforcing compliance by third parties to
195
- this License.
196
-
197
- 7. If, as a consequence of a court judgment or allegation of patent
198
- infringement or for any other reason (not limited to patent issues),
199
- conditions are imposed on you (whether by court order, agreement or
200
- otherwise) that contradict the conditions of this License, they do not
201
- excuse you from the conditions of this License. If you cannot
202
- distribute so as to satisfy simultaneously your obligations under this
203
- License and any other pertinent obligations, then as a consequence you
204
- may not distribute the Program at all. For example, if a patent
205
- license would not permit royalty-free redistribution of the Program by
206
- all those who receive copies directly or indirectly through you, then
207
- the only way you could satisfy both it and this License would be to
208
- refrain entirely from distribution of the Program.
209
-
210
- If any portion of this section is held invalid or unenforceable under
211
- any particular circumstance, the balance of the section is intended to
212
- apply and the section as a whole is intended to apply in other
213
- circumstances.
214
-
215
- It is not the purpose of this section to induce you to infringe any
216
- patents or other property right claims or to contest validity of any
217
- such claims; this section has the sole purpose of protecting the
218
- integrity of the free software distribution system, which is
219
- implemented by public license practices. Many people have made
220
- generous contributions to the wide range of software distributed
221
- through that system in reliance on consistent application of that
222
- system; it is up to the author/donor to decide if he or she is willing
223
- to distribute software through any other system and a licensee cannot
224
- impose that choice.
225
-
226
- This section is intended to make thoroughly clear what is believed to
227
- be a consequence of the rest of this License.
228
-
229
- 8. If the distribution and/or use of the Program is restricted in
230
- certain countries either by patents or by copyrighted interfaces, the
231
- original copyright holder who places the Program under this License
232
- may add an explicit geographical distribution limitation excluding
233
- those countries, so that distribution is permitted only in or among
234
- countries not thus excluded. In such case, this License incorporates
235
- the limitation as if written in the body of this License.
236
-
237
- 9. The Free Software Foundation may publish revised and/or new versions
238
- of the General Public License from time to time. Such new versions will
239
- be similar in spirit to the present version, but may differ in detail to
240
- address new problems or concerns.
241
-
242
- Each version is given a distinguishing version number. If the Program
243
- specifies a version number of this License which applies to it and "any
244
- later version", you have the option of following the terms and conditions
245
- either of that version or of any later version published by the Free
246
- Software Foundation. If the Program does not specify a version number of
247
- this License, you may choose any version ever published by the Free Software
248
- Foundation.
249
-
250
- 10. If you wish to incorporate parts of the Program into other free
251
- programs whose distribution conditions are different, write to the author
252
- to ask for permission. For software which is copyrighted by the Free
253
- Software Foundation, write to the Free Software Foundation; we sometimes
254
- make exceptions for this. Our decision will be guided by the two goals
255
- of preserving the free status of all derivatives of our free software and
256
- of promoting the sharing and reuse of software generally.
257
-
258
- NO WARRANTY
259
-
260
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
- FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
- PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
- TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
- REPAIR OR CORRECTION.
269
-
270
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
- REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
- OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
- TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
- YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
- PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
- POSSIBILITY OF SUCH DAMAGES.
279
-
280
- END OF TERMS AND CONDITIONS
281
-
282
- How to Apply These Terms to Your New Programs
283
-
284
- If you develop a new program, and you want it to be of the greatest
285
- possible use to the public, the best way to achieve this is to make it
286
- free software which everyone can redistribute and change under these terms.
287
-
288
- To do so, attach the following notices to the program. It is safest
289
- to attach them to the start of each source file to most effectively
290
- convey the exclusion of warranty; and each file should have at least
291
- the "copyright" line and a pointer to where the full notice is found.
292
-
293
- {description}
294
- Copyright (C) {year} {fullname}
295
-
296
- This program is free software; you can redistribute it and/or modify
297
- it under the terms of the GNU General Public License as published by
298
- the Free Software Foundation; either version 2 of the License, or
299
- (at your option) any later version.
300
-
301
- This program is distributed in the hope that it will be useful,
302
- but WITHOUT ANY WARRANTY; without even the implied warranty of
303
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
- GNU General Public License for more details.
305
-
306
- You should have received a copy of the GNU General Public License along
307
- with this program; if not, write to the Free Software Foundation, Inc.,
308
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
-
310
- Also add information on how to contact you by electronic and paper mail.
311
-
312
- If the program is interactive, make it output a short notice like this
313
- when it starts in an interactive mode:
314
-
315
- Gnomovision version 69, Copyright (C) year name of author
316
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
- This is free software, and you are welcome to redistribute it
318
- under certain conditions; type `show c' for details.
319
-
320
- The hypothetical commands `show w' and `show c' should show the appropriate
321
- parts of the General Public License. Of course, the commands you use may
322
- be called something other than `show w' and `show c'; they could even be
323
- mouse-clicks or menu items--whatever suits your program.
324
-
325
- You should also get your employer (if you work as a programmer) or your
326
- school, if any, to sign a "copyright disclaimer" for the program, if
327
- necessary. Here is a sample; alter the names:
328
-
329
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
-
332
- {signature of Ty Coon}, 1 April 1989
333
- Ty Coon, President of Vice
334
-
335
- This General Public License does not permit incorporating your program into
336
- proprietary programs. If your program is a subroutine library, you may
337
- consider it more useful to permit linking proprietary applications with the
338
- library. If this is what you want to do, use the GNU Lesser General
339
- Public License instead of this License.
1
+ MIT License
2
+
3
+ Copyright (c) 2014 Roland Moriz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -3,9 +3,8 @@
3
3
  Ultra simple tool to create postfix-compatible IP-blocklists based on AS-Numbers or IP-addresses. This is a very brutal way and should be limited to known spam providers.
4
4
 
5
5
  ## Installation
6
-
7
- Install Ruby 1.9.3+
8
- then:
6
+
7
+ Requires Ruby >= 3.2. Then:
9
8
 
10
9
  $ gem install unspam
11
10
 
@@ -22,40 +21,11 @@ After some research you come to the conclusion, that the ISP behind 171.25.200.2
22
21
 
23
22
  ```shell
24
23
  $ unspam nets 171.25.200.217 REJECT
24
+ 93.90.183.0/24 REJECT
25
25
  171.25.200.0/23 REJECT
26
- 178.20.96.0/21 REJECT
27
- 185.51.232.0/22 REJECT
26
+ 178.250.169.0/24 REJECT
28
27
  185.57.88.0/22 REJECT
29
- 188.64.40.0/22 REJECT
30
- 188.64.44.0/23 REJECT
31
- 188.64.46.0/23 REJECT
32
- 193.104.98.0/24 REJECT
33
- 193.105.250.0/24 REJECT
34
- 193.22.255.0/24 REJECT
35
- 193.25.114.0/23 REJECT
36
- 195.130.215.0/24 REJECT
37
28
  195.225.148.0/22 REJECT
38
- 195.5.120.0/23 REJECT
39
- 195.82.152.0/23 REJECT
40
- 2a00:5300:0:1::/64 REJECT
41
- 2a00:5300:0:2::/64 REJECT
42
- 2a00:5300:0:3::/64 REJECT
43
- 2a00:5300::/32 REJECT
44
- 2a00:fa40::/32 REJECT
45
- 5.44.100.0/22 REJECT
46
- 5.44.108.0/22 REJECT
47
- 5.44.96.0/22 REJECT
48
- 81.88.16.0/21 REJECT
49
- 81.88.24.0/22 REJECT
50
- 81.88.28.0/22 REJECT
51
- 89.22.96.0/19 REJECT
52
- 91.203.128.0/22 REJECT
53
- 91.203.212.0/22 REJECT
54
- 91.206.142.0/23 REJECT
55
- 91.207.94.0/23 REJECT
56
- 91.226.88.0/22 REJECT
57
- 91.227.246.0/23 REJECT
58
- 91.235.208.0/22 REJECT
59
29
  ```
60
30
 
61
31
  All announed prefixes of that spam ISP will be looked up using the [RIPE.net RESTful looking glass](https://stat.ripe.net/docs/data_api). Your optional message will appear right behind the net so you can easily paste/add this to your postfix client_checks file or wrap some shell commands around it.
@@ -65,7 +35,7 @@ You can use an IP-Address or AS-number to lookup the result.
65
35
  e.g.
66
36
 
67
37
  ```shell
68
- $ unspam net AS31342
38
+ $ unspam nets AS3163
69
39
  ```
70
40
 
71
41
  will produce the identical result.
@@ -81,3 +51,8 @@ $ unspam nets $( dig a +short hetzner.de | head -n1 )
81
51
  ```
82
52
 
83
53
  Enjoy!
54
+
55
+ ## License
56
+
57
+ Released under the MIT license, see [LICENSE](LICENSE). Changes per version are
58
+ listed in [CHANGELOG.md](CHANGELOG.md).
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task default: :test
data/lib/unspam/cli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'thor'
2
2
  require 'json'
3
+ require 'unspam/errors'
3
4
  require 'httparty'
4
5
  require 'ipaddr'
5
6
  require 'netaddr'
@@ -11,43 +12,78 @@ module Unspam
11
12
  map 'RIPE' => :nets
12
13
 
13
14
  desc 'nets ASN/IP [MESSAGE]', 'ASN or IP address. MESSAGE is optional'
14
- def nets(asn_or_ip, msg = nil)
15
+ def nets(resource, msg = nil)
15
16
  @msg = msg
16
-
17
- if asn_or_ip =~ /^AS|^[^\.]$/
18
- lookup_by_asn(asn_or_ip)
19
- else
20
- lookup_by_ip(asn_or_ip)
21
- end
17
+ asns = asns_for(resource)
18
+ warn "unspam: no AS found for #{resource}" if asns.empty?
19
+ print_prefixes(merge_prefixes(asns.flat_map { |asn| announced_prefixes(asn) }))
20
+ rescue LookupError => e
21
+ warn "unspam: #{e.message}"
22
+ exit 1
22
23
  end
23
24
 
24
25
  no_commands do
25
- def lookup_by_ip(ip)
26
- response = HTTParty.get "https://stat.ripe.net/data/searchcomplete/data.json?resource=#{ip}"
27
- result = JSON.parse(response.body)
26
+ private
27
+
28
+ def asns_for(resource)
29
+ input = resource.to_s.strip
30
+ if (match = input.match(/\A(?:AS)?(?<digits>\d+)\z/i))
31
+ ["AS#{match[:digits]}"]
32
+ else
33
+ IPAddr.new(input).then { lookup_asns(input) }
34
+ end
35
+ rescue IPAddr::Error
36
+ raise LookupError, "#{resource.inspect} is neither an AS number nor an IP address"
37
+ end
28
38
 
29
- as = []
39
+ def lookup_asns(ip)
40
+ data = ripe_get("https://stat.ripe.net/data/searchcomplete/data.json?resource=#{ip}")
41
+ asns = Array(data['categories']).flat_map { |cat| Array(cat['suggestions']).map { |s| s['value'] } }
42
+ asns.grep(/\AAS\d+\z/i).map(&:upcase).uniq
43
+ end
30
44
 
31
- result['data']['categories'].each do |cat|
32
- as += cat['suggestions'].map { |s| s['value'] }
45
+ def announced_prefixes(asn)
46
+ Array(ripe_get("https://stat.ripe.net/data/announced-prefixes/data.json?resource=#{asn}&min_peers_seeing=2")['prefixes'])
47
+ .map { |entry| entry['prefix'] }
48
+ end
49
+
50
+ def ripe_get(url)
51
+ response = begin
52
+ # One request per matched ASN, so a stalled collector must not hold
53
+ # the whole run hostage.
54
+ HTTParty.get(url, timeout: 20)
55
+ rescue StandardError => e
56
+ raise LookupError, "RIPE request failed for #{url}: #{e.message}"
33
57
  end
58
+ raise LookupError, "RIPE answered #{response.code} for #{url}" unless response.success?
34
59
 
35
- as.select { |v| v =~ /^AS/ }.each do |asn|
36
- lookup_by_asn(asn)
60
+ payload = begin
61
+ JSON.parse(response.body)
62
+ rescue JSON::ParserError
63
+ raise LookupError, "RIPE returned invalid JSON for #{url}"
37
64
  end
38
- end
65
+ raise LookupError, "RIPE returned #{payload.class} for #{url}" unless payload.is_a?(Hash)
66
+ raise LookupError, "RIPE reported #{payload['status'].inspect} for #{url}" unless payload['status'] == 'ok'
39
67
 
40
- def lookup_by_asn(asn)
41
- response = HTTParty.get "https://stat.ripe.net/data/announced-prefixes/data.json?resource=#{asn}&min_peers_seeing=2"
42
- result = JSON.parse(response.body)
68
+ payload['data'] || {}
69
+ end
43
70
 
44
- prefixes = Array.new
45
- result['data']['prefixes'].map { |h| h['prefix'] }.each do |prefix|
46
- prefixes.push(prefix)
71
+ # NetAddr's summerers filter to one address family, so split first and
72
+ # merge each family on its own. summ_* returns numerically sorted output.
73
+ def merge_prefixes(prefixes)
74
+ nets = prefixes.filter_map do |prefix|
75
+ NetAddr.parse_net(prefix.to_s)
76
+ rescue NetAddr::ValidationError
77
+ warn "unspam: ignoring unparseable prefix #{prefix.inspect}"
78
+ nil
47
79
  end
80
+ v4, v6 = nets.partition { |net| net.is_a?(NetAddr::IPv4Net) }
81
+ (NetAddr.summ_IPv4Net(v4) + NetAddr.summ_IPv6Net(v6)).map(&:to_s).uniq
82
+ end
48
83
 
49
- NetAddr.merge(prefixes.map{ |ip| NetAddr::CIDR.create(ip) }, :Short => true).each do |prefix|
50
- printf("%-25s%5s\n", prefix, @msg)
84
+ def print_prefixes(prefixes)
85
+ prefixes.each do |prefix|
86
+ @msg ? printf("%-25s%5s\n", prefix, @msg) : puts(prefix)
51
87
  end
52
88
  end
53
89
  end
@@ -0,0 +1,4 @@
1
+ module Unspam
2
+ # Raised for RIPE responses the CLI cannot act on.
3
+ class LookupError < StandardError; end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Unspam
2
- VERSION = '0.1.0'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/unspam.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'unspam/version'
2
+ require 'unspam/errors'
2
3
  require 'unspam/cli'
3
4
 
4
5
  module Unspam
@@ -0,0 +1,74 @@
1
+ require_relative 'test_helper'
2
+
3
+ class CliErrorsTest < Minitest::Test
4
+ def test_server_error_exits_non_zero
5
+ RipeStub.status(announced_url('AS64500'), 503, '<html>down</html>')
6
+
7
+ out, err, exit = run_cli_expecting_exit('AS64500')
8
+
9
+ assert_empty out
10
+ assert_equal 1, exit.status
11
+ assert_match(/503/, err)
12
+ end
13
+
14
+ def test_ripe_error_status_exits_non_zero
15
+ RipeStub.ok(announced_url('AS64500'), 'status' => 'error', 'data' => {})
16
+
17
+ _out, err, exit = run_cli_expecting_exit('AS64500')
18
+
19
+ assert_equal 1, exit.status
20
+ assert_match(/reported "error"/, err)
21
+ end
22
+
23
+ def test_transport_error_exits_non_zero
24
+ RipeStub.transport_error(announced_url('AS64500'),
25
+ SocketError.new('getaddrinfo: Name or service not known'))
26
+
27
+ out, err, exit = run_cli_expecting_exit('AS64500')
28
+
29
+ assert_empty out
30
+ assert_equal 1, exit.status
31
+ assert_match(/AS64500/, err)
32
+ assert_match(/Name or service not known/, err)
33
+ end
34
+
35
+ def test_non_object_json_exits_non_zero
36
+ RipeStub.ok(announced_url('AS64500'), 'null')
37
+
38
+ _out, err, exit = run_cli_expecting_exit('AS64500')
39
+
40
+ assert_equal 1, exit.status
41
+ assert_match(/NilClass/, err)
42
+ end
43
+
44
+ def test_ok_status_with_a_warning_message_still_prints
45
+ RipeStub.ok(announced_url('AS64500'),
46
+ 'status' => 'ok',
47
+ 'messages' => [{ 'type' => 'warning', 'text' => 'aligned to a less specific prefix' }],
48
+ 'data' => { 'prefixes' => [{ 'prefix' => '10.0.0.0/24' }] })
49
+
50
+ out, err = run_cli('AS64500')
51
+
52
+ assert_equal ['10.0.0.0/24'], out.split("\n")
53
+ assert_empty err
54
+ end
55
+
56
+ def test_invalid_json_exits_non_zero
57
+ RipeStub.ok(announced_url('AS64500'), '<!doctype html>')
58
+
59
+ _out, err, exit = run_cli_expecting_exit('AS64500')
60
+
61
+ assert_equal 1, exit.status
62
+ assert_match(/invalid JSON/i, err)
63
+ end
64
+
65
+ def test_requested_asn_is_echoed_in_the_error
66
+ RipeStub.status(announced_url('AS64500'), 500)
67
+
68
+ _out, err, exit = run_cli_expecting_exit('AS64500')
69
+
70
+ assert_equal 1, exit.status
71
+ assert_match(/AS64500/, err)
72
+ assert_match(/500/, err)
73
+ end
74
+ end
@@ -0,0 +1,117 @@
1
+ require_relative 'test_helper'
2
+
3
+ class CliPrefixesTest < Minitest::Test
4
+ def test_merges_adjacent_ipv4_prefixes
5
+ stub_announced('AS64500', %w[10.0.0.0/25 10.0.0.128/25 9.0.0.0/24])
6
+
7
+ out, _err = run_cli('AS64500')
8
+
9
+ assert_equal %w[9.0.0.0/24 10.0.0.0/24], out.split("\n")
10
+ end
11
+
12
+ def test_prints_ipv4_before_ipv6
13
+ # 9.0.0.0/24 sorts after both IPv6 strings lexicographically, so only a
14
+ # real family partition can yield this order.
15
+ stub_announced('AS64500', %w[2a00:5300::/32 9.0.0.0/24 2001:db8::/48])
16
+
17
+ out, _err = run_cli('AS64500')
18
+
19
+ assert_equal %w[9.0.0.0/24 2001:db8::/48 2a00:5300::/32], out.split("\n")
20
+ end
21
+
22
+ def test_prints_ipv6_in_numeric_not_lexicographic_order
23
+ # "9::/32" sorts after "a::/32" as a string, so only numeric ordering
24
+ # can yield this sequence.
25
+ stub_announced('AS64500', %w[a::/32 9::/32])
26
+
27
+ out, _err = run_cli('AS64500')
28
+
29
+ assert_equal %w[9::/32 a::/32], out.split("\n")
30
+ end
31
+
32
+ def test_summarises_adjacent_ipv6_prefixes
33
+ stub_announced('AS64500', %w[2001:db8:1::/48 2001:db8::/48])
34
+
35
+ out, _err = run_cli('AS64500')
36
+
37
+ assert_equal ['2001:db8::/47'], out.split("\n")
38
+ end
39
+
40
+ def test_message_is_appended_in_five_columns
41
+ stub_announced('AS64500', %w[10.0.0.0/24])
42
+
43
+ out, _err = run_cli('AS64500', 'REJECT')
44
+
45
+ assert_equal "10.0.0.0/24 REJECT\n", out
46
+ end
47
+
48
+ def test_empty_prefix_list_prints_nothing_and_succeeds
49
+ stub_announced('AS31342', [])
50
+
51
+ out, err = run_cli('AS31342')
52
+
53
+ assert_empty out
54
+ assert_empty err
55
+ end
56
+
57
+ def test_ip_without_any_asn_warns_and_succeeds
58
+ stub_search('171.25.200.217', [])
59
+
60
+ out, err = run_cli('171.25.200.217')
61
+
62
+ assert_empty out
63
+ assert_match(/no AS found for 171\.25\.200\.217/, err)
64
+ end
65
+
66
+ def test_skips_unparseable_prefix_with_a_warning
67
+ stub_announced('AS64500', %w[10.0.0.0/24 not-a-prefix])
68
+
69
+ out, err = run_cli('AS64500')
70
+
71
+ assert_equal ['10.0.0.0/24'], out.split("\n")
72
+ assert_match(/not-a-prefix/, err)
73
+ end
74
+
75
+ def test_skips_null_prefix_with_a_warning
76
+ stub_announced('AS64500', [nil, '10.0.0.0/24'])
77
+
78
+ out, err = run_cli('AS64500')
79
+
80
+ assert_equal ['10.0.0.0/24'], out.split("\n")
81
+ assert_match(/nil/, err)
82
+ end
83
+
84
+ def test_ip_is_resolved_through_searchcomplete
85
+ stub_search('171.25.200.217', %w[AS64500 AS64501])
86
+ stub_announced('AS64500', %w[10.0.0.0/24])
87
+ stub_announced('AS64501', %w[10.0.0.0/24 192.0.2.0/24])
88
+
89
+ out, _err = run_cli('171.25.200.217')
90
+
91
+ assert_equal %w[10.0.0.0/24 192.0.2.0/24], out.split("\n")
92
+ end
93
+
94
+ def test_bare_number_is_treated_as_an_asn
95
+ stub_announced('AS64500', %w[10.0.0.0/24])
96
+
97
+ out, _err = run_cli('64500')
98
+
99
+ assert_equal ['10.0.0.0/24'], out.split("\n")
100
+ end
101
+
102
+ def test_lowercase_asn_prefix_is_accepted
103
+ stub_announced('AS64500', %w[10.0.0.0/24])
104
+
105
+ out, _err = run_cli('as64500')
106
+
107
+ assert_equal ['10.0.0.0/24'], out.split("\n")
108
+ end
109
+
110
+ def test_junk_input_exits_non_zero
111
+ out, err, exit = run_cli_expecting_exit('foo')
112
+
113
+ assert_empty out
114
+ assert_equal 1, exit.status
115
+ assert_match(/foo/, err)
116
+ end
117
+ end
@@ -0,0 +1,73 @@
1
+ require 'minitest/autorun'
2
+ require 'json'
3
+ require 'unspam'
4
+
5
+ module RipeStub
6
+ Response = Struct.new(:body, :code) do
7
+ def success? = code == 200
8
+ end
9
+
10
+ def self.responses = (@responses ||= {})
11
+ def self.reset = @responses = {}
12
+
13
+ def self.ok(url, body)
14
+ responses[url] = Response.new(body.is_a?(String) ? body : JSON.generate(body), 200)
15
+ end
16
+
17
+ def self.status(url, code, body = '')
18
+ responses[url] = Response.new(body, code)
19
+ end
20
+
21
+ def self.transport_error(url, exception)
22
+ responses[url] = exception
23
+ end
24
+
25
+ def self.fetch(url)
26
+ result = responses.fetch(url) { raise "unstubbed RIPE URL: #{url}" }
27
+ raise result if result.is_a?(Exception)
28
+
29
+ result
30
+ end
31
+ end
32
+
33
+ module HTTPartyStub
34
+ def get(url, *_args, **_kwargs) = RipeStub.fetch(url)
35
+ end
36
+
37
+ HTTParty.singleton_class.prepend(HTTPartyStub)
38
+
39
+ class Minitest::Test
40
+ # before_setup, not setup: subclasses that define their own setup without
41
+ # calling super would otherwise silently lose the stub reset.
42
+ def before_setup
43
+ RipeStub.reset
44
+ super
45
+ end
46
+
47
+ def announced_url(asn) = "https://stat.ripe.net/data/announced-prefixes/data.json?resource=#{asn}&min_peers_seeing=2"
48
+ def search_url(ip) = "https://stat.ripe.net/data/searchcomplete/data.json?resource=#{ip}"
49
+
50
+ def stub_announced(asn, prefixes)
51
+ RipeStub.ok(announced_url(asn),
52
+ 'status' => 'ok',
53
+ 'data' => { 'prefixes' => prefixes.map { |p| { 'prefix' => p } } })
54
+ end
55
+
56
+ def stub_search(ip, asns)
57
+ RipeStub.ok(search_url(ip),
58
+ 'status' => 'ok',
59
+ 'data' => { 'categories' => [{ 'suggestions' => asns.map { |a| { 'value' => a } } },
60
+ { 'suggestions' => [{ 'value' => '15169' }] }] })
61
+ end
62
+
63
+ def run_cli(*args)
64
+ capture_io { Unspam::CLI.new.nets(*args) }
65
+ end
66
+
67
+ def run_cli_expecting_exit(*args)
68
+ out, err = capture_io do
69
+ @exit = assert_raises(SystemExit) { Unspam::CLI.new.nets(*args) }
70
+ end
71
+ [out, err, @exit]
72
+ end
73
+ end
data/unspam.gemspec CHANGED
@@ -1,27 +1,37 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path('lib', __dir__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'unspam/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = 'unspam'
8
- spec.version = Unspam::VERSION
9
- spec.authors = ['Roland Moriz']
10
- spec.email = ['roland@moriz.de']
11
- spec.summary = %q(returns IP prefixes by ASN.)
12
- spec.description = %q(returns IP prefixes by ASN.)
13
- spec.homepage = ''
14
- spec.license = 'MIT'
7
+ spec.name = 'unspam'
8
+ spec.version = Unspam::VERSION
9
+ spec.authors = ['Roland Moriz']
10
+ spec.email = ['roland@moriz.de']
11
+ spec.summary = 'turn an AS number or IP into a Postfix blocklist'
12
+ spec.description = 'returns IP prefixes by ASN.'
13
+ spec.homepage = 'https://github.com/rmoriz/unspam'
14
+ spec.licenses = ['MIT']
15
+ spec.required_ruby_version = '>= 3.2'
16
+
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
19
+ spec.metadata['rubygems_mfa_required'] = 'true'
15
20
 
16
21
  spec.files = `git ls-files -z`.split("\x0")
17
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
23
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
24
  spec.require_paths = ['lib']
20
25
 
21
- spec.add_dependency 'thor'
22
- spec.add_dependency 'httparty'
23
- spec.add_dependency 'netaddr'
26
+ spec.add_dependency 'thor', '~> 1.5'
27
+ spec.add_dependency 'httparty', '~> 0.25'
28
+ spec.add_dependency 'netaddr', '~> 2.0'
29
+ # Ruby 4 no longer ships these as default gems, but httparty's dependency
30
+ # chain needs them, so declare them or `gem install unspam` breaks on 4.0.
31
+ spec.add_dependency 'csv'
32
+ spec.add_dependency 'bigdecimal'
24
33
 
25
- spec.add_development_dependency 'bundler', '~> 1.6'
34
+ spec.add_development_dependency 'bundler', '>= 2.4'
26
35
  spec.add_development_dependency 'rake'
36
+ spec.add_development_dependency 'minitest'
27
37
  end
metadata CHANGED
@@ -1,31 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unspam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Moriz
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: thor
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: '1.5'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">="
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
25
+ version: '1.5'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: httparty
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.25'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.25'
40
+ - !ruby/object:Gem::Dependency
41
+ name: netaddr
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: csv
29
56
  requirement: !ruby/object:Gem::Requirement
30
57
  requirements:
31
58
  - - ">="
@@ -39,7 +66,7 @@ dependencies:
39
66
  - !ruby/object:Gem::Version
40
67
  version: '0'
41
68
  - !ruby/object:Gem::Dependency
42
- name: netaddr
69
+ name: bigdecimal
43
70
  requirement: !ruby/object:Gem::Requirement
44
71
  requirements:
45
72
  - - ">="
@@ -56,16 +83,16 @@ dependencies:
56
83
  name: bundler
57
84
  requirement: !ruby/object:Gem::Requirement
58
85
  requirements:
59
- - - "~>"
86
+ - - ">="
60
87
  - !ruby/object:Gem::Version
61
- version: '1.6'
88
+ version: '2.4'
62
89
  type: :development
63
90
  prerelease: false
64
91
  version_requirements: !ruby/object:Gem::Requirement
65
92
  requirements:
66
- - - "~>"
93
+ - - ">="
67
94
  - !ruby/object:Gem::Version
68
- version: '1.6'
95
+ version: '2.4'
69
96
  - !ruby/object:Gem::Dependency
70
97
  name: rake
71
98
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +107,20 @@ dependencies:
80
107
  - - ">="
81
108
  - !ruby/object:Gem::Version
82
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: minitest
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
83
124
  description: returns IP prefixes by ASN.
84
125
  email:
85
126
  - roland@moriz.de
@@ -88,22 +129,31 @@ executables:
88
129
  extensions: []
89
130
  extra_rdoc_files: []
90
131
  files:
132
+ - ".github/workflows/ci.yml"
91
133
  - ".gitignore"
134
+ - AGENTS.md
135
+ - CHANGELOG.md
92
136
  - Gemfile
137
+ - Gemfile.lock
93
138
  - LICENSE
94
- - LICENSE.txt
95
139
  - README.md
96
140
  - Rakefile
97
141
  - bin/unspam
98
142
  - lib/unspam.rb
99
143
  - lib/unspam/cli.rb
144
+ - lib/unspam/errors.rb
100
145
  - lib/unspam/version.rb
146
+ - test/cli_errors_test.rb
147
+ - test/cli_prefixes_test.rb
148
+ - test/test_helper.rb
101
149
  - unspam.gemspec
102
- homepage: ''
150
+ homepage: https://github.com/rmoriz/unspam
103
151
  licenses:
104
152
  - MIT
105
- metadata: {}
106
- post_install_message:
153
+ metadata:
154
+ source_code_uri: https://github.com/rmoriz/unspam
155
+ changelog_uri: https://github.com/rmoriz/unspam/blob/main/CHANGELOG.md
156
+ rubygems_mfa_required: 'true'
107
157
  rdoc_options: []
108
158
  require_paths:
109
159
  - lib
@@ -111,16 +161,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
161
  requirements:
112
162
  - - ">="
113
163
  - !ruby/object:Gem::Version
114
- version: '0'
164
+ version: '3.2'
115
165
  required_rubygems_version: !ruby/object:Gem::Requirement
116
166
  requirements:
117
167
  - - ">="
118
168
  - !ruby/object:Gem::Version
119
169
  version: '0'
120
170
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.4.5
123
- signing_key:
171
+ rubygems_version: 4.0.20
124
172
  specification_version: 4
125
- summary: returns IP prefixes by ASN.
126
- test_files: []
173
+ summary: turn an AS number or IP into a Postfix blocklist
174
+ test_files:
175
+ - test/cli_errors_test.rb
176
+ - test/cli_prefixes_test.rb
177
+ - test/test_helper.rb
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Roland Moriz
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.