-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
921 lines (803 loc) · 41.4 KB
/
index.php
File metadata and controls
921 lines (803 loc) · 41.4 KB
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
<?php
// Read a boolean from an environment variable, falling back to a default when unset.
// Accepts true/false, 1/0, yes/no, on/off.
function env_bool($name, $default) {
$value = getenv($name);
return $value === false ? $default : filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
// Configuration
// Values may be set directly below, or overridden via environment variables (e.g. for Docker).
$dashboard_config = [
'network' => getenv('NETWORK') ?: 'CHANGE_ME', // BTC, LTC, XMR (+ testnets tBTC, tLTC, tXMR, sXMR), or a custom ticker (see $networks below)
'node_ip' => getenv('NODE_IP') ?: 'CHANGE_ME', // Usually 127.0.0.1 if ran locally
'rpc_port' => getenv('RPC_PORT') ?: 'CHANGE_ME', // Default RPC ports: BTC 8332 (testnet 18332) | LTC 9332 (testnet 19332) | XMR 18081 (testnet 28081, stagenet 38081)
'rpc_user' => getenv('RPC_USER') ?: 'CHANGE_ME', // Note: not usually needed for XMR (leave blank if XMR)
'rpc_pass' => getenv('RPC_PASS') ?: 'CHANGE_ME', // Note: not usually needed for XMR (leave blank if XMR)
'show_node_info' => env_bool('SHOW_NODE_INFO', true),
'show_blockchain' => env_bool('SHOW_BLOCKCHAIN', true),
'show_mempool' => env_bool('SHOW_MEMPOOL', true),
'show_mining' => env_bool('SHOW_MINING', true),
'show_transactions' => env_bool('SHOW_TRANSACTIONS', true),
'show_fees' => env_bool('SHOW_FEES', true),
'theme' => getenv('THEME') ?: 'dark', // Default theme: dark, light, nord, solarized, or dracula
'show_theme_switcher' => env_bool('SHOW_THEME_SWITCHER', true), // Set false to lock the theme above and hide the dropdown
'refresh_seconds' => getenv('REFRESH_SECONDS') !== false ? (int) getenv('REFRESH_SECONDS') : 60, // Auto-refresh interval in seconds (0 disables)
'enable_json' => env_bool('ENABLE_JSON', true), // Set false to disable the ?format=json API (e.g. for public hosts)
// "Connect to this node" box, for advertising a public node. These are operator-provided
// public details (not the internal RPC settings above), and only show when an address is set.
'show_connect' => env_bool('SHOW_CONNECT', false), // Show the "Connect to this Node" box
'connect_address' => getenv('CONNECT_ADDRESS') ?: '', // Public address to advertise, e.g. node.example.com:18089
'connect_note' => getenv('CONNECT_NOTE') ?: '', // Optional note shown in the box (e.g. "Restricted RPC" or a Tor address)
];
$network = strtoupper($dashboard_config['network']);
$rpc_user = $dashboard_config['rpc_user'];
$rpc_password = $dashboard_config['rpc_pass'];
$theme = $dashboard_config['theme'] ?? 'dark';
$show_theme_switcher = $dashboard_config['show_theme_switcher'] ?? true;
$refresh_seconds = max(0, (int) ($dashboard_config['refresh_seconds'] ?? 60));
$enable_json = $dashboard_config['enable_json'] ?? true;
$show_connect = ($dashboard_config['show_connect'] ?? false) && ($dashboard_config['connect_address'] ?? '') !== '';
$connect_address = $dashboard_config['connect_address'] ?? '';
$connect_note = $dashboard_config['connect_note'] ?? '';
$errors = [];
// Network profiles. Bitcoin Core-compatible coins all share the 'bitcoin' family and
// differ only in a few parameters, so adding one is just another entry here. Monero is
// a one-off ('monero' family) since its RPC and economics are unlike Bitcoin's.
$networks = [
'BTC' => ['name' => 'Bitcoin', 'family' => 'bitcoin', 'unit' => 'BTC', 'halving_interval' => 210000, 'initial_subsidy' => 50, 'fee_unit' => 'sat/vB', 'decimals' => 8],
'LTC' => ['name' => 'Litecoin', 'family' => 'bitcoin', 'unit' => 'LTC', 'halving_interval' => 840000, 'initial_subsidy' => 50, 'fee_unit' => 'lit/vB', 'decimals' => 8],
'XMR' => ['name' => 'Monero', 'family' => 'monero', 'unit' => 'XMR'],
// Test networks share their mainnet's RPC and rules; only the node port and display differ.
'TBTC' => ['name' => 'Bitcoin Testnet', 'family' => 'bitcoin', 'unit' => 'tBTC', 'halving_interval' => 210000, 'initial_subsidy' => 50, 'fee_unit' => 'sat/vB', 'decimals' => 8],
'TLTC' => ['name' => 'Litecoin Testnet', 'family' => 'bitcoin', 'unit' => 'tLTC', 'halving_interval' => 840000, 'initial_subsidy' => 50, 'fee_unit' => 'lit/vB', 'decimals' => 8],
'TXMR' => ['name' => 'Monero Testnet', 'family' => 'monero', 'unit' => 'tXMR'],
'SXMR' => ['name' => 'Monero Stagenet', 'family' => 'monero', 'unit' => 'sXMR'],
];
// A custom Bitcoin Core-compatible network can be added as an entry above, or defined via
// environment variables (handy for Docker): set NETWORK to its ticker plus any CUSTOM_* vars.
$custom_defined = getenv('CUSTOM_NAME') || getenv('CUSTOM_UNIT') || getenv('CUSTOM_HALVING_INTERVAL')
|| getenv('CUSTOM_INITIAL_SUBSIDY') || getenv('CUSTOM_FEE_UNIT') || getenv('CUSTOM_DECIMALS');
if (!isset($networks[$network]) && $custom_defined) {
$networks[$network] = [
'name' => getenv('CUSTOM_NAME') ?: $network,
'family' => 'bitcoin',
'unit' => getenv('CUSTOM_UNIT') ?: $network,
'halving_interval' => (int) (getenv('CUSTOM_HALVING_INTERVAL') ?: 210000),
'initial_subsidy' => (float) (getenv('CUSTOM_INITIAL_SUBSIDY') ?: 50),
'fee_unit' => getenv('CUSTOM_FEE_UNIT') ?: 'sat/vB',
'decimals' => getenv('CUSTOM_DECIMALS') !== false ? (int) getenv('CUSTOM_DECIMALS') : 8,
];
}
if (!isset($networks[$network])) {
die("Configuration error: unknown network '" . htmlspecialchars($network) . "'. Use BTC, LTC, or XMR, add an entry to \$networks, or define a custom coin with the CUSTOM_* environment variables.");
}
$profile = $networks[$network];
$coin = $profile['name'];
$family = $profile['family'];
// RPC URL Construction (Monero uses a /json_rpc endpoint)
$url_schema = "http://{$dashboard_config['node_ip']}:{$dashboard_config['rpc_port']}";
if ($family === 'monero') {
$url_schema .= "/json_rpc";
}
// RPC function
function call_rpc($method, $params = [], $dashboard_config, $url_schema) {
global $errors, $networks;
$rpc_user = $dashboard_config['rpc_user'];
$rpc_password = $dashboard_config['rpc_pass'];
$network = strtoupper($dashboard_config['network']);
$is_monero = isset($networks[$network]) && $networks[$network]['family'] === 'monero';
if ($is_monero && in_array($method, ['get_transaction_pool_stats'])) {
$url = str_replace('/json_rpc', '', $url_schema) . "/$method";
$payload = json_encode((object)$params);
} elseif ($is_monero && in_array($method, ['get_info'])) {
$url = str_replace('/json_rpc', '', $url_schema) . "/$method";
$payload = json_encode((object)$params);
} else {
$url = $url_schema;
$payload = json_encode([
'jsonrpc' => '2.0',
'id' => 'php-client',
'method' => $method,
'params' => $params
]);
}
$ch = curl_init($url);
$curl_options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => ['Content-Type: application/json']
];
if (!empty($rpc_user) || !empty($rpc_password)) {
$curl_options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
$curl_options[CURLOPT_USERPWD] = "$rpc_user:$rpc_password";
}
curl_setopt_array($ch, $curl_options);
$response = curl_exec($ch);
if ($response === false) {
$errors[] = "cURL error on method `$method`: " . curl_error($ch);
curl_close($ch);
return null;
}
$result = json_decode($response, true);
curl_close($ch);
if (isset($result['error']) && $result['error'] !== null) {
$errors[] = "RPC error on `$method`: " . json_encode($result['error']);
return null;
}
return $result['result'] ?? $result;
}
// Cache function
function call_rpc_cached($method, $params, $dashboard_config, $url_schema, $ttlOverrides = [], $defaultTTL = 300) {
global $errors;
$network = strtolower($dashboard_config['network']);
$cacheFile = "{$network}_cache.json";
if (!file_exists($cacheFile)) {
file_put_contents($cacheFile, '{}');
}
$cacheData = json_decode(file_get_contents($cacheFile), true);
if (!is_array($cacheData)) {
$cacheData = [];
}
$cacheKey = $method . '_' . md5(json_encode($params));
$now = time();
$ttl = $ttlOverrides[$method] ?? $defaultTTL;
if (isset($cacheData[$cacheKey]) && ($now - $cacheData[$cacheKey]['timestamp']) < $ttl) {
return $cacheData[$cacheKey]['data'];
}
$result = call_rpc($method, $params, $dashboard_config, $url_schema);
if ($result === null) {
return null;
}
$cacheData[$cacheKey] = [
'timestamp' => $now,
'data' => $result
];
file_put_contents($cacheFile, json_encode($cacheData));
return $result;
}
// Format a byte count as a human-readable size (handles 0 safely)
function format_bytes($bytes) {
$bytes = (float) $bytes;
if ($bytes <= 0) {
return "0 Bytes";
}
$units = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
$unit = min(max((int) floor(log($bytes, 1024)), 0), count($units) - 1);
return number_format($bytes / (1024 ** $unit), 2) . " " . $units[$unit];
}
// Format a hashes-per-second value as a human-readable rate (handles 0 safely)
function format_hashrate($hashps) {
$hashps = (float) $hashps;
if ($hashps <= 0) {
return "0 H/s";
}
$units = ['H/s', 'KH/s', 'MH/s', 'GH/s', 'TH/s', 'PH/s'];
$unit = min(max((int) floor(log($hashps, 1000)), 0), count($units) - 1);
return number_format($hashps / (1000 ** $unit), 2) . " " . $units[$unit];
}
// TTL per RPC method cache
$ttlOverrides = [
'getblockchaininfo' => 30,
'getmempoolinfo' => 20,
'getnetworkinfo' => 90,
'getmininginfo' => 60,
'getchaintxstats' => 1800,
'estimatesmartfee' => 120
];
// Fetch info based on network family
if ($family === 'bitcoin') {
if ($dashboard_config['show_blockchain']) {
$blockinfo = call_rpc_cached('getblockchaininfo', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($blockinfo && is_array($blockinfo)) {
$blockcount = $blockinfo['blocks'] ?? 0;
$headercount = number_format($blockinfo['headers'] ?? 0);
$syncprogress = ($blockinfo['verificationprogress'] >= 0.99999) ? '100%' : round($blockinfo['verificationprogress'] * 100) . '%';
$chainsize = round(($blockinfo['size_on_disk'] ?? 0) / 1000000000, 2) . " GB";
} else {
$errors[] = 'Failed to fetch `getblockchaininfo`. RPC call returned null or invalid.';
}
}
if ($dashboard_config['show_node_info']) {
$netinfo = call_rpc_cached('getnetworkinfo', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($netinfo && is_array($netinfo) && $blockinfo && is_array($blockinfo)) {
$nodeversion = $netinfo['subversion'] ?? 'N/A';
$activechain = $blockinfo['chain'] ?? 'N/A';
$ispruned = ($blockinfo['pruned'] ?? false) ? 'true' : 'false';
$connections = $netinfo['connections'] ?? 0;
} else {
$errors[] = 'Failed to fetch `getnetworkinfo` or `getblockchaininfo` for node info.';
}
}
if ($dashboard_config['show_mempool']) {
$mempoolinfo = call_rpc_cached('getmempoolinfo', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($mempoolinfo && is_array($mempoolinfo)) {
$mempooltxns = number_format($mempoolinfo['size'] ?? 0);
$mempoolsize = format_bytes($mempoolinfo['bytes'] ?? 0);
$totalfees = sprintf('%.' . ($profile['decimals'] ?? 8) . 'f', $mempoolinfo['total_fee'] ?? 0) . " " . $profile['unit'];
} else {
$errors[] = 'Failed to fetch `getmempoolinfo`. RPC call returned null or invalid.';
}
}
if ($dashboard_config['show_mining']) {
$mininginfo = call_rpc_cached('getmininginfo', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($mininginfo && is_array($mininginfo) && $blockinfo && is_array($blockinfo)) {
$difficulty = number_format($blockinfo['difficulty'] ?? 0);
$hashrate = format_hashrate($mininginfo['networkhashps'] ?? 0);
$blockcount = $blockinfo['blocks'] ?? 0;
$currentsupply = 0.0;
$halvingInterval = $profile['halving_interval'];
$initialSubsidy = $profile['initial_subsidy'];
$lastHeight = $blockcount - 1;
$halvings = floor($lastHeight / $halvingInterval);
for ($i = 0; $i <= $halvings; $i++) {
$blockSubsidy = $initialSubsidy / pow(2, $i);
$start = $i * $halvingInterval;
$end = min(($i + 1) * $halvingInterval - 1, $lastHeight);
$blocks = $end - $start + 1;
$currentsupply += $blocks * $blockSubsidy;
}
$currentsupply = number_format($currentsupply, 0) . " " . $profile['unit'] . "\n";
$subsidy = ($initialSubsidy / (2 ** $halvings)) . " " . $profile['unit'];
$nextHalvingBlock = (floor($blockcount / $halvingInterval) + 1) * $halvingInterval;
$nexthalving = number_format($nextHalvingBlock - $blockcount);
$retarget = number_format(2016 - ($blockcount % 2016));
} else {
$errors[] = 'Failed to fetch `getmininginfo` or `getblockchaininfo` for mining section.';
}
}
if ($dashboard_config['show_fees']) {
$ratename = $profile['fee_unit'];
$fast = call_rpc_cached('estimatesmartfee', [1], $dashboard_config, $url_schema, $ttlOverrides);
$medium = call_rpc_cached('estimatesmartfee', [6], $dashboard_config, $url_schema, $ttlOverrides);
$slow = call_rpc_cached('estimatesmartfee', [144], $dashboard_config, $url_schema, $ttlOverrides);
if ($fast && isset($fast['feerate'])) {
$fastfees = round($fast['feerate'] * 100000000 / 1000);
} else {
$errors[] = 'Failed to fetch fast fee estimate.';
$fastfees = 'N/A';
}
if ($medium && isset($medium['feerate'])) {
$mediumfees = round($medium['feerate'] * 100000000 / 1000);
} else {
$errors[] = 'Failed to fetch medium fee estimate.';
$mediumfees = 'N/A';
}
if ($slow && isset($slow['feerate'])) {
$slowfees = round($slow['feerate'] * 100000000 / 1000);
} else {
$errors[] = 'Failed to fetch slow fee estimate.';
$slowfees = 'N/A';
}
}
if ($dashboard_config['show_transactions']) {
$chaintxstats = call_rpc_cached('getchaintxstats', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($chaintxstats && is_array($chaintxstats)) {
$totaltxns = number_format($chaintxstats['txcount'] ?? 0);
$averagetxns = sprintf('%.2f', $chaintxstats['txrate'] ?? 0);
$monthlytxns = number_format($chaintxstats['window_tx_count'] ?? 0);
} else {
$totaltxns = 'N/A';
$averagetxns = 'N/A';
$monthlytxns = 'N/A';
$errors[] = 'Unable to fetch `getchaintxstats`. RPC returned null or invalid data.';
}
}
} elseif ($family === 'monero') {
$ttlOverrides = [
'get_info' => 30,
'get_block_count' => 15,
'get_last_block_header' => 20,
'get_transaction_pool_stats' => 20,
'get_miner_data' => 20,
'get_fee_estimate' => 20,
];
if ($dashboard_config['show_blockchain']) {
$block_count = call_rpc_cached('get_block_count', [], $dashboard_config, $url_schema, $ttlOverrides);
$last_block_header = call_rpc_cached('get_last_block_header', [], $dashboard_config, $url_schema, $ttlOverrides);
$getinfo = call_rpc_cached('get_info', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($block_count && $last_block_header) {
$blockcount = $block_count['count'] ?? 0;
$syncprogress = $getinfo['synchronized'] ? 'Yes' : 'No';
$chainsize = round(($getinfo['database_size'] ?? 0) / 1000000000, 2) . " GB";
$headercount = number_format($blockcount);
} else {
$errors[] = 'Failed to fetch Monero blockchain info.';
}
}
if ($dashboard_config['show_node_info']) {
$getinfo = call_rpc_cached('get_info', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($getinfo && is_array($getinfo)) {
$nodeversion = $getinfo['version'] ?? 'N/A';
$activechain = $getinfo['nettype'] ?? 'N/A';
$connections = $getinfo['incoming_connections_count'] + $getinfo['outgoing_connections_count'];
} else {
$errors[] = 'Failed to fetch Monero node info.';
}
}
if ($dashboard_config['show_mempool']) {
$mempoolinfo = call_rpc_cached('get_transaction_pool_stats', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($mempoolinfo) {
$mempooltxns = number_format($mempoolinfo['pool_stats']['txs_total'] ?? 0);
$mempoolsize = format_bytes($mempoolinfo['pool_stats']['bytes_total'] ?? 0);
$totalfees = number_format(($mempoolinfo['pool_stats']['fee_total'] ?? 0) / 1e12, 6) . " " . $profile['unit'];
} else {
$errors[] = 'Failed to fetch Monero mempool info.';
}
}
if ($dashboard_config['show_mining']) {
$getinfo = call_rpc_cached('get_info', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($getinfo) {
$difficulty = number_format($getinfo['difficulty'] ?? 0);
$hashrate = format_hashrate(($getinfo['difficulty'] ?? 0) / 120);
$blockcount = $getinfo['height'] ?? 0;
} else {
$errors[] = 'Failed to fetch Monero mining info.';
}
}
if ($dashboard_config['show_transactions']) {
$getinfo = call_rpc_cached('get_info', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($getinfo) {
$totaltxns = number_format($getinfo['tx_count'] ?? 0);
$averagetxns = sprintf('%.2f', $getinfo['txrate'] ?? 0);
$monthlytxns = number_format($getinfo['window_tx_count'] ?? 0);
} else {
$errors[] = 'Failed to fetch Monero transaction info.';
}
$mininginfo = call_rpc_cached('get_miner_data', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($mininginfo) {
$currentsupply = number_format(($mininginfo['already_generated_coins'] ?? 0) / 1000000000000) . " " . $profile['unit'];
} else {
$errors[] = 'Failed to fetch Monero mining info.';
}
}
if ($dashboard_config['show_fees']) {
$getfees = call_rpc_cached('get_fee_estimate', [], $dashboard_config, $url_schema, $ttlOverrides);
if ($getfees) {
$ratename = "per kB";
$fastfees = number_format(($getfees['fees'][3] ?? 0) / 1000000000000, 12) . " " . $profile['unit'];
$mediumfees = number_format(($getfees['fees'][2] ?? 0) / 1000000000000, 12) . " " . $profile['unit'];
$slowfees = number_format(($getfees['fees'][1] ?? 0) / 1000000000000, 12) . " " . $profile['unit'];
$slowestfees = number_format(($getfees['fees'][0] ?? 0) / 1000000000000, 12) . " " . $profile['unit'];
} else {
$errors[] = 'Failed to fetch Monero fee estimates.';
}
}
}
// Machine-readable snapshot for JSON consumers (Home Assistant, Grafana, scripts, etc.).
// Request it with ?format=json. Values are raw/unformatted for easy parsing. The `?? null`
// guards keep it warning-free when a section is disabled or its RPC call failed.
$stats = [
'network' => $network,
'coin' => $coin,
'unit' => $profile['unit'],
'family' => $family,
'updated' => time(),
];
if ($family === 'bitcoin') {
$stats += [
'version' => $netinfo['subversion'] ?? null,
'chain' => $blockinfo['chain'] ?? null,
'pruned' => $blockinfo['pruned'] ?? null,
'connections' => $netinfo['connections'] ?? null,
'block_height' => $blockinfo['blocks'] ?? null,
'headers' => $blockinfo['headers'] ?? null,
'verification_progress' => $blockinfo['verificationprogress'] ?? null,
'size_on_disk' => $blockinfo['size_on_disk'] ?? null,
'mempool_txns' => $mempoolinfo['size'] ?? null,
'mempool_bytes' => $mempoolinfo['bytes'] ?? null,
'mempool_total_fee' => $mempoolinfo['total_fee'] ?? null,
'difficulty' => $blockinfo['difficulty'] ?? null,
'network_hashps' => $mininginfo['networkhashps'] ?? null,
'total_transactions' => $chaintxstats['txcount'] ?? null,
'tx_rate' => $chaintxstats['txrate'] ?? null,
'window_tx_count' => $chaintxstats['window_tx_count'] ?? null,
'fees_sat_vb' => ['fast' => $fastfees ?? null, 'medium' => $mediumfees ?? null, 'slow' => $slowfees ?? null],
];
} elseif ($family === 'monero') {
$stats += [
'version' => $getinfo['version'] ?? null,
'chain' => $getinfo['nettype'] ?? null,
'connections' => isset($getinfo['incoming_connections_count'], $getinfo['outgoing_connections_count'])
? $getinfo['incoming_connections_count'] + $getinfo['outgoing_connections_count'] : null,
'block_height' => $getinfo['height'] ?? ($block_count['count'] ?? null),
'synchronized' => $getinfo['synchronized'] ?? null,
'database_size' => $getinfo['database_size'] ?? null,
'mempool_txns' => $mempoolinfo['pool_stats']['txs_total'] ?? null,
'mempool_bytes' => $mempoolinfo['pool_stats']['bytes_total'] ?? null,
'mempool_total_fee' => isset($mempoolinfo['pool_stats']['fee_total']) ? $mempoolinfo['pool_stats']['fee_total'] / 1e12 : null,
'difficulty' => $getinfo['difficulty'] ?? null,
'total_transactions' => $getinfo['tx_count'] ?? null,
'supply' => isset($mininginfo['already_generated_coins']) ? $mininginfo['already_generated_coins'] / 1e12 : null,
'fees_per_kb' => $getfees['fees'] ?? null,
];
}
if (!empty($errors)) {
$stats['errors'] = $errors;
}
if ($enable_json && ($_GET['format'] ?? '') === 'json') {
header('Content-Type: application/json');
echo json_encode($stats, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit;
}
?>
<!DOCTYPE html>
<html data-theme="<?= htmlspecialchars($theme) ?>">
<head>
<meta charset="utf-8">
<title><?= $coin ?> Node Dashboard</title>
<meta name="description" content="A simple node dashboard for your <?= $coin ?> node.">
<?php if ($refresh_seconds > 0): ?><noscript><meta http-equiv="refresh" content="<?= (int) $refresh_seconds ?>"></noscript><?php endif; ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* Theme palettes, applied via the data-theme attribute on <html>.
The default (no attribute) matches the dark theme. */
:root,
html[data-theme="dark"] {
--bg: #0e0e0e;
--text: #cfcfcf;
--section-bg: #121212;
--section-border: #222;
--title-color: #fff;
--title-border: #333;
--label-color: #aaa;
--row-border: #2a2a2a;
--header-bg: #1a1a1a;
--header-text: #fff;
--link: #6ea8fe;
}
html[data-theme="light"] {
--bg: #f4f4f4;
--text: #1c1c1c;
--section-bg: #ffffff;
--section-border: #d8d8d8;
--title-color: #000;
--title-border: #cccccc;
--label-color: #555;
--row-border: #e2e2e2;
--header-bg: #ffffff;
--header-text: #000;
--link: #0d6efd;
}
html[data-theme="nord"] {
--bg: #2e3440;
--text: #d8dee9;
--section-bg: #3b4252;
--section-border: #434c5e;
--title-color: #eceff4;
--title-border: #4c566a;
--label-color: #a0aab9;
--row-border: #434c5e;
--header-bg: #3b4252;
--header-text: #eceff4;
--link: #88c0d0;
}
html[data-theme="solarized"] {
--bg: #002b36;
--text: #93a1a1;
--section-bg: #073642;
--section-border: #0a4250;
--title-color: #fdf6e3;
--title-border: #586e75;
--label-color: #839496;
--row-border: #0a4250;
--header-bg: #073642;
--header-text: #fdf6e3;
--link: #2aa198;
}
html[data-theme="dracula"] {
--bg: #282a36;
--text: #f8f8f2;
--section-bg: #343746;
--section-border: #44475a;
--title-color: #ff79c6;
--title-border: #44475a;
--label-color: #bd93f9;
--row-border: #44475a;
--header-bg: #343746;
--header-text: #f8f8f2;
--link: #8be9fd;
}
body {
margin: 0;
background: var(--bg);
color: var(--text);
font-family: 'Courier New', monospace;
font-size: 18px;
padding: 1rem;
}
a {
color: var(--link);
}
.section {
background: var(--section-bg);
border: 1px solid var(--section-border);
padding: 0.5rem 1rem;
box-sizing: border-box;
flex: 0 0 calc(33.333% - 1rem); /* limit to 3 per row */
max-width: calc(33.333% - 1rem);
min-width: 250px;
}
.section, .stat-row span {
word-break: break-word;
overflow-wrap: break-word;
}
/* Medium screens: 2 per row */
@media (max-width: 1240px) {
.section {
flex: 0 0 calc(50% - 1rem);
max-width: calc(50% - 1rem);
}
}
/* Small screens: 1 per row */
@media (max-width: 840px) {
.section {
flex: 1 1 100%;
max-width: 100%;
min-width: unset;
}
}
.section-title {
font-weight: bold;
color: var(--title-color);
margin-bottom: 0.5rem;
border-bottom: 1px solid var(--title-border);
padding-bottom: 0.25rem;
}
.stat-row {
display: flex;
justify-content: space-between;
padding: 0.15rem 0;
border-bottom: 1px dotted var(--row-border);
}
.stat-row span:first-child {
color: var(--label-color);
}
/* Stats with a tooltip explanation get a help cursor and a subtle hint underline */
.stat-row span[title] {
cursor: help;
text-decoration: underline dotted;
text-underline-offset: 3px;
}
/* The "Connect to this Node" box spans the full width as a banner above the grid */
.section.connect-box {
flex: 0 0 100%;
max-width: 100%;
text-align: center;
}
.section.connect-box .stat-row {
justify-content: center;
gap: 0.5rem;
border-bottom: none;
}
.dashboard-header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: var(--header-bg);
color: var(--header-text);
padding: 8px 12px;
font-size: 15px;
font-weight: bold;
z-index: 1000;
box-shadow: 0 1px 4px rgba(0,0,0,0.2);
text-align: center;
word-break: break-word;
}
.compact-dashboard {
display: flex;
flex-wrap: wrap;
gap: 1rem;
margin-top: 115px;
}
/* Without the switcher row the header is shorter, so reclaim the space */
.compact-dashboard.no-switcher {
margin-top: 80px;
}
.header-title {
margin: 0;
font-size: 18px;
}
.theme-switcher {
margin-top: 6px;
font-size: 13px;
font-weight: normal;
}
.theme-switcher select {
background: var(--section-bg);
color: var(--text);
border: 1px solid var(--section-border);
font-family: inherit;
font-size: 13px;
padding: 2px 6px;
border-radius: 3px;
}
.dashboard-footer {
color: var(--header-text);
font-size: 16px;
z-index: 1000;
}
</style>
<?php if ($show_theme_switcher): ?>
<script>
// Apply the visitor's saved theme before paint to avoid a flash of the
// server-rendered default, on every load. Only active when the switcher is
// enabled; with it hidden, the configured theme is final and localStorage is ignored.
(function () {
try {
var saved = localStorage.getItem('snd-theme');
if (saved) {
document.documentElement.setAttribute('data-theme', saved);
}
} catch (e) {}
})();
</script>
<?php endif; ?>
</head>
<body>
<div class="dashboard-header">
<span class="header-title"><?= $coin ?> Node Dashboard</span>
<br/>
<span>Updated:</span> <span id="updated" data-ts="<?= time() ?>"><?= gmdate("H:i:s") ?> UTC</span> | <span>Auto-refresh: <?= $refresh_seconds > 0 ? (int) $refresh_seconds . 's' : 'off' ?></span>
<?php if ($show_theme_switcher): ?>
<div class="theme-switcher">
Theme:
<select id="theme-select" aria-label="Select theme" onchange="setTheme(this.value)">
<option value="dark">Dark</option>
<option value="light">Light</option>
<option value="nord">Nord</option>
<option value="solarized">Solarized</option>
<option value="dracula">Dracula</option>
</select>
</div>
<?php endif; ?>
</div>
<?php if ($show_theme_switcher): ?>
<script>
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
try { localStorage.setItem('snd-theme', theme); } catch (e) {}
}
// Reflect the currently active theme in the dropdown on load.
(function () {
var current = document.documentElement.getAttribute('data-theme') || 'dark';
var select = document.getElementById('theme-select');
if (select) select.value = current;
})();
</script>
<?php endif; ?>
<div id="dashboard-content">
<div class="compact-dashboard<?= $show_theme_switcher ? '' : ' no-switcher' ?>">
<?php if ($show_connect): ?>
<div class="section connect-box">
<div class="section-title">Connect to this Node</div>
<div class="stat-row"><span title="The public address to point your wallet or client at.">Address</span><span><?= htmlspecialchars($connect_address) ?></span></div>
<?php if ($connect_note !== ''): ?>
<div class="stat-row"><span title="Additional connection details from the node operator.">Note</span><span><?= htmlspecialchars($connect_note) ?></span></div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($dashboard_config['show_node_info']): ?>
<div class="section">
<div class="section-title">Node Info</div>
<div class="stat-row"><span title="The version of the node software your node is running.">Version</span><span><?= $nodeversion ?></span></div>
<div class="stat-row"><span title="Which network this node is on (e.g. mainnet, testnet).">Chain</span><span><?= $activechain ?></span></div>
<?php if ($family !== 'monero'): ?>
<div class="stat-row"><span title="Whether the node deletes old block data to save disk space.">Pruned</span><span><?= $ispruned ?></span></div>
<?php endif; ?>
<div class="stat-row"><span title="Number of other nodes (peers) this node is connected to.">Connections</span><span><?= $connections ?></span></div>
</div>
<?php endif; ?>
<?php if ($dashboard_config['show_blockchain']): ?>
<div class="section">
<div class="section-title">Blockchain</div>
<div class="stat-row"><span title="The number of blocks this node has validated and stored.">Block Height</span><span><?= number_format($blockcount) ?></span></div>
<div class="stat-row"><span title="The number of block headers the node is aware of. Higher than block height while still syncing.">Block Headers</span><span><?= $headercount?></span></div>
<?php if ($family !== 'monero'): ?>
<div class="stat-row"><span title="How far the node has progressed verifying the blockchain. 100% means fully synced.">Sync Progress</span><span><?= $syncprogress ?></span></div>
<?php endif; ?>
<?php if ($family === 'monero'): ?>
<div class="stat-row"><span title="Whether the node is fully synced with the network.">Synced</span><span><?= $syncprogress ?></span></div>
<?php endif; ?>
<div class="stat-row"><span title="Disk space currently used by the blockchain data.">Chain Size</span><span><?= $chainsize ?></span></div>
</div>
<?php endif; ?>
<?php if ($dashboard_config['show_mempool']): ?>
<div class="section">
<div class="section-title">Mempool</div>
<div class="stat-row"><span title="Unconfirmed transactions waiting in the mempool to be included in a block.">Pending TX Count</span><span><?= $mempooltxns ?></span></div>
<div class="stat-row"><span title="Total size of all unconfirmed transactions currently in the mempool.">Total Size</span><span><?= $mempoolsize ?></span></div>
<?php if (isset($totalfees)): ?>
<div class="stat-row"><span title="Combined fees of all unconfirmed transactions in the mempool.">Total Fees</span><span><?= $totalfees ?></span></div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($dashboard_config['show_mining']): ?>
<div class="section">
<div class="section-title">Mining</div>
<div class="stat-row"><span title="A measure of how hard it is to mine a new block. Adjusts to keep block times steady.">Difficulty</span><span><?= $difficulty ?></span></div>
<div class="stat-row"><span title="Estimated total computing power miners are dedicating to the network.">Hash Rate</span><span><?= $hashrate ?></span></div>
<?php if ($family !== 'monero'): ?>
<div class="stat-row"><span title="Blocks remaining until the next mining difficulty adjustment (every 2016 blocks).">Blocks till retarget</span><span><?= $retarget ?></span></div>
<div class="stat-row"><span title="Blocks remaining until the next halving, when the block reward is cut in half.">Blocks till halving</span><span><?= $nexthalving ?></span></div>
<div class="stat-row"><span title="The amount of newly minted coin paid to a miner for finding a block.">Block Reward</span><span><?= $subsidy ?></span></div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($dashboard_config['show_transactions']): ?>
<div class="section">
<div class="section-title">Transactions</div>
<div class="stat-row"><span title="The all-time total number of transactions recorded on the blockchain.">Total Transactions</span><span><?= $totaltxns ?></span></div>
<div class="stat-row"><span title="The total amount of coin mined into existence so far.">Current Supply</span><span><?= $currentsupply ?></span></div>
<?php if ($family !== 'monero'): ?>
<div class="stat-row"><span title="Average number of transactions per second over the last 30 days.">Average tx/s (30-days)</span><span><?= $averagetxns ?></span></div>
<div class="stat-row"><span title="Number of transactions confirmed in the last 30 days.">30-day transactions</span><span><?= $monthlytxns ?></span></div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($dashboard_config['show_fees']): ?>
<div class="section">
<div class="section-title">Transaction Feerates (<?= $ratename ?>)</div>
<?php if ($family !== 'monero'): ?>
<div class="stat-row"><span title="Estimated fee rate to get confirmed within the next block (fastest).">1 block</span><span><?= $fastfees ?></span></div>
<div class="stat-row"><span title="Estimated fee rate to get confirmed within about 6 blocks (~1 hour).">6 blocks</span><span><?= $mediumfees ?></span></div>
<div class="stat-row"><span title="Estimated fee rate to get confirmed within about 144 blocks (~1 day, cheapest).">144 blocks</span><span><?= $slowfees ?></span></div>
<?php elseif ($family === 'monero'): ?>
<div class="stat-row"><span title="Higher fee for faster confirmation.">Fast</span><span><?= $fastfees ?></span></div>
<div class="stat-row"><span title="Balanced fee for typical confirmation times.">Medium</span><span><?= $mediumfees ?></span></div>
<div class="stat-row"><span title="Lower fee with slower confirmation.">Slow</span><span><?= $slowfees ?></span></div>
<div class="stat-row"><span title="Lowest fee with the slowest confirmation.">Slowest</span><span><?= $slowestfees ?></span></div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php if (!empty($errors)): ?>
<div style="color: black; margin-top: 30px; padding: 10px; border: 1px solid red; background: #fee;">
<h3>Errors:</h3>
<ul>
<?php foreach ($errors as $e): ?>
<li><?php echo htmlspecialchars($e); ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
<br/><br/>
<div class="dashboard-footer">
<center>
<span class="footer-title">Made by <a href="https://tech1k.com">Tech1k</a> | <a href="https://github.com/Tech1k/simple-node-dashboard">Source Code</a></span>
</center>
</div>
<script>
// Render the "Updated" time in the viewer's local timezone, and refresh the
// dashboard in place every 60s (no full-page reload, so scroll and theme persist).
(function () {
var intervalMs = <?= (int) $refresh_seconds ?> * 1000;
function renderTime() {
var el = document.getElementById('updated');
if (!el || !el.dataset.ts) return;
var d = new Date(el.dataset.ts * 1000);
el.textContent = d.toLocaleTimeString([], {
hour: '2-digit', minute: '2-digit', second: '2-digit', timeZoneName: 'short'
});
}
async function refresh() {
try {
var res = await fetch(location.href, { cache: 'no-store' });
if (!res.ok) return;
var doc = new DOMParser().parseFromString(await res.text(), 'text/html');
var fresh = doc.getElementById('dashboard-content');
var current = document.getElementById('dashboard-content');
if (fresh && current) current.replaceWith(fresh);
var freshTs = doc.getElementById('updated');
var liveTs = document.getElementById('updated');
if (freshTs && liveTs) liveTs.dataset.ts = freshTs.dataset.ts;
renderTime();
} catch (e) {}
}
renderTime();
if (intervalMs > 0) setInterval(refresh, intervalMs);
})();
</script>
</body>
</html>