Advertisement
Guest User

Untitled

a guest
Oct 27th, 2017
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. #!/opt/bin/bash
  2. #
  3. # Enable port forwarding when using Private Internet Access
  4. #
  5. # Usage:
  6. # ./port_forwarding.sh
  7. set -x
  8. exec 5>/etc/openvpn/mylog
  9. BASH_XTRACEFD="5"
  10. PS4='$LINENO: '
  11.  
  12. TRANSUSER=me
  13. TRANSPASS=mypass
  14. TRANSHOST=192.168.1.251
  15.  
  16. /bin/echo waiting 20s for vpn to connect and trasmission to start
  17. sleep 20
  18.  
  19. error( )
  20. {
  21. /bin/echo "$@" 1>&2
  22. exit 1
  23. }
  24.  
  25. error_and_usage( )
  26. {
  27. /bin/echo "$@" 1>&2
  28. usage_and_exit 1
  29. }
  30.  
  31. usage( )
  32. {
  33. /bin/echo "Usage: `dirname $0`/$PROGRAM"
  34. }
  35.  
  36. usage_and_exit( )
  37. {
  38. usage
  39. exit $1
  40. }
  41.  
  42. version( )
  43. {
  44. /bin/echo "$PROGRAM version $VERSION"
  45. }
  46.  
  47.  
  48. port_forward_assignment( )
  49. {
  50. client_id_file="/etc/openvpn/pia_client_id"
  51. if [ ! -f "$client_id_file" ]; then
  52. if hash /opt/bin/shasum 2>/dev/null; then
  53. /usr/bin/head -n 100 /dev/urandom | /opt/bin/shasum -a 256 | tr -d " -" > "$client_id_file"
  54. elif hash /opt/bin/sha256sum 2>/dev/null; then
  55. /usr/bin/head -n 100 /dev/urandom | /opt/bin/sha256sum | tr -d " -" > "$client_id_file"
  56. else
  57. /bin/echo "Please install shasum or sha256sum, and make sure it is visible in your $PATH"
  58. exit 1
  59. fi
  60. fi
  61. client_id=`/bin/cat "$client_id_file"`
  62. json=`/opt/bin/curl "http://209.222.18.222:2000/?client_id=$client_id" 2>/dev/null`
  63. if [ "$json" == "" ]; then
  64. json='Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding'
  65. fi
  66.  
  67. /bin/echo server returned message: $json
  68.  
  69. #trim VPN forwarded port from JSON
  70. PORT=$(echo $json | /usr/bin/awk 'BEGIN{r=1;FS="[{}":]+"} /port/{r=0; print $3} END{exit r}')
  71. /bin/echo if succesful port is:$PORT
  72.  
  73. #change transmission port on the fly
  74.  
  75. /opt/bin/transmission-remote $TRANSHOST --auth $TRANSUSER:$TRANSPASS -p "$PORT"
  76. /bin/echo your transmission details: $TRANSHOST $TRANSUSER $TRANSPASS
  77. }
  78.  
  79. /bin/echo remember to reconnect to VPN before running this script. Run no longer than 2 minutes after connection or this will fail!
  80.  
  81. EXITCODE=0
  82. PROGRAM=`basename $0`
  83. VERSION=2.1
  84.  
  85. while /usr/bin/test $# -gt 0
  86. do
  87. case $1 in
  88. --usage | --help | -h )
  89. usage_and_exit 0
  90. ;;
  91. --version | -v )
  92. version
  93. exit 0
  94. ;;
  95. *)
  96. error_and_usage "Unrecognised option: $1"
  97. ;;
  98. esac
  99. shift
  100. done
  101.  
  102. port_forward_assignment
  103.  
  104. exit 0
  105.  
  106. + PS4='$LINENO: '
  107. 12: TRANSUSER=me
  108. 13: TRANSPASS=mypass
  109. 14: TRANSHOST=192.168.1.251
  110. 16: /bin/echo waiting 20s for vpn to connect and trasmission to start
  111. 17: sleep 20
  112. 79: /bin/echo remember to reconnect to VPN before running this script. Run no longer than 2 minutes after connection or this will 'fail!'
  113. 81: EXITCODE=0
  114. 882: basename /etc/openvpn/test.sh
  115. 82: PROGRAM=test.sh
  116. 83: VERSION=2.1
  117. 85: /usr/bin/test 1 -gt 0
  118. 87: case $1 in
  119. 96: error_and_usage 'Unrecognized option: [AF_INET]45.136.190.211 1198'
  120. 27: /bin/echo 'Unrecognized option: [AF_INET]46.136.190.211 1198'
  121. 28: usage_and_exit 1
  122. 38: usage
  123. 333: dirname /etc/openvpn/test.sh
  124. 33: /bin/echo 'Usage: /etc/openvpn/test.sh'
  125. 39: exit 1
  126.  
  127. + PS4='$LINENO: '
  128. 12: TRANSUSER=me
  129. 13: TRANSPASS=mypass
  130. 14: TRANSHOST=192.168.1.251
  131. 16: /bin/echo waiting 20s for vpn to connect and trasmission to start
  132. 17: sleep 20
  133. 79: /bin/echo remember to reconnect to VPN before running this script. Run no longer than 2 minutes after connection or this will 'fail!'
  134. 81: EXITCODE=0
  135. 882: basename ./test.sh
  136. 82: PROGRAM=test.sh
  137. 83: VERSION=2.1
  138. 85: /usr/bin/test 0 -gt 0
  139. 102: port_forward_assignment
  140. 50: client_id_file=/etc/openvpn/pia_client_id
  141. 51: '[' '!' -f /etc/openvpn/pia_client_id ']'
  142. 661: /bin/cat /etc/openvpn/pia_client_id
  143. 61: client_id=080db0a6e936918d405683447a78bf426223e9a1ea2ecce744722ac3241d4232
  144. 662: /opt/bin/curl 'http://209.222.18.222:2000/?client_id=080db0a6e936918d405683447a78bf426273e9a1ea2ecce744722ac3241d4232'
  145. 62: json='{"port":44257}'
  146. 63: '[' '{"port":44257}' == '' ']'
  147. 67: /bin/echo server returned message: '{"port":44257}'
  148. 770: echo '{"port":44257}'
  149. 770: /usr/bin/awk 'BEGIN{r=1;FS="[{}":]+"} /port/{r=0; print $3} END{exit r}'
  150. 70: PORT=44257
  151. 71: /bin/echo if successful port is:44257
  152. 75: /opt/bin/transmission-remote 192.168.1.251 --auth me:mypass -p 44257
  153. 76: /bin/echo your transmission details: 192.168.1.251 me mypass
  154. 104: exit 0
  155.  
  156. # Automatically generated configuration
  157. daemon
  158. client
  159. dev tun11
  160. proto udp
  161. remote nl.privateinternetaccess.com 1198
  162. resolv-retry 30
  163. nobind
  164. persist-key
  165. persist-tun
  166. comp-lzo adaptive
  167. ncp-ciphers AES-128-GCM:AES-256-GCM:AES-128-CBC:AES-256-CBC
  168. cipher AES-128-CBC
  169. redirect-gateway def1
  170. verb 3
  171. script-security 2
  172. up updown.sh
  173. down updown.sh
  174. ca ca.crt
  175. status-version 2
  176. status status
  177.  
  178. # Custom Configuration
  179. syslog [progname]
  180. persist-key
  181. persist-tun
  182. tls-client
  183. auth-user-pass /tmp/password.txt
  184. comp-lzo
  185. verb 3
  186. reneg-sec 0
  187. ipchange "/etc/openvpn/test.sh"
  188. script-security 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement