mirror of
https://github.com/boringproxy/boringproxy.git
synced 2025-02-25 18:55:29 -06:00
Remove unused custom SSH key code
Was originally planning to allow people to upload public keys to use for tunnels, but so far no one has asked for this and I haven't needed it.
This commit is contained in:
parent
38cb381051
commit
b795ee0bc9
44
api.go
44
api.go
@ -254,17 +254,6 @@ func (a *Api) CreateTunnel(tokenData TokenData, params url.Values) (*Tunnel, err
|
||||
}
|
||||
}
|
||||
|
||||
sshKeyId := params.Get("ssh-key-id")
|
||||
|
||||
var sshKey SshKey
|
||||
if sshKeyId != "" {
|
||||
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")
|
||||
|
||||
clientPort := 0
|
||||
@ -317,7 +306,6 @@ func (a *Api) CreateTunnel(tokenData TokenData, params url.Values) (*Tunnel, err
|
||||
|
||||
request := Tunnel{
|
||||
Domain: domain,
|
||||
SshKey: sshKey.Key,
|
||||
Owner: owner,
|
||||
ClientName: clientName,
|
||||
ClientPort: clientPort,
|
||||
@ -490,35 +478,3 @@ func (a *Api) DeleteClient(tokenData TokenData, ownerId, clientId string) error
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Api) GetSshKeys(tokenData TokenData) map[string]SshKey {
|
||||
|
||||
user, _ := a.db.GetUser(tokenData.Owner)
|
||||
|
||||
var keys map[string]SshKey
|
||||
|
||||
if user.IsAdmin {
|
||||
keys = a.db.GetSshKeys()
|
||||
} else {
|
||||
keys = make(map[string]SshKey)
|
||||
|
||||
for id, key := range a.db.GetSshKeys() {
|
||||
if tokenData.Owner == key.Owner {
|
||||
keys[id] = key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
func (a *Api) DeleteSshKey(tokenData TokenData, params url.Values) error {
|
||||
id := params.Get("id")
|
||||
if id == "" {
|
||||
return errors.New("Invalid id parameter")
|
||||
}
|
||||
|
||||
a.db.DeleteSshKey(id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
63
database.go
63
database.go
@ -13,7 +13,6 @@ type Database struct {
|
||||
Tokens map[string]TokenData `json:"tokens"`
|
||||
Tunnels map[string]Tunnel `json:"tunnels"`
|
||||
Users map[string]User `json:"users"`
|
||||
SshKeys map[string]SshKey `json:"ssh_keys"`
|
||||
dnsRequests map[string]DNSRequest `json:"dns_requests"`
|
||||
mutex *sync.Mutex
|
||||
}
|
||||
@ -27,11 +26,6 @@ type User struct {
|
||||
Clients map[string]DbClient `json:"clients"`
|
||||
}
|
||||
|
||||
type SshKey struct {
|
||||
Owner string `json:"owner"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type DbClient struct {
|
||||
}
|
||||
|
||||
@ -49,7 +43,6 @@ type DNSRecord struct {
|
||||
type Tunnel struct {
|
||||
Owner string `json:"owner"`
|
||||
Domain string `json:"domain"`
|
||||
SshKey string `json:"ssh_key"`
|
||||
ServerAddress string `json:"server_address"`
|
||||
ServerPort int `json:"server_port"`
|
||||
ServerPublicKey string `json:"server_public_key"`
|
||||
@ -94,10 +87,6 @@ func NewDatabase() (*Database, error) {
|
||||
db.Users = make(map[string]User)
|
||||
}
|
||||
|
||||
if db.SshKeys == nil {
|
||||
db.SshKeys = make(map[string]SshKey)
|
||||
}
|
||||
|
||||
if db.dnsRequests == nil {
|
||||
db.dnsRequests = make(map[string]DNSRequest)
|
||||
}
|
||||
@ -325,58 +314,6 @@ func (d *Database) DeleteUser(username string) {
|
||||
d.persist()
|
||||
}
|
||||
|
||||
func (d *Database) GetSshKey(id string) (SshKey, bool) {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
|
||||
key, exists := d.SshKeys[id]
|
||||
|
||||
if !exists {
|
||||
return SshKey{}, false
|
||||
}
|
||||
|
||||
return key, true
|
||||
}
|
||||
|
||||
func (d *Database) GetSshKeys() map[string]SshKey {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
|
||||
keys := make(map[string]SshKey)
|
||||
|
||||
for k, v := range d.SshKeys {
|
||||
keys[k] = v
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
func (d *Database) AddSshKey(id string, key SshKey) error {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
|
||||
_, exists := d.SshKeys[id]
|
||||
|
||||
if exists {
|
||||
return errors.New("SSH key id exists")
|
||||
}
|
||||
|
||||
d.SshKeys[id] = key
|
||||
|
||||
d.persist()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Database) DeleteSshKey(id string) {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
|
||||
delete(d.SshKeys, id)
|
||||
|
||||
d.persist()
|
||||
}
|
||||
|
||||
func (d *Database) persist() {
|
||||
saveJson(d, "boringproxy_db.json")
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func (m *TunnelManager) RequestCreateTunnel(tunReq Tunnel) (Tunnel, error) {
|
||||
}
|
||||
}
|
||||
|
||||
privKey, err := m.addToAuthorizedKeys(tunReq.Domain, tunReq.TunnelPort, tunReq.AllowExternalTcp, tunReq.SshKey)
|
||||
privKey, err := m.addToAuthorizedKeys(tunReq.Domain, tunReq.TunnelPort, tunReq.AllowExternalTcp)
|
||||
if err != nil {
|
||||
return Tunnel{}, err
|
||||
}
|
||||
@ -158,7 +158,7 @@ func (m *TunnelManager) GetPort(domain string) (int, error) {
|
||||
return tunnel.TunnelPort, nil
|
||||
}
|
||||
|
||||
func (m *TunnelManager) addToAuthorizedKeys(domain string, port int, allowExternalTcp bool, sshKey string) (string, error) {
|
||||
func (m *TunnelManager) addToAuthorizedKeys(domain string, port int, allowExternalTcp bool) (string, error) {
|
||||
|
||||
authKeysPath := fmt.Sprintf("%s/.ssh/authorized_keys", m.user.HomeDir)
|
||||
|
||||
@ -178,17 +178,12 @@ func (m *TunnelManager) addToAuthorizedKeys(domain string, port int, allowExtern
|
||||
var privKey string
|
||||
var pubKey string
|
||||
|
||||
if sshKey == "" {
|
||||
pubKey, privKey, err = MakeSSHKeyPair()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
pubKey = strings.TrimSpace(pubKey)
|
||||
} else {
|
||||
privKey = ""
|
||||
pubKey = sshKey
|
||||
}
|
||||
|
||||
bindAddr := "127.0.0.1"
|
||||
if allowExternalTcp {
|
||||
|
@ -236,21 +236,6 @@ func (h *WebUiHandler) handleWebUiRequest(w http.ResponseWriter, r *http.Request
|
||||
h.confirmDeleteToken(w, r)
|
||||
case "/delete-token":
|
||||
h.deleteToken(w, r, tokenData)
|
||||
//case "/ssh-keys":
|
||||
// h.handleSshKeys(w, r, user, tokenData)
|
||||
//case "/delete-ssh-key":
|
||||
|
||||
// r.ParseForm()
|
||||
|
||||
// err := h.api.DeleteSshKey(tokenData, r.Form)
|
||||
// if err != nil {
|
||||
// w.WriteHeader(400)
|
||||
// h.alertDialog(w, r, err.Error(), "/ssh-keys")
|
||||
// return
|
||||
// }
|
||||
|
||||
// http.Redirect(w, r, "/ssh-keys", 303)
|
||||
|
||||
case "/confirm-logout":
|
||||
|
||||
data := &ConfirmData{
|
||||
@ -402,49 +387,6 @@ func (h *WebUiHandler) handleTokens(w http.ResponseWriter, r *http.Request, user
|
||||
}
|
||||
}
|
||||
|
||||
func (h *WebUiHandler) handleSshKeys(w http.ResponseWriter, r *http.Request, user User, tokenData TokenData) {
|
||||
|
||||
if r.Method != "POST" {
|
||||
w.WriteHeader(405)
|
||||
h.alertDialog(w, r, "Invalid method for /ssh-keys", "/ssh-keys")
|
||||
return
|
||||
}
|
||||
|
||||
r.ParseForm()
|
||||
|
||||
id := r.Form.Get("id")
|
||||
if id == "" {
|
||||
w.WriteHeader(400)
|
||||
h.alertDialog(w, r, "Invalid id parameter", "/ssh-keys")
|
||||
return
|
||||
}
|
||||
|
||||
keyParam := r.Form.Get("key")
|
||||
if keyParam == "" {
|
||||
w.WriteHeader(400)
|
||||
h.alertDialog(w, r, "Invalid key parameter", "/ssh-keys")
|
||||
return
|
||||
}
|
||||
|
||||
keyParam = strings.TrimSpace(keyParam)
|
||||
parts := strings.Split(keyParam, " ")
|
||||
|
||||
if len(parts) > 2 {
|
||||
keyParam = strings.Join(parts[:2], " ")
|
||||
}
|
||||
|
||||
key := SshKey{Owner: tokenData.Owner, Key: keyParam}
|
||||
|
||||
err := h.db.AddSshKey(id, key)
|
||||
if err != nil {
|
||||
w.WriteHeader(400)
|
||||
h.alertDialog(w, r, err.Error(), "/ssh-keys")
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/ssh-keys", 303)
|
||||
}
|
||||
|
||||
func (h *WebUiHandler) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if r.Method != "GET" {
|
||||
|
Loading…
Reference in New Issue
Block a user