Basic auth

This commit is contained in:
Xavier Henner
2019-08-17 00:16:57 +02:00
parent 9eff9ce803
commit 2eb4f9e4ea
5 changed files with 78 additions and 5 deletions

View File

@@ -20,6 +20,8 @@ type jsonInput struct {
type jsonInputParams struct {
Server string `json:"server"`
Session int `json:"session"`
User string `json:"user"`
Pass string `json:"password"`
}
type HttpServer struct {
@@ -74,14 +76,16 @@ func (h *HttpServer) ajaxHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Invalid request", 500)
return
}
h.ovpn.Debug(req)
h.ovpn.Debug(req.Action)
switch req.Action {
case "get-remotes":
jsonStr, err = json.Marshal(h.ovpn)
case "set-remote":
err = h.ovpn.SetRemote(req.Params.Server, req.Params.Session)
jsonStr = []byte("{\"status\": \"ok\"}")
case "auth-user-pass":
err = h.ovpn.AuthUserPass(req.Params.Session, req.Params.User, req.Params.Pass)
jsonStr = []byte("{\"status\": \"ok\"}")
case "get-sessions":
jsonStr, err = json.Marshal(h.ovpn)
case "version":