mirror of
https://github.com/boringproxy/boringproxy.git
synced 2025-02-25 18:55:29 -06:00
Add tunnel creation script
This commit is contained in:
parent
03baac2c7b
commit
bf54f27815
35
tunnel.sh
Executable file
35
tunnel.sh
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
server=$1
|
||||||
|
token=$2
|
||||||
|
domain=$3
|
||||||
|
localPort=$4
|
||||||
|
|
||||||
|
api="https://$server/api"
|
||||||
|
|
||||||
|
echo "Creating tunnel"
|
||||||
|
|
||||||
|
json=$(curl -s -H "Authorization: bearer $token" -X POST "$api/tunnels?domain=$domain")
|
||||||
|
|
||||||
|
serverAddress=$(echo "$json" | jq -r '.server_address')
|
||||||
|
serverPort=$(echo "$json" | jq -r '.server_port')
|
||||||
|
username=$(echo "$json" | jq -r '.username')
|
||||||
|
tunnelPort=$(echo "$json" | jq -r '.tunnel_port')
|
||||||
|
tunnelPrivateKey=$(echo "$json" | jq -r '.tunnel_private_key')
|
||||||
|
|
||||||
|
# TODO: It would be nice if we could avoid writing the private key to disk.
|
||||||
|
# I tried process substition but it didn't work.
|
||||||
|
keyFile=$(mktemp)
|
||||||
|
printf -- "$tunnelPrivateKey" > $keyFile
|
||||||
|
chmod 0600 $keyFile
|
||||||
|
|
||||||
|
echo "Connecting to tunnel"
|
||||||
|
|
||||||
|
ssh -i $keyFile \
|
||||||
|
-NR 127.0.0.1:$tunnelPort:127.0.0.1:$localPort \
|
||||||
|
$username@$serverAddress -p $serverPort
|
||||||
|
|
||||||
|
echo "Cleaning up"
|
||||||
|
|
||||||
|
rm $keyFile
|
||||||
|
curl -s -H "Authorization: bearer $token" -X DELETE "$api/tunnels?domain=$domain"
|
Loading…
Reference in New Issue
Block a user