rack-killswitch 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +18 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +48 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/lib/rack-killswitch.rb +1 -0
- data/lib/rack/killswitch.rb +50 -0
- data/rack-killswitch.gemspec +59 -0
- metadata +140 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
+
rack (1.1.1)
|
10
|
+
rake (0.8.7)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.0.0)
|
17
|
+
jeweler (~> 1.5.2)
|
18
|
+
rack (>= 1.1.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Rawnet
|
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,48 @@
|
|
1
|
+
= rack-killswitch
|
2
|
+
|
3
|
+
Live broadcast on app showing fire and blood everywhere? Image hosting site flooded with pornography? Or some other urgent reason to take your app offline in a hurry?
|
4
|
+
|
5
|
+
rack-killswitch to the rescue. Just add this to your app:
|
6
|
+
|
7
|
+
# config/environment.rb
|
8
|
+
config.middleware.use 'Rack::Killswitch',
|
9
|
+
:trigger => Rails.root.join('.kill'),
|
10
|
+
:page => Rails.root.join('public', 'holding.html')
|
11
|
+
|
12
|
+
Now, lean back in the comfort of knowing that should excrement hit the rotating device, you can just:
|
13
|
+
|
14
|
+
1. touch RAILS_ROOT/.kill (via SSH or have your app admin controller do it if you want to give that power to the users)
|
15
|
+
2. Rejoice in the sudden absence of blood and gore on your website as all requests return the contents of holding.html.
|
16
|
+
|
17
|
+
Because it's Rack middleware and doesn't ever access the DB, it'll work whether you're using nginx or Apache and do it's job even if your latest commit f'ed up the Rails app, the host lost your DB and the Queen annexed Iceland.
|
18
|
+
|
19
|
+
== <steve_jobs>One more thing...</steve_jobs>
|
20
|
+
|
21
|
+
Sometimes you'll want to access the app yourself though, just not have it open to the nosy public (screw 'em). The :override_path option sets a path that, when accessed, sets a cookie that will allow you access to the site for as long as you have the cookie and "bypass" the killswitch:
|
22
|
+
|
23
|
+
# config/environment.rb
|
24
|
+
config.middleware.use 'Rack::Killswitch',
|
25
|
+
:trigger => Rails.root.join('.kill'),
|
26
|
+
:page => Rails.root.join('public', 'holding.html'),
|
27
|
+
:override_path => '/letmein'
|
28
|
+
|
29
|
+
Go to 'http://www.wherever.com/letmein' and you're sorted for 24 hours.
|
30
|
+
|
31
|
+
== Installation
|
32
|
+
|
33
|
+
Rails? Good. Bundle it, and you're sorted.
|
34
|
+
|
35
|
+
== Contributing to rack-killswitch
|
36
|
+
|
37
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
38
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
39
|
+
* Fork the project
|
40
|
+
* Start a feature/bugfix branch
|
41
|
+
* Commit and push until you are happy with your contribution
|
42
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
43
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
44
|
+
|
45
|
+
== Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2011 Rawnet. See LICENSE.txt for further details.
|
48
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
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.name = "rack-killswitch"
|
15
|
+
gem.homepage = "http://github.com/rawnet/rack-killswitch"
|
16
|
+
gem.license = "MIT"
|
17
|
+
gem.summary = %Q{Rack middleware to disable access to a site with a twist}
|
18
|
+
gem.description = %Q{Live broadcast on app showing fire and blood everywhere? Image hosting site flooded with pornography? Or some other urgent reason to take your app offline in a hurry? rack-killswitch to the rescue.}
|
19
|
+
gem.email = "christian@rawnet.com"
|
20
|
+
gem.authors = ["Christian Sutter"]
|
21
|
+
gem.add_runtime_dependency 'rack', '>= 1.1.0'
|
22
|
+
end
|
23
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/killswitch'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
# Killswitch is a Rack Middleware to disable access to a Rails (or Rack) app
|
4
|
+
# Inspired by rack-maintenance - https://github.com/ddollar/rack-maintenance
|
5
|
+
# (Credit where credit is due!)
|
6
|
+
|
7
|
+
class Rack::Killswitch
|
8
|
+
attr_reader :app, :options
|
9
|
+
|
10
|
+
def initialize(app, options={})
|
11
|
+
@app = app
|
12
|
+
@options = options
|
13
|
+
|
14
|
+
raise(ArgumentError, 'Must specify a trigger file (:trigger)') unless options[:trigger]
|
15
|
+
raise(ArgumentError, 'Must specify a holding page (:page)') unless options[:page]
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
# If the site is down and the user visits the defined override path, set a cookie so he can get in
|
20
|
+
if down? and options[:override_path] and env['REQUEST_URI'] == options[:override_path]
|
21
|
+
# HTTP 303: "See Other"
|
22
|
+
# The response to the request can be found under a different URI and SHOULD be retrieved using a
|
23
|
+
# GET method on that resource. The new URI is not a substitute reference for the originally requested
|
24
|
+
# resource. The 303 response MUST NOT be cached.
|
25
|
+
response = Rack::Response.new([''], 303, { 'Location' => '/', 'Content-Length' => '0' })
|
26
|
+
response.set_cookie("override_killswitch", {:value => "true", :path => "/", :expires => Time.now+24*60*60})
|
27
|
+
response.finish
|
28
|
+
elsif down? and not cookie_set?(env)
|
29
|
+
# Ensure holding page exists
|
30
|
+
raise "Holding page file #{options[:page]} does not exist" unless File.exists?(options[:page])
|
31
|
+
|
32
|
+
# Get what's in there and send it over to the unsuspecting user
|
33
|
+
data = File.read(options[:page])
|
34
|
+
[ 503, { 'Content-Type' => 'text/html', 'Content-Length' => data.length.to_s }, [data] ]
|
35
|
+
else
|
36
|
+
# Business as usual
|
37
|
+
app.call(env)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def cookie_set?(env)
|
43
|
+
# true as String because it's a cookie!
|
44
|
+
Rack::Request.new(env).cookies['override_killswitch'] == "true"
|
45
|
+
end
|
46
|
+
|
47
|
+
def down?
|
48
|
+
File.exists?(options[:trigger])
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rack-killswitch}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Christian Sutter"]
|
12
|
+
s.date = %q{2011-03-10}
|
13
|
+
s.description = %q{Live broadcast on app showing fire and blood everywhere? Image hosting site flooded with pornography? Or some other urgent reason to take your app offline in a hurry? rack-killswitch to the rescue.}
|
14
|
+
s.email = %q{christian@rawnet.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/rack-killswitch.rb",
|
28
|
+
"lib/rack/killswitch.rb",
|
29
|
+
"rack-killswitch.gemspec"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/rawnet/rack-killswitch}
|
32
|
+
s.licenses = ["MIT"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.7}
|
35
|
+
s.summary = %q{Rack middleware to disable access to a site with a twist}
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_runtime_dependency(%q<rack>, [">= 1.1.0"])
|
43
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
44
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
45
|
+
s.add_runtime_dependency(%q<rack>, [">= 1.1.0"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<rack>, [">= 1.1.0"])
|
48
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
50
|
+
s.add_dependency(%q<rack>, [">= 1.1.0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rack>, [">= 1.1.0"])
|
54
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
|
+
s.add_dependency(%q<rack>, [">= 1.1.0"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-killswitch
|
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
|
+
- Christian Sutter
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-10 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
name: rack
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 19
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 1
|
34
|
+
- 0
|
35
|
+
version: 1.1.0
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
name: bundler
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 23
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
- 0
|
51
|
+
version: 1.0.0
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
name: jeweler
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 7
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 5
|
66
|
+
- 2
|
67
|
+
version: 1.5.2
|
68
|
+
requirement: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
name: rack
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 19
|
79
|
+
segments:
|
80
|
+
- 1
|
81
|
+
- 1
|
82
|
+
- 0
|
83
|
+
version: 1.1.0
|
84
|
+
requirement: *id004
|
85
|
+
description: Live broadcast on app showing fire and blood everywhere? Image hosting site flooded with pornography? Or some other urgent reason to take your app offline in a hurry? rack-killswitch to the rescue.
|
86
|
+
email: christian@rawnet.com
|
87
|
+
executables: []
|
88
|
+
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
extra_rdoc_files:
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.rdoc
|
94
|
+
files:
|
95
|
+
- .document
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.rdoc
|
100
|
+
- Rakefile
|
101
|
+
- VERSION
|
102
|
+
- lib/rack-killswitch.rb
|
103
|
+
- lib/rack/killswitch.rb
|
104
|
+
- rack-killswitch.gemspec
|
105
|
+
has_rdoc: true
|
106
|
+
homepage: http://github.com/rawnet/rack-killswitch
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
requirements: []
|
133
|
+
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.3.7
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Rack middleware to disable access to a site with a twist
|
139
|
+
test_files: []
|
140
|
+
|