-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmc-info.php
More file actions
58 lines (46 loc) · 1.57 KB
/
mc-info.php
File metadata and controls
58 lines (46 loc) · 1.57 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
<?php
/**
* Functions to collect and build information about a server running one or
* more Multichain nodes, based on the configuration in config.php
*
* @author Chris Baumann <c.baumann@baumann.at>
* @copyright 2020 baumann.at - concepts & solutions
* @version mc-info v0.2 - 26.4.2022
*/
require_once 'functions.php';
require_once 'auth_lib.php';
list($configs, $userConfig, $mcInfoConfig) = read_config();
//check mc-info password if used
if (isset($mcInfoConfig->user)) {
if (authOK($mcInfoConfig->user, $mcInfoConfig->pwd_hash, 'mc-info requires a valid user')) {};
}
$nodes = array();
foreach ($configs as $config) {
$name = $config['name'];
$nodes[$name] = getChainInfo($config);
}
$mcInfo = new stdClass;
$mcInfo->serverName = $mcInfoConfig->serverName;
$mcInfo->serverOwner = $mcInfoConfig->serverOwner;
$mcInfo->version = 'mc-info v0.1';
$mcInfo->extIPconfigured = $mcInfoConfig->externalIP;
$res = new stdClass;
$res->mcInfo = $mcInfo;
$res->nodes = $nodes;
header("Content-Type: application/json; charset=UTF-8");
echo (json_encode($res));
function getChainInfo($config) {
$res = array();
set_multichain_chain($config);
$getInfo = multichain('getinfo');
if (isset($getInfo['error']['code'])) {
$res['status'] = 'Error: Blockchain API returns: ' . $getInfo['error']['code'];
return ($res);
}
$res['status'] = 'OK 200';
$res['getinfo'] = $getInfo['result'];
$res['getconnectioncount'] = multichain('getconnectioncount') ['result'];
$res['getpeerinfo'] = multichain('getpeerinfo') ['result'];
return ($res);
}
?>