forked from niobio-cash-classic/Niobio-Faucet
-
Notifications
You must be signed in to change notification settings - Fork 3
/
request.php
116 lines (92 loc) · 3.6 KB
/
request.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
<?php
require_once 'classes/recaptcha.php';
require_once 'classes/jsonRPCClient.php';
require_once 'config.php';
$link = new PDO('mysql:host=' . $hostDB . ';dbname=' . $database, $userDB, $passwordDB);
function randomize($min, $max)
{
$range = $max - $min;
$num = $min + $range * mt_rand(0, 32767) / 32767;
return round($num, 3);
}
//Instantiate the Recaptcha class as $recaptcha
$recaptcha = new Recaptcha($keys);
if ($recaptcha->set()) {
if ($recaptcha->verify($_POST['g-recaptcha-response'])) {
//Checking address and payment ID characters
$wallet = $str = trim(preg_replace('/[^a-zA-Z0-9]/', '', $_POST['wallet']));
$paymentidPost = $str = trim(preg_replace('/[^a-zA-Z0-9]/', '', $_POST['paymentid']));
//Getting user IP
$direccionIP = $_SERVER['REMOTE_ADDR'];
if (empty($wallet) OR (strlen($wallet) < 95)) {
header('Location: ./?msg=wallet');
exit();
}
if (empty($paymentidPost)) {
$paymentID = '';
} else {
if ((strlen($paymentidPost) > 64) OR (strlen($paymentidPost) < 64)) {
header('Location: ./?msg=paymentID');
exit();
} else {
$paymentID = $paymentidPost;
}
}
$queryCheck = "SELECT `id` FROM `payouts` WHERE `timestamp` > NOW() - INTERVAL $rewardEvery HOUR AND ( `ip_address` = '$direccionIP' OR `payout_address` = '$wallet')";
$resultCheck = $link->query($queryCheck);
$count = 0;
foreach ($resultCheck->fetchAll(PDO::FETCH_ASSOC) as $cou) {
$count++;
}
if ($count) {
header('Location: ./?msg=notYet');
exit();
}
$bitcoin = new jsonRPCClient('http://127.0.0.1:8317/json_rpc');
$balance = $bitcoin->getbalance();
$balanceDisponible = $balance['available_balance'];
$transactionFee = 10000;
$dividirEntre = 100000000;
$hasta = number_format(round($balanceDisponible / $dividirEntre, 12), 2, '.', '');
if ($hasta > $maxReward) {
$hasta = $maxReward;
}
if ($hasta < ((float) $minReward + 0.1)) {
header('Location: ./?msg=dry');
exit();
}
$aleatorio = randomize($minReward, $hasta);
$cantidadEnviar = ($aleatorio * $dividirEntre) - $transactionFee;
$destination = array('amount' => $cantidadEnviar, 'address' => $wallet);
$date = new DateTime();
$timestampUnix = $date->getTimestamp() + 5;
$peticion = array(
'destinations' => $destination,
'payment_id' => $paymentID,
'fee' => $transactionFee,
'mixin' => 1, // need to increase mixin later
'unlock_time' => 0
);
$transferencia = $bitcoin->transfer($peticion);
if ($transferencia == 'Bad address') {
header('Location: ./?msg=wallet');
exit();
}
if (array_key_exists('tx_hash', $transferencia)) {
$query = "INSERT INTO `payouts` (`payout_amount`,`ip_address`,`payout_address`,`payment_id`,`timestamp`) VALUES ('$cantidadEnviar','$direccionIP','$wallet','$paymentID',NOW());";
if ($link->exec($query)) {
header('Location: ./?msg=success&txid=' . $transferencia['tx_hash'] . '&amount=' . $aleatorio);
} else {
header('Location: ./?msg=erro_banco');
}
exit();
}
} else {
header('Location: ./?msg=captcha');
exit();
}
} else {
header('Location: ./?msg=captcha');
exit();
}
exit();