mirror of
https://github.com/boringproxy/boringproxy.git
synced 2025-02-25 18:55:29 -06:00
Add button for downloading private keys
Allows users to access tunnels using standard SSH clients.
This commit is contained in:
parent
2ca14901fc
commit
1607d41e5c
29
api.go
29
api.go
@ -34,6 +34,25 @@ func (a *Api) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
a.mux.ServeHTTP(w, r)
|
a.mux.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Api) GetTunnel(tokenData TokenData, params url.Values) (Tunnel, error) {
|
||||||
|
domain := params.Get("domain")
|
||||||
|
if domain == "" {
|
||||||
|
return Tunnel{}, errors.New("Invalid domain parameter")
|
||||||
|
}
|
||||||
|
|
||||||
|
tun, exists := a.db.GetTunnel(domain)
|
||||||
|
if !exists {
|
||||||
|
return Tunnel{}, errors.New("Tunnel doesn't exist for domain")
|
||||||
|
}
|
||||||
|
|
||||||
|
user, _ := a.db.GetUser(tokenData.Owner)
|
||||||
|
if user.IsAdmin || tun.Owner == tokenData.Owner {
|
||||||
|
return tun, nil
|
||||||
|
} else {
|
||||||
|
return Tunnel{}, errors.New("Unauthorized")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Api) GetTunnels(tokenData TokenData) map[string]Tunnel {
|
func (a *Api) GetTunnels(tokenData TokenData) map[string]Tunnel {
|
||||||
|
|
||||||
user, _ := a.db.GetUser(tokenData.Owner)
|
user, _ := a.db.GetUser(tokenData.Owner)
|
||||||
@ -64,9 +83,13 @@ func (a *Api) CreateTunnel(tokenData TokenData, params url.Values) (*Tunnel, err
|
|||||||
|
|
||||||
sshKeyId := params.Get("ssh-key-id")
|
sshKeyId := params.Get("ssh-key-id")
|
||||||
|
|
||||||
sshKey, exists := a.db.GetSshKey(sshKeyId)
|
var sshKey SshKey
|
||||||
if !exists {
|
if sshKeyId != "" {
|
||||||
return nil, errors.New("SSH key does not exist")
|
var exists bool
|
||||||
|
sshKey, exists = a.db.GetSshKey(sshKeyId)
|
||||||
|
if !exists {
|
||||||
|
return nil, errors.New("SSH key does not exist")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clientName := params.Get("client-name")
|
clientName := params.Get("client-name")
|
||||||
|
@ -314,6 +314,20 @@ func (h *WebUiHandler) handleWebUiRequest(w http.ResponseWriter, r *http.Request
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "/tunnel-private-key":
|
||||||
|
|
||||||
|
r.ParseForm()
|
||||||
|
|
||||||
|
tun, err := h.api.GetTunnel(tokenData, r.Form)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
h.alertDialog(w, r, err.Error(), "/#/tunnels")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Disposition", "attachment; filename=id_rsa")
|
||||||
|
io.WriteString(w, tun.TunnelPrivateKey)
|
||||||
|
|
||||||
case "/tokens":
|
case "/tokens":
|
||||||
h.handleTokens(w, r, user, tokenData)
|
h.handleTokens(w, r, user, tokenData)
|
||||||
case "/confirm-delete-token":
|
case "/confirm-delete-token":
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
<a href="https://{{$domain}}">{{$domain}}</a>:{{$tunnel.TunnelPort}} -> {{$tunnel.ClientName}} -> {{$tunnel.ClientAddress}}:{{$tunnel.ClientPort}}
|
<a href="https://{{$domain}}">{{$domain}}</a>:{{$tunnel.TunnelPort}} -> {{$tunnel.ClientName}} -> {{$tunnel.ClientAddress}}:{{$tunnel.ClientPort}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<a class='button' href="/tunnel-private-key?domain={{$domain}}">Download Private Key</a>
|
||||||
|
|
||||||
<label class='button' for='toggle-tunnel-delete-dialog-{{$tunnel.CssId}}'>
|
<label class='button' for='toggle-tunnel-delete-dialog-{{$tunnel.CssId}}'>
|
||||||
Delete
|
Delete
|
||||||
</label>
|
</label>
|
||||||
|
Loading…
Reference in New Issue
Block a user