-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfaucet.php
More file actions
565 lines (517 loc) · 19.7 KB
/
faucet.php
File metadata and controls
565 lines (517 loc) · 19.7 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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/config.php';
if ($cfg_enable_nastyhosts) {
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/nastyhosts.php';
if (check_nastyhosts(user_ip())) {
header('Location: ' . $cfg_site_url . '/nastyhost.php', true, 302);
exit;
}
}
if ($cfg_enable_iphub) {
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/iphub.php';
if (check_iphub(user_ip())) {
header('Location: ' . $cfg_site_url . '/iphub_block.php', true, 302);
exit;
}
}
$amount = rand(9, 11) / 10;
include $_SERVER['DOCUMENT_ROOT'] . '/custom/claim_options_process.php';
date_default_timezone_set(date_default_timezone_get());
$dryrun = false;
$errmsg = '';
$overload = false;
$too_fast = false;
$referrer_abuse = false;
$faucet_empty = false;
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/faucethub.php';
if (!isset($_GET['address']) || !isset($_GET['currency'])) {
$dry_run = true;
goto end_payout;
}
$address = '' . $_GET['address'];
$currency = '' . $_GET['currency'];
if ($cfg_use_captcha || $cfg_use_shortlink) {
if (isset($_GET['key'])) {
if ($_GET['key'] != md5($address . ' ' . $cfg_cookie_key)) {
http_response_code(400);
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/ban.php';
ban_user('Invalid key');
die('Congragulations, you are banned!');
}
} else {
http_response_code(400);
die('Missing key.');
}
}
if ((strlen($address) < 1) || (strlen($currency) < 1)) {
http_response_code(400);
$errmsg = '<p>One of the parameters is empty.</p>';
goto end_payout;
}
switch ($currency) {
case 'BCH':
case 'BLK':
case 'BTC':
case 'BTX':
case 'DASH':
case 'DOGE':
case 'ETH':
case 'LTC':
case 'PPC':
case 'XPM':
case 'POT':
if (!${'cfg_' . $currency . '_enabled'}) {
http_response_code(400);
$errmsg = '<p>Invalid currency. Nice try.</p>';
goto end_payout;
}
$faucethub = new FaucetHub(${'cfg_' . $currency . '_api_key'}, $currency, false);
break;
default:
http_response_code(400);
$errmsg = '<p>Unknown currency.</p>';
goto end_payout;
}
$current_time = time();
$prev_time = 0;
if (!file_exists(sys_get_temp_dir() . '/floodgate'))
mkdir(sys_get_temp_dir() . '/floodgate');
if (!file_exists(sys_get_temp_dir() . '/floodgate/addresses'))
mkdir(sys_get_temp_dir() . '/floodgate/addresses');
function too_fast_address($addr) {
global $current_time;
global $prev_time;
global $cfg_refresh_time;
global $cfg_fh_username;
$tf = false;
$pth = sys_get_temp_dir() . '/floodgate/addresses/' . rawurlencode($addr);
if (file_exists($pth)) {
$fp = fopen($pth, 'r') or die('Unable to open file! <strong>Alert ' . $cfg_fh_username . ' immediately</strong>!');
$prev_time = intval(fread($fp, filesize($pth)));
fclose($fp);
$tf = ($current_time - $prev_time) < $cfg_refresh_time;
}
if (!$tf) {
$fp = fopen($pth, 'w') or die('Unable to open file! <strong>Alert ' . $cfg_fh_username . ' immediately</strong>!');
fwrite($fp, $current_time);
fclose($fp);
}
return $tf;
}
function too_fast_hash($hash) {
global $current_time;
global $faucethub;
global $prev_time;
global $cfg_refresh_time;
global $cfg_fh_username;
$tf = false;
$pth = 'users/' . rawurlencode($hash);
if (file_exists($pth)) {
$fp = fopen($pth, 'r') or die('Unable to open file! <strong>Alert ' . $cfg_fh_username . ' immediately</strong>!');
$prev_time = intval(fread($fp, filesize($pth)));
fclose($fp);
$tf = ($current_time - $prev_time) < $cfg_refresh_time;
}
if (!$tf) {
$fp = fopen($pth, 'w') or die('Unable to open file! <strong>Alert ' . $cfg_fh_username . ' immediately</strong>!');
fwrite($fp, $current_time);
fclose($fp);
}
return $tf;
}
if (too_fast_address($address)) {
$too_fast = true;
goto end_payout;
}
$a = $faucethub->checkAddress($address, $currency);
if (!isset($a['payout_user_hash'])) {
http_response_code(502);
$errmsg = '<p>Error connecting to FaucetHUB to check address!</p>'
. '<dl>'
. '<dt>Status</dt>'
. '<dd>' . $a['status'] . '</dd>'
. '<dt>Message</dt>'
. '<dd>' . $a['message'] . '</dd>'
. '</dl>';
if ($a['status'] == 441) {
http_response_code(503);
$overload = true;
}
goto end_payout;
}
$user_hash = $a['payout_user_hash'];
unset($a);
if (empty($user_hash)) {
goto end_payout;
}
if (too_fast_hash($user_hash)) {
$too_fast = true;
goto end_payout;
}
$user_ip = user_ip();
if (!$user_ip) {
http_response_code(400);
$errmsg = '<p>Could not detect IP address.</p>';
goto end_payout;
}
$referred = isset($_GET['r']);
if (!$referred) { // referral url not set, check for saved referrer
/* TODO: replace with generated code? */
if ($cfg_BCH_enabled) {
if (file_exists('referrers/BCH/' . rawurlencode($address))) {
$fp = fopen('referrers/BCH/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'BCH';
$referrer = fread($fp, filesize('referrers/BCH/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_BLK_enabled) {
if (file_exists('referrers/BLK/' . rawurlencode($address))) {
$fp = fopen('referrers/BLK/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'BLK';
$referrer = fread($fp, filesize('referrers/BLK/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_BTC_enabled) {
if (file_exists('referrers/BTC/' . rawurlencode($address))) {
$fp = fopen('referrers/BTC/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'BTC';
$referrer = fread($fp, filesize('referrers/BTC/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_BTX_enabled) {
if (file_exists('referrers/BTX/' . rawurlencode($address))) {
$fp = fopen('referrers/BTX/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'BTX';
$referrer = fread($fp, filesize('referrers/BTX/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_DASH_enabled) {
if (file_exists('referrers/DASH/' . rawurlencode($address))) {
$fp = fopen('referrers/DASH/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'DASH';
$referrer = fread($fp, filesize('referrers/DASH/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_DOGE_enabled) {
if (file_exists('referrers/DOGE/' . rawurlencode($address))) {
$fp = fopen('referrers/DOGE/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'DOGE';
$referrer = fread($fp, filesize('referrers/DOGE/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_ETH_enabled) {
if (file_exists('referrers/ETH/' . rawurlencode($address))) {
$fp = fopen('referrers/ETH/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'ETH';
$referrer = fread($fp, filesize('referrers/ETH/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_LTC_enabled) {
if (file_exists('referrers/LTC/' . rawurlencode($address))) {
$fp = fopen('referrers/LTC/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'LTC';
$referrer = fread($fp, filesize('referrers/LTC/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_PPC_enabled) {
if (file_exists('referrers/PPC/' . rawurlencode($address))) {
$fp = fopen('referrers/PPC/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'PPC';
$referrer = fread($fp, filesize('referrers/PPC/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_XPM_enabled) {
if (file_exists('referrers/XPM/' . rawurlencode($address))) {
$fp = fopen('referrers/XPM/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'XPM';
$referrer = fread($fp, filesize('referrers/XPM/' . rawurlencode($address)));
fclose($fp);
}
}
if ($cfg_POT_enabled) {
if (file_exists('referrers/POT/' . rawurlencode($address))) {
$fp = fopen('referrers/POT/' . rawurlencode($address), 'r') or die('I/O Error.');
$referred = true;
$refer_file = true;
$referrer_currency = 'POT';
$referrer = fread($fp, filesize('referrers/POT/' . rawurlencode($address)));
fclose($fp);
}
}
}
}
if ($referred) {
if (!$refer_file) {
if (!isset($_GET['r']) || !isset($_GET['rc'])) {
http_response_code(400);
$errmsg = '<p>The referral URL is incorrect. It should have both <code>&r=…</code> <em>and</em> <code>&rc=…</code>!</p>';
goto end_payout;
}
$referrer = $_GET['r'];
$referrer_currency = $_GET['rc'];
}
if ((strlen($referrer) < 1) || (strlen($referrer_currency) < 1)) {
http_response_code(400);
$errmsg = '<p>One of the parameters is empty.</p>';
goto end_payout;
}
switch ($referrer_currency) {
case 'BCH':
case 'BLK':
case 'BTC':
case 'BTX':
case 'DASH':
case 'DOGE':
case 'ETH':
case 'LTC':
case 'PPC':
case 'XPM':
case 'POT':
$faucethub_ref = new FaucetHub(${'cfg_' . $referrer_currency . '_api_key'}, $referrer_currency, false);
break;
default:
http_response_code(400);
$errmsg = '<p>Invalid referrer currency.</p>';
goto end_payout;
}
$a = $faucethub_ref->checkAddress($referrer, $referrer_currency);
if (!isset($a['payout_user_hash'])) {
http_response_code(502);
$errmsg = '<p>Error connecting to FaucetHUB to check referral!</p>'
. '<dl>'
. '<dt>Status</dt>'
. '<dd>' . $a['status'] . '</dd>'
. '<dt>Message</dt>'
. '<dd>' . $a['message'] . '</dd>'
. '</dl>';
if ($a['status'] == 441) {
http_response_code(503);
$overload = true;
}
goto end_payout;
}
$referrer_hash = $a['payout_user_hash'];
unset($a);
if ($referrer_hash == $user_hash) {
http_response_code(400);
$referrer_abuse = true;
goto end_payout;
}
$ref_result = $faucethub_ref->sendReferralEarnings(
$referrer,
intval(($amount
* ${'cfg_' . $referrer_currency . '_amount'})
/ 2)
);
if (!$refer_file) { // the user was referred and the referral isn't saved
if (!file_exists('referrers/' . rawurlencode($referrer_currency) . '/' . rawurlencode($address))) {
$fp = fopen('referrers/' . rawurlencode($referrer_currency) . '/' . rawurlencode($address), 'w');
if ($fp) {
fwrite($fp, $referrer);
fclose($fp);
}
}
}
}
$result = $faucethub->send(
$address,
intval($amount * ${'cfg_' . $currency . '_amount'}),
false,
$user_ip
);
end_payout:
if (isset($result)) {
switch (json_decode($result['response'], true)['status']) {
case 402:
$faucet_empty = true;
break;
case 441:
$overload = true;
break;
default:
break;
}
}
if (isset($ref_result)) {
switch (json_decode($ref_result['response'], true)['status']) {
case 402:
$faucet_empty = true;
break;
case 441:
$overload = true;
break;
default:
break;
}
}
if ($too_fast) {
http_response_code(429);
header(
'Retry-After: ' . (($prev_time + $cfg_refresh_time) - $current_time),
true
);
}
if ($overload) {
http_response_code(503);
}
if ($faucet_empty) {
http_response_code(503);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $cfg_site_name; ?></title>
<?php include $_SERVER['DOCUMENT_ROOT'] . '/custom/head.php'; ?>
<?php
if ($overload) {
echo '<meta http-equiv="refresh" content="2;url=' . $cfg_site_url . '/441.php"/>';
} else if ($too_fast) {
echo '<script type="text/javascript">setTimeout("location.reload(true);",' . ($cfg_real_refresh_time * 1000) . ');</script>';
} else if (isset($result)) {
if ($result['success'] === true) {
echo '<script type="text/javascript">setTimeout("';
if ($cfg_enable_google_analytics) {
echo 'window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}';
echo 'gtag(\'event\', \'complete_claim\');';
}
echo 'location.reload(true);';
echo '",' . ($cfg_real_refresh_time * 1000) . ');</script>';
}
}
?>
</head>
<body>
<header><?php include $_SERVER['DOCUMENT_ROOT'] . '/custom/navbar.php'; ?></header>
<main>
<h1><?php echo $cfg_site_name; ?></h1>
<?php
if ($dryrun) {
if ($cfg_enable_google_analytics) {
echo '<script type="text/javascript">';
echo 'gtag(\'event\', \'dry_run\');';
echo '</script>';
}
echo '<p>No claim detected, here is what the page looks like.</p>';
} else {
if ($faucet_empty) {
if ($cfg_enable_google_analytics) {
echo '<script type="text/javascript">';
echo 'gtag(\'event\', \'faucet_dry\', {';
echo '\'currency\': \'' . htmlspecialchars($currency, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '\',';
echo '});';
echo '</script>';
}
echo '<p>The faucet is out of this particular currency. Want to try another one?</p>';
echo '<p>(A few currencies depend on the exchange, the faucet will usually be re-filled once ' . $cfg_fh_username . 'ʼs ‘buy’ orders are filled.) (If you are <em>really</em> impatient, perhaps someone will /tip ' . $cfg_fh_username . ' some ' . htmlspecialchars($currency, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '?)</p>';
echo '<p>(I would put a little “faucet balance” widget on the main page, but that would currently result in a <em>TON</em> of API requests…)</p>';
} else if ($too_fast) {
if ($cfg_enable_google_analytics) {
echo '<script type="text/javascript">';
echo 'gtag(\'event\', \'too_fast\', {';
echo '\'currency\': \'' . htmlspecialchars($currency, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '\',';
echo '});';
echo '</script>';
}
echo '<p>Just leave this page open, and it should automatically send you more ' . htmlspecialchars($currency, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . ' every ' . ($cfg_refresh_time / 60) . ' minutes!</p>';
echo '<p>Time until next payout: ' . (($prev_time + $cfg_refresh_time) - $current_time) . ' seconds.</p>';
echo '<p>Referral link: <code>' . $cfg_site_url . '?r=' . htmlspecialchars($address, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '&rc=' . htmlspecialchars($currency, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '</code> (rotator owners, please append <code>&rotator=YOUR_ROTATOR_NAME</code> to the URL)</p>';
echo '<hr/><p>Timestamp of last claim: <time>' . $prev_time . '</time></p>';
echo '<hr/><p>Timestamp of last refresh: <time>' . $current_time . '</time></p>';
} else if ($referrer_abuse) {
if ($cfg_enable_google_analytics) {
echo '<script type="text/javascript">';
echo 'gtag(\'event\', \'double_claim\');';
echo '</script>';
}
echo '<p>You seem to have tried to cheat the system by double-claiming.</p>';
echo '<p>This means that the referral address belongs to you.</p>';
echo '<p>You can get in <em>deep</em> trouble if you do this on a faucet that does not block it; Faucet Hub will automatically detect it and freeze your account and reverse every faucet claim you have made.</p>';
} else if (isset($result)) {
echo $result['html'];
if ($result['success'] === true) {
if ($cfg_enable_google_analytics) {
echo '<script type="text/javascript">';
echo 'gtag(\'event\', \'claim\', {';
echo '\'currency\': \'' . htmlspecialchars($currency, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '\',';
if ($referred)
echo '\'referred\': true,';
else
echo '\'referred\': false,';
echo '});';
echo '</script>';
}
echo '<p>Just leave this page open, and it should automatically refresh and send you more ' . htmlspecialchars($currency, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . ' every ' . ($cfg_refresh_time / 60) . ' minutes!</p>';
echo '<p>Referral link: <code>' . htmlspecialchars($cfg_site_url, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '?r=' . rawurlencode($address) . '&rc=' . rawurlencode($currency) . '</code> (rotator owners, please append <code>&rotator=YOUR_ROTATOR_NAME</code> to the URL)</p>';
} else {
if ($cfg_enable_google_analytics) {
echo '<script type="text/javascript">';
echo 'gtag(\'event\', \'fh_error\', {';
echo '\'status\': \'' . htmlspecialchars($result['status'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '\',';
echo '});';
echo '</script>';
}
echo '<dl><dt>Status</dt><dd>' . htmlspecialchars($result['status'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '</dd><dt>Message</dt><dd>' . htmlspecialchars($result['message'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '</dd></dl>';
}
if (isset($ref_result)) {
echo '<section id="referral_status">';
echo '<h2>Referral</h2>';
echo $ref_result['html'];
if ($ref_result['success'] === false) {
if ($cfg_enable_google_analytics) {
echo '<script type="text/javascript">';
echo 'gtag(\'event\', \'fh_error\', {';
echo '\'status\': \'' . htmlspecialchars($result['status'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '\',';
echo '});';
echo '</script>';
}
echo '<dl><dt>Status</dt><dd>' . htmlspecialchars($result['status'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '</dd><dt>Message</dt><dd>' . htmlspecialchars($result['message'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '</dd></dl>';
}
}
} else {
if ($cfg_enable_google_analytics) {
echo '<script type="text/javascript">';
echo 'gtag(\'event\', \'error\');';
echo '</script>';
}
echo $errmsg;
}
}
?>
<hr/>
<p><strong>Do not bookmark this page!</strong> Use <a href="<?php echo $cfg_site_url; ?>"><?php echo htmlspecialchars($cfg_site_url, ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5); ?></a> instead. (If the claim URL changes and you visit this page directly, you might be mistaken for a bot and banned.)</p>
<hr/>
<?php include $_SERVER['DOCUMENT_ROOT'] . '/custom/iframetraffic.php'; ?>
</main>
<footer><?php include $_SERVER['DOCUMENT_ROOT'] . '/custom/ads.php'; ?></footer>
</body>
</html>