forked from PiSupply/iot-lora-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·265 lines (224 loc) · 6.76 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
<?php
/*
*IoT LoRa Gateway Controller
*Copyright (C) 2018-2019 Nebra LTD. T/a Pi Supply
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include('inc/header.php');
/*
* Lets load most of the information required to fill this page's details out
*
*/
//Linux uptime
$uptime = shell_exec('uptime -p');
$packetForwarder = shell_exec('systemctl is-active iot-lora-gateway.service');
if(strlen($packetForwarder) < 9) {
$packetForwarder = 1;
}
else {
$packetForwarder = 0;
}
//Lets check for external internet connectivity by doing a http request to three servers
$internetCheck1 = file_get_contents('http://www.google.com');
$internetCheck2 = file_get_contents('https://status.thethings.network/');
$internetCheck3 = file_get_contents('https://www.cloudflare.com/');
$internetStatus = 0;
if($internetCheck1 == FALSE) {
$internetStatus++;
}
if($internetCheck2 == FALSE) {
$internetStatus++;
}
if($internetCheck3 == FALSE) {
$internetStatus++;
}
//If the number is greater than 0 then either one of the sites is down, if all three are down there is likely an internet issue.
$gatewayIpAddress = getHostByName(getHostName());
$configHandler = fopen($configLocation, 'r');
$currentConfig = fread($configHandler, filesize($configLocation));
$jsonDecoded = json_decode($currentConfig,true)['gateway_conf'];
$jsonServers = $jsonDecoded['servers'][0];
$gatewayConfigured = 1;
if($jsonServers == NULL) {
$gatewayConfigured = 0;
$jsonServers['serv_gw_id'] = "GATEWAY CONFIG IS MISSING";
}
//Lets get the data from the NOC api
$ttnNocStatus = json_decode(file_get_contents('http://noc.thethingsnetwork.org:8085/api/v2/gateways/'.trim($jsonServers['serv_gw_id'])),true);
if($ttnNocStatus["rx_ok"]) {
$packetsRx = $ttnNocStatus["rx_ok"];
}
else {
$packetsRx = "0";
}
if($ttnNocStatus["tx_in"]) {
$packetsTx = $ttnNocStatus["tx_in"];
}
else {
$packetsTx = " 0";
}
$cpuTemp = shell_exec("cat /sys/class/thermal/thermal_zone0/temp");
$cpuTemp = $cpuTemp/1000;
?>
<h1>IoT LoRa Gateway Status Page</h1>
<h2>Gateway ID: <?php echo($jsonServers['serv_gw_id']);?></h2>
<?php
if($gatewayConfigured == 0) {
echo '
<div class="ui divided grid stackable">
<div class="row">
<div class="column wide">
<div class="ui error message">
<h3>Gateway Is Not Configured!</h3>
There is no configuration file detected for this gateway. Please use the change configuration tab to configure this gateway.
</div>
</div>
</div>
</div>
';
}
?>
<div class="ui divided grid stackable">
<div class="three column row">
<div class="column wide">
<?php
//Change the alert box's colour based on the status.
if($internetStatus == 0) {
echo("<div class=\"ui positive message segment\">");
}
elseif($internetStatus == 3) {
echo("<div class=\"ui error message segment\">");
}
else {
echo("<div class=\"ui warning message segment\">");
}
?>
<h3>Internet Connectivity <i class="globe icon"></i></h3>
<?php
//Change the text based on the status.
if($internetStatus == 0) {
echo("All good!");
}
elseif($internetStatus == 3) {
echo("All 3 Sites we've tested against are producing no response indicating an internet outage.");
}
else {
echo("One or more of the 3 sites we've tested against are producing no response indicating a potential outage");
}
?>
</div>
</div>
<div class="column wide">
<?php
//Change the alert box's colour based on the status.
if($packetForwarder == 1) {
echo("<div class=\"ui positive message segment\">");
}
else {
echo("<div class=\"ui error message segment\">");
}
?>
<h3>Packet Forwarder <i class="microchip icon"></i></h3>
The packet forwarder service is <?php if($packetForwarder==0){echo("not ");}?>running.
</div>
</div>
<div class="column wide">
<div class="ui info message segment">
<h3>Uptime <i class="calendar check icon"></i></h3>
This gateway has been online for:<br/>
<?php echo($uptime); ?>
</div>
</div>
</div>
</div>
<div class="ui divided grid stackable">
<div class="row">
<div class="column wide">
<div class="ui positive message">
<strong>Gateway IP Address:</strong> <?php echo($gatewayIpAddress);?>
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="ui positive message">
<strong>Configured TTN Server:</strong> <?php echo($jsonServers['server_address']);?>
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="ui info message">
<strong>CPU Temperature:</strong>
<div class="ui teal progress" id="progressBar" data-percent="<?php echo($cpuTemp); ?>">
<div class="bar"></div>
<div class="label"><?php echo($cpuTemp); ?> Degrees C</div>
</div>
</div>
</div>
</div>
</div>
<hr/>
<br/>
<div class="ui divided grid stackable centered">
<h2>Packet Statistics</h2>
<div class="two column row">
<div class="column wide">
<div class="ui statistics">
<div class="statistic">
<div class="value">
<i class="arrow down icon"></i> <?php echo $packetsRx;?>
</div>
<div class="label">
Packets Recieved
</div>
</div>
</div>
</div>
<div class="column wide">
<div class="ui statistics">
<div class="statistic">
<div class="value">
<i class="arrow up icon"></i><?php echo $packetsTx;?>
</div>
<div class="label">
Packets Transmitted
</div>
</div>
</div>
</div>
</div>
<h4>Packet statistics are from The Things Network Console</h4>
<br/>
<h4>
<a class="twitter-share-button"
href="https://twitter.com/intent/tweet?text=My%20@PiSupply%20IoT%20LoRa%20Gateway%20has%20recieved%20<?php echo $packetsRx;?>%20Packets%20on%20%23thethingsnetwork%20&hashtags=IoTLoraGateway,IoT,TTN,LoRaWAN&related=PiSupply,TheThingsNtwrk"
data-size="large"
>
<link rel="me"
href="https://twitter.com/pisupply"
>
Tweet</a>
</h4>
</div>
<br/><br/>
<br/><br/>
</div>
</div>
<script>
$('#progressBar').progress();
</script>
<?php
include('inc/footer.php');
?>