This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 310
/
index.php
365 lines (360 loc) · 18 KB
/
index.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
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
<?php
define("IN_WALLET", true);
require_once "classes/recaptchalib.php";
include('common.php');
$mysqli = new Mysqli($db_host, $db_user, $db_pass, $db_name);
if (!empty($_SESSION['user_session'])) {
if(empty($_SESSION['token'])) {
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
}
$user_session = $_SESSION['user_session'];
$admin = false;
if (!empty($_SESSION['user_admin']) && $_SESSION['user_admin']==1) {
$admin = true;
}
$error = array('type' => "none", 'message' => "");
$client = new Client($rpc_host, $rpc_port, $rpc_user, $rpc_pass);
$admin_action = false;
if ($admin && !empty($_GET['a'])) {
$admin_action = $_GET['a'];
}
if (!$admin_action) {
$noresbal = $client->getBalance($user_session);
$resbalance = $client->getBalance($user_session) - $reserve;
if ($resbalance < 0) {
$balance = $noresbal; //Don't show the user a negitive balance if they have no coins with us
} else {
$balance = $resbalance;
}
if (!empty($_POST['jsaction'])) {
$json = array();
switch ($_POST['jsaction']) {
case "new_address":
$client->getnewaddress($user_session);
$json['success'] = true;
$json['message'] = "A new address was added to your wallet";
$jsonbal = $client->getBalance($user_session);
$jsonbalreserve = $client->getBalance($user_session) - $reserve;
if ($jsonbalreserve < 0) {
$json['balance'] = $jsonbal;
} else {
$json['balance'] = $jsonbalreserve; }
$json['balance'] = $jsonbal;
$json['addressList'] = $client->getAddressList($user_session);
$json['transactionList'] = $client->getTransactionList($user_session);
echo json_encode($json); exit;
break;
case "withdraw":
$json['success'] = false;
if (!WITHDRAWALS_ENABLED) {
$json['message'] = "Withdrawals are temporarily disabled";
} elseif (empty($_POST['address']) || empty($_POST['amount']) || !is_numeric($_POST['amount'])) {
$json['message'] = "You have to fill all the fields";
} elseif ($_POST['token'] != $_SESSION['token']) {
$json['message'] = "Tokens do not match";
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
$json['newtoken'] = $_SESSION['token'];
} elseif ($_POST['amount'] > $balance) {
$json['message'] = "Withdrawal amount exceeds your wallet balance. Please note the wallet owner has set a reserve fee of $reserve $short.";
} else {
$withdraw_message = $client->withdraw($user_session, $_POST['address'], (float)$_POST['amount']);
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
$json['newtoken'] = $_SESSION['token'];
$json['success'] = true;
$json['message'] = "Withdrawal successful";
$json['balance'] = $client->getBalance($user_session);
$json['addressList'] = $client->getAddressList($user_session);
$json['transactionList'] = $client->getTransactionList($user_session);
}
echo json_encode($json); exit;
break;
case "password":
$user = new User($mysqli);
$json['success'] = false;
if (empty($_POST['oldpassword']) || empty($_POST['newpassword']) || empty($_POST['confirmpassword'])) {
$json['message'] = "You have to fill all the fields";
} elseif ($_POST['token'] != $_SESSION['token']) {
$json['message'] = "Tokens do not match";
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
$json['newtoken'] = $_SESSION['token'];
} else {
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
$json['newtoken'] = $_SESSION['token'];
$result = $user->updatePassword($user_session, $_POST['oldpassword'], $_POST['newpassword'], $_POST['confirmpassword']);
if ($result === true) {
$json['success'] = true;
$json['message'] = "Password updated successfully.";
} else {
$json['message'] = $result;
}
}
echo json_encode($json); exit;
break;
}
}
if (!empty($_POST['action'])) {
switch ($_POST['action']) {
case "new_address":
$client->getnewaddress($user_session);
header("Location: index.php");
break;
case "withdraw":
if (!WITHDRAWALS_ENABLED) {
$error['type'] = "withdraw";
$error['message'] = "Withdrawals are temporarily disabled";
} elseif (empty($_POST['address']) || empty($_POST['amount']) || !is_numeric($_POST['amount'])) {
$error['type'] = "withdraw";
$error['message'] = "You have to fill all the fields";
} elseif ($_POST['token'] != $_SESSION['token']) {
$error['type'] = "withdraw";
$error['message'] = "Tokens do not match";
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
} elseif ($_POST['amount'] > $balance) {
$error['type'] = "withdraw";
$error['message'] = "Withdrawal amount exceeds your wallet balance";
} else {
$withdraw_message = $client->withdraw($user_session, $_POST['address'], (float)$_POST['amount']);
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
header("Location: index.php");
}
break;
case "password":
$user = new User($mysqli);
if (empty($_POST['oldpassword']) || empty($_POST['newpassword']) || empty($_POST['confirmpassword'])) {
$error['type'] = "password";
$error['message'] = "You have to fill all the fields";
} elseif ($_POST['token'] != $_SESSION['token']) {
$error['type'] = "password";
$error['message'] = "Tokens do not match";
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
} else {
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
$result = $user->updatePassword($user_session, $_POST['oldpassword'], $_POST['newpassword'], $_POST['confirmpassword']);
if ($result === true) {
header("Location: index.php");
} else {
$error['type'] = "password";
$error['message'] = $result;
}
}
break;
case "logout":
session_destroy();
header("Location: index.php");
break;
case "support":
$error['message'] = "Please contact support via email at $support";
echo "Support Key: ";
echo $_SESSION['user_supportpin'];
break;
case "authgen":
$user = new User($mysqli);
$secret = $user->createSecret();
$gen=$user->enableauth();
echo $gen;
break;
case "disauth":
$user = new User($mysqli);
$disauth=$user->disauth();
echo $disauth;
break;
}
}
$addressList = $client->getAddressList($user_session);
$transactionList = $client->getTransactionList($user_session);
include("view/header.php");
include("view/wallet.php");
include("view/footer.php");
} else {
$user = new User($mysqli);
switch ($admin_action) {
case "info":
if (!empty($_GET['i'])) {
$info = $user->adminGetUserInfo($_GET['i']);
if (!empty($info)) {
$info['balance'] = $client->getBalance($info['username']);
if (!empty($_POST['jsaction'])) {
$json = array();
switch ($_POST['jsaction']) {
case "new_address":
$client->getnewaddress($info['username']);
$json['success'] = true;
$json['message'] = "A new address was added to your wallet";
$json['balance'] = $client->getBalance($info['username']);
$json['addressList'] = $client->getAddressList($info['username']);
$json['transactionList'] = $client->getTransactionList($info['username']);
echo json_encode($json); exit;
break;
case "withdraw":
$json['success'] = false;
if (!WITHDRAWALS_ENABLED) {
$json['message'] = "Withdrawals are temporarily disabled";
} elseif (empty($_POST['address']) || empty($_POST['amount']) || !is_numeric($_POST['amount'])) {
$json['message'] = "You have to fill all the fields";
} elseif ($_POST['amount'] > $info['balance']) {
$json['message'] = "Withdrawal amount exceeds your wallet balance";
} else {
$withdraw_message = $client->withdraw($info['username'], $_POST['address'], (float)$_POST['amount']);
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
$json['success'] = true;
$json['message'] = "Withdrawal successful";
$json['balance'] = $client->getBalance($info['username']);
$json['addressList'] = $client->getAddressList($info['username']);
$json['transactionList'] = $client->getTransactionList($info['username']);
}
echo json_encode($json); exit;
break;
case "password":
$json['success'] = false;
if ((is_numeric($_GET['i'])) && (!empty($_POST['password']))) {
$result = $user->adminUpdatePassword($_GET['i'], $_POST['password']);
if ($result === true) {
$json['success'] = true;
$json['message'] = "Password changed successfully.";
} else {
$json['message'] = $result;
}
} else {
$json['message'] = "Something went wrong (at least one field is empty).";
}
echo json_encode($json); exit;
break;
}
}
if (!empty($_POST['action'])) {
switch ($_POST['action']) {
case "new_address":
$client->getnewaddress($info['username']);
header("Location: index.php?a=info&i=" . $info['id']);
break;
case "withdraw":
if (!WITHDRAWALS_ENABLED) {
$error['type'] = "withdraw";
$error['message'] = "Withdrawals are temporarily disabled";
} elseif (empty($_POST['address']) || empty($_POST['amount']) || !is_numeric($_POST['amount'])) {
$error['type'] = "withdraw";
$error['message'] = "You have to fill all the fields";
} elseif ($_POST['amount'] > $info['balance']) {
$error['type'] = "withdraw";
$error['message'] = "Withdrawal amount exceeds your wallet balance";
} else {
$withdraw_message = $client->withdraw($info['username'], $_POST['address'], (float)$_POST['amount']);
$_SESSION['token'] = sha1('@s%a$l£t#'.rand(0,32000));
header("Location: index.php?a=info&i=" . $info['id']);
}
break;
case "password":
if ((is_numeric($_GET['i'])) && (!empty($_POST['password']))) {
$result = $user->adminUpdatePassword($_GET['i'], $_POST['password']);
if ($result === true) {
$error['type'] = "password";
$error['message'] = "Password changed successfully.";
header("Location: index.php?a=info&i=" . $info['id']);
} else {
$error['type'] = "password";
$error['message'] = $result;
}
} else {
$error['type'] = "password";
$error['message'] = "Something went wrong (at least one field is empty).";
}
break;
}
}
$addressList = $client->getAddressList($info['username']);
$transactionList = $client->getTransactionList($info['username']);
unset($info['password']);
}
}
include("view/header.php");
include("view/admin_info.php");
include("view/footer.php");
break;
default:
if ((!empty($_GET['m'])) && (!empty($_GET['i']))) {
switch ($_GET['m']) {
case "deadmin":
$user->adminDeprivilegeAccount($_GET['i']);
header("Location: index.php?a=home");
break;
case "admin":
$user->adminPrivilegeAccount($_GET['i']);
header("Location: index.php?a=home");
break;
case "unlock":
$user->adminUnlockAccount($_GET['i']);
header("Location: index.php?a=home");
break;
case "lock":
$user->adminLockAccount($_GET['i']);
header("Location: index.php?a=home");
break;
case "del":
$user->adminDeleteAccount($_GET['i']);
header("Location: index.php?a=home");
break;
}
}
$userList = $user->adminGetUserList();
include("view/header.php");
include("view/admin_home.php");
include("view/footer.php");
break;
}
}
} else {
$error = array('type' => "none", 'message' => "");
// verificar a chave secreta
$response = null;
$reCaptcha = new ReCaptcha($secret);
$response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
if ($response != null && $response->success) {
$username;$password;$auth;$captcha;
if(isset($_POST['username']))
$username=$_POST['username'];
if(isset($_POST['password']))
$password=$_POST['password'];
if(isset($_POST['auth']))
$auth=$_POST['auth'];
if(isset($_POST['g-recaptcha-response']))
$captcha=$_POST['g-recaptcha-response'];
// Code here to handle a successful verification
$error = array('type' => "none", 'message' => "");
$user = new User($mysqli);
switch ($_POST['action']) {
case "login":
$result = $user->logIn($_POST['username'], $_POST['password'], $_POST['auth']);
if (!is_array($result)) {
$error['type'] = "login";
$error['message'] = $result;
} else {
$_SESSION['user_session'] = $result['username'];
$_SESSION['user_admin'] = $result['admin'];
$_SESSION['user_supportpin'] = $result['supportpin'];
$_SESSION['user_id'] = $result['id'];
header("Location: index.php");
}
break;
case "register":
$result = $user->add($_POST['username'], $_POST['password'], $_POST['confirmPassword']);
if ($result !== true) {
$error['type'] = "register";
$error['message'] = $result;
} else {
$username = $mysqli->real_escape_string( strip_tags( $_POST['username'] ));
$_SESSION['user_session'] = $username;
$_SESSION['user_supportpin'] = "Please relogin for Support Key";
header("Location: index.php");
}
break;
}
}
else {
//insert error messenge here
}
include("view/header.php");
include("view/home.php");
include("view/footer.php");
}
$mysqli->close();
?>