-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathfunctions.php
More file actions
392 lines (347 loc) · 11.1 KB
/
Copy pathfunctions.php
File metadata and controls
392 lines (347 loc) · 11.1 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php
/**
* @author Amin Mahmoudi (MasterkinG)
* @copyright Copyright (c) 2019 - 2021, MasterkinG32. (https://masterking32.com)
* @link https://masterking32.com
* @Description : It's not masterking32 framework !
**/
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$error_msg = "";
$success_msg = "";
function getIP()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
//ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//ip pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function get_config($name)
{
global $config;
if (!empty($name)) {
if (isset($config[$name])) {
return $config[$name];
}
}
return false;
}
function get_core_config($name)
{
global $core_config;
if (!empty($name)) {
if (isset($core_config[$name])) {
return $core_config[$name];
}
}
return false;
}
function error_msg($input = false)
{
global $error_error;
if (!empty($error_error)) {
echo "<p class=\"alert alert-danger\">$error_error</p>";
} elseif (!empty($input)) {
$error_error = $input;
}
}
function success_msg($input = false)
{
global $success_msg;
if (!empty($success_msg)) {
echo "<p class=\"alert alert-success\">$success_msg</p>";
} elseif (!empty($input)) {
$success_msg = $input;
}
}
function GetRaceID($race)
{
switch ($race) {
case "HUMAN":
return 1;
case "ORC":
return 2;
case "DWARF":
return 3;
case "NIGHTELF":
return 4;
case "SCOURGE":
return 5;
case "TAUREN":
return 6;
case "GNOME":
return 7;
case "TROLL":
return 8;
case "BLOODELF":
return 10;
case "DRAENEI":
return 11;
default:
exit("error");
}
}
function GetClassID($class)
{
switch ($class) {
case "WARRIOR":
return 1;
case "PALADIN":
return 2;
case "HUNTER":
return 3;
case "ROGUE":
return 4;
case "PRIEST":
return 5;
case "DEATHKNIGHT":
return 6;
case "SHAMAN":
return 7;
case "MAGE":
return 8;
case "WARLOCK":
return 9;
case "DRUID":
return 11;
default:
exit("<br>YOUR CHARACTER CLASS IS NOT BLIZZLIKE FOR 3.3.5a<br>");
}
}
function get_human_time_from_sec($seconds)
{
$interval = new DateInterval("PT{$seconds}S");
$now = new DateTimeImmutable('now', new DateTimeZone('utc'));
return $now->diff($now->add($interval))->format('%a:%h:%i');
}
function send_phpmailer($email, $subject, $message)
{
try {
$mail = new PHPMailer(true);
if (get_config('debug_mode')) {
$mail->SMTPDebug = 2;
}
$mail->isSMTP();
$mail->Host = get_config('smtp_host');
$mail->SMTPAuth = get_config('smtp_auth');
$mail->Username = get_config('smtp_user');
$mail->Password = get_config('smtp_pass');
$mail->SMTPSecure = get_config('smtp_secure');
$mail->Port = get_config('smtp_port');
//Recipients
$mail->setFrom(get_config('smtp_mail'));
$mail->addAddress($email); // Add a recipient
$mail->addReplyTo(get_config('smtp_mail'));
// Content
$mail->CharSet = 'UTF-8';
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
} catch (Exception $e) {
if (get_config('debug_mode')) {
echo 'Message: ' . $e->getMessage();
}
}
return true;
}
function generateRandomString($length = 10)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function RemoteCommandWithSOAP($COMMAND)
{
global $soap_connection_info;
if (empty($COMMAND)) {
return false;
}
try {
$conn = new SoapClient(NULL, array(
'location' => 'http://' . get_config('soap_host') . ':' . get_config('soap_port') . '/',
'uri' => get_config('soap_uri'),
'style' => get_config('soap_style'),
'login' => get_config('soap_username'),
'password' => get_config('soap_password')
));
$conn->executeCommand(new SoapParam($COMMAND, 'command'));
unset($conn);
return true;
} catch (Exception $e) {
return false;
}
}
function validate_hcaptcha($value)
{
try {
$data = array(
'secret' => get_config('captcha_secret'),
'response' => $_POST['h-captcha-response']
);
$verify = curl_init();
curl_setopt($verify, CURLOPT_URL, "https://hcaptcha.com/siteverify");
curl_setopt($verify, CURLOPT_POST, true);
curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($verify);
$responseData = json_decode($response);
if ($responseData->success) {
return true;
}
} catch (Exception $e) {
}
return false;
}
function validate_recaptcha($value)
{
try {
$verify = curl_init();
curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify?secret=" . get_config('captcha_secret') . "&response=" . $_POST['g-recaptcha-response']);
curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($verify);
$responseData = json_decode($response, true);
if ($responseData["success"] == true) {
return true;
}
} catch (Exception $e) {
}
return false;
}
function captcha_validation()
{
if (empty(get_config('captcha_type')) && !empty($_POST['captcha']) && !empty($_SESSION['captcha'])) {
if (strtolower($_SESSION['captcha']) != strtolower($_POST['captcha'])) {
error_msg(lang('captcha_not_valid'));
return false;
}
unset($_SESSION['captcha']);
} else if (!empty(get_config('captcha_type')) && get_config('captcha_type') > 2) {
return true;
} elseif (!empty(get_config('captcha_type')) && get_config('captcha_type') == 1 && !empty($_POST['h-captcha-response'])) {
if (!validate_hcaptcha($_POST['h-captcha-response'])) {
error_msg(lang('hcaptcha_not_valid'));
return false;
}
} elseif (!empty(get_config('captcha_type')) && get_config('captcha_type') == 2 && !empty($_POST['g-recaptcha-response'])) {
if (!validate_recaptcha($_POST['g-recaptcha-response'])) {
error_msg(lang('recaptcha_not_valid'));
return false;
}
} else {
error_msg(lang('captcha_required'));
return false;
}
return true;
}
function getCaptchaJS()
{
if (!empty(get_config('captcha_type'))) {
if (get_config('captcha_type') == 1) {
return '<script src="https://hcaptcha.com/1/api.js?hl=' . get_config('captcha_language') . '" async defer></script><style>.h-captcha { display: inline-block;}</style>';
} else if (get_config('captcha_type') == 2) {
return '<script src="https://www.google.com/recaptcha/api.js?hl=' . get_config('captcha_language') . '" async defer></script><style>.g-recaptcha { display: inline-block;}</style>';
}
}
return '';
}
function GetCaptchaHTML($bootstrap = true)
{
if (!empty(get_config('captcha_type'))) {
if (get_config('captcha_type') == 1) {
return '<div class="row text-center"><div class="col-md-12 text-center"><div class="h-captcha" data-sitekey="' . get_config('captcha_key') . '" style=\'margin:10px auto\'></div></div></div>';
} else if (get_config('captcha_type') == 2) {
return '<div class="row text-center"><div class="col-md-12 text-center"><div class="g-recaptcha" data-sitekey="' . get_config('captcha_key') . '" style=\'margin:10px auto\'></div></div></div>';
} else {
return '';
}
}
if(empty($bootstrap))
{
return '<div class="input-group"><input type="text" placeholder="' . lang('captcha') . '" name="captcha"></div><p style="text-align: center;margin-top: 10px;"><img src="' . user::$captcha->inline() . '" style="border - radius: 5px;"/></p>';
}
return '<div class="input-group"><span class="input-group">' . lang('captcha') . '</span><input type="text" class="form-control" placeholder="' . lang('captcha') . '" name="captcha"></div><p style="text-align: center;margin-top: 10px;"><img src="' . user::$captcha->inline() . '" style="border - radius: 5px;"/></p>';
}
// Its from Trinitycore/account-creator
function calculateSRP6Verifier($username, $password, $salt)
{
// algorithm constants
$g = gmp_init(7);
$N = gmp_init('894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7', 16);
// calculate first hash
$h1 = sha1(strtoupper($username . ':' . $password), TRUE);
// calculate second hash
if(get_config('server_core') == 5)
{
$h2 = sha1(strrev($salt) . $h1, TRUE); // From haukw
} else {
$h2 = sha1($salt . $h1, TRUE);
}
// convert to integer (little-endian)
$h2 = gmp_import($h2, 1, GMP_LSW_FIRST);
// g^h2 mod N
$verifier = gmp_powm($g, $h2, $N);
// convert back to a byte array (little-endian)
$verifier = gmp_export($verifier, 1, GMP_LSW_FIRST);
// pad to 32 bytes, remember that zeros go on the end in little-endian!
$verifier = str_pad($verifier, 32, chr(0), STR_PAD_RIGHT);
// done!
if(get_config('server_core') == 5)
{
return strrev($verifier); // From haukw
} else {
return $verifier;
}
}
// Returns SRP6 parameters to register this username/password combination with
function getRegistrationData($username, $password)
{
// generate a random salt
$salt = random_bytes(32);
// calculate verifier using this salt
$verifier = calculateSRP6Verifier($username, $password, $salt);
// done - this is what you put in the account table!
if(get_config('server_core') == 5)
{
$salt = strtoupper(bin2hex($salt)); // From haukw
$verifier = strtoupper(bin2hex($verifier)); // From haukw
}
return array($salt, $verifier);
}
//From TrinityCore/AOWOW
function verifySRP6($user, $pass, $salt, $verifier)
{
$s = $salt;
if(get_config('server_core') == 5)
{
$s = pack("H*",strtolower($salt));
$v = strtoupper(bin2hex(calculateSRP6Verifier($user, $pass, $s)));
return ($verifier === $v);
}
$v = calculateSRP6Verifier($user, $pass, $s);
return ($verifier === $v);
}
// Get language text
function lang($val)
{
global $language;
if (!empty($language[$val])) {
return $language[$val];
}
return "";
}
// Echo language text
function elang($val)
{
echo lang($val);
}