forked from BlameByte/StarterFaucet
/
main.php
177 lines (165 loc) · 4.78 KB
/
main.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
<?php
require_once('functions/loader.php');
require_once('validator/address_validator.php');
class Main {
function __construct() {
$loader = new loader();
$this->api = $loader->load('selectapi');
$this->template = $loader->load('template');
$this->config = $loader->load('configuration');
$this->log = $loader->load('log');
$this->_message = '';
$this->_hasMessage = false;
if (isset($_GET['next'])) {
if ($this->validate()) {
$useraddr = $_POST['address'];
$amount = $this->config->faucet_amount();
$this->sendMoney($useraddr, $amount);
}
}
}
function getTitle() {
return $this->config->faucet_name();
}
function coinName() {
return $this->config->coin_name();
}
function coinCode() {
return $this->config->coin_code();;
}
function faucetAmount() {
return $this->config->faucet_amount();
}
function faucetTime() {
$ts = $this->config->wait_period();
$h = intval($ts/3600);
$m = intval($ts/60) % 60;
$s = intval($ts) % 60;
$ret = "";
if ($h==1) $ret .= "$h hora ";
elseif ($h) $ret .= "$h horas ";
if ($m==1) $ret .= "$m minuto ";
elseif ($m) $ret .= "$m minutos ";
if ($s==1) $ret .= "$s segundo";
elseif ($s) $ret .= "$s segundos";
return $ret;
}
function getBalance() {
if (!isset($this->balance)) {
$this->balance = $this->api->getBalance();
}
return $this->balance;
}
function useRecaptcha() {
return $this->config->enable_captcha();
}
function recaptchaPublic() {
return $this->config->recaptcha_public_key();
}
function hasMessage() {
return $this->_hasMessage;
}
function getMessage() {
return $this->_message;
}
function getAddress() {
if (!isset($this->useraddr)) {
$this->useraddr = $_POST['address'];
}
return $this->useraddr;
}
function isChecked() {
if (!isset($this->checked)) {
$this->checked = !empty($_POST['terms']);
}
return $this->checked;
}
function getChecked() {
if ($this->isChecked()) {
return ' checked="checked" ';
}
return '';
}
function clearForm() {
$this->useraddr = '';
$this->checked = false;
// força a reatualizar osaldo
unset($this->balance);
}
function getQuotedAddress() {
return htmlspecialchars($this->getAddress(), ENT_QUOTES);
}
// all teh work is here;
// has collateral effects on both $this->_message and $this->_hasMessage
function validate() {
$continue = false;
$msg = '';
$useraddr = $this->getAddress();
$terms = $_POST['terms'];
$continue = true;
$msg = '';
if (empty($terms)) {
$continue = false;
//$msg = 'Please agree to the terms of service.';
$msg = 'Você precisa aceitar os termos de uso.';
} elseif (empty($useraddr)) {
$continue = false;
//$msg = 'Please agree fill the address.';
$msg = 'Preencha seu endereço ' . $this->config->coin_name() . '.';
} elseif ($this->config->enable_captcha()) {
require_once('recaptcha/autoload.php');
$secret = $this->config->recaptcha_private_key();
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$continue = false;
//$msg = 'The captcha is incorrect, please try again.';
$msg = 'O Captcha foi preenchido incorretamente, tente novamente.';
if(isset($_POST['g-recaptcha-response'])) {
$captcha=$_POST['g-recaptcha-response'];
$remoteIp=$_SERVER['REMOTE_ADDR'];
$resp = $recaptcha->verify($captcha, $remoteIp);
if ($resp->isSuccess()) {
$continue = true;
$msg = '';
} else {
$msg .= ' Error: ' . implode(", ", $resp->getErrorCodes());
}
}
}
if ($continue && !checkAddress($useraddr, dechex(30))) { // dilmacoin specific, move this to config
$continue = false;
$msg = 'Preencha um endereço ' . $this->config->coin_name() . ' válido.';
}
if ($continue) {
$amount = $this->config->faucet_amount();
if ($this->getBalance() < $amount) {
$continue = false;
$msg = 'Não há fundos suficientes na Faucet, tente novamente mais tarde.';
}
}
if ($continue && !$this->log->checkIP()) {
$continue = false;
$msg = 'Você já usou o faucet. Aguarde ' . $this->config->wait_period() . ' segundos para tentar novamente.';
}
$this->_hasMessage = !$continue;
$this->_message = $msg;
return $continue;
}
function sendMoney($useraddr, $amount) {
$send = $this->api->sendMoney($useraddr, $amount);
if ($send->success) {
$sent = $this->log->getLog('sent');
// This updates the log to show how much is sent.
$this->log->saveLog('sent', $sent + $amount);
// Update the log to put the wait period in place.
$ret = $this->log->logIP();
// Unset the variables to clear the form.
$this->clearForm();
$msg = 'Sucesso, o depósito deve aparecer na sua carteira em breve. (txid ' . $send->success . ').';
} else {
$msg = 'Não foi possivel enviar para sua carteira. Código de erro: ' . $send->error;
}
$this->_hasMessage = true;
$this->_message = $msg;
}
}
?>