rack-dedos 0.2.2 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5358dccb09197e0042d35f689f02a913a8c566e975b2bac47c7dbdfbd4c01c56
4
- data.tar.gz: 63c029725b96d240ac4700c02585772b8a8a843c2e8fcca574ada29ae344a740
3
+ metadata.gz: c0f4f96c99d1126d17cd0ede822cce3e90e0d56cceb51cb4d8396e3f72242d03
4
+ data.tar.gz: 1fba85f7f58c450dcd7fc82b0a26098790d21befae28f411ae96c26f62d23811
5
5
  SHA512:
6
- metadata.gz: bc44d5579d132a3960f280f26f8c4f0b1eca01d7001d15d5dbfbe907fbc08f2a0d0ad775e610c018ff1f8f7cef6e47611bcf0ad0c4618cf5eed100d59cc97188
7
- data.tar.gz: 329b51f582b0c664b1754f8f8169b8623c0675695171560aadacd3ce6963863644ced781a144c8d55d35d8de5cd75801f85a1d7640ff4bba43e6f14ab0196679
6
+ metadata.gz: 86320d0b5bb8c3328f50101ff9b460a3efaf10f31b5ff54c7f350a436d5e594e4c6fabbcf11a943f766a136f7999a9610fb20912ffc4ad9843537c9871a49a4c
7
+ data.tar.gz: 9f5d286d924b2ab3cfb22402a9894cdfc0b96a0ca2fc31e451a572d43257237dbbe4226cc3c438a2bc5cf3f226fbe681ee8fc9fc9b6d16796b8b28507816d428
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  Nothing so far
4
4
 
5
+ ## 0.3.2
6
+
7
+ #### Changes
8
+ * Resolve all paths to prevent problems with relative paths
9
+
10
+ ## 0.3.1
11
+
12
+ #### Changes
13
+ * Root `File` operations to prevent clashes with Rack
14
+
15
+ ## 0.3.0
16
+
17
+ #### Changes
18
+ * Convert `geoipget` from Bash to Ruby
19
+
20
+ ## 0.2.4
21
+
22
+ #### Changes
23
+ * Use Bash for `geoipget` to prevent problems with `/bin/sh` diversity
24
+
25
+ ## 0.2.3
26
+
27
+ #### Additions
28
+ * `geoipget` shell script
29
+
5
30
  ## 0.2.2
6
31
 
7
32
  #### Changes
data/README.md CHANGED
@@ -125,18 +125,13 @@ Either allow or deny requests by probable country of origin. If both are set, th
125
125
 
126
126
  The MaxMind GeoLite2 database is free, however, you have to create an account on [maxmind.com](https://www.maxmind.com) and then download the country database.
127
127
 
128
- For automatic updates, create a `geoipupdate.conf` file and then use the [geoipupdate tool](https://github.com/maxmind/geoipupdate/releases) to fetch the latest country database:
128
+ For automatic updates, create a `geoipupdate.conf` file and then use the [geoipupdate tool for your arch](https://github.com/maxmind/geoipupdate/releases) to fetch the latest country database.
129
129
 
130
- ```
131
- version=4.10.0
132
- arch=linux_amd64
133
- conf=/etc/geoipupdate.conf
134
- dir=/var/db/maxmind/
130
+ The bundled `geoipget` executable does all this in one swipe:
135
131
 
136
- mkdir -p "${dir}"
137
- wget --quiet -O /tmp/geoipupdate.tgz https://github.com/maxmind/geoipupdate/releases/download/v${version}/geoipupdate_${version}_${arch}.tar.gz
138
- tar -xz -C /tmp -f /tmp/geoipupdate.tgz
139
- /tmp/geoipupdate_${version}_${arch}/geoipupdate -f "${conf}" -d "${dir}"
132
+ ```
133
+ geoipget --help
134
+ geoipget --dir . --arch linux_amd64 /etc/geoipupdate.conf
140
135
  ```
141
136
 
142
137
  ## Real Client IP
data/exe/geoipget ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rack/dedos'
4
+
5
+ Rack::Dedos::Executables::Geoipget.new.run
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+ require 'tmpdir'
5
+ require 'open-uri'
6
+ require 'json'
7
+ require 'rubygems/package'
8
+
9
+ module Rack
10
+ module Dedos
11
+ module Executables
12
+ class Geoipget
13
+ attr_reader :config, :dir, :arch
14
+
15
+ def initialize(**options)
16
+ @arch, @dir = 'linux_amd64', '.'
17
+ OptionParser.new do |o|
18
+ o.banner = <<~END
19
+ Download the geoip database from Maxmind.
20
+ Usage: #{::File.basename($0)} CONFIG_FILE
21
+ END
22
+ o.on('-a', '--arch ARCH', String, "architecture (default: #{arch})") { @arch = _1 }
23
+ o.on('-d', '--dir DIR', String, "destination directory (default: #{dir})") { @dir = _1 }
24
+ o.on('-A', '--about', 'show author/license information and exit') { self.class.about }
25
+ o.on('-V', '--version', 'show version and exit') { self.class.version }
26
+ end.parse!
27
+ @config = ARGV.first
28
+ end
29
+
30
+ def run
31
+ fail "cannot read config file #{config}" unless config && ::File.readable?(config)
32
+ Maxmind.new(::File.realpath(config), ::File.realpath(dir), arch).get
33
+ end
34
+
35
+ def self.about
36
+ puts 'Written by Sven Schwyn (bitcetera.com) and distributed under MIT license.'
37
+ exit
38
+ end
39
+
40
+ def self.version
41
+ puts Rack::Dedos::VERSION
42
+ exit
43
+ end
44
+
45
+ class Maxmind
46
+ REPO = "maxmind/geoipupdate"
47
+
48
+ attr_reader :config, :dir, :arch
49
+
50
+ def initialize(config, dir, arch)
51
+ @config, @dir, @arch = config, dir, arch
52
+ end
53
+
54
+ def get
55
+ prepare(latest_version) { download }
56
+ end
57
+
58
+ private
59
+
60
+ def latest_version
61
+ URI("https://api.github.com/repos/#{REPO}/releases/latest")
62
+ .read
63
+ .then { JSON.parse(_1) }
64
+ .fetch('tag_name')
65
+ .slice(1..)
66
+ end
67
+
68
+ def prepare(version)
69
+ uri = URI("https://github.com/#{REPO}/releases/download/v#{version}/geoipupdate_#{version}_#{arch}.tar.gz")
70
+ Dir.mktmpdir do |tmp|
71
+ Dir.chdir tmp
72
+ uri.open do |file|
73
+ Zlib::GzipReader.wrap(file) do |gz|
74
+ Gem::Package::TarReader.new(gz) do |tar|
75
+ tar.each do |entry|
76
+ if entry.full_name.match? %r(/geoipupdate$)
77
+ ::File.write('geoipupdate', entry.read)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ ::File.chmod(0755, 'geoipupdate')
84
+ yield
85
+ end
86
+ ensure
87
+ lockfile = "#{dir}/.geoipupdate.lock"
88
+ ::File.unlink(lockfile) if ::File.exist? lockfile
89
+ end
90
+
91
+ def download
92
+ `./geoipupdate -f "#{config}" -d "#{dir}"`
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  module Dedos
5
- VERSION = "0.2.2"
5
+ VERSION = "0.3.2"
6
6
  end
7
7
  end
data/lib/rack/dedos.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rack'
4
4
 
5
5
  require_relative 'dedos/version'
6
+ require_relative 'dedos/executables/geoipget'
6
7
 
7
8
  module Rack
8
9
  module Dedos
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-dedos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Schwyn
8
- bindir: bin
8
+ bindir: exe
9
9
  cert_chain:
10
10
  - |
11
11
  -----BEGIN CERTIFICATE-----
@@ -28,7 +28,7 @@ cert_chain:
28
28
  jTyRsT1gymASS2KHe+BaCTwD74GqO8q4woYLZgXnJ/PvgcFgY2FEi2Kn/sXLp4JE
29
29
  boIgxQCMT+nxBHCD
30
30
  -----END CERTIFICATE-----
31
- date: 2024-12-25 00:00:00.000000000 Z
31
+ date: 2025-01-16 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rack
@@ -195,7 +195,8 @@ description: |
195
195
  resort only to be enabled during an attack.
196
196
  email:
197
197
  - ruby@bitcetera.com
198
- executables: []
198
+ executables:
199
+ - geoipget
199
200
  extensions: []
200
201
  extra_rdoc_files:
201
202
  - README.md
@@ -205,8 +206,10 @@ files:
205
206
  - CHANGELOG.md
206
207
  - LICENSE.txt
207
208
  - README.md
209
+ - exe/geoipget
208
210
  - lib/rack/dedos.rb
209
211
  - lib/rack/dedos/cache.rb
212
+ - lib/rack/dedos/executables/geoipget.rb
210
213
  - lib/rack/dedos/filters/base.rb
211
214
  - lib/rack/dedos/filters/country.rb
212
215
  - lib/rack/dedos/filters/user_agent.rb
metadata.gz.sig CHANGED
Binary file