-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
307 lines (255 loc) · 8.44 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
<?php
namespace App;
ini_set('display_startup_errors',1);
ini_set('display_errors','on'); // 1
error_reporting(E_ALL); // 11
require_once 'src/Autoloader.php';
Autoloader::register();
// Set timezone
date_default_timezone_set('UTC');
// Check IP, deny access if not allowed
if(!(empty(Config::ACCESS_IP) OR $_SERVER['REMOTE_ADDR'] == '127.0.0.1' OR $_SERVER['REMOTE_ADDR'] == '::1' OR $_SERVER['REMOTE_ADDR'] == Config::ACCESS_IP OR $_SERVER['REMOTE_ADDR'] == Config::ACCESS_IP2 OR $_SERVER['REMOTE_ADDR'] == Config::ACCESS_IP3)){
header('Location: login.html');
exit;
}
// Cronjob Rule Run
if(isset($_GET['job']) AND $_GET['job'] === substr(hash('sha256', Config::PASSWORD.'ebe8d532'),0,24)){
require_once 'src/Utility.php';
$blocknetd = new jsonRPCClient('http://'.Config::RPC_USER.':'.Config::RPC_PASSWORD.'@'.Config::RPC_IP.'/');
Rule::run();
exit;
}
// Start check user session
session_start();
$passToken = hash('sha256', Config::PASSWORD.'ibe81rn6');
// Active Session
if(isset($_SESSION['login']) AND $_SESSION['login'] === TRUE){
// Nothing needs to be done
// Login Cookie available
}elseif(isset($_COOKIE['Login']) AND $_COOKIE['Login'] == $passToken){
$_SESSION['login'] = TRUE;
$_SESSION['csfrToken'] = hash('sha256', random_bytes(20));
// Login
}elseif(!isset($_SESSION['login']) AND isset($_POST['password']) AND $_POST['password'] == Config::PASSWORD){
ini_set('session.cookie_httponly', '1');
$passHashed = hash('sha256', Config::PASSWORD);
$_SESSION['login'] = TRUE;
$_SESSION['csfrToken'] = hash('sha256', random_bytes(20));
if(isset($_POST['stayloggedin'])){
setcookie('Login', $passToken, time()+2592000, '','',FALSE, TRUE);
}
// Not logged in or invalid data
//}else{
// header('Location: login.html');
// exit;
}
// Load utility and content creator functions
require_once 'src/Utility.php';
require_once 'src/Content.php';
require_once 'ccxt/ccxt.php';
// Globals
$error = '';
$message = '';
$trafficC = 0;
$trafficCIn = 0;
$trafficCOut = 0;
$newPeersCount = 0;
$blocknetd = new jsonRPCClient('http://'.Config::RPC_USER.':'.Config::RPC_PASSWORD.'@'.Config::RPC_IP.'/', Config::DEBUG);
use SQLite3;
$db = new SQLite3('data/blocknet.db');
// Do some database setup
$db->enableExceptions(true);
$db->exec('CREATE TABLE IF NOT EXISTS "pastorders"(
"id" VARCHAR PRIMARY KEY NOT NULL,
"timestamp" INTEGER NOT NULL,
"fee_txid" VARCHAR NOT NULL,
"nodepubkey" VARCHAR NOT NULL,
"taker" VARCHAR NOT NULL,
"taker_size" INTEGER NOT NULL,
"maker" VARCHAR NOT NULL,
"maker_size" INTEGER NOT NULL
)');
$db->exec('CREATE TABLE IF NOT EXISTS "events"(
"lastorderheight" INTEGER,
"lastproposal" INTEGER,
"timestamp" INTEGER
)');
$db->exec('CREATE TABLE IF NOT EXISTS "pastproposals"(
"hash" VARCHAR PRIMARY KEY NOT NULL,
"name" VARCHAR NOT NULL,
"superblock" INTEGER NOT NULL,
"amount" INTEGER NOT NULL,
"address" VARCHAR NOT NULL,
"url" VARCHAR NOT NULL,
"description" VARCHAR,
"yeas" INTEGER NOT NULL,
"nays" INTEGER NOT NULL,
"abstains" INTEGER NOT NULL,
"status" VARCHAR NOT NULL
)');
$db->exec('CREATE TABLE IF NOT EXISTS "scratch"(
"superblock" VARCHAR NOT NULL,
"txid" VARCHAR NOT NULL,
"amount" INTEGER NOT NULL,
"address" VARCHAR NOT NULL
)');
// Content
// Main Page
if(empty($_GET) OR $_GET['p'] == 'main') {
try{
$content = createMainContent();
}catch(\Exception $e) {
$error = 'Node offline or incorrect RPC data';
}
$data = array('section' => 'main', 'title' => 'Home', 'content' => $content);
// Peers Page
}elseif($_GET['p'] == 'peers') {
// Information for header
$content = createPeerContent();
// Create page specfic variables
$data = array('section' => 'peers', 'title' => 'Peers', 'content' => $content);
// Memory Pool Page
}elseif($_GET['p'] == 'mempool') {
if(isset($_GET['e']) AND ctype_digit($_GET['id'])){
$end = $_GET['e'];
}else{
$end = Config::DISPLAY_TXS;
}
$content = createMempoolContent($end);
$data = array('section' => 'mempool', 'title' => 'Memory Pool', 'content' => $content);
// Servicenodes Page
}elseif($_GET['p'] == 'servicenodes') {
$content = createSNodesContent();
$data = array('section' => 'servicenodes', 'title' => 'Servicenodes', 'content' => $content);
// Servicenode details Page
}elseif($_GET['p'] == 'servicenodedetails') {
if(isset($_GET['snode'])){
$snode = $_GET['snode'];
}
$content = createSNodeDetails($snode);
$data = array('section' => 'servicenodedetail', 'title' => 'Servicenode Details', 'content' => $content);
// Proposals Page
}elseif($_GET['p'] == 'proposals') {
$content = createGovernanceContent();
$data = array('section' => 'proposals', 'title' => 'Proposals', 'content' => $content);
// Past proposals Page
}elseif($_GET['p'] == 'pastproposals') {
$content = createPastProposalsContent();
$data = array('section' => 'pastproposals', 'title' => 'Past Proposals', 'content' => $content);
// Blocks Page
}elseif($_GET['p'] == 'blocks') {
$content= createBlocksContent();
$data = array('section' => 'blocks', 'title' => 'Blocks', 'content' => $content);
// Forks Page
}elseif($_GET['p'] == 'forks') {
$content= createForksContent();
$data = array('section' => 'forks', 'title' => 'Forks', 'content' => $content);
// Open Orders Page
}elseif($_GET['p'] == 'openorders') {
$content= createOpenOrdersContent();
$data = array('section' => 'openorders', 'title' => 'Open Orders', 'content' => $content);
// Past Orders Page
}elseif($_GET['p'] == 'pastorders') {
$days = 1;
$maker = '';
$taker = '';
$snode = '';
if(isset($_GET['days'])){
$days = $_GET['days'];
}
if(isset($_GET['maker'])){
$maker = $_GET['maker'];
}
if(isset($_GET['taker'])){
$taker = $_GET['taker'];
}
if(isset($_GET['snode'])){
$snode = $_GET['snode'];
}
$content= createPastOrdersContent($days, $maker, $taker, $snode);
$data = array('section' => 'pastorders', 'title' => 'Past Orders', 'content' => $content);
// DX/XR Wallets Page
}elseif($_GET['p'] == 'dxxrwallets') {
$content= createDxXrWallets();
$data = array('section' => 'dxxrwallets', 'title' => 'DX+XR Wallets', 'content' => $content);
// XRouter services Page
}elseif($_GET['p'] == 'xrservices') {
$service = '';
$coin = '';
$snode = '';
if(isset($_GET['service'])){
$service = $_GET['service'];
}
if(isset($_GET['coin'])){
$coin = $_GET['coin'];
}
if(isset($_GET['snode'])){
$snode = $_GET['snode'];
}
$content= createXrServices($snode, $coin, $service);
$data = array('section' => 'xrservices', 'title' => 'XRouter Services', 'content' => $content);
// XCloud services Page
}elseif($_GET['p'] == 'xcservices') {
$service = '';
$snode = '';
if(isset($_GET['service'])){
$service = $_GET['service'];
}
if(isset($_GET['snode'])){
$snode = $_GET['snode'];
}
$content= createXcServices($snode, $service);
$data = array('section' => 'xcservices', 'title' => 'XCloud Services', 'content' => $content);
// Trades and fees Page
}elseif($_GET['p'] == 'tradesfees') {
$days = '';
if(isset($_GET['days'])){
$days = $_GET['days'];
}
$content= createTradesAndFees($days);
$data = array('section' => 'tradesfees', 'title' => 'Trades and Fees', 'content' => $content);
// Database update Page
}elseif($_GET['p'] == 'dbupdate') {
$content= dbupdate(1);
$data = array('section' => 'dbupdate', 'title' => 'DB Update', 'content' => $content);
// Settings Page
}elseif($_GET['p'] == 'settings') {
if(isset($_GET['c']) AND $_GET['t'] == $_SESSION['csfrToken']){
if(isset($_GET['c']) AND $_GET['c'] == 'geosave'){
// Check if Geo Peer Tracing was changed
if(isset($_POST['geopeers']) AND $_POST['geopeers'] == 'on'){
$geoPeers = 'true';
}else{
$geoPeers = 'false';
}
// Write new settings in config.php
if (file_exists('config.php')){
$conf = file_get_contents('config.php');
$conf = preg_replace('/geoPeers = (true|false);/i', 'geoPeers = '.$geoPeers.';', $conf);
file_put_contents('config.php', $conf);
$message = 'Setings succesfully saved';
}else{
$error = 'Config file does not exist';
}
$message = 'Settings succesfully saved';
}
}
$data = array('section' => 'settings', 'title' => 'Settings', 'geoPeers' => Config::PEERS_GEO);
// About Page
}elseif($_GET['p'] == 'about') {
$content= dbupdate();
$data = array('section' => 'about', 'title' => 'About', 'content' => $content);
}else{
header('Location: index.php');
exit;
}
// Create HTML output
if(isset($error)){
$data['error'] = $error;
}
if(isset($message)){
$data['message'] = $message;
}
$tmpl = new Template($data);
echo $tmpl->render();
?>