Created
August 24, 2010 20:38
-
-
Save paulsmith/548270 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# | |
# ~ liberty.sh ~ | |
# | |
# Linux port of the Freedom network-disabling software for Mac & Win: | |
# http://macfreedom.com/ | |
# | |
# It is a Linux version of beloved Mac/Win software, therefore it is | |
# appropriately obscure and hard to use (but free!). | |
# | |
# Usage: | |
# | |
# Save this file to a directory on your computer, open a terminal, cd | |
# to the directory, chmod +x liberty.sh, and run it like so: | |
# | |
# $ sudo ./liberty.sh | |
# | |
# liberty.sh will prompt you for the length of time in minutes you'd | |
# like to be liberated from your Internet connection. | |
# | |
# If you'd like to have liberty.sh run without interactive prompting, | |
# you can simply pipe the number of minutes as standard input to | |
# liberty.sh: | |
# | |
# $ echo 60 | sudo ./liberty.sh | |
# | |
# You can also echo empty standard input and it will select a sensible | |
# default: | |
# | |
# $ echo | sudo ./liberty.sh | |
# | |
# You can confirm that liberty.sh is doing its thing by inspecting | |
# the iptables rules for the OUTPUT chain: | |
# | |
# $ sudo iptables -L -n | |
# | |
# liberty.sh creates two `at(1)' jobs to be run when the liberation | |
# time has expired. You can confirm this by typing: | |
# | |
# $ sudo atq | |
# | |
# liberty.sh doesn't disable *all* of your networking -- it leaves | |
# your loopback interface (lo0) alone, allowing you to continue to use | |
# the services on your local machine. You can keep developing that web | |
# app without distraction. | |
# | |
# Note that your humble author has not actually *used* Freedom, so | |
# liberty.sh emulates only as many features as he could see from | |
# screenshots on the Freedom site (minus the GUI, of course!). | |
DEFAULT_MINUTES=45 | |
MAX_MINUTES=480 | |
MIN_MINUTES=15 | |
IPTABLES_RULE="-j DROP" | |
# Uncomment the following if you'd prefer a less strict networking | |
# disabling that merely knocks out browsing to common WWW ports. | |
# IPTABLES_RULE="-p tcp -m multiport --dports 80,443 -j DROP" | |
if [ "$(id -u)" != "0" ]; then | |
echo "Please run $0 as root (or sudo)." 1>&2 | |
exit 1 | |
fi | |
prompt_minutes () { | |
echo "How many minutes of liberty would you like?" | |
echo "(default = $DEFAULT_MINUTES, minimum = $MIN_MINUTES, maximum = $MAX_MINUTES)" | |
echo -n "Enter # of minutes: " | |
} | |
is_int () { | |
test "$1" -eq "$1" >/dev/null 2>&1 | |
} | |
echo | |
echo " ~ $(basename $0) will disable your Linux networking for up to 8 hours (480 minutes). ~" | |
echo | |
MINUTES=0 | |
while : | |
do | |
prompt_minutes | |
read MINUTES | |
if is_int "$MINUTES"; then | |
if [ "$MINUTES" -ge "$MIN_MINUTES" -a "$MINUTES" -le "$MAX_MINUTES" ]; then | |
break | |
fi | |
elif [ "x$MINUTES" = "x" ]; then | |
MINUTES=$DEFAULT_MINUTES | |
break | |
fi | |
done | |
echo "iptables -D OUTPUT -d 127.0.0.1 -j ACCEPT" | at "now + $MINUTES minutes" >/dev/null 2>&1 | |
echo "iptables -D OUTPUT $IPTABLES_RULE" | at "now + $MINUTES minutes" >/dev/null 2>&1 | |
iptables -A OUTPUT -d 127.0.0.1 -j ACCEPT | |
iptables -A OUTPUT $IPTABLES_RULE | |
echo | |
echo "You've been liberated for the next $MINUTES minutes. Happiness." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment