parallel_node_polling.php 19.5 KB
Newer Older
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1
<?php
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/******
* parallel_node_polling script v3 by kg6wxc\eric satterlee kg6wxc@gmail.com
* Licensed under GPLv3 or later
*
* This file is part of the Mesh Mapping System.
* The Mesh Mapping System 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.
*
* The Mesh Mapping System 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 The Mesh Mapping System.  If not, see <http://www.gnu.org/licenses/>.
******/

21
22
23
24
25
26
27
if (PHP_SAPI !== 'cli') {
    $file = basename($_SERVER['PHP_SELF']);
    exit("<style>html{text-align: center;}p{display: inline;}</style>
        <br><strong>This script ($file) should only be run from the
        <p style='color: red;'>command line</p>!</strong>
        <br>exiting...");
}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
28
$INCLUDE_DIR = "..";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
29
30
$USER_SETTINGS = parse_ini_file($INCLUDE_DIR . "/scripts/user-settings.ini");
require $INCLUDE_DIR . "/scripts/wxc_functions.inc";
31
@include $INCLUDE_DIR . "/custom.inc";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
32
33
34
35

$ipAddr = $argv[1];
$do_sql = $argv[2];
$testNodePolling = $argv[3];
36
37
38
39
40
41
42
43
44
45
46
47
48

//output error messages only in the cron job
//if your system has an MTA installed you should get local emails from
//this script if there are errors, you can turn this on or off in the ini file.
//(not quite done yet)
$errOut = "0";

if(isset($GLOBALS['USER_SETTINGS']['errorsInCron'])) {
	$errOut = $GLOBALS['USER_SETTINGS']['errorsInCron'];
}else {
	$errOut = "0";
}

Eric - kg6wxc's avatar
Eric - kg6wxc committed
49
50
51
52
53
54
55
if ($do_sql) {
	$sql_connection =  wxc_connectToMySql();
}
$sql_db_tbl = $USER_SETTINGS['sql_db_tbl'];
$sql_db_tbl_node = $USER_SETTINGS['sql_db_tbl_node'];
$sql_db_tbl_topo = $USER_SETTINGS['sql_db_tbl_topo'];

56
57
58
59
//get sysinfo.json fron node
//this is the heart of the mapping system
$sysinfoJson = @file_get_contents("http://$ipAddr:8080/cgi-bin/sysinfo.json?services_local=1");

Eric - kg6wxc's avatar
Eric - kg6wxc committed
60
61
62
if($sysinfoJson === FALSE) {
	$error = error_get_last();
	wxc_checkErrorMessage($error, $ipAddr);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
63
64
65
66
	//just exit since there was an error
	//when running in parallel mode you wont see this
	//this script can be used to "target" a node and see what it returns tho
	if ($testNodePolling) {
67
		wxc_echoWithColor("There was an error retreiving the json file for: $ipAddr\n", "red");
Eric - kg6wxc's avatar
Eric - kg6wxc committed
68
69
	}
	exit();
Eric - kg6wxc's avatar
Eric - kg6wxc committed
70
71
}else {
	//get all the data from the json file and decode it
72
73
74
75
	//remove any "funny" characters from the sysinfo.json string *BEFORE* it gets decoded
	//these mainly occur when people get fancy with the description
	//use html name codes! do not use the hex codes!
	$sysinfoJson = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $sysinfoJson);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
76
77
	$result = json_decode($sysinfoJson,true);
	
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
	//if data was returned from the node, it will be an array
	//if it's not an array we probably got nothing back (or incomplete data or something else)
	//this steps thru each item in the $results array (the json info)
	//if the value is another arry, it steps thru that
	//and so on (there are only 3 "levels" so far)
	if(is_array($result)) {
		
		//
		//parse json data (this is where the real heart is)
		//
		
		//variables and defaults
		$meshRF = "on";
		$ethInf = "eth0";
		$wlanInf = "wlan0";
		
		$node = "";
		$wlan_ip = "";
		$uptime = "Not Available";
		$loadavg = "Not Available";
		$model = "Not Available";
		$firmware_version = "Not Available";
		$ssid = "None";
		$channel = "None";
		$chanbw = "None";
		$tunnel_installed = "false";
		$active_tunnel_count = "0";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
105
106
		$lat = 0.0;
		$lon = 0.0;
107
108
109
110
111
112
113
114
		$wifi_mac_address = "";
		$api_version = "0.0.0";
		$board_id = "Not Available";
		$firmware_mfg = "Not Available";
		$grid_square = "Not Available";
		$lan_ip = "Not Available";
		$services = "Not Available";
		$description = "";
115
		
116
117
118
119
120
		//new stuff for the future (not used yet)
		$signal = 0;
		$noise = 0;
		$freq = "";
		
121
122
123
		//quick hack for USB150 devices
		$eth3975 = 0;
		
124
125
126
		//check a couple of things at first
		if(isset($result['meshrf']['status']) && $result['meshrf']['status'] == "off") {
			$meshRF = "off";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
127
		}
128
129
		//start looping through the json data array
		foreach($result as $key => $value) {
130
			
131
132
133
			//find the local services on the node
			if($key == "services_local") {
				$services = serialize($value); // <-- this is an array that has been serialized!!
134
135
			}
			
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
			if(is_array($value) && $key != "services_local") { //<- $value is an array
				
				foreach($value as $key2 => $value2) { //<- step thru the array
					
					//find node load averages
					if($key2 === "loads") {
						$loadavg = serialize($value2); // <-- this is an array that has been serialized!!
					}
					
					if($key == "interfaces") {
						if(is_numeric($key2)) {
							switch($value2['name']) {
								case $wlanInf:
									$wifi_mac_address = $value2['mac'];
									break;
							}
152
							if(isset($value2['ip']) && $value2['ip'] != "none" && !$eth3975) {
153
154
155
156
157
158
159
160
161
162
								switch($value2['name']) {
									case $wlanInf:
										$wlan_ip = $value2['ip'];
										break;
										//for the HaP Lite Models
									case "wlan1":
											$wlan_ip = $value2['ip'];
											break;
									case "eth1.3975":
										$wlan_ip = $value2['ip'];
163
										$eth3975 = 1;
164
165
166
										break;
									case "eth0.3975":
										$wlan_ip = $value2['ip'];
167
										$eth3975 = 1;
168
169
170
171
172
173
174
175
176
177
178
										break;
								}
							}
						}else { //<- interfaces array keys are *not* numeric (it's a very old version of the json file)
							if(isset($value2['ip']) && $value2['ip'] != "none") {
								switch($key2) {
									case "$wlanInf":
										$wifi_mac_address = $value2['mac'];
										$wlan_ip = $value2['ip'];
								}
							}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
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
					else {
						if(isset($value2) && $value2 != '') {
							switch($key2) {
								
								//meshrf values
								case "status":
									$meshRF = $value2;
									break;
								case "chanbw":
									$chanbw = $value2;
									break;
								case "ssid":
									$ssid = $value2;
									break;
								case "channel":
									$channel = $value2;
									break;
									
									//tunnel values
								case "active_tunnel_count":
									$active_tunnel_count = $value2;
									break;
								case "tunnel_installed":
									$tunnel_installed = $value2;
									break;
									
									//uptime
								case "uptime":
									$uptime = $value2;
									break;
									
									//node info
								case "description":
									$description = $value2;
									break;
								case "model":
									$model = $value2;
									break;
								case "board_id":
									$board_id = $value2;
									break;
								case "firmware_mfg":
									$firmware_mfg = $value2;
									break;
								case "firmware_version":
									$firmware_version = $value2;
									break;
									
									//there was one "funny" version 1.5 of the json API
								case "node":
									$node = $value2;
									break;
								case "lat":
									if(isset($value2) && $value2 != '') {
										$lat = $value2;
									}
									break;
								case "lon":
									if(isset($value2) && $value2 != '') {
										$lon = $value2;
									}
									break;
							}
						}
					} // <- end $value2 is *not* array
					unset($key2);
				} //<- end $key2/$value2 foreach loop
				
			} // <-- end $value is_array
			else {
				//these values are in the root of the json file (for now)
				if(isset($value) && $value != '') {
					switch($key) {
						case "lon":
							$lon = $value;
							break;
						case "lat":
							$lat = $value;
							break;
						case "api_version":
							$api_version = $value;
							break;
						case "grid_square":
							$grid_square = $value;
							break;
						case "node":
							$node = $value;
							break;
							
							//catch old API entries
						case "ssid":
							$ssid = $value;
							break;
						case "model":
							$model = $value;
							break;
						case "board_id":
							$board_id = $value;
							break;
						case "firmware_version":
							$firmware_version = $value;
							break;
						case "firmware_mfg":
							$firmware_mfg = $value;
							break;
						case "channel":
							$channel = $value;
							break;
						case "chanbw":
							$chanbw = $value;
							break;
						case "active_tunnel_count":
							$active_tunnel_count = $value;
							break;
						case "tunnel_installed":
							$tunnel_installed = $value;
							break;
298
					}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
299
				}
300
301
302
303
304
305
306
307
308
309
310
			} // <- end $value is *not* array
			unset($key);
		} // <-- end first layer foreach loop
		
		//test mode echo to screen
		if ($testNodePolling) {
			echo "Name: "; wxc_echoWithColor($node, "purple"); echo "\n";
			echo "MAC Address: ";
			if($wifi_mac_address) {
				wxc_echoWithColor($wifi_mac_address, "green");
				echo "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
311
			}else {
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
				wxc_echoWithColor("No MAC Address Found!", "red");
			}
			echo "Model: " . $model . "\n";
			if ($firmware_version !== $USER_SETTINGS['current_stable_fw_version']) {
				if (version_compare($firmware_version, $USER_SETTINGS['current_stable_fw_version'], "<")) {
					if ($firmware_version === "Linux" || $firmware_version === "linux") {
						echo "Firmware: " . $firmware_version . "  <- \033[1;32mViva Linux!!!\033[0m\n";
					}else {
						echo "Firmware: " . $firmware_mfg . " ";
						wxc_echoWithColor($firmware_version, "red");
						wxc_echoWithColor(" Should update firmware!", "red");
						echo "\n";
					}
				}
				if (version_compare($firmware_version, $USER_SETTINGS['current_stable_fw_version'], ">")) {
					//echo "Firmware: " . $result['firmware_mfg'] . " " . $result['firmware_version'] . "  <- \033[31mBeta firmware!\033[0m\n";
					echo "Firmware: " . $firmware_mfg . " ";
					wxc_echoWithColor($firmware_version, "orange");
					wxc_echoWithColor(" Beta firmware!", "orange");
					echo "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
332
				}
333
334
335
			}else {
				//echo "Firmware Version: " . $firmware_version . "\n";
				echo "Firmware: \033[32m" . $firmware_mfg . " " . $firmware_version . "\033[0m\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
336
			}
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
			
			echo "LAN ip: ";
			if ($lan_ip == "Not Available") {
				wxc_echoWithColor($lan_ip, "orange");
			}else {
				echo $lan_ip;
			}
			echo " WLAN ip: " . $wlan_ip . "\n";
			
			if (($lat) && ($lon)) {
				echo "Location: \033[32m" . $lat . ", " . $lon. "\033[0m\n";
				//}elseif ($nodeLocationFixed = 1) {
				//	echo "\033[31mNo Location Info Set!\033[0m (FIXED!)\n";
				//	$nodeLocationFixed = 0;
			}else {
				echo "\033[31mNo Location Info Set!\033[0m\n";
				//K6GSE's solution to deal with non-null values in the DB
				//$lat = 0.0;
				//$lon = 0.0;
				//end
357
			}
358
359
360
361
362
363
364
365
366
			
			if($uptime != "Not Available") {
				echo "Uptime: ";
				wxc_echoWithColor($uptime, "green");
				echo "\n";
			}else {
				echo "Uptime: ";
				wxc_echoWithColor($uptime, "orange");
				echo "\n";
367
			}
368
369
370
371
372
373
374
375
376
377
378
			
			echo "Loads: ";
			if($loadavg != "Not Available") {
				$ldavgs = unserialize($loadavg);
				$ld1 = $ldavgs[0];
				$ld5 = $ldavgs[1];
				$ld15 = $ldavgs[2];
				if($ld1 > 1) {
					$ld1 = wxc_addColor($ld1, "red");
				}elseif ($ld1 < 1 && $ld1 > 0.5) {
					$ld1 = wxc_addColor($ld1, "orange");
Eric - kg6wxc's avatar
Eric - kg6wxc committed
379
				}else {
380
					$ld1 = wxc_addColor($ld1, "green");
Eric - kg6wxc's avatar
Eric - kg6wxc committed
381
				}
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
				if($ld5 > 1) {
					$ld5 = wxc_addColor($ld5, "red");
				}elseif ($ld5 < 1 && $ld5 > 0.5) {
					$ld5 = wxc_addColor($ld5, "orange");
				}else {
					$ld5 = wxc_addColor($ld5, "green");
				}
				if($ld15 > 1) {
					$ld15 = wxc_addColor($ld15, "red");
				}elseif ($ld15 < 1 && $ld15 > 0.5) {
					$ld15 = wxc_addColor($ld15, "orange");
				}else {
					$ld15 = wxc_addColor($ld15, "green");
				}
				
				echo "1 min: " . $ld1 . " 5 min: " . $ld5 . " 15 min: " . $ld15 . "\n";
			}else {
				wxc_echoWithColor($loadavg, "orange");
Eric - kg6wxc's avatar
Eric - kg6wxc committed
400
401
				echo "\n";
			}
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
			
			echo "Mesh RF: ";
			if($meshRF == "off") {
				wxc_echoWithColor($meshRF, "orange");
			}else {
				wxc_echoWithColor($meshRF, "green");
			}
			
			
			echo "  SSID: ";
			if($meshRF == "off") {
				wxc_echoWithColor($ssid, "orange");
			}else {
				wxc_echoWithColor($ssid, "green");
			}
			echo "\n";
			
			echo "API Version: ";
			switch($api_version) {
				case "1.6":
					wxc_echoWithColor($api_version, "green");
					break;
				case "1.5":
					wxc_echoWithColor($api_version, "orange");
					break;
				case "1.3":
					wxc_echoWithColor($api_version, "red");
					break;
				default:
					wxc_echoWithColor($api_version, "redBold");
					break;
			}
			echo "\n";
			
			echo "Tunnels: ";
			wxc_echoWithColor("$tunnel_installed", "orange");
			echo "  Count: ";
			wxc_echoWithColor($active_tunnel_count, "orange");
			echo "\n";
			
		} //<- end test mode echo to screen
Eric - kg6wxc's avatar
Eric - kg6wxc committed
443
444
		
		
445
446
447
448
449
450
451
452
		//SQL stuff
		if ($do_sql) {
			$removed_node = wxc_getMySql("SELECT node, wifi_mac_address FROM removed_nodes WHERE node = '$node' OR wifi_mac_address = '$wifi_mac_address'");
			
			if ($removed_node['node'] == $node || $removed_node['wifi_mac_address'] == $wifi_mac_address) {
				wxc_putMySql("DELETE FROM removed_nodes WHERE node = '$node' OR wifi_mac_address = '$wifi_mac_address'");
			}
			
Eric - kg6wxc's avatar
Eric - kg6wxc committed
453
		}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
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
		$sql	=	"INSERT INTO $sql_db_tbl(
						wifi_mac_address, node, model, firmware_version, lat, lon, grid_square, ssid, chanbw, api_version, board_id,
						tunnel_installed, active_tunnel_count, channel, firmware_mfg, lan_ip, wlan_ip, uptime, loadavg, services, last_seen)
						VALUES('$wifi_mac_address', '$node', '$model', '$firmware_version',
						'$lat', '$lon', '$grid_square', '$ssid', '$chanbw', '$api_version', '$board_id',
						'$tunnel_installed', '$active_tunnel_count', '$channel',
						'$firmware_mfg', '$lan_ip', '$wlan_ip', '$uptime', '$loadavg', '$services', NOW())
						ON DUPLICATE KEY UPDATE wifi_mac_address = '$wifi_mac_address', node = '$node', model = '$model', firmware_version = '$firmware_version',
						lat = '$lat', lon = '$lon', grid_square = '$grid_square', ssid = '$ssid', chanbw = '$chanbw', api_version = '$api_version',
						board_id = '$board_id', tunnel_installed = '$tunnel_installed',
						active_tunnel_count = '$active_tunnel_count', channel = '$channel',
						firmware_mfg = '$firmware_mfg', lan_ip = '$lan_ip', wlan_ip = '$wlan_ip',
						uptime = '$uptime', loadavg = '$loadavg', services = '$services', last_seen = NOW()";
		
		$sql_no_location_info  =    "INSERT INTO $sql_db_tbl(
						wifi_mac_address, node, model, firmware_version, grid_square, ssid, chanbw, api_version, board_id,
						tunnel_installed, active_tunnel_count, channel, firmware_mfg, lan_ip, wlan_ip, uptime, loadavg, services, last_seen)
						VALUES('$wifi_mac_address', '$node', '$model', '$firmware_version',
						'$grid_square', '$ssid', '$chanbw', '$api_version', '$board_id',
						'$tunnel_installed', '$active_tunnel_count', '$channel',
						'$firmware_mfg', '$lan_ip', '$wlan_ip', '$uptime', '$loadavg', '$services', NOW())
						ON DUPLICATE KEY UPDATE wifi_mac_address = '$wifi_mac_address', node = '$node', model = '$model', firmware_version = '$firmware_version',
						grid_square = '$grid_square', ssid = '$ssid', chanbw = '$chanbw', api_version = '$api_version',
						board_id = '$board_id', tunnel_installed = '$tunnel_installed',
						active_tunnel_count = '$active_tunnel_count', channel = '$channel',
						firmware_mfg = '$firmware_mfg', lan_ip = '$lan_ip', wlan_ip = '$wlan_ip',
						uptime = '$uptime', loadavg = '$loadavg', services = '$services', last_seen = NOW()";
		
		$sql_update_when_node_name_has_changed	=	"UPDATE $sql_db_tbl SET
		            	node = '$node', model = '$model',
		            	firmware_version = '$firmware_version',
		            	lat = '$lat', lon = '$lon', grid_square = '$grid_square', ssid = '$ssid', chanbw = '$chanbw',
		            	api_version = '$api_version', board_id = '$board_id',
		            	tunnel_installed = '$tunnel_installed',
		            	active_tunnel_count = '$active_tunnel_count',
		            	channel = '$channel', firmware_mfg = '$firmware_mfg',
		            	lan_ip = '$lan_ip', wlan_ip = '$wlan_ip',
						uptime = '$uptime', loadavg = '$loadavg', services = '$services', last_seen=NOW()
		            	WHERE wifi_mac_address = '$wifi_mac_address'";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
494
		
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
		$sql_update_when_node_name_has_changed_no_location_info	=	"UPDATE $sql_db_tbl SET
		            	node = '$node', model = '$model',
		            	firmware_version = '$firmware_version',
		            	grid_square = '$grid_square', ssid = '$ssid', chanbw = '$chanbw',
		            	api_version = '$api_version', board_id = '$board_id',
		            	tunnel_installed = '$tunnel_installed',
		            	active_tunnel_count = '$active_tunnel_count',
		            	channel = '$channel', firmware_mfg = '$firmware_mfg',
		            	lan_ip = '$lan_ip', wlan_ip = '$wlan_ip',
						uptime = '$uptime', loadavg = '$loadavg', services = '$services', last_seen=NOW()
		            	WHERE wifi_mac_address = '$wifi_mac_address'";
		
		//find the currently stored name and mac address of the node we are looking at
		if($do_sql) {
			$node_name_array	=	wxc_getMySql("SELECT node, wifi_mac_address FROM $sql_db_tbl WHERE wifi_mac_address = '$wifi_mac_address'");
			$existing_node_name	=	$node_name_array['node'];
			$existing_mac_addr	=	$node_name_array['wifi_mac_address'];
Eric - kg6wxc's avatar
Eric - kg6wxc committed
512
		}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
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
		//check if we are updating this nodes location info or not
		if($do_sql) {
			$fixedLocation = wxc_getMySql("SELECT location_fix FROM $sql_db_tbl_node WHERE node = '$node'");
			if ($fixedLocation['location_fix'] == "1") {
				//check if we have changed node name and have the same hardware.
				//the database itself should handle if there is new hardware with the same node name.
				//if name has not changed, update the DB as normal for each node
				if ($do_sql && $sysinfoJson) {
					if(!$existing_mac_addr) {
						wxc_putMySql($sql_no_location_info);
					}elseif($existing_mac_addr == $wifi_mac_address) {
						if ($existing_node_name !== $node) {
							wxc_putMySql($sql_update_when_node_name_has_changed_no_location_info);
							//echo "";
						}else {
							wxc_putMySQL($sql_no_location_info);
						}
					}
				}
				if ($testNodePolling) {
					wxc_echoWithColor('****This nodes location has been "fixed" in the Database!****', 'alert');
					echo "\n";
					wxc_echoWithColor('****It will not update from polling if the location changes****', 'alert');
					echo "\n";
				}
			}else {
				//check if we have changed node name and have the same hardware.
				//the database itself should handle if there is new hardware with the same node name.
				//if name has not changed, update the DB as normal for each node
				if ($do_sql && $sysinfoJson) {
					if(!$existing_mac_addr) {
						wxc_putMySql($sql);
					}elseif($existing_mac_addr == $wifi_mac_address) {
						if ($existing_node_name !== $node) {
							wxc_putMySql($sql_update_when_node_name_has_changed);
							//echo "";
						}else {
							wxc_putMySQL($sql);
						}
					}
				}
			}
		}
		if ($testNodePolling) {
			echo "\n";
		}
	} // <- end of json_decode into array
	else {
		if($errOut || $testNodePolling) {
			echo "There was a problem decoding the json file from node: " . $node . "(" . $ipAddr . ")\n";
		}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
	}
	//Thanks to K6GSE
	// Clear Variables so they do not carry over
	$wifi_mac_address = NULL;
	$node = NULL;
	$model = NULL;
	$firmware_version = NULL;
	$lat = NULL;
	$lon = NULL;
	$ssid = NULL;
	$chanbw = NULL;
	$api_version = NULL;
	$board_id = NULL;
	$tunnel_installed = NULL;
	$active_tunnel_count = NULL;
	$channel = NULL;
	$firmware_mfg = NULL;
	$lan_ip = NULL;
	$wlan_ip = NULL;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
584
585
586
	$uptime = NULL;
	$loadavg = NULL;
	$services = NULL;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
587
	$sysinfoJson = NULL;
588
} //<- end of if/else sysinfo.json good
Eric - kg6wxc's avatar
Eric - kg6wxc committed
589

590
//update the database with the time, so we know when this part of the script last ran
Eric - kg6wxc's avatar
Eric - kg6wxc committed
591
592
593
594
if($do_sql) {
	wxc_scriptUpdateDateTime("NODEINFO", "node_info");
	wxc_putMySql("UPDATE map_info SET currently_running = '0' WHERE id = 'NODEINFO'");
}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
595
?>