Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- ## (C) George Goulas, 2011
- ##
- ## Proxy service configuration script for OSX
- ## tested on MacOSX Lion 10.6
- ##
- ## SETTINGS
- ##
- # SOCKS PROXY PORT
- PORT=4242
- # SSH OPTIONS TO CREATE PROXY
- SSH_OPTS="-C2qTnNfD"
- # [label]=user@host (don't make one called "status" or "off")
- declare -A SSH_HOST
- SSH_HOST[seas]="USERNAME@eniac.seas.upenn.edu"
- # SSH PORT
- SSH_PORT=22
- # OSX network service to configure proxy for
- NET_SERVICE="wi-fi"
- # Verbose, if not empty, it prints diagnosing messages
- VERBOSE=1
- ##
- ## END OF SETTINGS, DO NOT MODIFY PAST THIS POINT
- ##
- function report {
- MSG=$1
- if [ -n "${VERBOSE}" ]; then
- echo $MSG
- fi
- }
- function enableProxy {
- sudo networksetup -setsocksfirewallproxy ${NET_SERVICE} localhost ${PORT}
- sudo networksetup -setsocksfirewallproxystate ${NET_SERVICE} on
- ${SSH_CMD}
- }
- function disableProxy {
- ps -ax | grep "${SSH_CMD}" | grep -v grep | awk '{print $1}'| xargs kill
- sudo networksetup -setsocksfirewallproxystate ${NET_SERVICE} off
- }
- function showStatus {
- ps -ax | grep "${SSH_CMD}" | grep -v grep > /dev/null
- if [ $? -eq 0 ]; then
- echo SSH SOCKS Proxy status: ON
- else
- echo SSH SOCKS Proxy status: OFF
- fi
- sudo networksetup -getsocksfirewallproxy ${NET_SERVICE} | grep Enabled | grep Yes > /dev/null
- if [ $? -eq 0 ]; then
- echo Proxy setting in network setup for ${NET_SERVICE}: ON
- else
- echo Proxy setting in network setup for ${NET_SERVICE}: OFF
- fi
- }
- case "$1" in
- off)
- report "Disabling Proxy"
- SSH_CMD="ssh ${SSH_OPTS} ${PORT} -p ${SSH_PORT}"
- disableProxy
- ;;
- status)
- echo status
- SSH_CMD="ssh ${SSH_OPTS} ${PORT} -p ${SSH_PORT}"
- showStatus
- ;;
- "")
- echo "Options: [proxy name] to enable proxy, off to disable, status to see status."
- ;;
- *)
- if [ -z ${SSH_HOST[$1]} ]
- then
- echo "Options: [proxy name] to enable proxy, off to disable, status to see status."
- else
- report "Enabling Proxy"
- SSH_CMD="ssh ${SSH_OPTS} ${PORT} -p ${SSH_PORT} ${SSH_HOST[$1]}"
- enableProxy
- fi
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement