staging_protection 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52ab40a40e2c8d892a8c4487011f8292a97a381b
4
+ data.tar.gz: 6f7fa872b6580040efa79012a512e6fd43f41135
5
+ SHA512:
6
+ metadata.gz: f4b2e01e5bd6a136dab00629129d5fe0a2025d8e3f9ce1b3574b2e479e913a333a39ad96666e645d3a5972ce2f8e62d9c42668a2cc94890dcea4829efd806523
7
+ data.tar.gz: 31b6d6987b8b27bf32065ffc68a3a8eef23061aaf058668202d1c08de48337f9249d15c5d9d6ab95c43c5fd7850ef4c8316f7648fb0a8dbbc2dcc9a9b2be8fd1
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in staging_protection.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Anna Kazakova (gaar4ica)
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # StagingProtection
2
+
3
+ A simple gem is desinged to hide staging apps from search engines and public access.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'staging_protection'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install staging_protection
18
+
19
+ Then run:
20
+
21
+ $ rake staging_protection:initialize
22
+
23
+ Or create config file manualy.
24
+
25
+ ## Usage
26
+
27
+ Set up your credentials in config file.
28
+ Don't forget to restart web server. And that's it. Open `http://localhost:3000` (or your site url) and you'll see it is forbidden.
29
+
30
+ Once use `http://localhost:3000/?password=<your password from config>`. Now you can walk trough your site without any password. Token is stored in cookies.
31
+
32
+ ### Customizing access
33
+
34
+ You can add an exclision conditions. For example, you don't want to protect action main from HomeController. This is very easy. Set method `protection_exclusion` to your HomeController.
35
+
36
+ ```ruby
37
+ def protection_exclusion
38
+ params[:action] == 'main'
39
+ end
40
+ ```
41
+ And here you are. Action main is not blocked now.
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,60 @@
1
+ module StagingProtection
2
+ module Base
3
+
4
+ def self.extended(base)
5
+ base.send :extend, ClassMethods
6
+ base.send :include, InstanceMethods
7
+ base.send :init
8
+ end
9
+
10
+ module ClassMethods
11
+ def init
12
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
13
+ def protection_exclusion
14
+ false
15
+ end
16
+ RUBY
17
+
18
+ [:password, :message, :token, :environment].each do |method|
19
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
20
+ def self.#{method}= value
21
+ @#{method} = value
22
+ end
23
+
24
+ def #{method}
25
+ StagingProtection.#{method}
26
+ end
27
+
28
+ def self.#{method}
29
+ @#{method}
30
+ end
31
+ RUBY
32
+ end
33
+ end
34
+
35
+ def config &block
36
+ @message = 'You are not authorized to access this page.'
37
+ @environment = :staging
38
+ yield self if block_given?
39
+ end
40
+ end
41
+
42
+ module InstanceMethods
43
+ def check_password_if_required
44
+ if Rails.env == environment && (request.format && (!request.format.json? || !request.format.js?)) && params[:format] != 'json'
45
+ if params[:pass] == password
46
+ cookies['secret_token'] = token
47
+ end
48
+ unless protection_exclusion || cookies[:secret_token] == token
49
+ render :text => message, :status => :not_found
50
+ end
51
+ end
52
+ end
53
+
54
+ def protection_exclusion
55
+ false
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ require 'staging_protection'
2
+
3
+ module StagingProtection
4
+ require 'rails'
5
+
6
+ class Railtie < Rails::Railtie
7
+ rake_tasks { load "tasks/init.rake" }
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module StagingProtection
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require "staging_protection/railtie" if defined?(Rails)
2
+ require "staging_protection/version"
3
+ require "staging_protection/base"
4
+
5
+ module StagingProtection
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ before_filter :check_password_if_required
11
+ end
12
+
13
+ private
14
+
15
+ extend Base
16
+
17
+ end
18
+
19
+ ActionController::Base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
20
+ include StagingProtection
21
+ RUBY
@@ -0,0 +1,26 @@
1
+ namespace :staging_protection do
2
+ desc "Create default configuration"
3
+ task :initialize do
4
+ path = "config/initializers/staging_protection.rb"
5
+ file = File.open("#{Rails.root}/#{path}","w")
6
+ text = <<-TEXT
7
+ StagingProtection.config do |config|
8
+ # Password should be changed
9
+ config.password = '123456'
10
+
11
+ # Token should be changed
12
+ config.token = '1234567819287321256789'
13
+
14
+ # Default error message can be overriden
15
+ # config.message = 'you are not authorized to access this page.'
16
+
17
+ # Default environment is staging, but it you can use any others.
18
+ # config.environment = 'development'
19
+ end
20
+ TEXT
21
+ file << text
22
+ file.close
23
+
24
+ puts "Created config for staging_protection gem.\nCheck it out here! #{path}\n"
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'staging_protection/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "staging_protection"
8
+ spec.version = StagingProtection::VERSION
9
+ spec.authors = ["Anna Kazakova (gaar4ica)"]
10
+ spec.email = ["gaar4ica@gmail.com"]
11
+ spec.description = "A simple gem to protect an application from search engine cache"
12
+ spec.summary = "Use password authentication for html-like requests"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: staging_protection
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anna Kazakova (gaar4ica)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A simple gem to protect an application from search engine cache
42
+ email:
43
+ - gaar4ica@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/staging_protection.rb
54
+ - lib/staging_protection/base.rb
55
+ - lib/staging_protection/railtie.rb
56
+ - lib/staging_protection/version.rb
57
+ - lib/tasks/init.rake
58
+ - staging_protection.gemspec
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Use password authentication for html-like requests
83
+ test_files: []