handcart 0.0.2
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +247 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/handcart/application.js +16 -0
- data/app/assets/stylesheets/handcart/application.css +15 -0
- data/app/assets/stylesheets/handcart/layout.css.scss +21 -0
- data/app/controllers/handcart/application_controller.rb +4 -0
- data/app/controllers/handcart/ip_addresses_controller.rb +56 -0
- data/app/controllers/handcart/subdomains_controller.rb +55 -0
- data/app/helpers/handcart/application_helper.rb +14 -0
- data/app/helpers/handcart/url_helper.rb +16 -0
- data/app/models/handcart/concerns/handcarts.rb +30 -0
- data/app/models/handcart/domain_constraint.rb +20 -0
- data/app/models/handcart/ip_address.rb +18 -0
- data/app/models/handcart/setting_constraint.rb +26 -0
- data/app/models/handcart/subdomain.rb +36 -0
- data/app/views/handcart/ip_addresses/_form.html.haml +12 -0
- data/app/views/handcart/ip_addresses/edit.html.haml +3 -0
- data/app/views/handcart/ip_addresses/index.html.haml +36 -0
- data/app/views/handcart/ip_addresses/new.html.haml +3 -0
- data/app/views/handcart/ip_addresses/show.html.haml +20 -0
- data/app/views/handcart/subdomains/_form.html.haml +9 -0
- data/app/views/handcart/subdomains/edit.html.haml +3 -0
- data/app/views/handcart/subdomains/index.html.haml +31 -0
- data/app/views/handcart/subdomains/new.html.haml +3 -0
- data/app/views/handcart/subdomains/show.html.haml +20 -0
- data/app/views/layouts/handcart/_navbar.html.haml +15 -0
- data/app/views/layouts/handcart/application.html.haml +60 -0
- data/config/handcart.json +6 -0
- data/config/locales/en.yml +61 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20131009165427_create_handcart_subdomains.rb +9 -0
- data/db/migrate/20131203000934_create_handcart_ip_addresses.rb +12 -0
- data/lib/handcart.rb +67 -0
- data/lib/handcart/acts_as_handcart.rb +16 -0
- data/lib/handcart/controller_additions.rb +152 -0
- data/lib/handcart/engine.rb +27 -0
- data/lib/handcart/ip_authorization.rb +27 -0
- data/lib/handcart/simple_form.rb +179 -0
- data/lib/handcart/strategies/base_ip_strategy.rb +21 -0
- data/lib/handcart/strategies/containment_strategy.rb +16 -0
- data/lib/handcart/strategies/inclusion_strategy.rb +17 -0
- data/lib/handcart/templates/rspec/controller/controller_spec.rb +17 -0
- data/lib/handcart/templates/rspec/scaffold/routing_spec.rb +40 -0
- data/lib/handcart/version.rb +3 -0
- data/spec/controllers/handcart/ip_addresses_controller_spec.rb +134 -0
- data/spec/controllers/handcart/subdomains_controller_spec.rb +138 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/layout.css.scss +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +7 -0
- data/spec/dummy/app/controllers/custom_constraints_controller.rb +2 -0
- data/spec/dummy/app/controllers/ip_addresses_controller.rb +7 -0
- data/spec/dummy/app/controllers/master/companies_controller.rb +51 -0
- data/spec/dummy/app/controllers/master/dashboard_controller.rb +4 -0
- data/spec/dummy/app/controllers/master_controller.rb +2 -0
- data/spec/dummy/app/controllers/public_controller.rb +12 -0
- data/spec/dummy/app/controllers/subdomain_controller.rb +8 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/company.rb +7 -0
- data/spec/dummy/app/views/ip_addresses/index.html.haml +12 -0
- data/spec/dummy/app/views/ip_addresses/show.html.haml +1 -0
- data/spec/dummy/app/views/layouts/_navbar.html.haml +11 -0
- data/spec/dummy/app/views/layouts/application.html.haml +53 -0
- data/spec/dummy/app/views/layouts/public.html.haml +41 -0
- data/spec/dummy/app/views/master/companies/_form.html.haml +19 -0
- data/spec/dummy/app/views/master/companies/edit.html.haml +7 -0
- data/spec/dummy/app/views/master/companies/index.html.haml +25 -0
- data/spec/dummy/app/views/master/companies/new.html.haml +5 -0
- data/spec/dummy/app/views/master/companies/show.html.haml +12 -0
- data/spec/dummy/app/views/master/dashboard/index.html.haml +2 -0
- data/spec/dummy/app/views/public/forbidden.html.haml +3 -0
- data/spec/dummy/app/views/public/index.html.haml +2 -0
- data/spec/dummy/app/views/subdomain/index.html.haml +2 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +40 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +26 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/handcart.json +6 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/handcart.rb +16 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +12 -0
- data/spec/dummy/config/routes.rb +23 -0
- data/spec/dummy/db/migrate/20131010194534_create_companies.rb +10 -0
- data/spec/dummy/db/migrate/20131016183624_add_active_to_companies.rb +5 -0
- data/spec/dummy/db/schema.rb +41 -0
- data/spec/dummy/log/development.log +14 -0
- data/spec/dummy/log/test.log +786 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/spec/models/company_spec.rb +36 -0
- data/spec/dummy/spec/routing/custom_constraints_routing_spec.rb +37 -0
- data/spec/dummy/tmp/cache/assets/development/sass/27d34b7cbcb5b92ab03220c4d4b91379cc64c2c0/layout.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sass/dc98e44780f42e6521ebbf14c4db22f6a78c41ef/layout.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/05974a1f812cf4a61bb242d48722fd19 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/063a74a7c73c9501ee373ef00111f159 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/073d2b13ed9366ce539940749eb3844d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0d76367ded60510a66afc3dea891e76a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/106c3f4e1fc71e9dc70abae55d432886 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13ae4613233656a42188d4d3ddbb7fc1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/18c826ba1d6dac1633cae2da25c0402a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/247df6a90ce931f763db1ade5227d4b1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2860df473a6cf4c483cd6f251fea3ae0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2a99072e783dcef4637b38221531ea61 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2ab4b3177ab6c9d837c0905b61eedad5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2b84c9cc30f71e24310dd1a4381caae8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2bebf0981bc585e24939ca8ffe10081c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2c45a1517014fd239c930e48a71a93f0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2d5147f4ea70131b4e330cab38aeb1a1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3124588878c79981009129f32d5fe408 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/33325c558d8db2071bf8a938517e5af2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/350c8c72b1dbd7a84f85424b5cd4def1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3a3d69c38e3b3d20e94420ebebd05a69 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3b1656b46a35a6120c3407b930d468ba +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3c0fc39d9b84afb4937545b620cd2d72 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3fa878a57cb0b42be266336564609b18 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/40f26b5e75d0f747e691c0b38529fb59 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/42aa8e53e39d8f5247f1b3e89cb00adc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/42e1f4c72bf58cf112dd11eae8ee768b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/433be3db83a4d9f93f5d1fa2ae3bde4e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4b6f9f46d7a2e230321d7f8df06ea470 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4c17c77b444339bb3ab293047da0ff0d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4ee93c096bb850d38032eb457afebf69 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4f25edc4354919ba67721f488ba10e12 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/58fb821d4a4a44fdb2a89d4f487a8390 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5f97a76ac644497413f4c8dc547ddea6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6076ab56e9c62fd04155d6f6c43e575e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/60b75d9635ed84e08a0b9a245d8a3202 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/64ad9f343408809fdfb1df851186853d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6e79870e51ea835a6847f8c65e23e14b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6e9d2e7aafa45c939731291fa453b8c2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/78f915513059378e161ceb6f2d14fbd9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8102cf6724f489a310fe3a6b764bb2e9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/81108a1123b15b10c7f7f2e0d1207267 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/81b3dcc0aa61577b08de13ba5633dbc4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/83e686634b5ac6d4b183677ed2edda8b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8581aae276f167a9b7b2158641b0bf87 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/94cb3819408e525700729fbd473432c8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/99eb5e50b6d0e5d0d6b6c37cbde33864 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a7c86e9a777f7789dd1c78d26a662a87 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a9e19eb45005fa24bc8b90b6a374089f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ac4492393938e58cede2b6277afb0bc6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ad1d96635f4dae7eb22d1984947d7440 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/af718c632887ccb6c1c35c4b65c61293 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b2f45720a78d375468b99bb25f121c4e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b559f2694561fc6c44e3319f507de1e7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b6e8c6ba59755a8fe132457f81065f96 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b796b57f310287a7a619afa9d5b99952 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b7c36a1c00d7804d9e827d704c0dd811 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bc28a210f3df576c74059aff8233eae3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bc414fbd5123e40c4f5e69f4c294f489 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c0181c32e0ed10ec8fa3049f9a80f551 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c17130f66131c854d6f8c2196902b596 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c4c0e10aa5c21ece42c0bfe998a5d8c0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c63bcc000975adbdf423db3ad43eb93f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c962f9220062a6407dfc7d9447565273 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cb8b538b6fce61b500edebe63156bf62 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cfcef2015b7df990ed90006632877389 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cff56d2d0a8b8a25d4b0388d242be9c8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d32fc7356f764b22ecbcebbcb9b47ee1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d776667bae72eb3d582da5803fc931ca +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dfc307d14a0cf64cf8c3a4e94fdbcfb9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e4b6570b82329477bc7043183b64b105 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/eff1316ad12dd5b8f4cbf0ba9e448229 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f2348b747b81ca6e3a24d5bd0b7023c4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f6f921309fcc78b6850abcf2418279fe +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7e1dbf50c19c9d439de52caa4296164 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ff2adfc3ed446b68ac2d0077e8af34e2 +0 -0
- data/spec/factories/companies.rb +7 -0
- data/spec/factories/handcart_ip_addresses.rb +8 -0
- data/spec/factories/handcart_subdomains.rb +5 -0
- data/spec/models/handcart/base_ip_strategy_spec.rb +23 -0
- data/spec/models/handcart/containment_strategy_spec.rb +23 -0
- data/spec/models/handcart/domain_constraint_spec.rb +38 -0
- data/spec/models/handcart/engine_spec.rb +14 -0
- data/spec/models/handcart/handcart_spec.rb +38 -0
- data/spec/models/handcart/inclusion_strategy_spec.rb +29 -0
- data/spec/models/handcart/ip_address_spec.rb +51 -0
- data/spec/models/handcart/ip_authorization_spec.rb +17 -0
- data/spec/models/handcart/subdomain_spec.rb +153 -0
- data/spec/routing/handcart/ip_addresses_routing_spec.rb +38 -0
- data/spec/routing/handcart/subdomains_routing_spec.rb +38 -0
- data/spec/spec_helper.rb +65 -0
- data/spec/support/subdomains.rb +26 -0
- metadata +565 -0
data/config/routes.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class CreateHandcartIpAddresses < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :handcart_ip_addresses do |t|
|
|
4
|
+
t.string :address
|
|
5
|
+
t.string :subnet_mask
|
|
6
|
+
t.belongs_to :handcart, index: true
|
|
7
|
+
t.boolean :blacklisted, default: false
|
|
8
|
+
|
|
9
|
+
t.timestamps
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
data/lib/handcart.rb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require "handcart/engine"
|
|
2
|
+
require "handcart/acts_as_handcart"
|
|
3
|
+
require "handcart/ip_authorization"
|
|
4
|
+
require 'handcart/controller_additions'
|
|
5
|
+
require 'haml'
|
|
6
|
+
require 'sass/rails'
|
|
7
|
+
require "handcart/simple_form"
|
|
8
|
+
require 'jquery-rails'
|
|
9
|
+
|
|
10
|
+
module Handcart
|
|
11
|
+
module Strategies
|
|
12
|
+
# Load the IP Authorization strategies
|
|
13
|
+
autoload :BaseIpStrategy, "handcart/strategies/base_ip_strategy"
|
|
14
|
+
autoload :InclusionStrategy, 'handcart/strategies/inclusion_strategy'
|
|
15
|
+
autoload :ContainmentStrategy, 'handcart/strategies/containment_strategy'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
mattr_accessor :subdomain_class
|
|
19
|
+
@@subdomain_class = "Handcart::Subdomain"
|
|
20
|
+
|
|
21
|
+
mattr_accessor :handcart_class
|
|
22
|
+
@@handcart_class = nil
|
|
23
|
+
|
|
24
|
+
mattr_accessor :handcart_show_path
|
|
25
|
+
@@handcart_show_path = nil
|
|
26
|
+
|
|
27
|
+
mattr_accessor :domain_constraints
|
|
28
|
+
@@domain_constraints = []
|
|
29
|
+
|
|
30
|
+
mattr_accessor :reserved_subdomains
|
|
31
|
+
@@reserved_subdomains = [
|
|
32
|
+
"www",
|
|
33
|
+
"ftp",
|
|
34
|
+
"ssh",
|
|
35
|
+
"pop3",
|
|
36
|
+
"staging",
|
|
37
|
+
"master",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
mattr_accessor :ip_authorization_strategy
|
|
41
|
+
@@ip_authorization_strategy = nil
|
|
42
|
+
|
|
43
|
+
# Enable Global IP Forwarding for certain environments
|
|
44
|
+
mattr_accessor :global_ip_forwarding_enabled_environments
|
|
45
|
+
@@global_ip_forwarding_enabled_environments = []
|
|
46
|
+
|
|
47
|
+
# Enable Gobal IP Blocking for certain environments
|
|
48
|
+
mattr_accessor :global_ip_blocking_enabled_environments
|
|
49
|
+
@@global_ip_blocking_enabled_environments = []
|
|
50
|
+
|
|
51
|
+
def self.setup
|
|
52
|
+
yield self
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.handcart_class
|
|
56
|
+
@@handcart_class.constantize
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.subdomain_class
|
|
60
|
+
@@subdomain_class.constantize
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.ip_authorization
|
|
64
|
+
IpAuthorization.instance
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Handcart
|
|
2
|
+
module ActsAsHandcart
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module ClassMethods
|
|
9
|
+
def acts_as_handcart
|
|
10
|
+
include Handcart::Concerns::Handcarts
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
ActiveRecord::Base.send :include, Handcart::ActsAsHandcart
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
module Handcart
|
|
2
|
+
|
|
3
|
+
# This module is automatically included into all controllers.
|
|
4
|
+
module ControllerAdditions
|
|
5
|
+
module ClassMethods
|
|
6
|
+
|
|
7
|
+
def enable_forwarding(forwarding, rejection, *args)
|
|
8
|
+
self.class_variable_set(:@@forwarding_url, forwarding)
|
|
9
|
+
self.class_variable_set(:@@rejection_url, rejection)
|
|
10
|
+
|
|
11
|
+
options = args.extract_options!
|
|
12
|
+
if Handcart.global_ip_forwarding_enabled_environments.include?(Rails.env)
|
|
13
|
+
before_action :setup_forwarding_resources, options.slice(:except, :only)
|
|
14
|
+
before_action :forward_or_reject, options.slice(:except, :only)
|
|
15
|
+
else
|
|
16
|
+
# No forwarding is enabled
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Enable IP Blocking on the sessions controller
|
|
21
|
+
def enable_blocking(rejection, *args)
|
|
22
|
+
options = args.extract_options!
|
|
23
|
+
self.class_variable_set(:@@rejection_url, rejection)
|
|
24
|
+
|
|
25
|
+
if Handcart.global_ip_blocking_enabled_environments.include?(Rails.env)
|
|
26
|
+
before_action :setup_blocking_resources, options.slice(:except, :only)
|
|
27
|
+
before_action :allow_or_reject, options.slice(:except, :only)
|
|
28
|
+
else
|
|
29
|
+
# Do nothing, no blocking is enabled
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Instance Methods here
|
|
35
|
+
def current_subdomain
|
|
36
|
+
@current_subdomain = Handcart::Subdomain.find_by_name(request.subdomain)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def current_handcart
|
|
40
|
+
@current_handcart = current_subdomain.handcart
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.included(base)
|
|
44
|
+
base.extend ClassMethods
|
|
45
|
+
base.helper_method :current_subdomain, :current_handcart
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def setup_forwarding_resources
|
|
51
|
+
@forwarding_url = self.class.class_variable_get(:@@forwarding_url)
|
|
52
|
+
@rejection_url = self.class.class_variable_get(:@@rejection_url)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def setup_blocking_resources
|
|
56
|
+
@rejection_url = self.class.class_variable_get(:@@rejection_url)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def forward_or_reject
|
|
60
|
+
# We assume the the rejection action is going to be on the public controller
|
|
61
|
+
# since we wouldn't want to forward the rejection to the handcart
|
|
62
|
+
my_forbidden_url = main_app.url_for({
|
|
63
|
+
subdomain: '',
|
|
64
|
+
host: Handcart::DomainConstraint.default_constraint.domain,
|
|
65
|
+
controller: @rejection_url.split("#").first,
|
|
66
|
+
action: @rejection_url.split("#").last,
|
|
67
|
+
trailing_slash: false,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
# Look for the IP Address
|
|
71
|
+
ip_address = Handcart::IpAddress.permitted.find_by_address(request.remote_ip)
|
|
72
|
+
if ip_address
|
|
73
|
+
# Do we have a current_handcart for this foreign IP?...
|
|
74
|
+
if ip_address.handcart.present?
|
|
75
|
+
# Does it respond to enable_ip_blocking? and if so, is it disabled right now?
|
|
76
|
+
if ip_address.handcart.respond_to?(:enable_ip_blocking?)
|
|
77
|
+
truthiness = ip_address.handcart.present? && !ip_address.handcart.enable_ip_blocking?
|
|
78
|
+
else
|
|
79
|
+
# otherwise, it doesn't respond to it, so just make sure the handcart is present
|
|
80
|
+
truthiness = ip_address.handcart.present?
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Now do the forwarding
|
|
85
|
+
if truthiness
|
|
86
|
+
my_forwarding_url = main_app.url_for({
|
|
87
|
+
subdomain: ip_address.handcart.subdomain.name,
|
|
88
|
+
host: Handcart::DomainConstraint.default_constraint.domain,
|
|
89
|
+
controller: @forwarding_url.split("#").first,
|
|
90
|
+
action: @forwarding_url.split("#").last,
|
|
91
|
+
trailing_slash: false,
|
|
92
|
+
})
|
|
93
|
+
redirect_to my_forwarding_url
|
|
94
|
+
else
|
|
95
|
+
# Franchisee hasn't been activated yet, or this IP Address isn't associated with a franchisee yet.
|
|
96
|
+
flash[:error] = 'Cannot login from this IP address!'
|
|
97
|
+
redirect_to my_forbidden_url
|
|
98
|
+
end
|
|
99
|
+
else
|
|
100
|
+
# Blacklisted
|
|
101
|
+
flash[:error] = "IP Address has not been authorized to access this site"
|
|
102
|
+
redirect_to my_forbidden_url
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Don't allow unauthorized or blacklisted foreign IP addresses to hit
|
|
107
|
+
# what we assume is the session controller for the franchisee.
|
|
108
|
+
def allow_or_reject
|
|
109
|
+
# We assume the the rejection action is going to be on the public controller
|
|
110
|
+
# since we wouldn't want to forward the rejection to the handcart
|
|
111
|
+
my_rejection_url = main_app.url_for({
|
|
112
|
+
# subdomain: '',
|
|
113
|
+
host: Handcart::DomainConstraint.default_constraint.domain,
|
|
114
|
+
controller: @rejection_url.split("#").first,
|
|
115
|
+
action: @rejection_url.split("#").last,
|
|
116
|
+
trailing_slash: false,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
# See if they have enable IP blocking if they respond to that.
|
|
120
|
+
if current_handcart.respond_to?(:enable_ip_blocking?)
|
|
121
|
+
truthiness = current_handcart.enable_ip_blocking?
|
|
122
|
+
else
|
|
123
|
+
# Default to true
|
|
124
|
+
truthiness = true
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
if truthiness
|
|
128
|
+
ip_address = current_handcart.ip_addresses.permitted.find_by_address(request.remote_ip)
|
|
129
|
+
if ip_address
|
|
130
|
+
if Handcart.ip_authorization.strategy.is_in_range?(ip_address.address, current_handcart)
|
|
131
|
+
# Do nothing, let them login
|
|
132
|
+
else
|
|
133
|
+
# # The strategy doesn't match
|
|
134
|
+
redirect_to my_rejection_url
|
|
135
|
+
end
|
|
136
|
+
else
|
|
137
|
+
# No IP Address was found
|
|
138
|
+
redirect_to my_rejection_url
|
|
139
|
+
end
|
|
140
|
+
else
|
|
141
|
+
# Do nothing, blocking mode is disabled
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
if defined? ActionController::Base
|
|
149
|
+
ActionController::Base.class_eval do
|
|
150
|
+
include Handcart::ControllerAdditions
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Handcart
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
config.generators do |g|
|
|
4
|
+
g.test_framework :rspec, fixture: false, view_specs: false
|
|
5
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
|
6
|
+
g.template_engine :haml
|
|
7
|
+
g.stylesheet_engine :scss
|
|
8
|
+
g.assets false
|
|
9
|
+
g.helper false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
config.after_initialize do
|
|
13
|
+
if File.exists?(File.join(Rails.root, 'config', 'handcart.json')) && !Rails.env.test?
|
|
14
|
+
# Don't load the app's config file when we're testing the gem
|
|
15
|
+
config_file = File.join(Rails.root, 'config', 'handcart.json')
|
|
16
|
+
elsif File.exists?(File.join(Handcart::Engine.root, 'config', 'handcart.json'))
|
|
17
|
+
# But default to using the gem config if one can't be found
|
|
18
|
+
config_file = File.join(Handcart::Engine.root, 'config', 'handcart.json')
|
|
19
|
+
end
|
|
20
|
+
my_config_file = JSON.parse(File.read(config_file))
|
|
21
|
+
CONFIG = my_config_file.fetch(Rails.env, {})
|
|
22
|
+
CONFIG.symbolize_keys!
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
isolate_namespace Handcart
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'singleton'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
class IpAuthorization
|
|
5
|
+
# A singleton
|
|
6
|
+
attr_accessor :ip_authorization_strategy, :strategy
|
|
7
|
+
|
|
8
|
+
include Singleton
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@ip_authorization_strategy = Handcart.ip_authorization_strategy
|
|
12
|
+
|
|
13
|
+
# Setup what strategy we're using
|
|
14
|
+
case @ip_authorization_strategy
|
|
15
|
+
when :none
|
|
16
|
+
nil
|
|
17
|
+
when :containment
|
|
18
|
+
@strategy = Handcart::Strategies::ContainmentStrategy.new
|
|
19
|
+
when :inclusion
|
|
20
|
+
@strategy = Handcart::Strategies::InclusionStrategy.new
|
|
21
|
+
else
|
|
22
|
+
nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# lib/my-engine/simple-form.rb
|
|
2
|
+
require 'simple_form'
|
|
3
|
+
|
|
4
|
+
# Use this setup block to configure all options available in SimpleForm.
|
|
5
|
+
SimpleForm.setup do |config|
|
|
6
|
+
# Wrappers are used by the form builder to generate a
|
|
7
|
+
# complete input. You can remove any component from the
|
|
8
|
+
# wrapper, change the order or even add your own to the
|
|
9
|
+
# stack. The options given below are used to wrap the
|
|
10
|
+
# whole input.
|
|
11
|
+
config.wrappers :default, class: :input,
|
|
12
|
+
hint_class: :field_with_hint, error_class: :field_with_errors do |b|
|
|
13
|
+
## Extensions enabled by default
|
|
14
|
+
# Any of these extensions can be disabled for a
|
|
15
|
+
# given input by passing: `f.input EXTENSION_NAME => false`.
|
|
16
|
+
# You can make any of these extensions optional by
|
|
17
|
+
# renaming `b.use` to `b.optional`.
|
|
18
|
+
|
|
19
|
+
# Determines whether to use HTML5 (:email, :url, ...)
|
|
20
|
+
# and required attributes
|
|
21
|
+
b.use :html5
|
|
22
|
+
|
|
23
|
+
# Calculates placeholders automatically from I18n
|
|
24
|
+
# You can also pass a string as f.input placeholder: "Placeholder"
|
|
25
|
+
b.use :placeholder
|
|
26
|
+
|
|
27
|
+
## Optional extensions
|
|
28
|
+
# They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
|
|
29
|
+
# to the input. If so, they will retrieve the values from the model
|
|
30
|
+
# if any exists. If you want to enable the lookup for any of those
|
|
31
|
+
# extensions by default, you can change `b.optional` to `b.use`.
|
|
32
|
+
|
|
33
|
+
# Calculates maxlength from length validations for string inputs
|
|
34
|
+
b.optional :maxlength
|
|
35
|
+
|
|
36
|
+
# Calculates pattern from format validations for string inputs
|
|
37
|
+
b.optional :pattern
|
|
38
|
+
|
|
39
|
+
# Calculates min and max from length validations for numeric inputs
|
|
40
|
+
b.optional :min_max
|
|
41
|
+
|
|
42
|
+
# Calculates readonly automatically from readonly attributes
|
|
43
|
+
b.optional :readonly
|
|
44
|
+
|
|
45
|
+
## Inputs
|
|
46
|
+
b.use :label_input
|
|
47
|
+
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
|
48
|
+
b.use :error, wrap_with: { tag: :span, class: :error }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
|
|
52
|
+
b.use :html5
|
|
53
|
+
b.use :placeholder
|
|
54
|
+
b.use :label
|
|
55
|
+
b.wrapper tag: 'div', class: 'controls' do |ba|
|
|
56
|
+
ba.use :input
|
|
57
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
|
|
58
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
|
|
63
|
+
b.use :html5
|
|
64
|
+
b.use :placeholder
|
|
65
|
+
b.use :label
|
|
66
|
+
b.wrapper tag: 'div', class: 'controls' do |input|
|
|
67
|
+
input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
|
|
68
|
+
prepend.use :input
|
|
69
|
+
end
|
|
70
|
+
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
|
|
71
|
+
input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
config.wrappers :append, tag: 'div', class: "control-group", error_class: 'error' do |b|
|
|
76
|
+
b.use :html5
|
|
77
|
+
b.use :placeholder
|
|
78
|
+
b.use :label
|
|
79
|
+
b.wrapper tag: 'div', class: 'controls' do |input|
|
|
80
|
+
input.wrapper tag: 'div', class: 'input-append' do |append|
|
|
81
|
+
append.use :input
|
|
82
|
+
end
|
|
83
|
+
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
|
|
84
|
+
input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
|
|
89
|
+
# Check the Bootstrap docs (http://twitter.github.com/bootstrap)
|
|
90
|
+
# to learn about the different styles for forms and inputs,
|
|
91
|
+
# buttons and other elements.
|
|
92
|
+
config.default_wrapper = :bootstrap
|
|
93
|
+
|
|
94
|
+
# Define the way to render check boxes / radio buttons with labels.
|
|
95
|
+
# Defaults to :nested for bootstrap config.
|
|
96
|
+
# inline: input + label
|
|
97
|
+
# nested: label > input
|
|
98
|
+
config.boolean_style = :nested
|
|
99
|
+
|
|
100
|
+
# Default class for buttons
|
|
101
|
+
config.button_class = 'btn'
|
|
102
|
+
|
|
103
|
+
# Method used to tidy up errors.
|
|
104
|
+
# config.error_method = :first
|
|
105
|
+
|
|
106
|
+
# Default tag used for error notification helper.
|
|
107
|
+
config.error_notification_tag = :div
|
|
108
|
+
|
|
109
|
+
# CSS class to add for error notification helper.
|
|
110
|
+
config.error_notification_class = 'alert alert-error'
|
|
111
|
+
|
|
112
|
+
# ID to add for error notification helper.
|
|
113
|
+
# config.error_notification_id = nil
|
|
114
|
+
|
|
115
|
+
# Series of attempts to detect a default label method for collection.
|
|
116
|
+
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
|
|
117
|
+
|
|
118
|
+
# Series of attempts to detect a default value method for collection.
|
|
119
|
+
# config.collection_value_methods = [ :id, :to_s ]
|
|
120
|
+
|
|
121
|
+
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
|
|
122
|
+
# config.collection_wrapper_tag = nil
|
|
123
|
+
|
|
124
|
+
# You can define the class to use on all collection wrappers. Defaulting to none.
|
|
125
|
+
# config.collection_wrapper_class = nil
|
|
126
|
+
|
|
127
|
+
# You can wrap each item in a collection of radio/check boxes with a tag,
|
|
128
|
+
# defaulting to :span. Please note that when using :boolean_style = :nested,
|
|
129
|
+
# SimpleForm will force this option to be a label.
|
|
130
|
+
# config.item_wrapper_tag = :span
|
|
131
|
+
|
|
132
|
+
# You can define a class to use in all item wrappers. Defaulting to none.
|
|
133
|
+
# config.item_wrapper_class = nil
|
|
134
|
+
|
|
135
|
+
# How the label text should be generated altogether with the required text.
|
|
136
|
+
# config.label_text = lambda { |label, required| "#{required} #{label}" }
|
|
137
|
+
|
|
138
|
+
# You can define the class to use on all labels. Default is nil.
|
|
139
|
+
config.label_class = 'control-label'
|
|
140
|
+
|
|
141
|
+
# You can define the class to use on all forms. Default is simple_form.
|
|
142
|
+
# config.form_class = :simple_form
|
|
143
|
+
|
|
144
|
+
# You can define which elements should obtain additional classes
|
|
145
|
+
# config.generate_additional_classes_for = [:wrapper, :label, :input]
|
|
146
|
+
|
|
147
|
+
# Whether attributes are required by default (or not). Default is true.
|
|
148
|
+
# config.required_by_default = true
|
|
149
|
+
|
|
150
|
+
# Tell browsers whether to use default HTML5 validations (novalidate option).
|
|
151
|
+
# Default is enabled.
|
|
152
|
+
config.browser_validations = false
|
|
153
|
+
|
|
154
|
+
# Collection of methods to detect if a file type was given.
|
|
155
|
+
# config.file_methods = [ :mounted_as, :file?, :public_filename ]
|
|
156
|
+
|
|
157
|
+
# Custom mappings for input types. This should be a hash containing a regexp
|
|
158
|
+
# to match as key, and the input type that will be used when the field name
|
|
159
|
+
# matches the regexp as value.
|
|
160
|
+
# config.input_mappings = { /count/ => :integer }
|
|
161
|
+
|
|
162
|
+
# Default priority for time_zone inputs.
|
|
163
|
+
# config.time_zone_priority = nil
|
|
164
|
+
|
|
165
|
+
# Default priority for country inputs.
|
|
166
|
+
# config.country_priority = nil
|
|
167
|
+
|
|
168
|
+
# Default size for text inputs.
|
|
169
|
+
# config.default_input_size = 50
|
|
170
|
+
|
|
171
|
+
# When false, do not use translations for labels.
|
|
172
|
+
# config.translate_labels = true
|
|
173
|
+
|
|
174
|
+
# Automatically discover new inputs in Rails' autoload path.
|
|
175
|
+
# config.inputs_discovery = true
|
|
176
|
+
|
|
177
|
+
# Cache SimpleForm inputs discovery
|
|
178
|
+
# config.cache_discovery = !Rails.env.development?
|
|
179
|
+
end
|