/
overridevpn.go
58 lines (48 loc) · 1.4 KB
/
overridevpn.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package api
import (
"github.com/gin-gonic/gin"
"../players/auth"
"../players"
"../smurf"
"time"
)
func HttpReqOverrideVPN(c *gin.Context) {
mapResponse := make(map[string]interface{});
sCookieSessID, errCookieSessID := c.Cookie("session_id");
sIP := c.Query("ip");
sVPN := c.Query("isvpn");
mapResponse["success"] = false;
if (sIP != "" && sVPN != "") {
if (errCookieSessID == nil && sCookieSessID != "") {
oSession, bAuthorized := auth.GetSession(sCookieSessID, c.Query("csrf"));
if (bAuthorized) {
players.MuPlayers.RLock();
iAccess := players.MapPlayers[oSession.SteamID64].Access;
players.MuPlayers.RUnlock();
if (iAccess == 4) { //only admin can override vpn info
bVPN := (sVPN == "true");
smurf.MuVPN.Lock();
oNewVPNInfo := smurf.EntVPNInfo{
IsVPN: bVPN,
IsInCheck: false,
UpdatedAt: time.Now().Unix(),
};
smurf.MapVPNs[sIP] = oNewVPNInfo;
smurf.MuVPN.Unlock();
mapResponse["success"] = true;
} else {
mapResponse["error"] = "You dont have access to this command";
}
} else {
mapResponse["error"] = "Please authorize first";
}
} else {
mapResponse["error"] = "Please authorize first";
}
} else {
mapResponse["error"] = "Bad parameters";
}
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("origin"));
c.Header("Access-Control-Allow-Credentials", "true");
c.JSON(200, mapResponse);
}