Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Fix network routing issues caused by Cisco AnyConnect VPN when using
  4. # VirtualBox and boot2docker on Mac OS X.
  5. #
  6. # Environment:
  7. # Mac OS X 10.9.5
  8. # VirtualBox 4.3.20
  9. # Cisco AnyConnect 3.1.04074
  10. # boot2docker v1.4.1 (Git commit: 43241cb)
  11.  
  12. [ $(id -u) = 0 ] || { echo "You must be root (or use 'sudo')" ; exit 1; }
  13.  
  14. : ${VPN_HOST:?"Need to set VPN_HOST"}
  15. : ${VPN_USER:?"Need to set VPN_USER"}
  16.  
  17. CISCO_PATH=$(dirname $(find /opt/cisco -depth -name vpnagentd))
  18. : ${CISCO_PATH:?"Can't find Cisco path"}
  19. VPN="$CISCO_PATH/vpn"
  20.  
  21. fwrule=`ipfw -a list | grep "deny ip from any to any"`
  22. fwrule_id=`echo $fwrule | awk '{ print $1 }'`
  23. if [ "$fwrule" != "" ]; then
  24. echo "Found blocking firewall rule: $(tput setaf 1)${fwrule}$(tput sgr0)"
  25. printf "Deleting rule ${fwrule_id} ... "
  26. ipfw delete ${fwrule_id}
  27. if [ $? == 0 ]; then
  28. echo "$(tput setaf 2)[OK]$(tput sgr0)"
  29. else
  30. echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
  31. exit 1
  32. fi
  33. else
  34. echo "No blocking firewall rules found."
  35. fi
  36.  
  37. # Add route to be able to connect to boot2docker VM
  38. docker_interface=$(sudo -u $(logname) VBoxManage showvminfo boot2docker-vm | grep -o -E 'vboxnet\d\d?')
  39. if [ -z "${docker_interface}" ]; then
  40. echo "No docker VM found"
  41. exit 1
  42. else
  43. echo "Found docker interface at $(tput setaf 1)${docker_interface}$(tput sgr0). Updating routes ..."
  44.  
  45. # Disconnect Cisco VPN because it does not allow changes to route table
  46. echo "Disconnecting VPN ..."
  47. "$VPN" disconnect > /dev/null
  48.  
  49. current_route=$(netstat -rn | grep 192.168.59)
  50. if [ -z "${current_route}" ]; then
  51. # no route, let's add it!
  52. route -nv add -net 192.168.59 -interface ${docker_interface} > /dev/null
  53. else
  54. route -nv change -net 192.168.59 -interface ${docker_interface} > /dev/null
  55. fi
  56.  
  57. if [ $? == 0 ]; then
  58. echo "$(tput setaf 2)[OK]$(tput sgr0)"
  59. else
  60. echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
  61. exit 1
  62. fi
  63. netstat -rn | grep 192.168.59
  64.  
  65. # Reconnect VPN, get password from keychain
  66. echo "Reconnecting VPN ..."
  67. echo -e "$VPN_USER\n$(security find-generic-password -s AnyConnect -w)" | "$VPN" -s connect $VPN_HOST >/dev/null
  68. fi
  69.  
  70. "$VPN" state
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement