From 3cc26eb919cd08b4f88b262a221384c6f5a87c29 Mon Sep 17 00:00:00 2001 From: Dev Purkayastha Date: Wed, 4 Nov 2009 12:01:02 -0500 Subject: [PATCH] customize block list with a .rc file --- README.textile | 4 +++- b-productive.rb | 20 ++++++++++++++++++-- productity_ftwrc.sample | 3 +++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 productity_ftwrc.sample diff --git a/README.textile b/README.textile index 4d5c725..5d9398a 100644 --- a/README.textile +++ b/README.textile @@ -12,11 +12,13 @@ and fire off the productivity enhancing server: sudo ruby productivity_ftw.rb +(you'll probably need to install the bjeanes-ghost gem first) + note that you *have to use sudo* cause you are taking over port 80, not sure if it's required on windows also. h2. Adding more hosts to block -open the b-productive.rb file and add to the BLOCK_LIST host array, a better solution is welcome, i am just lazy. +To create your own blocklist, create a ~/.productivity_ftwrc file in your home directory. See productivity_ftwrc.sample for an example of the right format. h2. "Thank you"s diff --git a/b-productive.rb b/b-productive.rb index 33850f9..15ed39d 100644 --- a/b-productive.rb +++ b/b-productive.rb @@ -4,13 +4,29 @@ class Productivity require 'rubygems' begin - gem 'ghost' + gem 'bjeanes-ghost' require 'ghost' rescue Gem::LoadError puts "you need to install the ghost gem from http://github.com/bjeanes/ghost" end + + # Format of .productivity_ftwrc (saved in home dir): + # - Each line is a space-separated list of one or more words. + # - First word is the base of the subdomain. + # - If not qualified with .com/.net/.org, assumed to be .com + # - The www. prefix is assumed to be blocked. + # - subsequent words are subdomains to block. + productivity_ftwrc = "#{ENV['HOME']}/.productivity_ftwrc" + if File.exists?(productivity_ftwrc) + BLOCK_LIST = File.read(productivity_ftwrc).split("\n").map do |domain, subdomains| + domain += ".com" unless domain =~ /\.(org|net|com)/ + subdomains ||= [] + ["#{domain}", "www.#{domain}"] + subdomains.map{|subdomain| "#{subdomain}.#{domain}"} + end.flatten + else + BLOCK_LIST = ["facebook.com", "www.facebook.com", "www.twitter.com", "api.twitter.com", "twitter.com"] + end - BLOCK_LIST = ["facebook.com", "www.facebook.com", "www.twitter.com", "api.twitter.com", "twitter.com"] ALLOWED_ACTIONS = ["start", "stop"] def self.start diff --git a/productity_ftwrc.sample b/productity_ftwrc.sample new file mode 100644 index 0000000..43adbb7 --- /dev/null +++ b/productity_ftwrc.sample @@ -0,0 +1,3 @@ +twitter api search +facebook.com +mls-rumors.net \ No newline at end of file