Skip to content

Commit

Permalink
Implement endpoints for changing skysocks password and skysocks-clien…
Browse files Browse the repository at this point in the history
…t PK
  • Loading branch information
nkryuchkov committed Jan 7, 2020
1 parent 5920cfb commit 48d949d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ func (m *Node) getApp() http.HandlerFunc {
func (m *Node) putApp() http.HandlerFunc {
return m.withCtx(m.appCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
var reqBody struct {
Autostart *bool `json:"autostart,omitempty"`
Status *int `json:"status,omitempty"`
Autostart *bool `json:"autostart,omitempty"`
Status *int `json:"status,omitempty"`
Passcode *string `json:"passcode,omitempty"`
PK *cipher.PubKey `json:"pk,omitempty"`
}

if err := httputil.ReadJSON(r, &reqBody); err != nil {
Expand All @@ -310,6 +312,7 @@ func (m *Node) putApp() http.HandlerFunc {
}
}
}

if reqBody.Status != nil {
switch *reqBody.Status {
case 0:
Expand All @@ -328,6 +331,26 @@ func (m *Node) putApp() http.HandlerFunc {
return
}
}

const (
skysocksName = "skysocks"
skysocksClientName = "skysocks-client"
)

if reqBody.Passcode != nil && ctx.App.Name == skysocksName {
if err := ctx.RPC.SetSocksPassword(*reqBody.Passcode); err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}
}

if reqBody.PK != nil && ctx.App.Name == skysocksClientName {
if err := ctx.RPC.SetSocksClientPK(*reqBody.PK); err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}
}

httputil.WriteJSON(w, r, http.StatusOK, ctx.App)
})
}
Expand Down

0 comments on commit 48d949d

Please sign in to comment.