manual-connections icon indicating copy to clipboard operation
manual-connections copied to clipboard

[feature request] Allow a user-specified callback for port_forwarding.sh

Open JasonMaloney opened this issue 2 years ago • 0 comments

Hi all, I would like to request the ability to pass a user-specified callback script to port_forwarding.sh to be executed after binding the port.

I already have an existing OpenVPN configuration and scripts to connect to PIA (which also perform iptables and routing rules to force a split VPN for a specified user account). This worked great until the old port forwarding API stopped working recently. To be able to utilize the port_forwarding.sh script in this project, I made a small change to execute a callback script (this is immediately above the sleep command:

154 if [ -n "$PF_CALLBACK" ]; then 155 # Execute the specified callback script 156 export PF_PORT=$port 157 /usr/bin/env bash -c "$PF_CALLBACK" 158 # Unset so this does not get called again 159 PF_CALLBACK= 160 fi

This allows me to do the following:

  1. Wrap get_token.sh and port_forwarding.sh into a daemon that runs independently.
  2. Immediately receive the port number after binding, for use in other scripts.
  3. Capture the exported payload_and_signature variable for future calls to port_forwarding.sh (for example, upon VPN reconnect).

Obviously this is a fairly simple implementation, and you may wish to write it differently or more robustly. Any thoughts? This would be extremely useful for allowing people to use the port forwarding script with only minimal changes to existing setups.

JasonMaloney avatar Nov 16 '21 20:11 JasonMaloney