mirror of
https://github.com/boringproxy/boringproxy.git
synced 2025-02-25 18:55:29 -06:00
Move /tunnels GET to /api
This commit is contained in:
parent
5b5f474853
commit
6ee5a5d3f4
8
api.go
8
api.go
@ -44,6 +44,14 @@ func (a *Api) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (a *Api) handleTunnels(w http.ResponseWriter, r *http.Request) {
|
func (a *Api) handleTunnels(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
|
case "GET":
|
||||||
|
body, err := json.Marshal(a.tunMan.GetTunnels())
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
w.Write([]byte("Error encoding tunnels"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Write([]byte(body))
|
||||||
case "POST":
|
case "POST":
|
||||||
a.validateSession(http.HandlerFunc(a.handleCreateTunnel)).ServeHTTP(w, r)
|
a.validateSession(http.HandlerFunc(a.handleCreateTunnel)).ServeHTTP(w, r)
|
||||||
default:
|
default:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/GeertJohan/go.rice"
|
"github.com/GeertJohan/go.rice"
|
||||||
"html/template"
|
"html/template"
|
||||||
@ -119,17 +118,10 @@ func (p *BoringProxy) handleTunnels(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
|
|
||||||
if r.Method == "GET" {
|
switch r.Method {
|
||||||
body, err := json.Marshal(p.db.GetTunnels())
|
case "POST":
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(500)
|
|
||||||
w.Write([]byte("Error encoding tunnels"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Write([]byte(body))
|
|
||||||
} else if r.Method == "POST" {
|
|
||||||
p.handleCreateTunnel(w, r)
|
p.handleCreateTunnel(w, r)
|
||||||
} else if r.Method == "DELETE" {
|
case "DELETE":
|
||||||
if len(query["host"]) != 1 {
|
if len(query["host"]) != 1 {
|
||||||
w.WriteHeader(400)
|
w.WriteHeader(400)
|
||||||
w.Write([]byte("Invalid host parameter"))
|
w.Write([]byte("Invalid host parameter"))
|
||||||
@ -138,7 +130,11 @@ func (p *BoringProxy) handleTunnels(w http.ResponseWriter, r *http.Request) {
|
|||||||
host := query["host"][0]
|
host := query["host"][0]
|
||||||
|
|
||||||
p.tunMan.DeleteTunnel(host)
|
p.tunMan.DeleteTunnel(host)
|
||||||
}
|
default:
|
||||||
|
w.WriteHeader(405)
|
||||||
|
w.Write([]byte("Invalid method for /tunnels"))
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *BoringProxy) handleLogin(w http.ResponseWriter, r *http.Request) {
|
func (p *BoringProxy) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -45,6 +45,10 @@ func NewTunnelManager(db *Database, certConfig *certmagic.Config) *TunnelManager
|
|||||||
return &TunnelManager{db, nextPort, mutex, certConfig, user}
|
return &TunnelManager{db, nextPort, mutex, certConfig, user}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *TunnelManager) GetTunnels() map[string]Tunnel {
|
||||||
|
return m.db.GetTunnels()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *TunnelManager) SetTunnel(host string, port int) error {
|
func (m *TunnelManager) SetTunnel(host string, port int) error {
|
||||||
err := m.certConfig.ManageSync([]string{host})
|
err := m.certConfig.ManageSync([]string{host})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -95,6 +99,8 @@ func (m *TunnelManager) DeleteTunnel(domain string) error {
|
|||||||
return errors.New("Tunnel doesn't exist")
|
return errors.New("Tunnel doesn't exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.db.DeleteTunnel(domain)
|
||||||
|
|
||||||
authKeysPath := fmt.Sprintf("%s/.ssh/authorized_keys", m.user.HomeDir)
|
authKeysPath := fmt.Sprintf("%s/.ssh/authorized_keys", m.user.HomeDir)
|
||||||
|
|
||||||
akBytes, err := ioutil.ReadFile(authKeysPath)
|
akBytes, err := ioutil.ReadFile(authKeysPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user