forked from mrgrshift/shift-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
167 lines (126 loc) · 6.11 KB
/
test.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
/* CHECKING IF THE SETTINGS ARE CORRECT
_________________________________________ */
// initialization
require(dirname(__FILE__).'/config.php');
require(dirname(__FILE__).'/includes/functions.php');
require(dirname(__FILE__).'/includes/init.php');
$trustedNodeRequired = ($recoveryEnabled || $createSnapshots || $switchingEnabled);
$telegramEnabled = ($recoveryMessages || $debugMessages);
echo "\n\t\t$uline$bold CONFIG TEST STARTED $endStyle\n\n";
// getting arguments
if ($argc > 1) {
for ($i = 1; $i < $argc; $i++) {
switch ($argv[$i]) {
case "-m":
if ($i === 1) {
$inputRole = "m";
break;
}
if ($i === 2) {
$inputNetwork = "m";
break;
}
case "--main":
$inputRole = "m";
break;
case "-b":
case "--backup":
$inputRole = "b";
break;
case "--mainnet":
$inputNetwork = "m";
break;
case "-t":
case "--testnet":
$inputNetwork = "t";
break;
default:
if (substr($argv[$i], 1, 1) == '-') {
echo "Unknown option: {$argv[$i]}\n";
}
break;
}
}
}
// user input
if (!isset($inputRole) || !isset($inputNetwork)) {
$stdin = fopen("php://stdin", "r");
echo "Is this your ".$uline."Main node".$endStyle." (".$bold."m".$endStyle.") or your ".$uline."Backup node".$endStyle." (".$bold."b".$endStyle.")? ".$dim."(m/b)".$endStyle.": ";
$inputRole = trim(fgets($stdin));
echo "".$uline."Mainnet".$endStyle." (".$bold."m".$endStyle.") or ".$uline."Testnet".$endStyle." (".$bold."t".$endStyle.")? ".$dim."(m/t)".$endStyle.": ";
$inputNetwork = trim(fgets($stdin));
fclose($stdin);
}
$inputRole = (($inputRole == "m") ? "MAIN " : "BACKUP ");
$inputNetwork = (($inputNetwork == "m") ? "MAINNET" : "TESTNET");
// get data
$shiftDir = $pathtoapp;
$localRole = (($thisMain) ? "MAIN " : "BACKUP ");
$localNetwork = ((strpos($localNode, "9305")) ? "MAINNET" : "TESTNET");
$localAPI = ((ping($localNode)) ? "AVAIBLE" : "INACCESSIBLE");
$localForgingAPI = ((checkForging($localNode, $public) == "true" || (checkForging($localNode, $public) == "false")) ? "AVAIBLE" : (((checkForging($localNode, $public) == "error") ? "INACCESSIBLE" : "NO SECRET")));
$shiftDirNetwork = ((strpos(tailCustom($shiftDir."config.json", 500), "9305")) ? "MAINNET" : ((strpos(tailCustom($shiftDir."config.json", 500), "9405")) ? "TESTNET" : "NO SHIFT-LISK INSTALLATION"));
['height' => $localHeight] = getNodeAPIData($localNode);
if ($trustedNodeRequired) {
$trustedNode = $trustedNode; // add check
['height' => $trustedHeight] = getNodeAPIData($trustedNode);
$trustedAPI = ((ping($trustedNode)) ? "AVAIBLE" : "INACCESSIBLE");
}
if ($switchingEnabled) {
$remoteNetwork = (($remoteNode == "DISABLED") ? "DISABLED" : ((strpos($remoteNode, "9305") ? "MAINNET" : ((strpos($remoteNode, "9405") ? "TESTNET" : "NO PORT")))));
$remoteAPI = ((ping($remoteNode)) ? "AVAIBLE" : "INACCESSIBLE");
$remoteForgingAPI = ((checkForging($remoteNode, $public) == "true" || (checkForging($remoteNode, $public) == "false")) ? "AVAIBLE" : (((checkForging($remoteNode, $public) == "error") ? "INACCESSIBLE" : "NO SECRET")));
['height' => $remoteHeight] = getNodeAPIData($remoteNode);
}
if ($telegramEnabled) {
$Tmsg = "*".$nodeName."*:\n\n" . $checkmarkEmoji . " Hello from *shift-checker*" . $wavehandEmoji . $robotEmoji;
$telegramResponse = sendMessage($Tmsg, true);
$telegramResponse = json_decode($telegramResponse, true);
$telegramResponse = (($telegramResponse['ok'] == "true") ? "SENT " : "FAIL ");
}
// echo with tests
echo "\n\n";
myEcho("shift-lisk directory:", $shiftDir);
(($switchingEnabled) ? myEcho("Remote node: ", $remoteNode) : "");
(($trustedNodeRequired) ? myEcho("Trusted node: ", $trustedNode) : "");
echo "\n";
myEcho("This node is: ", $localRole, $inputRole); // must be MAIN
echo "\n";
myEcho("Directory network:", $shiftDirNetwork, $inputNetwork); // must be same as an input network
myEcho("Local node network:", $localNetwork, $inputNetwork); // must be same as an input network
(($switchingEnabled) ? myEcho("Remote node network:", $remoteNetwork, $inputNetwork) : ""); // must be same as an input network
echo "\n";
myEcho("Local node API:", $localAPI, "AVAIBLE"); // must be avaible
(($switchingEnabled) ? myEcho("Remote node API:", $remoteAPI, "AVAIBLE") : ""); // must be avaible
myEcho("Local forging API:", $localForgingAPI, "AVAIBLE"); // must be avaible
(($switchingEnabled) ? myEcho("Remote forging API:", $remoteForgingAPI, "AVAIBLE") : ""); // must be avaible
if ($trustedNodeRequired) {
myEcho("Trusted node API:", $trustedAPI, "AVAIBLE"); // must be avaible
echo "\n";
myEcho("Trusted node height:", $trustedHeight, $localHeight, "height"); // must be same as local height
myEcho("Local node height:", $localHeight, $trustedHeight, "height"); // must be same as trusted height
(($switchingEnabled) ? myEcho("Remote node height:", $remoteHeight, $trustedHeight, "height") : ""); // must be same as trusted height
} else {
myEcho("Local node height:", "ok", "ok");
}
echo "\n";
(($telegramEnabled) ? myEcho("Telegram notification:", $telegramResponse, "SENT ") : "" );
echo "\n";
// functions
function myEcho($string, $value, $compare=false, $h=false) {
global $bold, $red, $green, $endStyle;
if ($compare === false) {
echo $bold.$string.$endStyle." \t $value \n";
} else {
echo $bold.$string.$endStyle." \t $value" . redOrGreen($value, $compare, $h) . "\n";
}
}
function redOrGreen($first, $second, $h=false) {
global $bold, $red, $green, $endStyle;
if ($h == "height") {
return (($first >= $second - 2) ? "\t".$bold.$green."OK".$endStyle : "\t".$bold.$red."FAIL".$endStyle);
}
return (($first === $second) ? "\t".$bold.$green."OK".$endStyle : "\t".$bold.$red."FAIL".$endStyle);
}
?>