Automatically Start/Stop CF Tunnels & Automatically Use them Based On DNS Entries #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this commit tunnels are now automatically started/stopped when needed.
Instead of having to connect to a localhost address this mod will now create the tunnel with the hostname we're connecting to and automatically route the connection though the tunnel it just created it.
It can also automatically start using a tunnel based on DNS entries, or (as a fallback) the user can define hostnames in the
forced_tunnels.json
file. For this the user also no longer needs to define anything other than the hostname, as the mod will automatically do everything else.DNS Spec:
We look for a TXT record on the same subdomain as the server we are connecting to.
If there is a TXT record with the value
cloudflared-use-tunnel
orcloudflared-route=<route>
we know that we should use a CF tunnel to connect to the server.If the server has the TXT record
cloudflared-route=<route>
, it will use the route as the route for the tunnel.If the server has the TXT record
cloudflared-use-tunnel
, it will use the server address as the route for the tunnel.If the server has neither of the TXT records, it will not use a tunnel. (unless it is in the forced tunnels list)
Note: Only one of the above records are needed.
To do this quite a few internal changes were made.
We're now mixing into the Connection & Disconnection methods to start/stop the CF Tunnels.
The method that downloads cloudflare now returns a future that holds the
CloudflareProgram
If we want to start/stop a tunnel before we've finished downloading cloudflared we wait for the future to become ready.We're no longer loading a list of
Accesses
fromaccess.json
. Instead we're loading a list of hostnames fromforced_tunnels.json
which looks like:Access
no longer holds a reference toCloudflaredProgram
, so thecommand
method now takes a reference toCloudflaredProgram
.The
startAccess
method now creates takes in aAccess
object which defines the tunnel it should create. We no longer have a list of accesses (since there is no reason to have multiple tunnels running at the same time)Known Issues: