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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?
include ('../init.php');
include ('../func/fn_common.php');
include ('../tools/gc_func.php');
include ('../tools/email.php');
include ('../tools/sms.php');
function getUserIdFromAPIKey($key)
{
global $ms;
$q = "SELECT * FROM `gs_users` WHERE `api_key`='".$key."'";
$r = mysqli_query($ms, $q);
$row = mysqli_fetch_array($r);
if($row["api"] == "true")
{
return $row["id"];
}
else
{
return false;
}
}
function getUserIdFromUsername($username)
{
global $ms;
$q = "SELECT * FROM `gs_users` WHERE `username`='".$username."'";
$r = mysqli_query($ms, $q);
$row = mysqli_fetch_array($r);
return $row["id"];
}
function getUserIdFromEmail($email)
{
global $ms;
$q = "SELECT * FROM `gs_users` WHERE `email`='".$email."'";
$r = mysqli_query($ms, $q);
if (!$r)
{
return false;
}
$row = mysqli_fetch_array($r);
return $row["id"];
}
function getUserAPIKeyFromEmail($email)
{
global $ms;
$q = "SELECT * FROM `gs_users` WHERE `email`='".$email."'";
$r = mysqli_query($ms, $q);
if (!$r)
{
return false;
}
$row = mysqli_fetch_array($r);
return $row["api_key"];
}
// validate access to api
$api_access = false;
$api = @$_GET['api'];
$ver = @$_GET['ver'];
$key = @$_GET['key'];
$cmd = @$_GET['cmd'];
if ($api == '') { die; }
if ($ver != '1.0') { die; }
if ($cmd == '') { die; }
if ($api == 'server')
{
if ($key != $gsValues['SERVER_API_KEY']) { die; }
$api_access = true;
include ('api_server.php');
}
if ($api == 'user')
{
$user_id = getUserIdFromAPIKey($key);
if ($user_id == false) { die; }
//check user usage
if (!checkUserUsage($user_id, 'api')) { die; }
//update user usage
updateUserUsage($user_id, false, false, false, 1);
$api_access = true;
include ('api_user.php');
}
die;
?>