This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 9th, 2013  |  syntax: None  |  size: 2.24 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env bash
  2. ## (C) George Goulas, 2011
  3. ##
  4. ## Proxy service configuration script for OSX
  5. ## tested on MacOSX Lion 10.6
  6. ##
  7.  
  8. ## SETTINGS
  9. ##
  10. # SOCKS PROXY PORT
  11. PORT=4242
  12. # SSH OPTIONS TO CREATE PROXY
  13. SSH_OPTS="-C2qTnNfD"
  14. # [label]=user@host (don't make one called "status" or "off")
  15. declare -A SSH_HOST
  16. SSH_HOST[seas]="USERNAME@eniac.seas.upenn.edu"
  17. # SSH PORT
  18. SSH_PORT=22
  19. # OSX network service to configure proxy for
  20. NET_SERVICE="wi-fi"
  21. # Verbose, if not empty, it prints diagnosing messages
  22. VERBOSE=1
  23. ##
  24. ## END OF SETTINGS, DO NOT MODIFY PAST THIS POINT
  25. ##
  26.  
  27. function report {
  28.     MSG=$1
  29.     if [ -n "${VERBOSE}" ]; then
  30.         echo $MSG
  31.     fi
  32. }
  33.  
  34. function enableProxy {
  35.     sudo networksetup  -setsocksfirewallproxy ${NET_SERVICE} localhost ${PORT}
  36.     sudo networksetup  -setsocksfirewallproxystate ${NET_SERVICE} on
  37.     ${SSH_CMD}
  38. }
  39.  
  40. function disableProxy {
  41.     ps -ax | grep "${SSH_CMD}" | grep -v grep | awk '{print $1}'| xargs kill
  42.     sudo networksetup  -setsocksfirewallproxystate ${NET_SERVICE} off
  43. }
  44.  
  45. function showStatus {
  46.     ps -ax | grep "${SSH_CMD}" | grep -v grep > /dev/null
  47.     if [ $? -eq 0 ]; then
  48.         echo SSH SOCKS Proxy status: ON
  49.     else
  50.         echo SSH SOCKS Proxy status: OFF
  51.     fi
  52.     sudo networksetup -getsocksfirewallproxy ${NET_SERVICE} | grep Enabled | grep Yes > /dev/null
  53.     if [ $? -eq 0 ]; then
  54.         echo Proxy setting in network setup for ${NET_SERVICE}: ON
  55.     else
  56.         echo Proxy setting in network setup for ${NET_SERVICE}: OFF
  57.     fi
  58. }
  59.  
  60. case "$1" in
  61.  
  62.     off)
  63.         report "Disabling Proxy"
  64.         SSH_CMD="ssh ${SSH_OPTS} ${PORT} -p ${SSH_PORT}"
  65.         disableProxy
  66.         ;;
  67.  
  68.     status)
  69.         echo status
  70.         SSH_CMD="ssh ${SSH_OPTS} ${PORT} -p ${SSH_PORT}"
  71.         showStatus
  72.         ;;
  73.  
  74.     "")
  75.         echo "Options: [proxy name] to enable proxy, off to disable, status to see status."
  76.         ;;
  77.  
  78.     *)
  79.         if [ -z ${SSH_HOST[$1]} ]
  80.         then
  81.             echo "Options: [proxy name] to enable proxy, off to disable, status to see status."
  82.         else
  83.             report "Enabling Proxy"
  84.             SSH_CMD="ssh ${SSH_OPTS} ${PORT} -p ${SSH_PORT} ${SSH_HOST[$1]}"
  85.             enableProxy
  86.         fi
  87.         ;;
  88.  
  89. esac
clone this paste RAW Paste Data