censorstrike 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +8 -0
- data/Guardfile +6 -0
- data/README.md +45 -0
- data/Rakefile +7 -0
- data/censorstrike.gemspec +22 -0
- data/lib/censorstrike.rb +39 -0
- data/lib/censorstrike/version.rb +3 -0
- data/message.html +65 -0
- data/spec/censorstrike_spec.rb +32 -0
- data/spec/spec_helper.rb +12 -0
- metadata +92 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Censorstrike
|
2
|
+
|
3
|
+
Censorstrike is a simple Rack Middleware that looks for a certain time window and then short-circuits your application to display a protest message. It was created to make it easy to "go on strike" for the Reddit-led January 18 protest against SOPA and PIPA.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Simply add the gem to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'censorstrike'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then add it as a Rack Middleware in your application. For Rails apps you can create an initializer `config/initializers/censorstrike.rb`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Rails.application.config.middleware.use Censorstrike::Middleware
|
17
|
+
```
|
18
|
+
|
19
|
+
For other Rack apps, you can just use the middleware:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
use Censorstrike::Middleware
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
By default you don't need to supply any arguments and [this message will be displayed](http://intridea.github.com/censorstrike) on January 18 from 8:00am EST to 8:00pm EST. However, you can customize the middleware by passing options like so:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
use Censorstrike::Middleware,
|
31
|
+
:begin => Time.now, # when to start the blackout
|
32
|
+
:end => (Time.now + 500), # when to end the blackout
|
33
|
+
:message => "My HTML", # custom HTML message
|
34
|
+
:file => "/path/to/my/file" # custom HTML file message
|
35
|
+
```
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
Copyright (c) 2012 Intridea, Inc.
|
40
|
+
|
41
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
42
|
+
|
43
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/censorstrike/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Michael Bleigh"]
|
6
|
+
gem.email = ["michael@intridea.com"]
|
7
|
+
gem.description = %q{A middleware to display a message in protest of SOPA/PIPA}
|
8
|
+
gem.summary = %q{A middleware to display a message in protest of SOPA/PIPA}
|
9
|
+
gem.homepage = "https://github.com/intridea/censorstrike"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "censorstrike"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_dependency 'rack'
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
gem.add_development_dependency 'rack-test'
|
20
|
+
|
21
|
+
gem.version = Censorstrike::VERSION
|
22
|
+
end
|
data/lib/censorstrike.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "censorstrike/version"
|
2
|
+
|
3
|
+
module Censorstrike
|
4
|
+
class Middleware
|
5
|
+
def self.default_options
|
6
|
+
{
|
7
|
+
:begin => Time.at(1326891600).utc,
|
8
|
+
:end => Time.at(1326938400).utc,
|
9
|
+
:file => File.dirname(__FILE__) + '/../message.html'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :app, :options
|
14
|
+
|
15
|
+
def initialize(app, options = {})
|
16
|
+
@app = app
|
17
|
+
@options = Censorstrike::Middleware.default_options.merge(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(env)
|
21
|
+
if now > options[:begin] && now < options[:end]
|
22
|
+
render
|
23
|
+
else
|
24
|
+
app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def now
|
29
|
+
Time.now.utc
|
30
|
+
end
|
31
|
+
|
32
|
+
def render
|
33
|
+
response = Rack::Response.new([], 503, 'Content-Type' => 'text/html')
|
34
|
+
body = options[:message] ? options[:message] : File.read(options[:file])
|
35
|
+
response.write(body)
|
36
|
+
response.finish
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/message.html
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We Stand With The Internet Against Censorship</title>
|
5
|
+
<style type='text/css'>
|
6
|
+
@import url(http://fonts.googleapis.com/css?family=Arimo:400,700,400italic,700italic|Oswald);
|
7
|
+
|
8
|
+
h1 {
|
9
|
+
font-family: Oswald, sans-serif;
|
10
|
+
text-align: center;
|
11
|
+
font-size: 4em;
|
12
|
+
text-transform: uppercase;
|
13
|
+
letter-spacing: -0.05em;
|
14
|
+
background: black;
|
15
|
+
margin: 100px -100px 40px;
|
16
|
+
-moz-transform: rotate(-1.5deg);
|
17
|
+
-webkit-transform: rotate(-1.5deg);
|
18
|
+
-ms-transform: rotate(-1.5deg);
|
19
|
+
transform: rotate(-1.5deg);
|
20
|
+
}
|
21
|
+
|
22
|
+
body {
|
23
|
+
font-family: Arimo, sans-serif;
|
24
|
+
background: #333 url(http://subtlepatterns.com/patterns/broken_noise.png);
|
25
|
+
color: #eee;
|
26
|
+
}
|
27
|
+
|
28
|
+
#main_message {
|
29
|
+
width: 700px;
|
30
|
+
margin: 0 auto;
|
31
|
+
font-size: 1.2em;
|
32
|
+
}
|
33
|
+
|
34
|
+
a {
|
35
|
+
font-weight: bold;
|
36
|
+
color: #dff;
|
37
|
+
}
|
38
|
+
|
39
|
+
#small_message {
|
40
|
+
font-size: 0.8em;
|
41
|
+
margin: 0 auto;
|
42
|
+
width: 700px;
|
43
|
+
padding: 6px 0;
|
44
|
+
background: #222;
|
45
|
+
text-align: center;
|
46
|
+
-moz-border-radius: 5px;
|
47
|
+
-webkit-border-radius: 5px;
|
48
|
+
border-radius: 5px;
|
49
|
+
}
|
50
|
+
</style>
|
51
|
+
</head>
|
52
|
+
<body>
|
53
|
+
<h1>We Stand With The Internet</h1>
|
54
|
+
|
55
|
+
<div id='main_message'>
|
56
|
+
<p>We apologize, but our site's normal content will be unavailable until 8pm Eastern time today. We have joined with other communities including <a href='http://reddit.com'>Reddit</a> and <a href='http://wikipedia.org'>Wikipedia</a> in using this one day to send a clear message of protest against legislation that stands to threaten everything amazing that has been built on the internet.</p>
|
57
|
+
|
58
|
+
<p>The Stop Online Piracy Act (SOPA) in the House of Representatives and the Protect Intellectual Property Act (PIPA) in the Senate pose a very real threat to the freedom, collaboration, and openness of the internet. While ostensibly aimed to curtail illegal activities by foreign websites, these bills contain provisions and measures that amount to legal enforcement without due process and, in some cases, could very well damage the infrastructure of the internet as a whole.</p>
|
59
|
+
|
60
|
+
<p>We do not take shutting our site down, even for just one day, lightly. We believe that this issue is one that is too important for us to remain silent. We urge you to learn more about the bill and what you can do to fight it by visiting the <a href='https://action.eff.org/o/9042/p/dia/action/public/?action_KEY=8173'>Electronic Frontier Foundation</a>.</p>
|
61
|
+
</div>
|
62
|
+
|
63
|
+
<div id='small_message'>Do you have a website? Join the protest, <a href='http://github.com/intridea/stand-with-the-internet'>add this message</a> to your own pages!</div>
|
64
|
+
</body>
|
65
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Censorstrike::Middleware do
|
4
|
+
let(:base){ lambda{|env| [200, {}, ["Hello world."]]} }
|
5
|
+
let(:options){ {} }
|
6
|
+
let(:app) do
|
7
|
+
b = Rack::Builder.new
|
8
|
+
b.use Censorstrike::Middleware, options
|
9
|
+
b.run base
|
10
|
+
b.to_app
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should render the app outside the time window' do
|
14
|
+
get '/'
|
15
|
+
last_response.status.should == 200
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'in the window' do
|
19
|
+
before{ options.merge!(:begin => (Time.now - 500), :end => (Time.now + 500)) }
|
20
|
+
|
21
|
+
it 'should render with a 503 inside the window' do
|
22
|
+
get '/'
|
23
|
+
last_response.status.should == 503
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should render :message if one is supplied' do
|
27
|
+
options.merge!(:message => 'Down with censorship!')
|
28
|
+
get '/'
|
29
|
+
last_response.body.should == 'Down with censorship!'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.push File.dirname(__FILE__) + "/../lib"
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'censorstrike'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.include Rack::Test::Methods
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: censorstrike
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Bleigh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-17 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &70345414450420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70345414450420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70345414449780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70345414449780
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rack-test
|
38
|
+
requirement: &70345414443420 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70345414443420
|
47
|
+
description: A middleware to display a message in protest of SOPA/PIPA
|
48
|
+
email:
|
49
|
+
- michael@intridea.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- Gemfile
|
57
|
+
- Guardfile
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- censorstrike.gemspec
|
61
|
+
- lib/censorstrike.rb
|
62
|
+
- lib/censorstrike/version.rb
|
63
|
+
- message.html
|
64
|
+
- spec/censorstrike_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/intridea/censorstrike
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.10
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: A middleware to display a message in protest of SOPA/PIPA
|
90
|
+
test_files:
|
91
|
+
- spec/censorstrike_spec.rb
|
92
|
+
- spec/spec_helper.rb
|