rack-staging 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ h1. Staging Gem
2
+
3
+ Staging rack application purpose to protect you Rails application from anonymous and prying.
4
+
5
+ h1. Usage
6
+
7
+ h2. Examples
8
+
9
+ h3. In you Rails initializer
10
+
11
+ <pre><code>config.middleware.use 'Rack::Staging', :code => 'Hfgo_JHg+47'</code></pre>
12
+
13
+ <pre><code>config.middleware.use 'Rack::Staging',
14
+ :code => 'Hfgo_JHg+47',
15
+ :template_path => "#{Rails.root}/app/views/staging/index.html" # custom template</code></pre>
16
+
17
+ h3. … and now you are ready to protected staging!
18
+
@@ -0,0 +1,52 @@
1
+ # Hi! I'am rack middleware!
2
+ # I was born for protect you staging application from anonymous and prying
3
+
4
+ # My author's name was Aleksandr Koss. Mail him at kossnocorp@gmail.com
5
+ # Nice to MIT you!
6
+
7
+ module Rack
8
+ class Staging
9
+
10
+ def initialize(app, options = {})
11
+ @app = app
12
+ @options = options
13
+ end
14
+
15
+ def call(env)
16
+ request = Rack::Request.new(env)
17
+
18
+ # Check code in session and return Rails call if is valid
19
+ return @app.call(env) if already_auth?(request)
20
+
21
+ # If post method check :code_param value
22
+ if request.post? and code_valid?(request.params["staging_code"])
23
+ request.session[:staging_code] = request.params["staging_code"]
24
+ [301, {'Location' => '/'}, ''] # Redirect if code is valid
25
+ else
26
+ render_staging
27
+ end
28
+ end
29
+
30
+ private
31
+ # Render staging html file
32
+ def render_staging
33
+ [200, {'Content-Type' => 'text/html'}, [
34
+ ::File.open(html_template, 'rb').read
35
+ ]]
36
+ end
37
+
38
+ def html_template
39
+ @options[:template_path] || ::File.expand_path('../rack-staging/index.html', __FILE__)
40
+ end
41
+
42
+ # Validate code
43
+ def code_valid?(code)
44
+ @options[:code] == code
45
+ end
46
+
47
+ def already_auth?(request)
48
+ code_valid?(request.session[:staging_code])
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Staging protection</title>
5
+ </head>
6
+ <body onLoad='document.forms[0].elements[0].focus();' style='text-align: center; margin-top:100px'>
7
+ <form action="/" method="post">
8
+ <label>
9
+ <h1>Staging code</h1>
10
+ <input type="password" name="staging_code" />
11
+ </label>
12
+ <input type="submit" />
13
+ </form>
14
+ </body>
15
+ </html>
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Staging
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-staging
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Aleksandr Koss
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-31 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15424063
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ - rc
35
+ - 5
36
+ version: 1.0.0.rc.5
37
+ type: :development
38
+ version_requirements: *id001
39
+ description: Staging rack application purpose to protect you Rails application from anonymous and prying.
40
+ email:
41
+ - kossnocorp@gmail.com
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ extra_rdoc_files: []
47
+
48
+ files:
49
+ - lib/rack-staging/index.html
50
+ - lib/rack-staging/version.rb
51
+ - lib/rack-staging.rb
52
+ - README.textile
53
+ has_rdoc: true
54
+ homepage: http://github.com/kossnocorp/staging
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 23
77
+ segments:
78
+ - 1
79
+ - 3
80
+ - 6
81
+ version: 1.3.6
82
+ requirements: []
83
+
84
+ rubyforge_project: rack-staging
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Protect you Rails application from anonymous and prying.
89
+ test_files: []
90
+