mirror of
https://github.com/boringproxy/boringproxy.git
synced 2025-02-25 18:55:29 -06:00
Implement selecting tunnel port
This is useful for when you want to use boringproxy more like a normal reverse proxy, ie if boringproxy and your service are on the same machine, you can just use the port of the service as the tunnel port and boringproxy will forward directly to it without using SSH. This would normally be used with no client set.
This commit is contained in:
parent
ffc8e45e85
commit
2b74f6ee0c
11
api.go
11
api.go
@ -282,6 +282,16 @@ func (a *Api) CreateTunnel(tokenData TokenData, params url.Values) (*Tunnel, err
|
||||
clientAddr = "127.0.0.1"
|
||||
}
|
||||
|
||||
tunnelPort := 0
|
||||
tunnelPortParam := params.Get("tunnel-port")
|
||||
if tunnelPortParam != "" && tunnelPortParam != "Random" {
|
||||
var err error
|
||||
tunnelPort, err = strconv.Atoi(tunnelPortParam)
|
||||
if err != nil {
|
||||
return nil, errors.New("Invalid tunnel-port parameter")
|
||||
}
|
||||
}
|
||||
|
||||
allowExternalTcp := params.Get("allow-external-tcp") == "on"
|
||||
|
||||
passwordProtect := params.Get("password-protect") == "on"
|
||||
@ -312,6 +322,7 @@ func (a *Api) CreateTunnel(tokenData TokenData, params url.Values) (*Tunnel, err
|
||||
ClientName: clientName,
|
||||
ClientPort: clientPort,
|
||||
ClientAddress: clientAddr,
|
||||
TunnelPort: tunnelPort,
|
||||
AllowExternalTcp: allowExternalTcp,
|
||||
AuthUsername: username,
|
||||
AuthPassword: password,
|
||||
|
@ -70,12 +70,21 @@ func (m *TunnelManager) RequestCreateTunnel(tunReq Tunnel) (Tunnel, error) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
port, err := randomOpenPort()
|
||||
if err != nil {
|
||||
return Tunnel{}, err
|
||||
if tunReq.TunnelPort == 0 {
|
||||
var err error
|
||||
tunReq.TunnelPort, err = randomOpenPort()
|
||||
if err != nil {
|
||||
return Tunnel{}, err
|
||||
}
|
||||
} else {
|
||||
for _, tun := range m.db.GetTunnels() {
|
||||
if tunReq.TunnelPort == tun.TunnelPort {
|
||||
return Tunnel{}, errors.New("Tunnel port already in use")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
privKey, err := m.addToAuthorizedKeys(tunReq.Domain, port, tunReq.AllowExternalTcp, tunReq.SshKey)
|
||||
privKey, err := m.addToAuthorizedKeys(tunReq.Domain, tunReq.TunnelPort, tunReq.AllowExternalTcp, tunReq.SshKey)
|
||||
if err != nil {
|
||||
return Tunnel{}, err
|
||||
}
|
||||
@ -84,7 +93,6 @@ func (m *TunnelManager) RequestCreateTunnel(tunReq Tunnel) (Tunnel, error) {
|
||||
tunReq.ServerPort = m.config.SshServerPort
|
||||
tunReq.ServerPublicKey = ""
|
||||
tunReq.Username = m.user.Username
|
||||
tunReq.TunnelPort = port
|
||||
tunReq.TunnelPrivateKey = privKey
|
||||
|
||||
m.db.SetTunnel(tunReq.Domain, tunReq)
|
||||
|
@ -89,6 +89,10 @@
|
||||
<input type="text" id="domain" name="domain" required>
|
||||
<input type="hidden" id="tunnel-owner" name="owner" value="{{$.UserId}}">
|
||||
</div>
|
||||
<div class='input'>
|
||||
<label for="tunnel-port">Tunnel Port:</label>
|
||||
<input type="text" id="tunnel-port" name="tunnel-port" value="Random">
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<div class='input'>
|
||||
|
Loading…
Reference in New Issue
Block a user