Skip to content
Browse files

Initial import.

  • Loading branch information...
0 parents commit 9e730d8c0beed429c49d83fbdd9ad598242f4897 Michael Bleigh committed Jan 17, 2012
Showing with 258 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +2 −0 .rspec
  3. +8 −0 Gemfile
  4. +6 −0 Guardfile
  5. +45 −0 README.md
  6. +7 −0 Rakefile
  7. +22 −0 censorstrike.gemspec
  8. +39 −0 lib/censorstrike.rb
  9. +3 −0 lib/censorstrike/version.rb
  10. +65 −0 message.html
  11. +32 −0 spec/censorstrike_spec.rb
  12. +12 −0 spec/spec_helper.rb
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
8 Gemfile
@@ -0,0 +1,8 @@
+source 'http://rubygems.org'
+
+# Specify your gem's dependencies in censorstrike.gemspec
+gemspec
+
+gem 'guard'
+gem 'guard-rspec'
+gem 'growl'
6 Guardfile
@@ -0,0 +1,6 @@
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
+
45 README.md
@@ -0,0 +1,45 @@
+# Censorstrike
+
+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.
+
+## Usage
+
+Simply add the gem to your `Gemfile`:
+
+```ruby
+gem 'censorstrike'
+```
+
+And then add it as a Rack Middleware in your application. For Rails apps you can create an initializer `config/initializers/censorstrike.rb`:
+
+```ruby
+Rails.application.config.middleware.use Censorstrike::Middleware
+```
+
+For other Rack apps, you can just use the middleware:
+
+```ruby
+use Censorstrike::Middleware
+```
+
+## Configuration
+
+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:
+
+```ruby
+use Censorstrike::Middleware,
+ :begin => Time.now, # when to start the blackout
+ :end => (Time.now + 500), # when to end the blackout
+ :message => "My HTML", # custom HTML message
+ :file => "/path/to/my/file" # custom HTML file message
+```
+
+## License
+
+Copyright (c) 2012 Intridea, Inc.
+
+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:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+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.
7 Rakefile
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new
+
+task :default => :spec
22 censorstrike.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/censorstrike/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["TODO: Write your name"]
+ gem.email = ["michael@intridea.com"]
+ gem.description = %q{TODO: Write a gem description}
+ gem.summary = %q{TODO: Write a gem summary}
+ gem.homepage = ""
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "censorstrike"
+ gem.require_paths = ["lib"]
+
+ gem.add_dependency 'rack'
+ gem.add_development_dependency 'rspec'
+ gem.add_development_dependency 'rack-test'
+
+ gem.version = Censorstrike::VERSION
+end
39 lib/censorstrike.rb
@@ -0,0 +1,39 @@
+require "censorstrike/version"
+
+module Censorstrike
+ class Middleware
+ def self.default_options
+ {
+ :begin => Time.at(1326891600).utc,
+ :end => Time.at(1326938400).utc,
+ :file => File.dirname(__FILE__) + '/../message.html'
+ }
+ end
+
+ attr_reader :app, :options
+
+ def initialize(app, options = {})
+ @app = app
+ @options = Censorstrike::Middleware.default_options.merge(options)
+ end
+
+ def call(env)
+ if now > options[:begin] && now < options[:end]
+ render
+ else
+ app.call(env)
+ end
+ end
+
+ def now
+ Time.now.utc
+ end
+
+ def render
+ response = Rack::Response.new([], 503, 'Content-Type' => 'text/html')
+ body = options[:message] ? options[:message] : File.read(options[:file])
+ response.write(body)
+ response.finish
+ end
+ end
+end
3 lib/censorstrike/version.rb
@@ -0,0 +1,3 @@
+module Censorstrike
+ VERSION = "0.0.1"
+end
65 message.html
@@ -0,0 +1,65 @@
+<!doctype html>
+<html>
+ <head>
+ <title>We Stand With The Internet Against Censorship</title>
+ <style type='text/css'>
+ @import url(http://fonts.googleapis.com/css?family=Arimo:400,700,400italic,700italic|Oswald);
+
+ h1 {
+ font-family: Oswald, sans-serif;
+ text-align: center;
+ font-size: 4em;
+ text-transform: uppercase;
+ letter-spacing: -0.05em;
+ background: black;
+ margin: 100px -100px 40px;
+ -moz-transform: rotate(-1.5deg);
+ -webkit-transform: rotate(-1.5deg);
+ -ms-transform: rotate(-1.5deg);
+ transform: rotate(-1.5deg);
+ }
+
+ body {
+ font-family: Arimo, sans-serif;
+ background: #333 url(http://subtlepatterns.com/patterns/broken_noise.png);
+ color: #eee;
+ }
+
+ #main_message {
+ width: 700px;
+ margin: 0 auto;
+ font-size: 1.2em;
+ }
+
+ a {
+ font-weight: bold;
+ color: #dff;
+ }
+
+ #small_message {
+ font-size: 0.8em;
+ margin: 0 auto;
+ width: 700px;
+ padding: 6px 0;
+ background: #222;
+ text-align: center;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+ }
+</style>
+ </head>
+ <body>
+ <h1>We Stand With The Internet</h1>
+
+ <div id='main_message'>
+ <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>
+
+ <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>
+
+ <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>
+ </div>
+
+ <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>
+ </body>
+</html>
32 spec/censorstrike_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe Censorstrike::Middleware do
+ let(:base){ lambda{|env| [200, {}, ["Hello world."]]} }
+ let(:options){ {} }
+ let(:app) do
+ b = Rack::Builder.new
+ b.use Censorstrike::Middleware, options
+ b.run base
+ b.to_app
+ end
+
+ it 'should render the app outside the time window' do
+ get '/'
+ last_response.status.should == 200
+ end
+
+ context 'in the window' do
+ before{ options.merge!(:begin => (Time.now - 500), :end => (Time.now + 500)) }
+
+ it 'should render with a 503 inside the window' do
+ get '/'
+ last_response.status.should == 503
+ end
+
+ it 'should render :message if one is supplied' do
+ options.merge!(:message => 'Down with censorship!')
+ get '/'
+ last_response.body.should == 'Down with censorship!'
+ end
+ end
+end
12 spec/spec_helper.rb
@@ -0,0 +1,12 @@
+$:.push File.dirname(__FILE__) + "/../lib"
+
+require 'rspec'
+require 'censorstrike'
+require 'rack/test'
+
+RSpec.configure do |config|
+ config.include Rack::Test::Methods
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+end

0 comments on commit 9e730d8

Please sign in to comment.
Something went wrong with that request. Please try again.