rack_restrictor 1.0.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.
- data/.document +5 -0
- data/.redcar/tags +9 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +56 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/exemples/exemple.ru +11 -0
- data/lib/rack_restrictor.rb +40 -0
- data/test/helper.rb +18 -0
- data/test/test_rack_restrictor.rb +7 -0
- metadata +139 -0
data/.document
ADDED
data/.redcar/tags
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
1292937098
|
2
|
+
PAGE_CODE /home/hassane/ruby_apps/rack_restrictor/lib/rack_restrictor.rb PAGE_CODE =
|
3
|
+
Rack /home/hassane/ruby_apps/rack_restrictor/lib/rack_restrictor.rb module Rack
|
4
|
+
Restrictor /home/hassane/ruby_apps/rack_restrictor/lib/rack_restrictor.rb class Restrictor
|
5
|
+
TestCase /home/hassane/ruby_apps/rack_restrictor/test/helper.rb class Test::Unit::TestCase
|
6
|
+
TestRackRestrictor /home/hassane/ruby_apps/rack_restrictor/test/test_rack_restrictor.rb class TestRackRestrictor
|
7
|
+
authorized? /home/hassane/ruby_apps/rack_restrictor/lib/rack_restrictor.rb def authorized?( ip )
|
8
|
+
call /home/hassane/ruby_apps/rack_restrictor/lib/rack_restrictor.rb def call(env)
|
9
|
+
initialize /home/hassane/ruby_apps/rack_restrictor/lib/rack_restrictor.rb def initialize(app, plage)
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.5.2)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.8.7)
|
10
|
+
rcov (0.9.9)
|
11
|
+
shoulda (2.11.3)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 1.0.0)
|
18
|
+
jeweler (~> 1.5.2)
|
19
|
+
rcov
|
20
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Hassane Moustapha
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= Rack::Restriction
|
2
|
+
En gros :
|
3
|
+
|
4
|
+
Rack::Restriction est un middleware qui vous permet de restreindre l'accés à votre application à une plage d'adresss IP.
|
5
|
+
|
6
|
+
== Pourquoi Rack::Restrictor ?
|
7
|
+
|
8
|
+
On a une application intranet, et qui ne doit être accéssible qu'à certains postes. Comment faire ?
|
9
|
+
Ben .... Rack::Restrictor est là pour ça.
|
10
|
+
|
11
|
+
|
12
|
+
== Comment Rack::Restrictor le fait-il ?
|
13
|
+
|
14
|
+
La réponse ....
|
15
|
+
<pre>
|
16
|
+
<code>
|
17
|
+
|
18
|
+
# exemple.ru
|
19
|
+
|
20
|
+
require 'rubygems'
|
21
|
+
require 'rack_restrictor'
|
22
|
+
|
23
|
+
class MonApp
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
[200, {"Content-Type" => "text/plain"}, "Hello wolrd"]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
use Rack::Restrictor, "192.168.1.1/24"
|
32
|
+
|
33
|
+
run MonApp.new
|
34
|
+
|
35
|
+
</code>
|
36
|
+
# Et lancez le programme avec l'outil "rackup"
|
37
|
+
|
38
|
+
# rackup exemple.ru -p 3000
|
39
|
+
|
40
|
+
# Allez sur http://localhost:3000
|
41
|
+
</pre>
|
42
|
+
|
43
|
+
MonApp ne sera accessible qu'aux postes se trouvant sur cette plage d'adresses.
|
44
|
+
|
45
|
+
== Moi
|
46
|
+
|
47
|
+
Twitter: @hassanemoustaph
|
48
|
+
|
49
|
+
== Contributing to rack_restrictor
|
50
|
+
Vous voulez contribuer ?
|
51
|
+
|
52
|
+
== Copyright
|
53
|
+
|
54
|
+
Copyright (c) 2010 Hassane Moustapha. See LICENSE.txt for
|
55
|
+
further details.
|
56
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "rack_restrictor"
|
16
|
+
gem.homepage = "http://github.com/hkairi/rack_restrictor"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Rack::Restrictor}
|
19
|
+
gem.description = %Q{Matriser l'acces a vos applications}
|
20
|
+
gem.email = "hassanemoustapha@gmail.com"
|
21
|
+
gem.authors = ["Hassane Moustapha"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "rack_restrictor #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/exemples/exemple.ru
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
module Rack
|
3
|
+
class Restrictor
|
4
|
+
PAGE_CODE = <<-EOCODE
|
5
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
6
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
7
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
8
|
+
<head>
|
9
|
+
<title> Anauthorized access</title>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1> Anauthorized access</h1>
|
13
|
+
</body>
|
14
|
+
</html>
|
15
|
+
EOCODE
|
16
|
+
|
17
|
+
def initialize(app, plage)
|
18
|
+
@app = app
|
19
|
+
@plage = IPAddr.new( plage.to_s )
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
if authorized?( env['REMOTE_ADDR'].to_s )
|
24
|
+
status, headers, body = @app.call(env)
|
25
|
+
else
|
26
|
+
status, headers, body =
|
27
|
+
401, {"Content-Type" => "text/html"}, PAGE_CODE
|
28
|
+
end
|
29
|
+
|
30
|
+
[status, headers, body]
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def authorized?( ip )
|
36
|
+
@plage.include?(IPAddr.new( ip ))
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'rack_restrictor'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_restrictor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Hassane Moustapha
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-21 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 23
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
version: 1.0.0
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: jeweler
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 7
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 5
|
63
|
+
- 2
|
64
|
+
version: 1.5.2
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rcov
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
description: Matriser l'acces a vos applications
|
82
|
+
email: hassanemoustapha@gmail.com
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- .redcar/tags
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- VERSION
|
99
|
+
- exemples/exemple.ru
|
100
|
+
- lib/rack_restrictor.rb
|
101
|
+
- test/helper.rb
|
102
|
+
- test/test_rack_restrictor.rb
|
103
|
+
has_rdoc: true
|
104
|
+
homepage: http://github.com/hkairi/rack_restrictor
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
requirements: []
|
131
|
+
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.3.7
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Rack::Restrictor
|
137
|
+
test_files:
|
138
|
+
- test/helper.rb
|
139
|
+
- test/test_rack_restrictor.rb
|