forked from palark/ovpn-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router-vpn-mgmt.go
43 lines (37 loc) · 1.05 KB
/
router-vpn-mgmt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"encoding/json"
"errors"
"log"
"net/http"
"rpiadm/backend/auth"
)
type ConnectionId struct {
ClientId int64 `json:"clientId"`
}
func (app *OvpnAdmin) apiConnectionKill(w http.ResponseWriter, r *http.Request, username string) {
//log.Printf("%s %s", r.RemoteAddr, r.RequestURI)
//if enableCors(&w, r) {
// return
//}
if !auth.HasWriteRole(app.applicationPreferences.JwtData, r) {
returnErrorMessage(w, http.StatusForbidden, errors.New("access denied"))
return
}
var req ConnectionId
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
returnErrorMessage(w, http.StatusUnprocessableEntity, errors.New("can't parse JSON"))
return
}
client, conn := app.getUserConnection(username, req.ClientId)
if client == nil {
returnErrorMessage(w, http.StatusBadRequest, errors.New("connection not found"))
}
log.Printf("killing collection %v", conn)
if err := app.killAndRemoveConnection(client, conn); err != nil {
returnErrorMessage(w, http.StatusInternalServerError, err)
return
}
w.WriteHeader(http.StatusNoContent)
}