This repository has been archived by the owner on Jan 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
167 lines (161 loc) · 5.28 KB
/
admin.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
<?php
require("config.php");
function daemonrpc_get($path) {
global $daemonHost, $daemonPort;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://" . $daemonHost . ":" . $daemonPort . $path,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
)
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$response = json_decode($response);
return $response;
}
function walletrpc_post($method, $params = NULL) {
global $walletHost, $walletPort, $walletPassword;
if (is_null($params)) {
$params = (Object) Array();
}
$curl = curl_init();
$fields = array("jsonrpc" => "2.0",
"method" => $method,
"password" => $walletPassword,
"params" => $params,
"id" => "1");
$fields = json_encode((object) $fields);
curl_setopt_array($curl, array(
CURLOPT_URL => "http://" . $walletHost . ":" . $walletPort . "/json_rpc",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $fields,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
)
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$response = json_decode($response);
if (array_key_exists('result', $response)) {
return $response->result;
} else {
return $response;
}
}
$copyright = "© 2018-" . date("Y") . " Bittorium Project" ;
?>
<html>
<head>
<title>Bittorium Masternode</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css" />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="admin.css" />
</head>
<body>
<div class="logo"><img src="images/logo.png"></div>
<div class="banner">Bittorium Masternode</div>
<div class="clear-left"></div>
<?php
if(!isset($_COOKIE["admin_password"]) || $_COOKIE["admin_password"] != $walletPassword) {
if($_POST["password"] != $walletPassword) {
setcookie("admin_password", "", time() - 3600);
echo "<form action='admin.php' method='post'>";
echo "Password:";
echo "<input name='password' type='password' />";
echo "<input name='submit' type='submit' value='Login' />";
echo "</form>";
echo "<hr />";
echo $copyright;
echo "</body>";
echo "</html>";
exit();
}
}
// Expire session 5 minutes after latest page load
setcookie("admin_password", $walletPassword, time() + 300);
$info = daemonrpc_get("/getinfo");
$height = $info->height;
echo "<table id='info'>";
echo "<tr><th>Blockchain height</th><td>" . $height . "</td></tr>";
$balance = walletrpc_post("getBalance");
$balance = $balance->availableBalance;
echo "<tr><th>Balance</th><td>" . $balance / 100 . " BTOR</td></tr>";
echo "<tr><th>Number of transactions</th><td>";
ob_start();
$getAddresses = walletrpc_post("getAddresses");
$addresses = $getAddresses->addresses;
echo "<tr><th rowspan=" . count($addresses) . " id='wallet'>Wallet addresses</th><td>";
echo implode("</td></tr><tr><td>", $addresses);
echo "</td></tr>";
echo "</table>";
$txs_params = Array("addresses" => $addresses, "firstBlockIndex" => 0, "blockCount" => $height);
$txs = walletrpc_post("getTransactions", $txs_params);
$blocks = $txs->items;
echo "<h2>Transactions</h2>";
echo "<table id='transactions'>";
echo "<tr><th>Time</th><th class='amount'>Amount</th></tr>";
$ntrans = 0;
$skip = is_numeric($_POST["skip"]) ? $_POST["skip"] : 0;
if ($skip < 0) {
$skip = 0;
}
// List transactions in reverse order, from newest to oldest
$blocks = array_reverse($blocks);
foreach ($blocks as $block) {
$transactions = array_reverse($block->transactions);
foreach ($transactions as $transaction) {
if ($transaction->amount > 0) {
if ($ntrans >= $skip && $ntrans < $skip + 20) {
echo "<tr>";
echo "<td>" . date("D, d M y H:i:s", $transaction->timestamp) . "</td>";
echo "<td class='amount'>" . number_format($transaction->amount / 100, 2) . "</td>";
echo "</tr>";
}
$ntrans++;
}
}
}
echo "</table>";
echo "<table>";
echo "<tr>";
if ($skip > 0) {
echo "<td><form action='admin.php' method='post'>";
echo "<input name='skip' type='hidden' value='0' />";
echo "<input name='submit' type='submit' value='First 20' />";
echo "</form></td>";
echo "<td><form action='admin.php' method='post'>";
echo "<input name='skip' type='hidden' value='" . ($skip - 20) . "' />";
echo "<input name='submit' type='submit' value='Previous 20' />";
echo "</form></td>";
}
if ($ntrans > $skip + 20) {
echo "<td><form action='admin.php' method='post'>";
echo "<input name='skip' type='hidden' value='" . ($skip + 20) . "' />";
echo "<input name='submit' type='submit' value='Next 20' />";
echo "</form></td>";
echo "<td><form action='admin.php' method='post'>";
echo "<input name='skip' type='hidden' value='" . ($ntrans - 20) . "' />";
echo "<input name='submit' type='submit' value='Last 20' />";
echo "</form></td>";
}
echo "</tr>";
echo "</table>";
$buf = ob_get_contents();
ob_end_clean();
echo $ntrans . "</td></tr>";
echo $buf;
echo "<hr />";
echo $copyright;
?>
</body>
</html>