-
Notifications
You must be signed in to change notification settings - Fork 10
/
search.php
507 lines (348 loc) · 13.4 KB
/
search.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
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
<!DOCTYPE html>
<html>
<head>
<title>Search Records</title>
<!-- Include Bootstrap CSS link here -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body {
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f8f9fa;
}
.container {
max-width: 1300px;
}
</style>
<script>
function checkStatus(bitcoinAddress, ItemType,PayWith) {
// Implement your logic here to check the status using the provided parameters
// You can use AJAX to make a request to the server or perform any other necessary action
console.log("Checking status for Bitcoin Address:", bitcoinAddress);
console.log("Item Type:", ItemType);
console.log("PayWith:", PayWith);
// You can also submit a form to post the data
document.getElementById("bitcoinAddress").value = bitcoinAddress;
document.getElementById("ItemType").value = ItemType;
document.getElementById("PayWith").value = PayWith;
document.getElementById("statusForm").submit();
}
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="search.php">Order</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<!-- ... Search form and PHP result code ... -->
<div class="card">
<div class="card-header">
<h1 class="card-title">Search Records</h1>
</div>
<div class="card-body">
<form action="search.php" method="GET">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" name="email" required>
</div>
<button type="submit" class="btn btn-primary">Search</button>
</form>
</div>
</div>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'encryption.php';
require_once 'globals.php';
//////******////////
//$ItemType =$PurchaseItem[0];
//////******////////
//$PayAmount = $Payments["Bitcoin"];
//echo $ItemType;
//echo $PayAmount;
if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET['bitcoin_address'])&& isset($_GET['ItemType'])&& isset($_GET['PayWith'])&& isset($_GET['emailPost']) ) {
$Address = filter_var(trim($_GET['bitcoin_address']), FILTER_SANITIZE_STRING);
$ItemType = filter_var(trim($_GET['ItemType']), FILTER_SANITIZE_STRING);
$PayWith = filter_var(trim($_GET['PayWith']), FILTER_SANITIZE_STRING);
$emailPost = filter_var(trim($_GET['emailPost']), FILTER_SANITIZE_STRING);
require_once 'balance.php';
$balance= getBalance($Address,$PayWith);
if ($balance >= $Payments[$PayWith]) {
//if ($balance >= 0) {
updatePaymentStatus($Address,"complete",$ItemType,$PayWith);
GoToSearch($emailPost);
# code...
}else
{
echo '<br><br><div class="card"><div class="card-body">';
echo $Address . "<br>Balance:<h3 class='text-danger'>" .$balance ."</h3> <br>Not detect payment,if you have transfered funds to our address,Please try again in a few minutes.";
echo '</div></div>';
}
}
//
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$Address = $_POST['bitcoinAddress'];
$ItemType = $_POST['ItemType'];
$PayWith = $_POST['PayWith'];
// getBitcoinAddressBalancePHP($bitcoinAddress,$ItemType,$PayWith);
//require_once 'balance.php';
$balance= getBalance($Address,$PayWith);
//echo "BBB:".$balance ;
if ($balance >= $Payments[$PayWith]) {
// if ($balance >= 0) {
updatePaymentStatus($Address,"complete",$ItemType,$PayWith);
# code...
}else
{
echo "Balance:".$balance ." Not detect payment,if you have transfered funds to our address,Please try again in a few minutes.";
}
}
/*
function getBalance($address,$network) {
//$CurrentNetwork=$network;
// echo $network;
if ($network=="Bitcoin") {
echo "Bitcoin:".$address;
$url = "https://api.blockcypher.com/v1/btc/main/addrs/$address";
$response = file_get_contents($url);
$data = json_decode($response, true);
if (isset($data['balance'])) {
$balance = $data['balance'] / 100000000; // Convert from satoshis to BTC
echo $balance;
return $balance;
} else {
echo 'bitcoin Error: ' ;
//return null;
return 0;
}
}else{
$rpcUrl="";
if ($network=="Ethereum") {
$rpcUrl="https://eth.drpc.org";
}else if ($network=="BinanceBNB") {
$rpcUrl="https://bsc-dataseed1.binance.org:443";
}
//$rpcUrl = $Networks[$network];
// Create a JSON-RPC request to get the balance of the address
$request = json_encode([
'jsonrpc' => '2.0',
'id' => 1,
'method' => 'eth_getBalance',
'params' => [
$address,
'latest' // You can use 'latest' to get the latest balance
]
]);
// Initialize cURL session
$ch = curl_init($rpcUrl);
// Set cURL options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($request)
]);
// Execute the cURL request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'cURL Error: ' . curl_error($ch);
exit;
}
// Close cURL session
curl_close($ch);
// Decode the JSON response
$responseData = json_decode($response, true);
// Check if the response is valid
if (isset($responseData['result'])) {
// The balance is returned in Wei, you can convert it to MATIC or other units as needed
$balanceWei = hexdec($responseData['result']);
$balance = $balanceWei / 1e18; // Convert Wei to MATIC
echo "Balance of $address : $balance";
return $balance;
} else {
echo "Error: Unable to fetch balance";
return 0;
}
}
}
*/
function validateEmail($email) {
// Use a regular expression to validate email format
$pattern = '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';
return preg_match($pattern, $email);
}
function generateActivationKey($email,$ItemType)
{
$hash = md5($email, true);
$Code="";
if ($ItemType=="Software 1") {
$Code=substr(str_replace('-', '', bin2hex($hash)), 2, 18);
}else if($ItemType=="Software 2") {
$Code=substr(str_replace('-', '', bin2hex($hash)), 3, 16);
}
$uppercaseString = strtoupper($Code);
return $uppercaseString;
}
function GoToSearch($email) {
header("Location: search.php" . "?email=" .$email);
exit;
}
function updatePaymentStatus($address, $newStatus,$ItemType,$PayWith) {
try {
//$db = new SQLite3("paymentsfioeqpfjsdjfoieireieriueruwowowi232125466565876454.db"); // Open your SQLite database
$db = new SQLite3($GLOBALS['DatabaseName']);
$currentTime = time();
// Check if ItemType and email are already in the database
$checkQuery = $db->prepare('SELECT COUNT(*) FROM payments WHERE bitcoin_address = :address AND PayWith = :PayWith AND status != "complete"');
$checkQuery->bindValue(':address', $address, SQLITE3_TEXT);
$checkQuery->bindValue(':PayWith', $PayWith, SQLITE3_TEXT);
$result = $checkQuery->execute();
$row = $result->fetchArray(SQLITE3_ASSOC);
$key="";
$email="";
if ($row['COUNT(*)'] > 0) {
$key= generateActivationKey($row['email'],$ItemType);
$key=encryptString($key);
$email=$row['email'];
}
$query = "UPDATE payments SET status = :newStatus,key = :key WHERE bitcoin_address = :address AND ItemType = :ItemType AND PayWith = :PayWith";
$stmt = $db->prepare($query);
$stmt->bindParam(':newStatus', $newStatus, SQLITE3_TEXT);
$stmt->bindParam(':address', $address, SQLITE3_TEXT);
$stmt->bindParam(':ItemType', $ItemType, SQLITE3_TEXT);
$stmt->bindParam(':key', $key, SQLITE3_TEXT);
$stmt->bindParam(':PayWith', $PayWith, SQLITE3_TEXT);
$result = $stmt->execute();
if ($result) {
echo "Status updated successfully.";
//GoToSearch($email);
} else {
echo "Failed to update status.";
}
$db->close(); // Close the database connection
} catch (Exception $e) {
echo "database Error: " . $e->getMessage();
}
}
/*
function getBitcoinAddressBalancePHP($address,$ItemType) {
// echo "";
//echo "Address:".$address;
$config = json_decode(file_get_contents('config.json'), true);
$ItemType = $config['PruchaseItem']['ItemType'];
$PayAmount = $config['Amount'][$ItemType];
$url = "https://api.blockcypher.com/v1/btc/main/addrs/$address";
$response = file_get_contents($url);
$data = json_decode($response, true);
if (isset($data['balance'])) {
$balance = $data['balance'] / 100000000; // Convert from satoshis to BTC
//echo "Btc Balance:".$balance;
//echo "PayAmount:".$PayAmount;
if ($balance >= $PayAmount) {
//if ($balance >= 0) {
updatePaymentStatus($address,"complete",$ItemType);
# code...
}else
{
echo "<br>Balance:<h3 class='text-danger'>".$balance ."</h3> <br>Not detect payment,if you have transfered funds to our address,Please try again in a few minutes.";
}
return $balance;
} else {
return null;
}
}
*/
if (isset($_GET['email']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
// ... Rest of the PHP code for displaying results ...
$email = $_GET['email'];
// Connect to SQLite database
$db = new SQLite3($GLOBALS['DatabaseName']);
$currentTime = date('Y-m-d H:i:s');
// set order visible time as 30 days
$date = new DateTime($currentTime);
$date->modify('+30 days');
$futureTime = $date->format('Y-m-d H:i:s');
$query = "SELECT * FROM payments WHERE email = :email AND expiration_time < '$futureTime'";
// Prepare and execute the query
//$query = "SELECT * FROM payments WHERE email = :email AND status = 'complete'";
//$query = "SELECT * FROM payments WHERE email = :email";
//$query = "SELECT * FROM payments WHERE email = :email AND expiration_time > '$currentTime'";
$stmt = $db->prepare($query);
$stmt->bindValue(':email', $email, SQLITE3_TEXT);
$result = $stmt->execute();
// Display results as a table
echo "<div class='card mt-3'>";
echo "<div class='card-body'>";
echo "<h1 class='card-title'>Your orders</h1>";
echo "<h8 class='card-title'>If you have already transferred funds to the cyrptocurrency address below, please wait a few minutes for the account to arrive and click the update button to see your activation code.</h8>";
echo "<form id='statusForm' method='POST' action='search.php'>";
echo "<table class='table table-bordered'>
<tr>
<th>Email</th>
<th>ItemType</th>
<th>Pay To Address</th>
<th>Amount</th>
<th>Key</th>
<th>PayWith</th>
<th>Status</th>
<th>Update Status</th>
</tr>";
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
// Decrypt the encrypted data
$decryptedKey = decryptString($row['key']);
echo "<tr>
<td>{$row['email']}</td>
<td>{$row['ItemType']}</td>
<td>{$row['bitcoin_address']}</td>
<td>{$row['amount']}</td>
<td class='text-danger'>{$decryptedKey}</td>
<td><image src='images/{$row['PayWith']}.png' width='20' height='20' class='rounded'>{$row['PayWith']}</td>";
if ($row['status']=="complete") {
echo "<td><img width='20' height='20' src='checkmark.png'>{$row['status']}</td> ";
}else{
echo "<td>{$row['status']}</td> ";
}
if ($row['status']=="complete") {
echo "<td>-</td> ";
}else{
$combineString= '?bitcoin_address='. $row['bitcoin_address'] . '&ItemType=' . $row['ItemType'] . '&PayWith=' . $row['PayWith']. '&emailPost=' . $row['email'] ;
echo "<td>
<a href='{$combineString}' class='btn btn-primary' >
update
</a>
</td>
</tr>";
}
}
echo "</table>";
echo "</form>";
echo "</div>";
echo "</div>";
// Close the database connection
$db->close();
}
?>
</div>
<!-- <input type='hidden' id='bitcoinAddress' name='bitcoinAddress' value=''>
<input type='hidden' id='ItemType' name='ItemType' value=''>
<input type='hidden' id='PayWith' name='PayWith' value=''>
<button type='button' class='btn btn-primary' onclick=\"checkStatus('{$row['bitcoin_address']}', '{$row['ItemType']}', '{$row['PayWith']}')\">Update</button>-->
<!-- Include Bootstrap JS and jQuery scripts here -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>