forked from easy-wi/developer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
209 lines (151 loc) · 6.99 KB
/
api.php
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* File: api.php.
* Author: Ulrich Block
* Date: 20.05.12
* Time: 13:41
* Contact: <[email protected]>
*
* This file is part of Easy-WI.
*
* Easy-WI is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Easy-WI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Easy-WI. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von Easy-WI.
*
* Easy-WI ist Freie Software: Sie koennen es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder spaeteren
* veroeffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Easy-WI wird in der Hoffnung, dass es nuetzlich sein wird, aber
* OHNE JEDE GEWAEHELEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewaehrleistung der MARKTFAEHIGKEIT oder EIGNUNG FUER EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License fuer weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*/
define('EASYWIDIR', dirname(__FILE__));
if (is_dir(EASYWIDIR . '/install')) {
die('Please remove the "install" folder');
}
$logininclude = true;
include(EASYWIDIR . '/stuff/methods/vorlage.php');
include(EASYWIDIR . '/stuff/methods/class_validator.php');
include(EASYWIDIR . '/stuff/methods/functions.php');
include(EASYWIDIR . '/stuff/settings.php');
include(EASYWIDIR . '/stuff/keyphrasefile.php');
if ($ui->ip4('REMOTE_ADDR', 'server') and $ui->names('user', 255, 'post')) {
$query = $sql->prepare("SELECT `ip`,`active`,`pwd`,`salt`,`user`,i.`resellerID` FROM `api_ips` i INNER JOIN `api_settings` s ON s.`resellerID`=i.`resellerID` WHERE `ip`=?");
$query->execute(array($ui->ip4('REMOTE_ADDR', 'server')));
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
if ($row['active'] == 'Y' and passwordhash($ui->password('pwd', 255, 'post'), $row['salt']) == $row['pwd'] and $ui->names('user', 255, 'post') == $row['user']) {
$resellerIDs[] = $row['resellerID'];
}
}
} else if ($ui->ip4('REMOTE_ADDR', 'server')) {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: No valid access data. No API user given. Request IP is: ' . $ui->ip4('REMOTE_ADDR', 'server'));
} else {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: No valid access data. No API user given. No IP4 can be found at REMOTE_ADDR.');
}
if (in_array($ui->smallletters('type', 10, 'post'), array('gserver', 'list', 'tsdns', 'mysql', 'user', 'voice', 'web'))) {
$type = $ui->smallletters('type', 10, 'post');
}
if (isset($resellerIDs) and count($resellerIDs) == 1 and isset($type)) {
$data = array();
$resellerID = $resellerIDs[0];
$reseller_id = $resellerID;
$resellerLockupID = $resellerID;
$licenceDetails = serverAmount($resellerID);
if (is_numeric($licenceDetails['left']) and (0 > $licenceDetails['left'] or 0 > $licenceDetails['lG'] or 0 > $licenceDetails['lVo'] or 0 > $licenceDetails['lVs'] or 0 > $licenceDetails['lD'])) {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: More servers are stored than allowed!');
}
if ($ui->escaped('json', 'post')) {
$apiType = 'json';
$data = @json_decode(urldecode(base64_decode($ui->escaped('json', 'post'))));
if (!$data) {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: JSON not vaild');
}
} else if ($ui->escaped('xml', 'post')) {
$apiType = 'xml';
$data = @simplexml_load_string(urldecode(base64_decode($ui->escaped('xml', 'post'))));
if (!$data) {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: XML not valid');
}
} else {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: Neither POST value xml, nor JSON has been send!');
}
$tempArray = array();
$bad = array(false, null, '');
$data = (array)$data;
foreach ($data as $key => $value) {
$tempArray[$key] = (is_object($value)) ? null : $value;
}
$data = $tempArray;
unset($tempArray);
$licenceDetails = serverAmount($resellerID);
if (is_numeric($licenceDetails['left']) and (0 > $licenceDetails['left'] or 0 > $licenceDetails['lG'] or 0 > $licenceDetails['lVo'] or 0 > $licenceDetails['lVs'] or 0 > $licenceDetails['lD'])) {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: Server amount already exceeds licence limits!');
}
$gsModule = (is_numeric($licenceDetails['mG']) and $licenceDetails['mG'] == 0) ? false : true;
$vModule = (is_numeric($licenceDetails['mVs']) and $licenceDetails['mVs'] == 0) ? false : true;
$voModule = (is_numeric($licenceDetails['mVo']) and $licenceDetails['mVo'] == 0) ? false : true;
$dModule = (is_numeric($licenceDetails['mD']) and $licenceDetails['mD'] == 0) ? false : true;
if ($type == 'list') {
include(EASYWIDIR . '/stuff/api/api_list.php');
} else if ($type == 'user') {
include(EASYWIDIR . '/stuff/api/api_users.php');
} else if ($type == 'web') {
include(EASYWIDIR . '/stuff/api/api_web.php');
} else if ($type == 'voice') {
if ($voModule == true) {
include(EASYWIDIR . '/stuff/api/api_voice.php');
} else {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: Voice module is inactive');
}
} else if ($type == 'tsdns') {
if ($voModule == true) {
include(EASYWIDIR . '/stuff/api/api_tsdns.php');
} else {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: Voice module is inactive');
}
} else if ($type == 'mysql') {
include(EASYWIDIR . '/stuff/api/api_mysql.php');
} else if ($type == 'gserver') {
if ($gsModule == true) {
include(EASYWIDIR . '/stuff/api/api_gserver.php');
} else {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: Gameserver module is inactive');
}
}
} else if (isset($resellerIDs) and count($resellerIDs) == 1 and $ui->smallletters('type', 10, 'post')) {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: Type ' . $ui->smallletters('type', 10, 'post') . 'is not known');
} else if (isset($resellerIDs) and count($resellerIDs) == 1 and !isset($type)) {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: Type is not defined');
} else {
header('HTTP/1.1 403 Forbidden');
die('403 Forbidden: No valid api data Request IP is: ' . $ui->ip4('REMOTE_ADDR', 'server'));
}