Skip to content

Commit

Permalink
Implement the new port forwarding API
Browse files Browse the repository at this point in the history
  • Loading branch information
pschmitt committed Feb 4, 2017
1 parent 6eb20c2 commit 3b327c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
22 changes: 6 additions & 16 deletions pia-tools
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ fi
usage() {
echo "Usage: $1 [-p|r] [-a|d] [-u] [-c] [-h]"
echo "-p: Request new port"
echo "-r: Refresh (request port forwarding again) [default]"
echo "-a: Block non VPN traffic (iptables)"
echo "-d: Unblock non VPN traffic (iptables) [default]"
echo "-g: Use PIA DNS (updates resolv.conf)"
Expand Down Expand Up @@ -203,24 +202,20 @@ transmission_peer_port_update() {

# Return a new client ID
new_client_id() {
head -n 100 /dev/urandom | md5sum | tr -d " -" | tee $PIA_CLIENT_ID_FILE
head -n 100 /dev/urandom | sha256sum | tr -d " -" | tee $PIA_CLIENT_ID_FILE
}

request_port() {
local username="$(head -1 $PIA_PASSWD_FILE)"
local passwd="$(tail -1 $PIA_PASSWD_FILE)"
local local_vpn_ip="$(ip addr show $VIRT_NET_DEV | awk '/inet / { print $2; exit}')"
local client_id="$1"
[[ -z "$local_vpn_ip" ]] && local_vpn_ip=$LOCAL_IP
echo -n "Updating port forwarding... "
if test "$VERBOSE"; then
echo "Username: $username"
echo "Client ID: $client_id"
echo "VPN local IP: $local_vpn_ip"
fi
PIA_OPEN_PORT_NEW="$(\
curl -Ld "user=$username&pass=$passwd&client_id=$client_id&local_ip=$local_vpn_ip" \
https://www.privateinternetaccess.com/vpninfo/port_forward_assignment \
curl -qqs http://209.222.18.222:2000/?client_id=$client_id \
| grep -oE "[0-9]+" 2>&1)"
if test "$PIA_OPEN_PORT_NEW"; then
echo "$PIA_OPEN_PORT_NEW" > "$PIA_OPEN_PORT_FILE"
Expand Down Expand Up @@ -335,18 +330,18 @@ restore_dns() {
mv -f /etc/resolv.conf.orig /etc/resolv.conf
}

# If no option -> refresh
# If no option -> portfwd
if [[ $# -eq 0 ]]; then
action_port=refresh
action_port=portfwd
#action_fw=disallow
fi

# Every function except help needs root permissions
check_root "$*"

ARGS=$(getopt -o "adprfguscihv" \
ARGS=$(getopt -o "adpfguscihv" \
-l "allow,disallow,\
port,refresh,pia-dns,google-dns,restore-dns,\
port,pia-dns,google-dns,restore-dns,\
restore,force,check,\
update,setup,info,help,verbose" \
-n "$0" -- "$@")
Expand All @@ -372,11 +367,6 @@ while true; do
action_port=portfwd
shift
;;
-r|--refresh)
test "$action_port" && exit 1
action_port=refresh
shift
;;
-g|--pia-dns)
test "$action_dns" && exit 1
action_dns=pia
Expand Down
3 changes: 0 additions & 3 deletions pia-tools.groff
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ Script to automate privateinternetacces port forwarding and starting/stopping tr
\fB\-p\fR, \fB \-\-port\fR
Request a new forwarding port
.TP
\fB\-r\fR, \fB \-\-refresh\fR
Request port forwarding [default]
.TP
\fB\-a\fR, \fB \-\-allow\fR
Unblock all non-VPN traffic [default]
.TP
Expand Down

0 comments on commit 3b327c4

Please sign in to comment.