1
|
|
|
<?php |
2
|
|
|
function encrypt($text) |
3
|
|
|
{ |
4
|
|
|
$settings = require('config/settings.php'); |
5
|
|
|
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $settings['key'], $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)))); |
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
function decrypt($text) |
9
|
|
|
{ |
10
|
|
|
$settings = require('config/settings.php'); |
11
|
|
|
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $settings['key'], base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
function masterConnect() |
15
|
|
|
{ |
16
|
|
|
$settings = require('config/settings.php'); |
17
|
|
|
|
18
|
|
|
if (isset($settings['db']['port'])) { |
19
|
|
|
$db_connection = new mysqli(decrypt($settings['db']['host']), decrypt($settings['db']['user']), decrypt($settings['db']['pass']), decrypt($settings['db']['name']), decrypt($settings['db']['port'])); |
20
|
|
|
} else { |
21
|
|
|
$db_connection = new mysqli(decrypt($settings['db']['host']), decrypt($settings['db']['user']), decrypt($settings['db']['pass']), decrypt($settings['db']['name'])); |
22
|
|
|
} |
23
|
|
|
if (!$db_connection->set_charset("utf8")) { |
24
|
|
|
$db_connection->errors[] = $db_connection->error; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return $db_connection; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function serverConnect($dbid = NULL) |
31
|
|
|
{ |
32
|
|
|
if (isset($_SESSION['dbid']) && empty($dbid)) { |
33
|
|
|
$dbid = $_SESSION['dbid']; |
34
|
|
|
} |
35
|
|
|
$settings = require('config/settings.php'); |
36
|
|
|
$db_connection = masterConnect(); |
37
|
|
|
|
38
|
|
|
$sql = "SELECT `sql_host`, `sql_name`, `sql_pass`, `sql_user` FROM `db` WHERE `dbid` = '$dbid';"; |
39
|
|
|
$server = $db_connection->query($sql); |
40
|
|
|
|
41
|
|
|
if ($server->num_rows === 1) { |
42
|
|
|
$server = $server->fetch_object(); |
43
|
|
|
$host = decrypt($server->sql_host); |
44
|
|
|
|
45
|
|
|
if (strpos($host, ":")) { |
46
|
|
|
$SQL = explode(":", $host); |
47
|
|
|
$host = $SQL['0']; |
48
|
|
|
$port = $SQL['1']; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (isset($port)) { |
52
|
|
|
$db_link = new mysqli($host, decrypt($server->sql_user), decrypt($server->sql_pass), decrypt($server->sql_name), $port); |
53
|
|
|
} else { |
54
|
|
|
$db_link = new mysqli($host, decrypt($server->sql_user), decrypt($server->sql_pass), decrypt($server->sql_name)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (!$db_link->set_charset("utf8")) { |
58
|
|
|
$db_link->errors[] = $db_link->error; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $db_link; |
62
|
|
|
} else { |
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
function carType($car, $lang) |
69
|
|
|
{ |
70
|
|
|
switch ($car) { |
71
|
|
|
case 'Car': |
72
|
|
|
return $lang['car']; |
73
|
|
|
break; |
74
|
|
|
case 'Air': |
75
|
|
|
return $lang['air']; |
76
|
|
|
break; |
77
|
|
|
case 'Ship': |
78
|
|
|
return $lang['ship']; |
79
|
|
|
break; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function yesNo($input, $lang) |
84
|
|
|
{ |
85
|
|
|
if ($input == 1) { |
86
|
|
|
return $lang['yes']; |
87
|
|
|
} else if ($input == 0) { |
88
|
|
|
return $lang['no']; |
89
|
|
|
} else { |
90
|
|
|
return $lang['error']; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function select($val, $row) |
95
|
|
|
{ |
96
|
|
|
if ($row == $val) { |
97
|
|
|
return 'selected'; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
View Code Duplication |
function nameID($pId, $db_link) |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
global $playerIdColumn; |
104
|
|
|
$sql = "SELECT `name` FROM `players` WHERE `$playerIdColumn` LIKE '$pId';"; |
105
|
|
|
$result_of_query = $db_link->query($sql); |
106
|
|
|
|
107
|
|
|
if ($result_of_query->num_rows > 0) { |
108
|
|
|
while ($row = mysqli_fetch_assoc($result_of_query)) { |
109
|
|
|
return $row['name']; |
110
|
|
|
} |
111
|
|
|
} else { |
112
|
|
|
return $pId; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
View Code Duplication |
function uID($pId, $db_link) |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
global $playerIdColumn; |
119
|
|
|
$sql = "SELECT `uid` FROM `players` WHERE `$playerIdColumn` = '$pId';"; |
120
|
|
|
$result_of_query = $db_link->query($sql); |
121
|
|
|
if ($result_of_query->num_rows > 0) { |
122
|
|
|
while ($row = mysqli_fetch_assoc($result_of_query)) { |
123
|
|
|
return $row['uid']; |
124
|
|
|
} |
125
|
|
|
} else { |
126
|
|
|
return $pId; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
function uIDname($uID, $db_link) |
131
|
|
|
{ |
132
|
|
|
$sql = "SELECT `name` FROM `players` WHERE `uid` = '$uID';"; |
133
|
|
|
$result_of_query = $db_link->query($sql); |
134
|
|
|
if ($result_of_query->num_rows > 0) { |
135
|
|
|
while ($row = mysqli_fetch_assoc($result_of_query)) { |
136
|
|
|
return $row['name']; |
137
|
|
|
} |
138
|
|
|
} else { |
139
|
|
|
return $uID; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
function IDname($name, $db_link) |
144
|
|
|
{ |
145
|
|
|
global $playerIdColumn; |
146
|
|
|
$sql = "SELECT `name`, $playerIdColumn as playerid FROM `players` WHERE `name` LIKE '%$name%';"; |
147
|
|
|
$result_of_query = $db_link->query($sql); |
148
|
|
|
|
149
|
|
|
if ($result_of_query->num_rows > 0) { |
150
|
|
|
while ($row = mysqli_fetch_array($result_of_query)) { |
151
|
|
|
} |
152
|
|
|
} else { |
153
|
|
|
return $name; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $action |
159
|
|
|
* @param integer $level |
160
|
|
|
*/ |
161
|
|
|
function logAction($user, $action, $level) |
162
|
|
|
{ |
163
|
|
|
$settings = require('config/settings.php'); |
164
|
|
|
|
165
|
|
|
if ($settings['logging']) { |
166
|
|
|
$db_connection = masterConnect(); |
167
|
|
|
$sql = "INSERT INTO `logs` (`user`, `action`, `level`) VALUES ('$user', '$action', '$level');"; |
168
|
|
|
$db_connection->query($sql); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
function message($text) |
173
|
|
|
{ |
174
|
|
|
echo "<br><div class='row'><div class='col-lg-12'>"; |
175
|
|
|
echo "<div class='alert alert-danger alert-dismissable'>"; |
176
|
|
|
echo "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>"; |
177
|
|
|
echo "<i class='fa fa-info-circle'></i> " . $text . "</div></div></div>"; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
function error($errno, $errstr, $errfile, $errline) |
181
|
|
|
{ |
182
|
|
|
echo '<h4><b>PHP ERROR ' . $errno . '</b> ' . $errstr . ' - ' . $errfile . ':' . $errline . '</h4>'; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param integer $code |
187
|
|
|
*/ |
188
|
|
|
function errorMessage($code, $lang) |
189
|
|
|
{ |
190
|
|
|
switch ($code) |
191
|
|
|
{ |
192
|
|
|
case 1: |
193
|
|
|
return $lang['lowVersion']; //Version too low |
194
|
|
|
case 2: |
195
|
|
|
return $lang['dbConnect']; //Db Connection |
196
|
|
|
case 3: |
197
|
|
|
return $lang['noRes']; //No Results |
198
|
|
|
case 4: |
199
|
|
|
return $lang['404']; //404 Not Found |
200
|
|
|
case 5: |
201
|
|
|
return $lang['noPerm']; //No Permissions |
202
|
|
|
case 6: |
203
|
|
|
return $lang['banned']; //User Banned |
204
|
|
|
case 7: |
205
|
|
|
return $lang['pluginNF']; //Pulgin Not Found |
206
|
|
|
case 8: |
207
|
|
|
return $lang['noID']; //No ID |
208
|
|
|
case 9: |
209
|
|
|
return $lang['noPlayers']; // RCON no players online |
210
|
|
|
case 10: |
211
|
|
|
return $lang['selDB']; // Select A DB |
212
|
|
|
case 11: |
213
|
|
|
return $lang['noServer']; // Select A DB |
214
|
|
|
case 31: |
215
|
|
|
return $lang['noHouse']; //No House |
216
|
|
|
case 32: |
217
|
|
|
return $lang['noVeh']; //No Vehicle |
218
|
|
|
case 33: |
219
|
|
|
return $lang['noGang']; //No Gang |
220
|
|
|
case 34: |
221
|
|
|
return $lang['noCrimes']; //No Crimes |
222
|
|
|
case 35: |
223
|
|
|
return $lang['noCrimes']; //No Crimes |
224
|
|
|
case 36: |
225
|
|
|
return $lang['noPlayer']; //No Player |
226
|
|
|
case 37: |
227
|
|
|
return $lang['noLic']; //No License |
228
|
|
View Code Duplication |
case 371: |
|
|
|
|
229
|
|
|
return $lang['no'] . ' ' . $lang['civil'] . ' ' . $lang['licenses']; //No Civillian Licenses |
230
|
|
View Code Duplication |
case 372: |
|
|
|
|
231
|
|
|
return $lang['no'] . ' ' . $lang['medic'] . ' ' . $lang['licenses']; //No Medic Licenses |
232
|
|
View Code Duplication |
case 373: |
|
|
|
|
233
|
|
|
return $lang['no'] . ' ' . $lang['police'] . ' ' . $lang['licenses']; //No Police Licenses |
234
|
|
|
case 38: |
235
|
|
|
return $lang['no'] . ' ' . $lang['gear']; //No License |
236
|
|
View Code Duplication |
case 381: |
|
|
|
|
237
|
|
|
return $lang['no'] . ' ' . $lang['civil'] . ' ' . $lang['gear']; //No Civillian Licenses |
238
|
|
View Code Duplication |
case 382: |
|
|
|
|
239
|
|
|
return $lang['no'] . ' ' . $lang['medic'] . ' ' . $lang['gear']; //No Medic Licenses |
240
|
|
View Code Duplication |
case 383: |
|
|
|
|
241
|
|
|
return $lang['no'] . ' ' . $lang['police'] . ' ' . $lang['gear']; //No Police Licenses |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
View Code Duplication |
function random($length) |
|
|
|
|
246
|
|
|
{ |
247
|
|
|
$max = ceil($length / 40); |
248
|
|
|
$random = ''; |
249
|
|
|
for ($i = 0; $i < $max; $i++) { |
250
|
|
|
$random .= sha1(microtime(true) . mt_rand(10000, 90000)); |
251
|
|
|
} |
252
|
|
|
return substr($random, 0, $length); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
function steamBanned($PID) |
256
|
|
|
{ |
257
|
|
|
$settings = require('config/settings.php'); |
258
|
|
|
if (!empty($settings['steamAPI'])) { |
259
|
|
|
$api = "http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=" . $settings['steamAPI'] . "&steamids=" . $PID; |
260
|
|
|
$bans = json_decode(file_get_contents($api), true); |
261
|
|
|
if ($bans['players']['0']['VACBanned']) { |
262
|
|
|
return '<h4><span class="label label-danger" style="margin-left:3px; line-height:2;">VAC BANNED</span></h4>'; |
263
|
|
|
} |
264
|
|
|
//todo:formatting |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
function multiDB() |
269
|
|
|
{ |
270
|
|
|
$db_connection = masterConnect(); |
271
|
|
|
|
272
|
|
|
$sql = "SELECT `sid`,`dbid`,`type` FROM `servers`;"; |
273
|
|
|
$db = $db_connection->query($sql); |
274
|
|
|
if ($db->num_rows == 1) { |
275
|
|
|
$iamDB = $db->fetch_object(); |
276
|
|
|
$_SESSION['multiDB'] = false; |
277
|
|
|
$_SESSION['server_type'] = $iamDB->type; |
278
|
|
|
$_SESSION['dbid'] = $iamDB->dbid; |
279
|
|
|
} else { |
280
|
|
|
$_SESSION['multiDB'] = true; |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
function tokenGen($length) |
285
|
|
|
{ |
286
|
|
|
return substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, $length); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
function stripArray($input, $type) |
290
|
|
|
{ |
291
|
|
|
switch ($type) { |
292
|
|
View Code Duplication |
case 0: |
|
|
|
|
293
|
|
|
$array = explode("],[", $input); |
294
|
|
|
$array = str_replace('"[[', '', $array); |
295
|
|
|
$array = str_replace(']]"', '', $array); |
296
|
|
|
return str_replace('`', '', $array); |
297
|
|
View Code Duplication |
case 1: |
|
|
|
|
298
|
|
|
$array = explode(",", $input); |
299
|
|
|
$array = str_replace('"[', '', $array); |
300
|
|
|
$array = str_replace(']"', '', $array); |
301
|
|
|
return str_replace('`', '', $array); |
302
|
|
View Code Duplication |
case 2: |
|
|
|
|
303
|
|
|
$array = explode(",", $input); |
304
|
|
|
$array = str_replace('"[', '', $array); |
305
|
|
|
$array = str_replace(']"', '', $array); |
306
|
|
|
return str_replace('`', '', $array); |
307
|
|
|
case 3: |
308
|
|
|
$input = str_replace('[`', '', $input); |
309
|
|
|
$input = str_replace('`]', '', $input); |
310
|
|
|
return explode("`,`", $input); |
311
|
|
|
break; |
312
|
|
|
default: |
313
|
|
|
return []; |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
function clean($input, $type) |
318
|
|
|
{ |
319
|
|
|
if ($type == 'string') { |
320
|
|
|
return filter_var(htmlspecialchars(trim($input)), FILTER_SANITIZE_STRING); |
321
|
|
|
} elseif ($type == 'int') { |
322
|
|
|
$input = filter_var(htmlspecialchars(trim($input)), FILTER_SANITIZE_NUMBER_INT); |
323
|
|
|
if ($input < 0) { |
324
|
|
|
return 0; |
325
|
|
|
} |
326
|
|
|
return $input; |
327
|
|
|
} elseif ($type == 'url') { |
328
|
|
|
return filter_var(htmlspecialchars(trim($input)), FILTER_SANITIZE_URL); |
329
|
|
|
} elseif ($type == 'email') { |
330
|
|
|
return filter_var(htmlspecialchars(trim($input)), FILTER_SANITIZE_EMAIL); |
331
|
|
|
} elseif ($type == 'boolean') { |
332
|
|
|
return ($input === 'true'); |
333
|
|
|
} elseif ($type == 'intbool' && ($input == 1 || $input == 0)) { |
334
|
|
|
return $input; |
335
|
|
|
} |
336
|
|
|
return ''; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
function before($needle, $haystack) |
340
|
|
|
{ |
341
|
|
|
return substr($haystack, 0, strpos($haystack, $needle)); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
function after($needle, $haystack) |
345
|
|
|
{ |
346
|
|
|
if (!is_bool(strpos($haystack, $needle))) { |
347
|
|
|
return substr($haystack, strpos($haystack, $needle) + strlen($needle)); |
348
|
|
|
} |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
function getGravatar($email, $s = 80, $d = 'mm', $r = 'x', $img = false, $atts = array() ) { |
352
|
|
|
$url = 'https://www.gravatar.com/avatar/'; |
353
|
|
|
$url .= md5( strtolower( trim( $email ) ) ); |
354
|
|
|
$url .= "?s=$s&d=$d&r=$r"; |
355
|
|
|
if ( $img ) { |
356
|
|
|
$url = '<img src="' . $url . '"'; |
357
|
|
|
foreach ( $atts as $key => $val ) |
358
|
|
|
$url .= ' ' . $key . '="' . $val . '"'; |
359
|
|
|
$url .= ' />'; |
360
|
|
|
} |
361
|
|
|
return $url; |
362
|
|
|
} |
363
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.