Skip to content

Instantly share code, notes, and snippets.

@benubois
Created September 13, 2012 22:53
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benubois/3718344 to your computer and use it in GitHub Desktop.
Save benubois/3718344 to your computer and use it in GitHub Desktop.
Enable and disable the pow firewall rule for Cisco AnyConnect
#!/usr/bin/env bash
# Set up the environment.
set -e
POW_ROOT="$HOME/Library/Application Support/Pow"
POW_CURRENT_PATH="$POW_ROOT/Current"
POW_VERSIONS_PATH="$POW_ROOT/Versions"
POWD_PLIST_PATH="$HOME/Library/LaunchAgents/cx.pow.powd.plist"
FIREWALL_PLIST_PATH="/Library/LaunchDaemons/cx.pow.firewall.plist"
# Read the firewall plist, if possible, to figure out what ports are in use.
if [[ -a "$FIREWALL_PLIST_PATH" ]]; then
ports=($(ruby -e'puts $<.read.scan(/fwd .*?,([\d]+).*?dst-port ([\d]+)/)' "$FIREWALL_PLIST_PATH"))
HTTP_PORT=${ports[0]}
DST_PORT=${ports[1]}
fi
# Assume reasonable defaults otherwise.
[[ -z "$HTTP_PORT" ]] && HTTP_PORT=20559
[[ -z "$DST_PORT" ]] && DST_PORT=80
case $1 in
"enable")
sudo ipfw add fwd 127.0.0.1,$HTTP_PORT tcp from any to me dst-port $DST_PORT in && sysctl -w net.inet.ip.forwarding=1
;;
"disable")
# Try to find the ipfw rule and delete it.
RULE=$(sudo ipfw show | (grep ",$HTTP_PORT .* dst-port $DST_PORT in" || true) | cut -f 1 -d " ")
[[ -n "$RULE" ]] && sudo ipfw del "$RULE"
;;
*)
echo "Usage pow <action>"
echo ""
echo " enable"
echo " disable"
;;
esac
@cliftonlabrum
Copy link

Forgive my ignorance, but is the above something one should execute once as a bash script, or is this to be added to ~/.powconfig or something?

@cliftonlabrum
Copy link

Disregard. I got it to work. :)

@bbohling
Copy link

What did you do to get it to work?

@cliftonlabrum
Copy link

Here's what I did:

  1. Save the above code to pow.sh
  2. In Terminal, browse to where you saved that script.
  3. Then type ./pow.sh disable

@cliftonlabrum
Copy link

It seems I have to do this every time I reboot my computer, though. Is there a permanent way to delete the ipfw rule?

@weyus
Copy link

weyus commented Oct 2, 2014

Wait, is this to allow the firewall rule to work alongside Cisco AnyConnect (which seems to disable it by default), or is there some other purpose?

@andreineculau
Copy link

hmm ipfw got removed in yosemite..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment