rack-cloudflare 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/README.md +2 -2
- data/lib/rack/cloudflare/ips.rb +1 -0
- data/lib/rack/cloudflare/middleware/access_control.rb +28 -6
- data/lib/rack/cloudflare/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d583c505204a0ac54be1748df8eb4b4e2fa1889366a8065dcc00f70d16d7075
|
4
|
+
data.tar.gz: '079af617a6d6c75e93992c7d43cc537f025b887f3620c686986473cf069c0131'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b290cd1c7eb02e12d7accd551bf910088f33272c5bf1f7d89dfe382a951a1fc196eed3944769439dd3fe2dff119ac6f6f967185b7d5520e8c7cab06e37c1cc21
|
7
|
+
data.tar.gz: 6f2a38f93c166ceaabe0dd1089f7ce61ba00e00adb0ec816e4119d980cd21c88204aa4beed10b689b5553e5499c83d13e25ef1b8bfe309434546ebcd5f55f13c
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -34,10 +34,10 @@ use Rack::Cloudflare::Middleware::AccessControl
|
|
34
34
|
config.middleware.unshift Rack::Cloudflare::Middleware::AccessControl
|
35
35
|
|
36
36
|
# Configure custom blocked message (defaults to "Forbidden")
|
37
|
-
Rack::Cloudflare::Middleware::AccessControl.
|
37
|
+
Rack::Cloudflare::Middleware::AccessControl.message = "You don't belong here..."
|
38
38
|
|
39
39
|
# Fully customize the Rack response (such as making it a redirect)
|
40
|
-
Rack::Cloudflare::Middleware::AccessControl.
|
40
|
+
Rack::Cloudflare::Middleware::AccessControl.response = lambda do |_env|
|
41
41
|
[301, { 'Location' => 'https://somewhere.else.xyz' }, ["Redirecting...\n"]]
|
42
42
|
end
|
43
43
|
```
|
data/lib/rack/cloudflare/ips.rb
CHANGED
@@ -4,15 +4,37 @@ module Rack
|
|
4
4
|
class Cloudflare
|
5
5
|
module Middleware
|
6
6
|
class AccessControl
|
7
|
+
PRESETS = {
|
8
|
+
forbidden: {
|
9
|
+
message: 'Forbidden',
|
10
|
+
response: lambda do |_env|
|
11
|
+
[403, { 'Content-Type' => 'text/plain' }, ["#{AccessControl.message.strip}\n"]]
|
12
|
+
end
|
13
|
+
},
|
14
|
+
not_found: {
|
15
|
+
message: 'Not Found',
|
16
|
+
response: lambda do |_env|
|
17
|
+
[404, { 'Content-Type' => 'text/plain' }, ["#{AccessControl.message.strip}\n"]]
|
18
|
+
end
|
19
|
+
}
|
20
|
+
}.freeze
|
21
|
+
|
7
22
|
class << self
|
8
|
-
attr_accessor :
|
9
|
-
|
23
|
+
attr_accessor :response, :message
|
24
|
+
|
25
|
+
def as(preset, message: nil)
|
26
|
+
self.message,
|
27
|
+
self.response = PRESETS.fetch(preset).values_at :message, :response
|
10
28
|
|
11
|
-
|
12
|
-
|
13
|
-
|
29
|
+
self.message = message unless message.nil?
|
30
|
+
|
31
|
+
self
|
32
|
+
end
|
14
33
|
end
|
15
34
|
|
35
|
+
# Default setup
|
36
|
+
as :forbidden
|
37
|
+
|
16
38
|
def initialize(app)
|
17
39
|
@app = app
|
18
40
|
end
|
@@ -25,7 +47,7 @@ module Rack
|
|
25
47
|
@app.call(env)
|
26
48
|
else
|
27
49
|
Cloudflare.warn "[#{self.class.name}] Untrusted Network (REMOTE_ADDR): #{headers.target_headers}"
|
28
|
-
AccessControl.
|
50
|
+
AccessControl.response.call(env)
|
29
51
|
end
|
30
52
|
end
|
31
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cloudflare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Van Horn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|