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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab4c47613f24dc1d1cfb47b75324a3ed31c46eb8d509069304f803b56ff2bcb1
4
- data.tar.gz: 2470bf3a84bd1436bc30d8bf796f2f7d8ae8c9f79072981273ff798b559d844d
3
+ metadata.gz: 9d583c505204a0ac54be1748df8eb4b4e2fa1889366a8065dcc00f70d16d7075
4
+ data.tar.gz: '079af617a6d6c75e93992c7d43cc537f025b887f3620c686986473cf069c0131'
5
5
  SHA512:
6
- metadata.gz: a7bc139b0d11dc4050bb21720c8fd1bab5a3bca26939175da26b8ff54742bbf325d9a9561df60ca2aa079f29e7d52c9f55b924ebf155c5d4c56eac22fb3ce428
7
- data.tar.gz: 21ac336b1586f7c770b8f63016093445beb4d19b2869526b563d1948c53dde128129fbe314e10daac02322ac75c3c1b09c23b85d2440d70349af8db9c56b9496
6
+ metadata.gz: b290cd1c7eb02e12d7accd551bf910088f33272c5bf1f7d89dfe382a951a1fc196eed3944769439dd3fe2dff119ac6f6f967185b7d5520e8c7cab06e37c1cc21
7
+ data.tar.gz: 6f2a38f93c166ceaabe0dd1089f7ce61ba00e00adb0ec816e4119d980cd21c88204aa4beed10b689b5553e5499c83d13e25ef1b8bfe309434546ebcd5f55f13c
data/.rubocop.yml CHANGED
@@ -40,4 +40,8 @@ Style/Documentation:
40
40
 
41
41
  Metrics/ModuleLength:
42
42
  Exclude:
43
- - 'lib/rack/cloudflare/countries.rb'
43
+ - 'lib/rack/cloudflare/countries.rb'
44
+
45
+ Naming/FileName:
46
+ Exclude:
47
+ - 'rack-cloudflare.gemspec'
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.blocked_message = "You don't belong here..."
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.blocked_response = lambda do |_env|
40
+ Rack::Cloudflare::Middleware::AccessControl.response = lambda do |_env|
41
41
  [301, { 'Location' => 'https://somewhere.else.xyz' }, ["Redirecting...\n"]]
42
42
  end
43
43
  ```
@@ -37,6 +37,7 @@ module Rack
37
37
 
38
38
  def parse(string)
39
39
  return [] if string.to_s.strip.empty?
40
+
40
41
  string.strip.split(/[,\s]+/).map { |ip| ::IPAddr.new(ip.strip) }
41
42
  end
42
43
  end
@@ -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 :blocked_response, :blocked_message
9
- end
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
- self.blocked_message = 'Forbidden'
12
- self.blocked_response = lambda do |_env|
13
- [403, { 'Content-Type' => 'text/plain' }, ["#{blocked_message.strip}\n"]]
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.blocked_response.call(env)
50
+ AccessControl.response.call(env)
29
51
  end
30
52
  end
31
53
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class Cloudflare
5
- VERSION = '1.0.3'
5
+ VERSION = '1.0.4'
6
6
  end
7
7
  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.3
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-15 00:00:00.000000000 Z
11
+ date: 2018-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler