maiha-hosts_access 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +25 -0
- data/Rakefile +22 -0
- data/init.rb +4 -0
- data/install.rb +1 -0
- data/lib/hosts_access.rb +44 -0
- data/tasks/hosts_access_tasks.rake +4 -0
- data/test/hosts_access_test.rb +8 -0
- data/uninstall.rb +1 -0
- metadata +61 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
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
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
HostsAccess
|
2
|
+
===========
|
3
|
+
|
4
|
+
Rails plugin that controls host access like hosts.allow
|
5
|
+
|
6
|
+
|
7
|
+
Usage
|
8
|
+
=====
|
9
|
+
config/environment.rb:
|
10
|
+
|
11
|
+
# specify hosts to allow access
|
12
|
+
HostsAccess.allow = ['127.0.0.1', 'ac.wota.jp']
|
13
|
+
|
14
|
+
# allow_controller means non-acl controllers
|
15
|
+
HostsAccess.allow_controller = ['account', 'stats_report']
|
16
|
+
|
17
|
+
Note
|
18
|
+
====
|
19
|
+
|
20
|
+
All accesses are allowed if no rules are given
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
Copyright (c) 2008 maiha@wota.jp, released under the MIT license
|
25
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the hosts_access plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the hosts_access plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'HostsAccess'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/hosts_access.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
|
3
|
+
module HostsAccess
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
include InstanceMethods
|
7
|
+
before_filter :hosts_access
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
mattr_accessor :allow
|
12
|
+
mattr_accessor :allow_controller
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
private
|
16
|
+
def hosts_access
|
17
|
+
if allow.blank?
|
18
|
+
logger.info "[HostsAccess] OK: not restricted (no rules)"
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
|
22
|
+
if allow_controller
|
23
|
+
Array(allow_controller).each do |name|
|
24
|
+
if name == controller_name
|
25
|
+
logger.info "[HostsAccess] OK: #{controller_name} controller is not restricted"
|
26
|
+
return true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Array(allow).each do |host|
|
32
|
+
address = host
|
33
|
+
address = Resolv.getaddress(host) rescue host unless /\A[\d\.]+\Z/ === host
|
34
|
+
if request.remote_ip == address
|
35
|
+
logger.info "[HostsAccess] OK: #{host} is allowed"
|
36
|
+
return true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
logger.info "[HostsAccess] NG: #{request.remote_ip} is denied"
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maiha-hosts_access
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- maiha
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-25 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: ""
|
17
|
+
email: maiha@wota.jp
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README
|
27
|
+
- Rakefile
|
28
|
+
- init.rb
|
29
|
+
- install.rb
|
30
|
+
- lib/hosts_access.rb
|
31
|
+
- tasks/hosts_access_tasks.rake
|
32
|
+
- test/hosts_access_test.rb
|
33
|
+
- uninstall.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/maiha/hosts_access
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.2.0
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: ""
|
60
|
+
test_files: []
|
61
|
+
|