Completed
Push — master ( a1100a...646b2b )
by Yannick
32:53
created
scripts/daemon-spotter.php 1 patch
Indentation   +1221 added lines, -1221 removed lines patch added patch discarded remove patch
@@ -15,65 +15,65 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) {
18
-    require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19 19
 }
20 20
 if (isset($globalMarine) && $globalMarine) {
21
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
22
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
22
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
23 23
 }
24 24
 
25 25
 if (!isset($globalDebug)) $globalDebug = FALSE;
26 26
 
27 27
 if ($globalInstalled === FALSE) {
28
-    echo "This script MUST be run after install script. Use your web browser to run install/index.php";
29
-    sleep(5);
30
-    die();
28
+	echo "This script MUST be run after install script. Use your web browser to run install/index.php";
29
+	sleep(5);
30
+	die();
31 31
 }
32 32
 
33 33
 
34 34
 // Check if schema is at latest version
35 35
 $Connection = new Connection();
36 36
 if ($Connection->connectionExists() === false) {
37
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
38
-    exit();
37
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
38
+	exit();
39 39
 }
40 40
 if ($Connection->latest() === false) {
41
-    echo "You MUST update to latest schema. Use your web browser to run install/index.php";
42
-    exit();
41
+	echo "You MUST update to latest schema. Use your web browser to run install/index.php";
42
+	exit();
43 43
 }
44 44
 if (PHP_SAPI != 'cli') {
45
-    echo "This script MUST be called from console, not a web browser.";
45
+	echo "This script MUST be called from console, not a web browser.";
46 46
 //    exit();
47 47
 }
48 48
 
49 49
 // This is to be compatible with old version of settings.php
50 50
 if (!isset($globalSources)) {
51
-    if (isset($globalSBS1Hosts)) {
52
-        //$hosts = $globalSBS1Hosts;
53
-        foreach ($globalSBS1Hosts as $host) {
54
-	    $globalSources[] = array('host' => $host);
55
-    	}
56
-    } else {
57
-        if (!isset($globalSBS1Host)) {
58
-	    echo '$globalSources MUST be defined !';
59
-	    die;
51
+	if (isset($globalSBS1Hosts)) {
52
+		//$hosts = $globalSBS1Hosts;
53
+		foreach ($globalSBS1Hosts as $host) {
54
+		$globalSources[] = array('host' => $host);
55
+		}
56
+	} else {
57
+		if (!isset($globalSBS1Host)) {
58
+		echo '$globalSources MUST be defined !';
59
+		die;
60 60
 	}
61 61
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
62 62
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
63
-    }
63
+	}
64 64
 }
65 65
 
66 66
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
67 67
 //if (isset($options['s'])) $hosts = array($options['s']);
68 68
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 69
 if (isset($options['s'])) {
70
-    $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
-    else $globalSources[] = array('host' => $options['s']);
70
+	$globalSources = array();
71
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
+	else $globalSources[] = array('host' => $options['s']);
73 73
 } elseif (isset($options['source'])) {
74
-    $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
-    else $globalSources[] = array('host' => $options['source']);
74
+	$globalSources = array();
75
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
+	else $globalSources[] = array('host' => $options['source']);
77 77
 }
78 78
 if (isset($options['aprsserverhost'])) {
79 79
 	$globalServerAPRS = TRUE;
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 if (isset($options['idsource'])) $id_source = $options['idsource'];
113 113
 else $id_source = 1;
114 114
 if (isset($globalServer) && $globalServer) {
115
-    if ($globalDebug) echo "Using Server Mode\n";
116
-    $SI=new SpotterServer();
115
+	if ($globalDebug) echo "Using Server Mode\n";
116
+	$SI=new SpotterServer();
117 117
 /*
118 118
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 119
     $SI = new adsb2aprs();
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
125 125
 if (isset($globalMarine) && $globalMarine) {
126
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
127
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
126
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
127
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
128 128
 }
129 129
 
130 130
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
131 131
 if (isset($globalMarine) && $globalMarine) {
132
-    $AIS = new AIS();
133
-    $MI = new MarineImport($Connection->db);
132
+	$AIS = new AIS();
133
+	$MI = new MarineImport($Connection->db);
134 134
 }
135 135
 //$APRS=new APRS($Connection->db);
136 136
 $SBS=new SBS();
@@ -143,12 +143,12 @@  discard block
 block discarded – undo
143 143
 //$servertz = system('date +%Z');
144 144
 // signal handler - playing nice with sockets and dump1090
145 145
 if (function_exists('pcntl_fork')) {
146
-    pcntl_signal(SIGINT,  function() {
147
-        global $sockets;
148
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149
-        die("Bye!\n");
150
-    });
151
-    pcntl_signal_dispatch();
146
+	pcntl_signal(SIGINT,  function() {
147
+		global $sockets;
148
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149
+		die("Bye!\n");
150
+	});
151
+	pcntl_signal_dispatch();
152 152
 }
153 153
 
154 154
 // let's try and connect
@@ -158,47 +158,47 @@  discard block
 block discarded – undo
158 158
 $reset = 0;
159 159
 
160 160
 function connect_all($hosts) {
161
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163
-    $reset++;
164
-    if ($globalDebug) echo 'Connect to all...'."\n";
165
-    foreach ($hosts as $id => $value) {
161
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163
+	$reset++;
164
+	if ($globalDebug) echo 'Connect to all...'."\n";
165
+	foreach ($hosts as $id => $value) {
166 166
 	$host = $value['host'];
167 167
 	$udp = false;
168 168
 	$globalSources[$id]['last_exec'] = 0;
169 169
 	// Here we check type of source(s)
170 170
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
-            if (preg_match('/deltadb.txt$/i',$host)) {
172
-        	//$formats[$id] = 'deltadbtxt';
173
-        	$globalSources[$id]['format'] = 'deltadbtxt';
174
-        	//$last_exec['deltadbtxt'] = 0;
175
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
177
-        	//$formats[$id] = 'vatsimtxt';
178
-        	$globalSources[$id]['format'] = 'vatsimtxt';
179
-        	//$last_exec['vatsimtxt'] = 0;
180
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
182
-        	//$formats[$id] = 'aircraftlistjson';
183
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
184
-        	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
187
-        	//$formats[$id] = 'aircraftjson';
188
-        	$globalSources[$id]['format'] = 'aircraftjson';
189
-        	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
-    	    } else if (preg_match('/aircraft$/i',$host)) {
192
-        	//$formats[$id] = 'planefinderclient';
193
-        	$globalSources[$id]['format'] = 'planefinderclient';
194
-        	//$last_exec['aircraftlistjson'] = 0;
195
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
-    	    } else if (preg_match('/opensky/i',$host)) {
197
-        	//$formats[$id] = 'aircraftlistjson';
198
-        	$globalSources[$id]['format'] = 'opensky';
199
-        	//$last_exec['aircraftlistjson'] = 0;
200
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
201
-    	    /*
171
+			if (preg_match('/deltadb.txt$/i',$host)) {
172
+			//$formats[$id] = 'deltadbtxt';
173
+			$globalSources[$id]['format'] = 'deltadbtxt';
174
+			//$last_exec['deltadbtxt'] = 0;
175
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
177
+			//$formats[$id] = 'vatsimtxt';
178
+			$globalSources[$id]['format'] = 'vatsimtxt';
179
+			//$last_exec['vatsimtxt'] = 0;
180
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
182
+			//$formats[$id] = 'aircraftlistjson';
183
+			$globalSources[$id]['format'] = 'aircraftlistjson';
184
+			//$last_exec['aircraftlistjson'] = 0;
185
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
+			} else if (preg_match('/aircraft.json$/i',$host)) {
187
+			//$formats[$id] = 'aircraftjson';
188
+			$globalSources[$id]['format'] = 'aircraftjson';
189
+			//$last_exec['aircraftlistjson'] = 0;
190
+			if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
+			} else if (preg_match('/aircraft$/i',$host)) {
192
+			//$formats[$id] = 'planefinderclient';
193
+			$globalSources[$id]['format'] = 'planefinderclient';
194
+			//$last_exec['aircraftlistjson'] = 0;
195
+			if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
+			} else if (preg_match('/opensky/i',$host)) {
197
+			//$formats[$id] = 'aircraftlistjson';
198
+			$globalSources[$id]['format'] = 'opensky';
199
+			//$last_exec['aircraftlistjson'] = 0;
200
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
201
+			/*
202 202
     	    // Disabled for now, site change source format
203 203
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
204 204
         	//$formats[$id] = 'radarvirtueljson';
@@ -210,131 +210,131 @@  discard block
 block discarded – undo
210 210
         	    exit(0);
211 211
         	}
212 212
     	    */
213
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
214
-        	//$formats[$id] = 'planeupdatefaa';
215
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
216
-        	//$last_exec['planeupdatefaa'] = 0;
217
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
218
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220
-        	    exit(0);
221
-        	}
222
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
223
-        	//$formats[$id] = 'phpvmacars';
224
-        	$globalSources[$id]['format'] = 'phpvmacars';
225
-        	//$last_exec['phpvmacars'] = 0;
226
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228
-        	//$formats[$id] = 'phpvmacars';
229
-        	$globalSources[$id]['format'] = 'vaos';
230
-        	//$last_exec['phpvmacars'] = 0;
231
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
233
-        	//$formats[$id] = 'phpvmacars';
234
-        	$globalSources[$id]['format'] = 'vam';
235
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
-            } else if (preg_match('/whazzup/i',$host)) {
237
-        	//$formats[$id] = 'whazzup';
238
-        	$globalSources[$id]['format'] = 'whazzup';
239
-        	//$last_exec['whazzup'] = 0;
240
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
-            } else if (preg_match('/blitzortung/i',$host)) {
242
-        	$globalSources[$id]['format'] = 'blitzortung';
243
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
-            } else if (preg_match('/airwhere/i',$host)) {
245
-        	$globalSources[$id]['format'] = 'airwhere';
246
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
-            } else if (preg_match('/recentpireps/i',$host)) {
248
-        	//$formats[$id] = 'pirepsjson';
249
-        	$globalSources[$id]['format'] = 'pirepsjson';
250
-        	//$last_exec['pirepsjson'] = 0;
251
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253
-        	//$formats[$id] = 'fr24json';
254
-        	$globalSources[$id]['format'] = 'fr24json';
255
-        	//$last_exec['fr24json'] = 0;
256
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
257
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259
-        	    exit(0);
260
-        	}
261
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
262
-        	//$formats[$id] = 'fr24json';
263
-        	$globalSources[$id]['format'] = 'myshiptracking';
264
-        	//$last_exec['fr24json'] = 0;
265
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
266
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268
-        	    exit(0);
269
-        	}
270
-            //} else if (preg_match('/10001/',$host)) {
271
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272
-        	//$formats[$id] = 'tsv';
273
-        	$globalSources[$id]['format'] = 'tsv';
274
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275
-            }
276
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
279
-    		    if ($idf !== false) {
280
-    			$httpfeeds[$id] = $idf;
281
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
-    		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
-	    $hostport = explode(':',$host);
288
-	    if (isset($hostport[1])) {
213
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
214
+			//$formats[$id] = 'planeupdatefaa';
215
+			$globalSources[$id]['format'] = 'planeupdatefaa';
216
+			//$last_exec['planeupdatefaa'] = 0;
217
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
218
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220
+				exit(0);
221
+			}
222
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
223
+			//$formats[$id] = 'phpvmacars';
224
+			$globalSources[$id]['format'] = 'phpvmacars';
225
+			//$last_exec['phpvmacars'] = 0;
226
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
+			} else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228
+			//$formats[$id] = 'phpvmacars';
229
+			$globalSources[$id]['format'] = 'vaos';
230
+			//$last_exec['phpvmacars'] = 0;
231
+			if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
233
+			//$formats[$id] = 'phpvmacars';
234
+			$globalSources[$id]['format'] = 'vam';
235
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
+			} else if (preg_match('/whazzup/i',$host)) {
237
+			//$formats[$id] = 'whazzup';
238
+			$globalSources[$id]['format'] = 'whazzup';
239
+			//$last_exec['whazzup'] = 0;
240
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
+			} else if (preg_match('/blitzortung/i',$host)) {
242
+			$globalSources[$id]['format'] = 'blitzortung';
243
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
+			} else if (preg_match('/airwhere/i',$host)) {
245
+			$globalSources[$id]['format'] = 'airwhere';
246
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
+			} else if (preg_match('/recentpireps/i',$host)) {
248
+			//$formats[$id] = 'pirepsjson';
249
+			$globalSources[$id]['format'] = 'pirepsjson';
250
+			//$last_exec['pirepsjson'] = 0;
251
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253
+			//$formats[$id] = 'fr24json';
254
+			$globalSources[$id]['format'] = 'fr24json';
255
+			//$last_exec['fr24json'] = 0;
256
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
257
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259
+				exit(0);
260
+			}
261
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
262
+			//$formats[$id] = 'fr24json';
263
+			$globalSources[$id]['format'] = 'myshiptracking';
264
+			//$last_exec['fr24json'] = 0;
265
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
266
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268
+				exit(0);
269
+			}
270
+			//} else if (preg_match('/10001/',$host)) {
271
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272
+			//$formats[$id] = 'tsv';
273
+			$globalSources[$id]['format'] = 'tsv';
274
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275
+			}
276
+		} elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277
+			if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
279
+				if ($idf !== false) {
280
+				$httpfeeds[$id] = $idf;
281
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
+				} elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
+			} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
+			elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
+			elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
+		$hostport = explode(':',$host);
288
+		if (isset($hostport[1])) {
289 289
 		$port = $hostport[1];
290 290
 		$hostn = $hostport[0];
291
-	    } else {
291
+		} else {
292 292
 		$port = $globalSources[$id]['port'];
293 293
 		$hostn = $globalSources[$id]['host'];
294
-	    }
295
-	    $Common = new Common();
296
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
298
-    	    } else {
299
-    		$udp = true;
300
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
301
-	    }
302
-	    if ($s) {
303
-    	        $sockets[$id] = $s;
304
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
294
+		}
295
+		$Common = new Common();
296
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
298
+			} else {
299
+			$udp = true;
300
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
301
+		}
302
+		if ($s) {
303
+				$sockets[$id] = $s;
304
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
306 306
 			//$formats[$id] = 'aprs';
307 307
 			$globalSources[$id]['format'] = 'aprs';
308 308
 			//$aprs_connect = 0;
309 309
 			//$use_aprs = true;
310
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
310
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
311 311
 			$globalSources[$id]['format'] = 'vrstcp';
312
-    		    } elseif ($port == '10001') {
313
-        		//$formats[$id] = 'tsv';
314
-        		$globalSources[$id]['format'] = 'tsv';
315
-		    } elseif ($port == '30002') {
316
-        		//$formats[$id] = 'raw';
317
-        		$globalSources[$id]['format'] = 'raw';
318
-		    } elseif ($port == '5001') {
319
-        		//$formats[$id] = 'raw';
320
-        		$globalSources[$id]['format'] = 'flightgearmp';
321
-		    } elseif ($port == '30005') {
312
+				} elseif ($port == '10001') {
313
+				//$formats[$id] = 'tsv';
314
+				$globalSources[$id]['format'] = 'tsv';
315
+			} elseif ($port == '30002') {
316
+				//$formats[$id] = 'raw';
317
+				$globalSources[$id]['format'] = 'raw';
318
+			} elseif ($port == '5001') {
319
+				//$formats[$id] = 'raw';
320
+				$globalSources[$id]['format'] = 'flightgearmp';
321
+			} elseif ($port == '30005') {
322 322
 			// Not yet supported
323
-        		//$formats[$id] = 'beast';
324
-        		$globalSources[$id]['format'] = 'beast';
325
-		    //} else $formats[$id] = 'sbs';
326
-		    } else $globalSources[$id]['format'] = 'sbs';
327
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
323
+				//$formats[$id] = 'beast';
324
+				$globalSources[$id]['format'] = 'beast';
325
+			//} else $formats[$id] = 'sbs';
326
+			} else $globalSources[$id]['format'] = 'sbs';
327
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
328 328
 		}
329 329
 		if ($globalDebug && $udp) echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330 330
 		elseif ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
331
-            } else {
331
+			} else {
332 332
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
333 333
 		sleep(10);
334 334
 		connect_all($hosts);
335
-    	    }
336
-        }
337
-    }
335
+			}
336
+		}
337
+	}
338 338
 }
339 339
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
340 340
 
@@ -357,9 +357,9 @@  discard block
 block discarded – undo
357 357
 //connect_all($globalSources);
358 358
 
359 359
 if (isset($globalProxy) && $globalProxy) {
360
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
360
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
361 361
 } else {
362
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
362
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
363 363
 }
364 364
 
365 365
 // APRS Configuration
@@ -368,21 +368,21 @@  discard block
 block discarded – undo
368 368
 	die;
369 369
 }
370 370
 foreach ($globalSources as $key => $source) {
371
-    if (!isset($source['format'])) {
372
-        $globalSources[$key]['format'] = 'auto';
373
-    }
374
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
375
-        unset($globalSources[$key]);
376
-    }
371
+	if (!isset($source['format'])) {
372
+		$globalSources[$key]['format'] = 'auto';
373
+	}
374
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
375
+		unset($globalSources[$key]);
376
+	}
377 377
 }
378 378
 connect_all($globalSources);
379 379
 foreach ($globalSources as $key => $source) {
380
-    if (isset($source['format']) && $source['format'] == 'aprs') {
380
+	if (isset($source['format']) && $source['format'] == 'aprs') {
381 381
 	$aprs_connect = 0;
382 382
 	$use_aprs = true;
383 383
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
384 384
 	break;
385
-    }
385
+	}
386 386
 }
387 387
 
388 388
 if ($use_aprs) {
@@ -423,173 +423,173 @@  discard block
 block discarded – undo
423 423
 
424 424
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
425 425
 while ($i > 0) {
426
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
426
+	if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
427 427
 
428
-    if (!$globalDaemon) $i = $endtime-time();
429
-    // Delete old ATC
430
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
428
+	if (!$globalDaemon) $i = $endtime-time();
429
+	// Delete old ATC
430
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431 431
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
432
-        $ATC->deleteOldATC();
433
-    }
432
+		$ATC->deleteOldATC();
433
+	}
434 434
     
435
-    if (count($last_exec) == count($globalSources)) {
435
+	if (count($last_exec) == count($globalSources)) {
436 436
 	$max = $globalMinFetch;
437 437
 	foreach ($last_exec as $last) {
438
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
438
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
439 439
 	}
440 440
 	if ($max < $globalMinFetch) {
441
-	    if ($globalDebug) echo 'Sleeping...'."\n";
442
-	    sleep($globalMinFetch-$max+2);
441
+		if ($globalDebug) echo 'Sleeping...'."\n";
442
+		sleep($globalMinFetch-$max+2);
443
+	}
443 444
 	}
444
-    }
445 445
 
446 446
     
447
-    //foreach ($formats as $id => $value) {
448
-    foreach ($globalSources as $id => $value) {
447
+	//foreach ($formats as $id => $value) {
448
+	foreach ($globalSources as $id => $value) {
449 449
 	date_default_timezone_set('UTC');
450 450
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
451 451
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
452 452
 	if ($value['format'] === 'deltadbtxt' && 
453
-	    (
453
+		(
454 454
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
455 455
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
456
-	    )
456
+		)
457 457
 	) {
458
-        //$buffer = $Common->getData($hosts[$id]);
459
-        $buffer = $Common->getData($value['host']);
460
-        if ($buffer != '') $reset = 0;
461
-        $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462
-        $buffer = explode('\n', $buffer);
463
-        foreach ($buffer as $line) {
464
-            if ($line != '' && count($line) > 7) {
465
-                $line = explode(',', $line);
466
-                $data = array();
467
-                $data['hex'] = $line[1]; // hex
468
-                $data['ident'] = $line[2]; // ident
469
-                if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
-                if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
-                if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
-                if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
-                if (isset($line[7])) $data['longitude'] = $line[7]; // long
474
-                $data['verticalrate'] = ''; // vertical rate
475
-                //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476
-                $data['emergency'] = ''; // emergency
477
-                $data['datetime'] = date('Y-m-d H:i:s');
478
-                $data['format_source'] = 'deltadbtxt';
479
-                $data['id_source'] = $id_source;
480
-                if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
-                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
-                if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
483
-                $SI->add($data);
484
-                unset($data);
485
-            }
486
-        }
487
-        $last_exec[$id]['last'] = time();
488
-    } elseif ($value['format'] === 'radarcapejson' &&
489
-            (
490
-                (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
491
-                (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
492
-            )
493
-        ) {
494
-            //$buffer = $Common->getData($hosts[$id]);
495
-            $buffer = $Common->getData($value['host']);
496
-            if ($buffer != '') {
497
-                $all_data = json_decode($buffer,true);
498
-                foreach ($all_data as $line) {
499
-                    $data = array();
500
-                    $data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
501
-                    $data['hex'] = $line['hex']; // hex
502
-                    $data['ident'] = $line['fli']; // ident
503
-                    $data['altitude'] = $line['alt']; // altitude
504
-                    $data['speed'] = $line['spd']; // speed
505
-                    $data['heading'] = $line['trk']; // heading
506
-                    $data['latitude'] = $line['lat']; // lat
507
-                    $data['longitude'] = $line['lon']; // long
508
-                    $data['verticalrate'] = $line['vrt']; // vertical rate
509
-                    $data['squawk'] = $line['squ']; // squawk
510
-                    $data['ground'] = $line['gda']; // ground
511
-                    $data['registration'] = $line['reg'];
512
-                    //$data['emergency'] = ''; // emergency
513
-                    $data['datetime'] = date('Y-m-d H:i:s');
514
-                    $data['format_source'] = 'radarcapejson';
515
-                    $data['id_source'] = $id_source;
516
-                    if (isset($value['name']) && $value['name'] != '') {
517
-                        if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
-                        else $data['source_name'] = $value['name'];
519
-                    } elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
-                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
-                    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
458
+		//$buffer = $Common->getData($hosts[$id]);
459
+		$buffer = $Common->getData($value['host']);
460
+		if ($buffer != '') $reset = 0;
461
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462
+		$buffer = explode('\n', $buffer);
463
+		foreach ($buffer as $line) {
464
+			if ($line != '' && count($line) > 7) {
465
+				$line = explode(',', $line);
466
+				$data = array();
467
+				$data['hex'] = $line[1]; // hex
468
+				$data['ident'] = $line[2]; // ident
469
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
474
+				$data['verticalrate'] = ''; // vertical rate
475
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476
+				$data['emergency'] = ''; // emergency
477
+				$data['datetime'] = date('Y-m-d H:i:s');
478
+				$data['format_source'] = 'deltadbtxt';
479
+				$data['id_source'] = $id_source;
480
+				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
+				if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
483
+				$SI->add($data);
484
+				unset($data);
485
+			}
486
+		}
487
+		$last_exec[$id]['last'] = time();
488
+	} elseif ($value['format'] === 'radarcapejson' &&
489
+			(
490
+				(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
491
+				(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
492
+			)
493
+		) {
494
+			//$buffer = $Common->getData($hosts[$id]);
495
+			$buffer = $Common->getData($value['host']);
496
+			if ($buffer != '') {
497
+				$all_data = json_decode($buffer,true);
498
+				foreach ($all_data as $line) {
499
+					$data = array();
500
+					$data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
501
+					$data['hex'] = $line['hex']; // hex
502
+					$data['ident'] = $line['fli']; // ident
503
+					$data['altitude'] = $line['alt']; // altitude
504
+					$data['speed'] = $line['spd']; // speed
505
+					$data['heading'] = $line['trk']; // heading
506
+					$data['latitude'] = $line['lat']; // lat
507
+					$data['longitude'] = $line['lon']; // long
508
+					$data['verticalrate'] = $line['vrt']; // vertical rate
509
+					$data['squawk'] = $line['squ']; // squawk
510
+					$data['ground'] = $line['gda']; // ground
511
+					$data['registration'] = $line['reg'];
512
+					//$data['emergency'] = ''; // emergency
513
+					$data['datetime'] = date('Y-m-d H:i:s');
514
+					$data['format_source'] = 'radarcapejson';
515
+					$data['id_source'] = $id_source;
516
+					if (isset($value['name']) && $value['name'] != '') {
517
+						if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
+						else $data['source_name'] = $value['name'];
519
+					} elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
+					if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
+					if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
522 522
 
523
-                    $SI->add($data);
524
-                    unset($data);
525
-                }
526
-            }
527
-            $last_exec[$id]['last'] = time();
523
+					$SI->add($data);
524
+					unset($data);
525
+				}
526
+			}
527
+			$last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] === 'aisnmeatxt' && 
529
-	    (
529
+		(
530 530
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
531 531
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
532
-	    )
532
+		)
533 533
 	) {
534
-	    date_default_timezone_set('CET');
535
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536
-	    date_default_timezone_set('UTC');
537
-	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
540
-	    foreach ($buffer as $line) {
534
+		date_default_timezone_set('CET');
535
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536
+		date_default_timezone_set('UTC');
537
+		if ($buffer != '') $reset = 0;
538
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
+		$buffer = explode('\n',$buffer);
540
+		foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542
-		    //echo "'".$line."'\n";
543
-		    $add = false;
544
-		    $ais_data = $AIS->parse_line(trim($line));
545
-		    $data = array();
546
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558
-		    if (isset($ais_data['timestamp'])) {
542
+			//echo "'".$line."'\n";
543
+			$add = false;
544
+			$ais_data = $AIS->parse_line(trim($line));
545
+			$data = array();
546
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
+			if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
+			if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558
+			if (isset($ais_data['timestamp'])) {
559 559
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
560 560
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
561
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562
-			    $add = true;
561
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562
+				$add = true;
563 563
 			}
564
-		    } else {
564
+			} else {
565 565
 			$data['datetime'] = date('Y-m-d H:i:s');
566 566
 			$add = true;
567
-		    }
568
-		    $data['format_source'] = 'aisnmeatxt';
569
-    		    $data['id_source'] = $id_source;
570
-		    //print_r($data);
571
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
573
-		    unset($data);
567
+			}
568
+			$data['format_source'] = 'aisnmeatxt';
569
+				$data['id_source'] = $id_source;
570
+			//print_r($data);
571
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
573
+			unset($data);
574 574
 		}
575
-    	    }
576
-    	    $last_exec[$id]['last'] = time();
575
+			}
576
+			$last_exec[$id]['last'] = time();
577 577
 	} elseif ($value['format'] === 'aisnmeahttp') {
578
-	    $arr = $httpfeeds;
579
-	    $w = $e = null;
578
+		$arr = $httpfeeds;
579
+		$w = $e = null;
580 580
 	    
581
-	    if (isset($arr[$id])) {
581
+		if (isset($arr[$id])) {
582 582
 		$nn = stream_select($arr,$w,$e,$timeout);
583 583
 		if ($nn > 0) {
584
-		    foreach ($httpfeeds as $feed) {
584
+			foreach ($httpfeeds as $feed) {
585 585
 			$buffer = stream_get_line($feed,2000,"\n");
586 586
 			if ($buffer === FALSE) {
587
-			    connect_all($globalSources);
587
+				connect_all($globalSources);
588 588
 			}
589 589
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
590 590
 			$buffer = explode('\n',$buffer);
591 591
 			foreach ($buffer as $line) {
592
-			    if ($line != '') {
592
+				if ($line != '') {
593 593
 				$ais_data = $AIS->parse_line(trim($line));
594 594
 				$data = array();
595 595
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -607,117 +607,117 @@  discard block
 block discarded – undo
607 607
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608 608
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
609 609
 				if (isset($ais_data['timestamp'])) {
610
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
610
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
611 611
 				} else {
612
-				    $data['datetime'] = date('Y-m-d H:i:s');
612
+					$data['datetime'] = date('Y-m-d H:i:s');
613 613
 				}
614 614
 				$data['format_source'] = 'aisnmeahttp';
615 615
 				$data['id_source'] = $id_source;
616 616
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
617 617
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
618 618
 				unset($data);
619
-			    }
619
+				}
620
+			}
620 621
 			}
621
-		    }
622 622
 		} else {
623
-		    $format = $value['format'];
624
-		    if (isset($tt[$format])) $tt[$format]++;
625
-		    else $tt[$format] = 0;
626
-		    if ($tt[$format] > 30) {
623
+			$format = $value['format'];
624
+			if (isset($tt[$format])) $tt[$format]++;
625
+			else $tt[$format] = 0;
626
+			if ($tt[$format] > 30) {
627 627
 			if ($globalDebug) echo 'Reconnect...'."\n";
628 628
 			sleep(2);
629 629
 			//$sourceeen[] = $value;
630 630
 			//connect_all($sourceeen);
631 631
 			//$sourceeen = array();
632 632
 			connect_all($globalSources);
633
-		    }
633
+			}
634
+		}
634 635
 		}
635
-	    }
636 636
 	} elseif ($value['format'] === 'myshiptracking' && 
637
-	    (
637
+		(
638 638
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
639 639
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
640
-	    )
640
+		)
641 641
 	) {
642
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
643
-	    if ($buffer != '') {
642
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
643
+		if ($buffer != '') {
644 644
 		//echo $buffer;
645 645
 		$all_data = json_decode($buffer,true);
646 646
 		//print_r($all_data);
647 647
 		if (isset($all_data[0]['DATA'])) {
648
-		    foreach ($all_data[0]['DATA'] as $line) {
648
+			foreach ($all_data[0]['DATA'] as $line) {
649 649
 			if ($line != '') {
650
-			    $data = array();
651
-			    $data['ident'] = $line['NAME'];
652
-			    $data['mmsi'] = $line['MMSI'];
653
-			    if (strlen($data['mmsi']) > 9) {
650
+				$data = array();
651
+				$data['ident'] = $line['NAME'];
652
+				$data['mmsi'] = $line['MMSI'];
653
+				if (strlen($data['mmsi']) > 9) {
654 654
 				$data['mmsi'] = substr($data['mmsi'],-9);
655
-			    }
656
-			    $data['speed'] = $line['SOG'];
657
-			    $data['heading'] = $line['COG'];
658
-			    $data['latitude'] = $line['LAT'];
659
-			    $data['longitude'] = $line['LNG'];
660
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661
-			    //$data['type_id'] = $line['TYPE'];
662
-			    $data['imo'] = $line['IMO'];
663
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666
-			    $data['format_source'] = 'myshiptracking';
667
-			    $data['id_source'] = $id_source;
668
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
669
-			    $MI->add($data);
670
-			    unset($data);
655
+				}
656
+				$data['speed'] = $line['SOG'];
657
+				$data['heading'] = $line['COG'];
658
+				$data['latitude'] = $line['LAT'];
659
+				$data['longitude'] = $line['LNG'];
660
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661
+				//$data['type_id'] = $line['TYPE'];
662
+				$data['imo'] = $line['IMO'];
663
+				if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
+				if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666
+				$data['format_source'] = 'myshiptracking';
667
+				$data['id_source'] = $id_source;
668
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
669
+				$MI->add($data);
670
+				unset($data);
671
+			}
671 672
 			}
672
-		    }
673 673
 		}
674
-	    }
675
-	    $last_exec[$id]['last'] = time();
674
+		}
675
+		$last_exec[$id]['last'] = time();
676 676
 	} elseif ($value['format'] === 'boatbeaconapp' && 
677
-	    (
677
+		(
678 678
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
679 679
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
680
-	    )
680
+		)
681 681
 	) {
682
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
683
-	    if ($buffer != '') {
682
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
683
+		if ($buffer != '') {
684 684
 		$all_data = json_decode($buffer,true);
685 685
 		if (isset($all_data[0]['mmsi'])) {
686
-		    foreach ($all_data as $line) {
686
+			foreach ($all_data as $line) {
687 687
 			if ($line != '') {
688
-			    $data = array();
689
-			    $data['ident'] = $line['shipname'];
690
-			    $data['callsign'] = $line['callsign'];
691
-			    $data['mmsi'] = substr($line['mmsi'],-9);
692
-			    $data['speed'] = $line['sog'];
693
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694
-			    $data['latitude'] = $line['latitude'];
695
-			    $data['longitude'] = $line['longitude'];
696
-			    $data['type_id'] = $line['shiptype'];
697
-			    $data['arrival_code'] = $line['destination'];
698
-			    $data['datetime'] = $line['time'];
699
-			    $data['format_source'] = 'boatbeaconapp';
700
-			    $data['id_source'] = $id_source;
701
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
-			    $MI->add($data);
703
-			    unset($data);
688
+				$data = array();
689
+				$data['ident'] = $line['shipname'];
690
+				$data['callsign'] = $line['callsign'];
691
+				$data['mmsi'] = substr($line['mmsi'],-9);
692
+				$data['speed'] = $line['sog'];
693
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694
+				$data['latitude'] = $line['latitude'];
695
+				$data['longitude'] = $line['longitude'];
696
+				$data['type_id'] = $line['shiptype'];
697
+				$data['arrival_code'] = $line['destination'];
698
+				$data['datetime'] = $line['time'];
699
+				$data['format_source'] = 'boatbeaconapp';
700
+				$data['id_source'] = $id_source;
701
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
+				$MI->add($data);
703
+				unset($data);
704
+			}
704 705
 			}
705
-		    }
706 706
 		}
707 707
 		
708
-	    }
709
-    	    $last_exec[$id]['last'] = time();
708
+		}
709
+			$last_exec[$id]['last'] = time();
710 710
 	} elseif ($value['format'] === 'boatnerd' && 
711
-	    (
711
+		(
712 712
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
713 713
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
714
-	    )
714
+		)
715 715
 	) {
716
-	    $buffer = $Common->getData($value['host']);
717
-	    if ($buffer != '') {
716
+		$buffer = $Common->getData($value['host']);
717
+		if ($buffer != '') {
718 718
 		$all_data = json_decode($buffer,true);
719 719
 		if (isset($all_data['features'][0]['id'])) {
720
-		    foreach ($all_data['features'] as $line) {
720
+			foreach ($all_data['features'] as $line) {
721 721
 			print_r($line);
722 722
 			$data = array();
723 723
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
@@ -737,75 +737,75 @@  discard block
 block discarded – undo
737 737
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
738 738
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
739 739
 			unset($data);
740
-		    }
740
+			}
741 741
 		}
742 742
 		
743
-	    }
744
-    	    $last_exec[$id]['last'] = time();
743
+		}
744
+			$last_exec[$id]['last'] = time();
745 745
 	} elseif ($value['format'] === 'shipplotter' && 
746
-	    (
746
+		(
747 747
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
748 748
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
749
-	    )
749
+		)
750 750
 	) {
751
-	    if ($globalDebug) echo 'download...';
752
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
-	    if ($globalDebug) echo 'done !'."\n";
754
-	    // FIXME: Need more work
755
-	    if ($buffer != '') $reset = 0;
756
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
-	    $buffer = explode('\n',$buffer);
758
-	    foreach ($buffer as $line) {
751
+		if ($globalDebug) echo 'download...';
752
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
+		if ($globalDebug) echo 'done !'."\n";
754
+		// FIXME: Need more work
755
+		if ($buffer != '') $reset = 0;
756
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
+		$buffer = explode('\n',$buffer);
758
+		foreach ($buffer as $line) {
759 759
 		if ($line != '') {
760
-		    $data = array();
761
-		    //echo $line."\n";
762
-		    $data['mmsi'] = (int)substr($line,0,9);
763
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
-		    $data['status_id'] = substr($line,21,2);
765
-		    $data['type_id'] = substr($line,24,3);
766
-		    $data['latitude'] = substr($line,29,9);
767
-		    $data['longitude'] = substr($line,41,9);
768
-		    $data['speed'] = round(substr($line,51,5));
769
-		    //$data['course'] = substr($line,57,5);
770
-		    $data['heading'] = round(substr($line,63,3));
771
-		    //$data['draft'] = substr($line,67,4);
772
-		    //$data['length'] = substr($line,72,3);
773
-		    //$data['beam'] = substr($line,76,2);
774
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
775
-		    //$data['callsign'] = trim(substr($line,100,7);
776
-		    $data['arrival_code'] = substr($line,108,20);
777
-		    //$data['etaDate'] = substr($line,129,5);
778
-		    //$data['etaTime'] = substr($line,135,5);
779
-		    $data['format_source'] = 'shipplotter';
780
-    		    $data['id_source'] = $id_source;
781
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
782
-		    //print_r($data);
783
-		    //echo 'Add...'."\n";
784
-		    $MI->add($data);
785
-		    unset($data);
760
+			$data = array();
761
+			//echo $line."\n";
762
+			$data['mmsi'] = (int)substr($line,0,9);
763
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
+			$data['status_id'] = substr($line,21,2);
765
+			$data['type_id'] = substr($line,24,3);
766
+			$data['latitude'] = substr($line,29,9);
767
+			$data['longitude'] = substr($line,41,9);
768
+			$data['speed'] = round(substr($line,51,5));
769
+			//$data['course'] = substr($line,57,5);
770
+			$data['heading'] = round(substr($line,63,3));
771
+			//$data['draft'] = substr($line,67,4);
772
+			//$data['length'] = substr($line,72,3);
773
+			//$data['beam'] = substr($line,76,2);
774
+			$data['ident'] = trim(utf8_encode(substr($line,78,20)));
775
+			//$data['callsign'] = trim(substr($line,100,7);
776
+			$data['arrival_code'] = substr($line,108,20);
777
+			//$data['etaDate'] = substr($line,129,5);
778
+			//$data['etaTime'] = substr($line,135,5);
779
+			$data['format_source'] = 'shipplotter';
780
+				$data['id_source'] = $id_source;
781
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
782
+			//print_r($data);
783
+			//echo 'Add...'."\n";
784
+			$MI->add($data);
785
+			unset($data);
786 786
 		}
787
-    	    }
788
-    	    $last_exec[$id]['last'] = time();
787
+			}
788
+			$last_exec[$id]['last'] = time();
789 789
 	} elseif ($value['format'] === 'sailawayfull' && 
790
-	    (
790
+		(
791 791
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 5*60))
792
-	    )
792
+		)
793 793
 	) {
794
-	    if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
794
+		if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
795 795
 		$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
796 796
 		//echo $authsailaway;
797 797
 		preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $authsailaway, $setcookie);
798 798
 		if (isset($setcookie[1][0])) {
799
-		    $sailaway_authcookie = $setcookie[1][0];
799
+			$sailaway_authcookie = $setcookie[1][0];
800
+		}
800 801
 		}
801
-	    }
802 802
 
803
-	    if ($globalDebug) echo '! Download... ';
804
-	    for ($i =0; $i <= 1; $i++) {
803
+		if ($globalDebug) echo '! Download... ';
804
+		for ($i =0; $i <= 1; $i++) {
805 805
 		if ($globalDebug) echo 'Racetype: '.$i.' ';
806 806
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
807
-	    if ($globalDebug) echo 'done'."\n";
808
-	    if ($buffer != '') {
807
+		if ($globalDebug) echo 'done'."\n";
808
+		if ($buffer != '') {
809 809
 		$all_data = json_decode($buffer,true);
810 810
 		if (isset($all_data['missions'])) {
811 811
 			foreach ($all_data['missions'] as $mission) {
@@ -826,19 +826,19 @@  discard block
 block discarded – undo
826 826
 					//print_r($race_data);
827 827
 					unset($racebuffer);
828 828
 					if (isset($race_data['mission'])) {
829
-					    $datar = array();
830
-					    $datar['id'] = $mission['misnr'];
831
-					    $datar['desc'] = $race_data['mission']['misdescr'];
832
-					    $datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['usrname'])));
833
-					    $datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['mistitle'])));
834
-					    $datar['startdate'] = $race_data['mission']['misstartdatetime'];
835
-					    $markers = array();
836
-					    foreach ($race_data['mission']['course'] as $course) {
829
+						$datar = array();
830
+						$datar['id'] = $mission['misnr'];
831
+						$datar['desc'] = $race_data['mission']['misdescr'];
832
+						$datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['usrname'])));
833
+						$datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['mistitle'])));
834
+						$datar['startdate'] = $race_data['mission']['misstartdatetime'];
835
+						$markers = array();
836
+						foreach ($race_data['mission']['course'] as $course) {
837 837
 						$markers[] = array('lat' => $course['miclat'],'lon' => $course['miclon'],'name' => $course['micname'],'type' => $course['mictype']);
838
-					    }
839
-					    $datar['markers'] = json_encode($markers);
840
-					    //print_r($datar);
841
-					    $MI->race_add($datar);
838
+						}
839
+						$datar['markers'] = json_encode($markers);
840
+						//print_r($datar);
841
+						$MI->race_add($datar);
842 842
 					}
843 843
 				}
844 844
 				if ($bufferm != '') {
@@ -903,16 +903,16 @@  discard block
 block discarded – undo
903 903
 				sleep(30);
904 904
 			}
905 905
 		}
906
-	    }
907
-	    sleep(5);
908
-	    }
909
-    	    $last_exec[$id]['last'] = time();
906
+		}
907
+		sleep(5);
908
+		}
909
+			$last_exec[$id]['last'] = time();
910 910
 	} elseif ($value['format'] === 'sailaway' && 
911
-	    (
911
+		(
912 912
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 5*60))
913
-	    )
913
+		)
914 914
 	) {
915
-	    /*
915
+		/*
916 916
 	    if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
917 917
 		$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
918 918
 		//echo $authsailaway;
@@ -923,20 +923,20 @@  discard block
 block discarded – undo
923 923
 		}
924 924
 	    }
925 925
 	    */
926
-	    if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
926
+		if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
927 927
 		echo 'Sailaway API key MUST be defined';
928 928
 		exit(0);
929
-	    }
930
-	    if ($globalDebug) echo '! Download... ';
931
-	    $sailawayoption = array('key' => $globalSailaway['key']);
932
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
933
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
934
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
935
-	    if ($buffer != '') {
929
+		}
930
+		if ($globalDebug) echo '! Download... ';
931
+		$sailawayoption = array('key' => $globalSailaway['key']);
932
+		if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
933
+		if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
934
+		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
935
+		if ($buffer != '') {
936 936
 		$data = json_decode($buffer,true);
937 937
 		//print_r($data);
938 938
 		if (isset($data['boats'])) {
939
-		    foreach ($data['boats'] as $sail) {
939
+			foreach ($data['boats'] as $sail) {
940 940
 			$data = array();
941 941
 			$data['id'] = $sail['ubtnr'];
942 942
 			$data['datetime'] = date('Y-m-d H:i:s');
@@ -956,35 +956,35 @@  discard block
 block discarded – undo
956 956
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
957 957
 			$MI->add($data);
958 958
 			unset($data);
959
-		    }
959
+			}
960 960
 		} elseif ($globalDebug) echo 'Error in JSON parsing';
961
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
962
-    	    $last_exec[$id]['last'] = time();
961
+		} elseif ($globalDebug) echo 'Empty result !'."\n";
962
+			$last_exec[$id]['last'] = time();
963 963
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
964 964
 	} elseif (
965
-	    (
965
+		(
966 966
 		$value['format'] === 'whazzup' && 
967 967
 		(
968
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
969
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
968
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
969
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
970 970
 		)
971
-	    ) || (
971
+		) || (
972 972
 		$value['format'] === 'vatsimtxt' && 
973 973
 		(
974
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
975
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
974
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
975
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
976
+		)
976 977
 		)
977
-	    )
978 978
 	) {
979
-	    //$buffer = $Common->getData($hosts[$id]);
980
-	    $buffer = $Common->getData($value['host']);
981
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
982
-	    $buffer = explode('\n',$buffer);
983
-	    $reset = 0;
984
-	    foreach ($buffer as $line) {
985
-    		if ($line != '') {
986
-    		    $line = explode(':', $line);
987
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
979
+		//$buffer = $Common->getData($hosts[$id]);
980
+		$buffer = $Common->getData($value['host']);
981
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
982
+		$buffer = explode('\n',$buffer);
983
+		$reset = 0;
984
+		foreach ($buffer as $line) {
985
+			if ($line != '') {
986
+				$line = explode(':', $line);
987
+				if (count($line) > 30 && $line[0] != 'callsign') {
988 988
 			$data = array();
989 989
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
990 990
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -997,37 +997,37 @@  discard block
 block discarded – undo
997 997
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
998 998
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
999 999
 			$data['latitude'] = $line[5]; // lat
1000
-	        	$data['longitude'] = $line[6]; // long
1001
-	        	$data['verticalrate'] = ''; // vertical rate
1002
-	        	$data['squawk'] = ''; // squawk
1003
-	        	$data['emergency'] = ''; // emergency
1004
-	        	$data['waypoints'] = $line[30];
1000
+				$data['longitude'] = $line[6]; // long
1001
+				$data['verticalrate'] = ''; // vertical rate
1002
+				$data['squawk'] = ''; // squawk
1003
+				$data['emergency'] = ''; // emergency
1004
+				$data['waypoints'] = $line[30];
1005 1005
 			$data['datetime'] = date('Y-m-d H:i:s');
1006 1006
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
1007 1007
 			//if (isset($line[37])) $data['last_update'] = $line[37];
1008
-		        $data['departure_airport_icao'] = $line[11];
1009
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
1010
-		        $data['arrival_airport_icao'] = $line[13];
1008
+				$data['departure_airport_icao'] = $line[11];
1009
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
1010
+				$data['arrival_airport_icao'] = $line[13];
1011 1011
 			$data['frequency'] = $line[4];
1012 1012
 			$data['type'] = $line[18];
1013 1013
 			$data['range'] = $line[19];
1014 1014
 			if (isset($line[35])) $data['info'] = $line[35];
1015
-    			$data['id_source'] = $id_source;
1016
-	    		//$data['arrival_airport_time'] = ;
1017
-	    		if ($line[9] != '') {
1018
-	    		    $aircraft_data = explode('/',$line[9]);
1019
-	    		    if (isset($aircraft_data[1])) {
1020
-	    			$data['aircraft_icao'] = $aircraft_data[1];
1021
-	    		    }
1022
-        		}
1023
-	    		/*
1015
+				$data['id_source'] = $id_source;
1016
+				//$data['arrival_airport_time'] = ;
1017
+				if ($line[9] != '') {
1018
+					$aircraft_data = explode('/',$line[9]);
1019
+					if (isset($aircraft_data[1])) {
1020
+					$data['aircraft_icao'] = $aircraft_data[1];
1021
+					}
1022
+				}
1023
+				/*
1024 1024
 	    		if ($value === 'whazzup') $data['format_source'] = 'whazzup';
1025 1025
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
1026 1026
 	    		*/
1027
-	    		$data['format_source'] = $value['format'];
1027
+				$data['format_source'] = $value['format'];
1028 1028
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029 1029
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
-    			if ($line[3] === 'PILOT') $SI->add($data);
1030
+				if ($line[3] === 'PILOT') $SI->add($data);
1031 1031
 			elseif ($line[3] === 'ATC') {
1032 1032
 				//print_r($data);
1033 1033
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -1048,21 +1048,21 @@  discard block
 block discarded – undo
1048 1048
 					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
1049 1049
 				}
1050 1050
 			}
1051
-    			unset($data);
1052
-    		    }
1053
-    		}
1054
-    	    }
1055
-    	    //if ($value === 'whazzup') $last_exec['whazzup'] = time();
1056
-    	    //elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
1057
-    	    $last_exec[$id]['last'] = time();
1058
-    	} elseif ($value['format'] === 'airwhere' && 
1059
-    	    (
1060
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1061
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1062
-    	    )
1063
-    	) {
1064
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1065
-	    if ($buffer != '') {
1051
+				unset($data);
1052
+				}
1053
+			}
1054
+			}
1055
+			//if ($value === 'whazzup') $last_exec['whazzup'] = time();
1056
+			//elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
1057
+			$last_exec[$id]['last'] = time();
1058
+		} elseif ($value['format'] === 'airwhere' && 
1059
+			(
1060
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1061
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1062
+			)
1063
+		) {
1064
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1065
+		if ($buffer != '') {
1066 1066
 		$all_data = simplexml_load_string($buffer);
1067 1067
 		foreach($all_data->children() as $childdata) {
1068 1068
 			$data = array();
@@ -1084,10 +1084,10 @@  discard block
 block discarded – undo
1084 1084
 			$SI->add($data);
1085 1085
 			unset($data);
1086 1086
 		}
1087
-	    }
1088
-	    $Source->deleteOldLocationByType('gs');
1089
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1090
-	    if ($buffer != '') {
1087
+		}
1088
+		$Source->deleteOldLocationByType('gs');
1089
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1090
+		if ($buffer != '') {
1091 1091
 		$all_data = simplexml_load_string($buffer);
1092 1092
 		foreach($all_data->children() as $childdata) {
1093 1093
 			$data = array();
@@ -1105,8 +1105,8 @@  discard block
 block discarded – undo
1105 1105
 			}
1106 1106
 			unset($data);
1107 1107
 		}
1108
-	    }
1109
-	    $last_exec[$id]['last'] = time();
1108
+		}
1109
+		$last_exec[$id]['last'] = time();
1110 1110
 	/*
1111 1111
 	} if ($value['format'] === 'aircraftlistjson') {
1112 1112
 	    print_r($globalSources);
@@ -1114,17 +1114,17 @@  discard block
 block discarded – undo
1114 1114
 	    echo $globalMinFetch;
1115 1115
 	*/
1116 1116
 	} elseif ($value['format'] === 'aircraftlistjson' && 
1117
-	    (
1117
+		(
1118 1118
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1119 1119
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1120
-	    )
1120
+		)
1121 1121
 	) {
1122
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
1123
-	    if ($buffer != '') {
1124
-	        $all_data = json_decode($buffer,true);
1122
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
1123
+		if ($buffer != '') {
1124
+			$all_data = json_decode($buffer,true);
1125 1125
 		if (isset($all_data['acList'])) {
1126
-		    $reset = 0;
1127
-		    foreach ($all_data['acList'] as $line) {
1126
+			$reset = 0;
1127
+			foreach ($all_data['acList'] as $line) {
1128 1128
 			$data = array();
1129 1129
 			$data['hex'] = $line['Icao']; // hex
1130 1130
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1147,10 +1147,10 @@  discard block
 block discarded – undo
1147 1147
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1148 1148
 			if (isset($data['latitude'])) $SI->add($data);
1149 1149
 			unset($data);
1150
-		    }
1150
+			}
1151 1151
 		} elseif (is_array($all_data)) {
1152
-		    $reset = 0;
1153
-		    foreach ($all_data as $line) {
1152
+			$reset = 0;
1153
+			foreach ($all_data as $line) {
1154 1154
 			$data = array();
1155 1155
 			$data['hex'] = $line['hex']; // hex
1156 1156
 			$data['ident'] = $line['flight']; // ident
@@ -1170,291 +1170,291 @@  discard block
 block discarded – undo
1170 1170
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1171 1171
 			$SI->add($data);
1172 1172
 			unset($data);
1173
-		    }
1173
+			}
1174 1174
 		}
1175
-	    } elseif ($globalDebug) echo 'No data'."\n";
1176
-    	    //$last_exec['aircraftlistjson'] = time();
1177
-    	    $last_exec[$id]['last'] = time();
1178
-    	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1179
-    	} elseif ($value['format'] === 'planeupdatefaa' && 
1180
-    	    (
1181
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1182
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1183
-    	    )
1184
-    	) {
1185
-	    $buffer = $Common->getData($value['host']);
1186
-	    $all_data = json_decode($buffer,true);
1187
-	    if (isset($all_data['planes'])) {
1175
+		} elseif ($globalDebug) echo 'No data'."\n";
1176
+			//$last_exec['aircraftlistjson'] = time();
1177
+			$last_exec[$id]['last'] = time();
1178
+		//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1179
+		} elseif ($value['format'] === 'planeupdatefaa' && 
1180
+			(
1181
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1182
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1183
+			)
1184
+		) {
1185
+		$buffer = $Common->getData($value['host']);
1186
+		$all_data = json_decode($buffer,true);
1187
+		if (isset($all_data['planes'])) {
1188 1188
 		$reset = 0;
1189 1189
 		foreach ($all_data['planes'] as $key => $line) {
1190
-		    $data = array();
1191
-		    $data['hex'] = $key; // hex
1192
-		    $data['ident'] = $line[3]; // ident
1193
-		    $data['altitude'] = $line[6]; // altitude
1194
-		    $data['speed'] = $line[8]; // speed
1195
-		    $data['heading'] = $line[7]; // heading
1196
-		    $data['latitude'] = $line[4]; // lat
1197
-		    $data['longitude'] = $line[5]; // long
1198
-		    //$data['verticalrate'] = $line[]; // verticale rate
1199
-		    $data['squawk'] = $line[10]; // squawk
1200
-		    $data['emergency'] = ''; // emergency
1201
-		    $data['registration'] = $line[2];
1202
-		    $data['aircraft_icao'] = $line[0];
1203
-		    $deparr = explode('-',$line[1]);
1204
-		    if (count($deparr) === 2) {
1190
+			$data = array();
1191
+			$data['hex'] = $key; // hex
1192
+			$data['ident'] = $line[3]; // ident
1193
+			$data['altitude'] = $line[6]; // altitude
1194
+			$data['speed'] = $line[8]; // speed
1195
+			$data['heading'] = $line[7]; // heading
1196
+			$data['latitude'] = $line[4]; // lat
1197
+			$data['longitude'] = $line[5]; // long
1198
+			//$data['verticalrate'] = $line[]; // verticale rate
1199
+			$data['squawk'] = $line[10]; // squawk
1200
+			$data['emergency'] = ''; // emergency
1201
+			$data['registration'] = $line[2];
1202
+			$data['aircraft_icao'] = $line[0];
1203
+			$deparr = explode('-',$line[1]);
1204
+			if (count($deparr) === 2) {
1205 1205
 			$data['departure_airport_icao'] = $deparr[0];
1206 1206
 			$data['arrival_airport_icao'] = $deparr[1];
1207
-		    }
1208
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1209
-	    	    $data['format_source'] = 'planeupdatefaa';
1210
-    		    $data['id_source'] = $id_source;
1211
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1212
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1213
-		    $SI->add($data);
1214
-		    unset($data);
1207
+			}
1208
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1209
+				$data['format_source'] = 'planeupdatefaa';
1210
+				$data['id_source'] = $id_source;
1211
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1212
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1213
+			$SI->add($data);
1214
+			unset($data);
1215 1215
 		}
1216
-	    }
1217
-	    //$last_exec['planeupdatefaa'] = time();
1218
-	    $last_exec[$id]['last'] = time();
1216
+		}
1217
+		//$last_exec['planeupdatefaa'] = time();
1218
+		$last_exec[$id]['last'] = time();
1219 1219
 	} elseif ($value['format'] === 'opensky' && 
1220
-	    (
1220
+		(
1221 1221
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1222 1222
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1223
-	    )
1223
+		)
1224 1224
 	) {
1225
-	    $buffer = $Common->getData($value['host']);
1226
-	    $all_data = json_decode($buffer,true);
1227
-	    if (isset($all_data['states'])) {
1225
+		$buffer = $Common->getData($value['host']);
1226
+		$all_data = json_decode($buffer,true);
1227
+		if (isset($all_data['states'])) {
1228 1228
 		$reset = 0;
1229 1229
 		foreach ($all_data['states'] as $key => $line) {
1230
-		    $data = array();
1231
-		    $data['hex'] = $line[0]; // hex
1232
-		    $data['ident'] = trim($line[1]); // ident
1233
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
1234
-		    $data['speed'] = round($line[9]*1.94384); // speed
1235
-		    $data['heading'] = round($line[10]); // heading
1236
-		    $data['latitude'] = $line[6]; // lat
1237
-		    $data['longitude'] = $line[5]; // long
1238
-		    $data['verticalrate'] = $line[11]; // verticale rate
1239
-		    //$data['squawk'] = $line[10]; // squawk
1240
-		    //$data['emergency'] = ''; // emergency
1241
-		    //$data['registration'] = $line[2];
1242
-		    //$data['aircraft_icao'] = $line[0];
1243
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1244
-		    $data['format_source'] = 'opensky';
1245
-		    $data['id_source'] = $id_source;
1246
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1247
-		    $SI->add($data);
1248
-		    unset($data);
1230
+			$data = array();
1231
+			$data['hex'] = $line[0]; // hex
1232
+			$data['ident'] = trim($line[1]); // ident
1233
+			$data['altitude'] = round($line[7]*3.28084); // altitude
1234
+			$data['speed'] = round($line[9]*1.94384); // speed
1235
+			$data['heading'] = round($line[10]); // heading
1236
+			$data['latitude'] = $line[6]; // lat
1237
+			$data['longitude'] = $line[5]; // long
1238
+			$data['verticalrate'] = $line[11]; // verticale rate
1239
+			//$data['squawk'] = $line[10]; // squawk
1240
+			//$data['emergency'] = ''; // emergency
1241
+			//$data['registration'] = $line[2];
1242
+			//$data['aircraft_icao'] = $line[0];
1243
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1244
+			$data['format_source'] = 'opensky';
1245
+			$data['id_source'] = $id_source;
1246
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1247
+			$SI->add($data);
1248
+			unset($data);
1249 1249
 		}
1250
-	    }
1251
-	    //$last_exec['planeupdatefaa'] = time();
1252
-	    $last_exec[$id]['last'] = time();
1250
+		}
1251
+		//$last_exec['planeupdatefaa'] = time();
1252
+		$last_exec[$id]['last'] = time();
1253 1253
 	} elseif ($value['format'] === 'aircraftjson' && 
1254
-	    (
1254
+		(
1255 1255
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1256 1256
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1257
-	    )
1257
+		)
1258 1258
 	) {
1259
-	    $buffer = $Common->getData($value['host']);
1260
-	    $all_data = json_decode($buffer,true);
1261
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1259
+		$buffer = $Common->getData($value['host']);
1260
+		$all_data = json_decode($buffer,true);
1261
+		if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1262 1262
 		$reset = 0;
1263 1263
 		foreach ($all_data['aircraft'] as $key => $line) {
1264
-		    $data = array();
1265
-		    // add support for ground vehicule with ~ in front of hex
1266
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1267
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1268
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1269
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1270
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1271
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1272
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1273
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1274
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1275
-		    //$data['emergency'] = ''; // emergency
1276
-		    //$data['registration'] = $line[2];
1277
-		    //$data['aircraft_icao'] = $line[0];
1278
-		    $data['datetime'] = date('Y-m-d H:i:s');
1279
-		    $data['format_source'] = 'aircraftjson';
1280
-		    $data['id_source'] = $id_source;
1281
-		    if (isset($value['name']) && $value['name'] != '') {
1282
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1283
-			    else $data['source_name'] = $value['name'];
1284
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1285
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1286
-		    $SI->add($data);
1287
-		    unset($data);
1264
+			$data = array();
1265
+			// add support for ground vehicule with ~ in front of hex
1266
+			if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1267
+			if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1268
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1269
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1270
+			if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1271
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1272
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1273
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1274
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1275
+			//$data['emergency'] = ''; // emergency
1276
+			//$data['registration'] = $line[2];
1277
+			//$data['aircraft_icao'] = $line[0];
1278
+			$data['datetime'] = date('Y-m-d H:i:s');
1279
+			$data['format_source'] = 'aircraftjson';
1280
+			$data['id_source'] = $id_source;
1281
+			if (isset($value['name']) && $value['name'] != '') {
1282
+				if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1283
+				else $data['source_name'] = $value['name'];
1284
+			} elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1285
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1286
+			$SI->add($data);
1287
+			unset($data);
1288 1288
 		}
1289
-	    }
1290
-	    //$last_exec['planeupdatefaa'] = time();
1291
-	    $last_exec[$id]['last'] = time();
1289
+		}
1290
+		//$last_exec['planeupdatefaa'] = time();
1291
+		$last_exec[$id]['last'] = time();
1292 1292
 	} elseif ($value['format'] === 'planefinderclient' && 
1293
-	    (
1293
+		(
1294 1294
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1295 1295
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1296
-	    )
1296
+		)
1297 1297
 	) {
1298
-	    $buffer = $Common->getData($value['host']);
1299
-	    $all_data = json_decode($buffer,true);
1300
-	    if (isset($all_data['aircraft'])) {
1298
+		$buffer = $Common->getData($value['host']);
1299
+		$all_data = json_decode($buffer,true);
1300
+		if (isset($all_data['aircraft'])) {
1301 1301
 		$reset = 0;
1302 1302
 		foreach ($all_data['aircraft'] as $key => $line) {
1303
-		    $data = array();
1304
-		    $data['hex'] = $key; // hex
1305
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1306
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1307
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1308
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1309
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1310
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1311
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1312
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1313
-		    //$data['emergency'] = ''; // emergency
1314
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1315
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1316
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1317
-		    $data['format_source'] = 'planefinderclient';
1318
-		    $data['id_source'] = $id_source;
1319
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1320
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1321
-		    $SI->add($data);
1322
-		    unset($data);
1303
+			$data = array();
1304
+			$data['hex'] = $key; // hex
1305
+			if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1306
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1307
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1308
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1309
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1310
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1311
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1312
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1313
+			//$data['emergency'] = ''; // emergency
1314
+			if (isset($line['reg'])) $data['registration'] = $line['reg'];
1315
+			if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1316
+			$data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1317
+			$data['format_source'] = 'planefinderclient';
1318
+			$data['id_source'] = $id_source;
1319
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1320
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1321
+			$SI->add($data);
1322
+			unset($data);
1323 1323
 		}
1324
-	    }
1325
-	    $last_exec[$id]['last'] = time();
1324
+		}
1325
+		$last_exec[$id]['last'] = time();
1326 1326
 	//} elseif ($value === 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
1327 1327
 	} elseif ($value['format'] === 'fr24json' && 
1328
-	    (
1328
+		(
1329 1329
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1330 1330
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1331
-	    )
1331
+		)
1332 1332
 	) {
1333
-	    //$buffer = $Common->getData($hosts[$id]);
1334
-	    $buffer = $Common->getData($value['host']);
1335
-	    $all_data = json_decode($buffer,true);
1336
-	    if (!empty($all_data)) $reset = 0;
1337
-	    foreach ($all_data as $key => $line) {
1333
+		//$buffer = $Common->getData($hosts[$id]);
1334
+		$buffer = $Common->getData($value['host']);
1335
+		$all_data = json_decode($buffer,true);
1336
+		if (!empty($all_data)) $reset = 0;
1337
+		foreach ($all_data as $key => $line) {
1338 1338
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1339
-		    $data = array();
1340
-		    $data['hex'] = $line[0];
1341
-		    $data['ident'] = $line[16]; //$line[13]
1342
-	    	    $data['altitude'] = $line[4]; // altitude
1343
-	    	    $data['speed'] = $line[5]; // speed
1344
-	    	    $data['heading'] = $line[3]; // heading
1345
-	    	    $data['latitude'] = $line[1]; // lat
1346
-	    	    $data['longitude'] = $line[2]; // long
1347
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1348
-	    	    $data['squawk'] = $line[6]; // squawk
1349
-	    	    $data['aircraft_icao'] = $line[8];
1350
-	    	    $data['registration'] = $line[9];
1351
-		    $data['departure_airport_iata'] = $line[11];
1352
-		    $data['arrival_airport_iata'] = $line[12];
1353
-	    	    $data['emergency'] = ''; // emergency
1354
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1355
-	    	    $data['format_source'] = 'fr24json';
1356
-    		    $data['id_source'] = $id_source;
1357
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1358
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1359
-		    $SI->add($data);
1360
-		    unset($data);
1339
+			$data = array();
1340
+			$data['hex'] = $line[0];
1341
+			$data['ident'] = $line[16]; //$line[13]
1342
+				$data['altitude'] = $line[4]; // altitude
1343
+				$data['speed'] = $line[5]; // speed
1344
+				$data['heading'] = $line[3]; // heading
1345
+				$data['latitude'] = $line[1]; // lat
1346
+				$data['longitude'] = $line[2]; // long
1347
+				$data['verticalrate'] = $line[15]; // verticale rate
1348
+				$data['squawk'] = $line[6]; // squawk
1349
+				$data['aircraft_icao'] = $line[8];
1350
+				$data['registration'] = $line[9];
1351
+			$data['departure_airport_iata'] = $line[11];
1352
+			$data['arrival_airport_iata'] = $line[12];
1353
+				$data['emergency'] = ''; // emergency
1354
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1355
+				$data['format_source'] = 'fr24json';
1356
+				$data['id_source'] = $id_source;
1357
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1358
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1359
+			$SI->add($data);
1360
+			unset($data);
1361 1361
 		}
1362
-	    }
1363
-	    //$last_exec['fr24json'] = time();
1364
-	    $last_exec[$id]['last'] = time();
1362
+		}
1363
+		//$last_exec['fr24json'] = time();
1364
+		$last_exec[$id]['last'] = time();
1365 1365
 	//} elseif ($value === 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1366 1366
 	} elseif ($value['format'] === 'radarvirtueljson' && 
1367
-	    (
1367
+		(
1368 1368
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1369 1369
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1370
-	    )
1370
+		)
1371 1371
 	) {
1372
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1373
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1374
-	    //echo $buffer;
1375
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1376
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1377
-	    $all_data = json_decode($buffer,true);
1378
-	    if (json_last_error() != JSON_ERROR_NONE) {
1372
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1373
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1374
+		//echo $buffer;
1375
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1376
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1377
+		$all_data = json_decode($buffer,true);
1378
+		if (json_last_error() != JSON_ERROR_NONE) {
1379 1379
 		die(json_last_error_msg());
1380
-	    }
1381
-	    if (isset($all_data['mrkrs'])) {
1380
+		}
1381
+		if (isset($all_data['mrkrs'])) {
1382 1382
 		$reset = 0;
1383 1383
 		foreach ($all_data['mrkrs'] as $key => $line) {
1384
-		    if (isset($line['inf'])) {
1384
+			if (isset($line['inf'])) {
1385 1385
 			$data = array();
1386 1386
 			$data['hex'] = $line['inf']['ia'];
1387 1387
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1388
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1389
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1390
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1391
-	    		$data['latitude'] = $line['pt'][0]; // lat
1392
-	    		$data['longitude'] = $line['pt'][1]; // long
1393
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1394
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1395
-	    		//$data['aircraft_icao'] = $line[8];
1396
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1388
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1389
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1390
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1391
+				$data['latitude'] = $line['pt'][0]; // lat
1392
+				$data['longitude'] = $line['pt'][1]; // long
1393
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1394
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1395
+				//$data['aircraft_icao'] = $line[8];
1396
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1397 1397
 			//$data['departure_airport_iata'] = $line[11];
1398 1398
 			//$data['arrival_airport_iata'] = $line[12];
1399
-	    		//$data['emergency'] = ''; // emergency
1399
+				//$data['emergency'] = ''; // emergency
1400 1400
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1401
-	    		$data['format_source'] = 'radarvirtueljson';
1402
-    			$data['id_source'] = $id_source;
1401
+				$data['format_source'] = 'radarvirtueljson';
1402
+				$data['id_source'] = $id_source;
1403 1403
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1404 1404
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1405 1405
 			$SI->add($data);
1406 1406
 			unset($data);
1407
-		    }
1407
+			}
1408 1408
 		}
1409
-	    }
1410
-	    //$last_exec['radarvirtueljson'] = time();
1411
-	    $last_exec[$id]['last'] = time();
1409
+		}
1410
+		//$last_exec['radarvirtueljson'] = time();
1411
+		$last_exec[$id]['last'] = time();
1412 1412
 	//} elseif ($value === 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1413 1413
 	} elseif ($value['format'] === 'pirepsjson' && 
1414
-	    (
1414
+		(
1415 1415
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1416 1416
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1417
-	    )
1417
+		)
1418 1418
 	) {
1419
-	    //$buffer = $Common->getData($hosts[$id]);
1420
-	    $buffer = $Common->getData($value['host'].'?'.time());
1421
-	    $all_data = json_decode(utf8_encode($buffer),true);
1419
+		//$buffer = $Common->getData($hosts[$id]);
1420
+		$buffer = $Common->getData($value['host'].'?'.time());
1421
+		$all_data = json_decode(utf8_encode($buffer),true);
1422 1422
 	    
1423
-	    if (isset($all_data['pireps'])) {
1423
+		if (isset($all_data['pireps'])) {
1424 1424
 		$reset = 0;
1425
-	        foreach ($all_data['pireps'] as $line) {
1426
-		    $data = array();
1427
-		    $data['id'] = $line['id'];
1428
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1429
-		    $data['ident'] = $line['callsign']; // ident
1430
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1431
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1432
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1433
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1434
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1435
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1436
-		    $data['latitude'] = $line['lat']; // lat
1437
-		    $data['longitude'] = $line['lon']; // long
1438
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1439
-		    //$data['squawk'] = $line['squawk']; // squawk
1440
-		    //$data['emergency'] = ''; // emergency
1441
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1442
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1443
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1444
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1445
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1446
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1447
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1448
-		    else $data['info'] = '';
1449
-		    $data['format_source'] = 'pireps';
1450
-    		    $data['id_source'] = $id_source;
1451
-		    $data['datetime'] = date('Y-m-d H:i:s');
1452
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1453
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1454
-		    if ($line['icon'] === 'plane') {
1425
+			foreach ($all_data['pireps'] as $line) {
1426
+			$data = array();
1427
+			$data['id'] = $line['id'];
1428
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1429
+			$data['ident'] = $line['callsign']; // ident
1430
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1431
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1432
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1433
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1434
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1435
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1436
+			$data['latitude'] = $line['lat']; // lat
1437
+			$data['longitude'] = $line['lon']; // long
1438
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1439
+			//$data['squawk'] = $line['squawk']; // squawk
1440
+			//$data['emergency'] = ''; // emergency
1441
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1442
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1443
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1444
+			//$data['arrival_airport_time'] = $line['arrtime'];
1445
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1446
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1447
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1448
+			else $data['info'] = '';
1449
+			$data['format_source'] = 'pireps';
1450
+				$data['id_source'] = $id_source;
1451
+			$data['datetime'] = date('Y-m-d H:i:s');
1452
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1453
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1454
+			if ($line['icon'] === 'plane') {
1455 1455
 			$SI->add($data);
1456
-		    //    print_r($data);
1457
-    		    } elseif ($line['icon'] === 'ct') {
1456
+			//    print_r($data);
1457
+				} elseif ($line['icon'] === 'ct') {
1458 1458
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1459 1459
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1460 1460
 			$typec = substr($data['ident'],-3);
@@ -1469,209 +1469,209 @@  discard block
 block discarded – undo
1469 1469
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1470 1470
 			else $data['type'] = 'Observer';
1471 1471
 			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1472
-		    }
1473
-		    unset($data);
1472
+			}
1473
+			unset($data);
1474 1474
 		}
1475
-	    }
1476
-	    //$last_exec['pirepsjson'] = time();
1477
-	    $last_exec[$id]['last'] = time();
1475
+		}
1476
+		//$last_exec['pirepsjson'] = time();
1477
+		$last_exec[$id]['last'] = time();
1478 1478
 	//} elseif ($value === 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1479 1479
 	} elseif ($value['format'] === 'phpvmacars' && 
1480
-	    (
1480
+		(
1481 1481
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1482 1482
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1483
-	    )
1483
+		)
1484 1484
 	) {
1485
-	    //$buffer = $Common->getData($hosts[$id]);
1486
-	    if ($globalDebug) echo 'Get Data...'."\n";
1487
-	    $buffer = $Common->getData($value['host']);
1488
-	    $all_data = json_decode($buffer,true);
1489
-	    if ($buffer != '' && is_array($all_data)) {
1485
+		//$buffer = $Common->getData($hosts[$id]);
1486
+		if ($globalDebug) echo 'Get Data...'."\n";
1487
+		$buffer = $Common->getData($value['host']);
1488
+		$all_data = json_decode($buffer,true);
1489
+		if ($buffer != '' && is_array($all_data)) {
1490 1490
 		$reset = 0;
1491 1491
 		foreach ($all_data as $line) {
1492
-	    	    $data = array();
1493
-	    	    //$data['id'] = $line['id']; // id not usable
1494
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1495
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1496
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1497
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1498
-	    	    $data['ident'] = $line['flightnum']; // ident
1499
-	    	    $data['altitude'] = $line['alt']; // altitude
1500
-	    	    $data['speed'] = $line['gs']; // speed
1501
-	    	    $data['heading'] = $line['heading']; // heading
1502
-	    	    $data['latitude'] = $line['lat']; // lat
1503
-	    	    $data['longitude'] = $line['lng']; // long
1504
-	    	    $data['verticalrate'] = ''; // verticale rate
1505
-	    	    $data['squawk'] = ''; // squawk
1506
-	    	    $data['emergency'] = ''; // emergency
1507
-	    	    //$data['datetime'] = $line['lastupdate'];
1508
-	    	    //$data['last_update'] = $line['lastupdate'];
1509
-	    	    if (isset($value['timezone'])) {
1510
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1511
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1512
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1513
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1514
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1515
-	    	    $data['departure_airport_time'] = $line['deptime'];
1516
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1517
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1518
-    		    if (isset($line['registration'])) {
1519
-    			$data['registration'] = $line['registration'];
1520
-    			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1521
-    		    } else $data['registration'] = $line['aircraft'];
1522
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1523
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1524
-		    if (isset($line['aircraftname'])) {
1492
+				$data = array();
1493
+				//$data['id'] = $line['id']; // id not usable
1494
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1495
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1496
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1497
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1498
+				$data['ident'] = $line['flightnum']; // ident
1499
+				$data['altitude'] = $line['alt']; // altitude
1500
+				$data['speed'] = $line['gs']; // speed
1501
+				$data['heading'] = $line['heading']; // heading
1502
+				$data['latitude'] = $line['lat']; // lat
1503
+				$data['longitude'] = $line['lng']; // long
1504
+				$data['verticalrate'] = ''; // verticale rate
1505
+				$data['squawk'] = ''; // squawk
1506
+				$data['emergency'] = ''; // emergency
1507
+				//$data['datetime'] = $line['lastupdate'];
1508
+				//$data['last_update'] = $line['lastupdate'];
1509
+				if (isset($value['timezone'])) {
1510
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1511
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1512
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1513
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1514
+				$data['departure_airport_icao'] = $line['depicao'];
1515
+				$data['departure_airport_time'] = $line['deptime'];
1516
+				$data['arrival_airport_icao'] = $line['arricao'];
1517
+				$data['arrival_airport_time'] = $line['arrtime'];
1518
+				if (isset($line['registration'])) {
1519
+				$data['registration'] = $line['registration'];
1520
+				//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1521
+				} else $data['registration'] = $line['aircraft'];
1522
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1523
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1524
+			if (isset($line['aircraftname'])) {
1525 1525
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1526 1526
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1527
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1528
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1529
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1530
-	    		else {
1531
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1532
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1533
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1534
-	    		}
1535
-	    	    }
1536
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1537
-    		    $data['id_source'] = $id_source;
1538
-	    	    $data['format_source'] = 'phpvmacars';
1539
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1540
-		    $SI->add($data);
1541
-		    unset($data);
1527
+				$aircraft_data = explode('-',$line['aircraftname']);
1528
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1529
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1530
+				else {
1531
+					$aircraft_data = explode(' ',$line['aircraftname']);
1532
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1533
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1534
+				}
1535
+				}
1536
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1537
+				$data['id_source'] = $id_source;
1538
+				$data['format_source'] = 'phpvmacars';
1539
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1540
+			$SI->add($data);
1541
+			unset($data);
1542 1542
 		}
1543 1543
 		if ($globalDebug) echo 'No more data...'."\n";
1544 1544
 		unset($buffer);
1545 1545
 		unset($all_data);
1546
-	    }
1547
-	    //$last_exec['phpvmacars'] = time();
1548
-	    $last_exec[$id]['last'] = time();
1546
+		}
1547
+		//$last_exec['phpvmacars'] = time();
1548
+		$last_exec[$id]['last'] = time();
1549 1549
 	} elseif ($value['format'] === 'vaos' && 
1550
-	    (
1550
+		(
1551 1551
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1552 1552
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1553
-	    )
1553
+		)
1554 1554
 	) {
1555
-	    //$buffer = $Common->getData($hosts[$id]);
1556
-	    if ($globalDebug) echo 'Get Data...'."\n";
1557
-	    $buffer = $Common->getData($value['host']);
1558
-	    $all_data = json_decode($buffer,true);
1559
-	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1555
+		//$buffer = $Common->getData($hosts[$id]);
1556
+		if ($globalDebug) echo 'Get Data...'."\n";
1557
+		$buffer = $Common->getData($value['host']);
1558
+		$all_data = json_decode($buffer,true);
1559
+		if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1560 1560
 		$reset = 0;
1561 1561
 		foreach ($all_data['ACARSData'] as $line) {
1562
-		    //print_r($line);
1563
-	    	    $data = array();
1564
-	    	    //$data['id'] = $line['id']; // id not usable
1565
-	    	    $data['id'] = $line['id'];
1566
-	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1567
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1568
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1569
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1570
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1571
-	    	    $data['altitude'] = $line['altitude']; // altitude
1572
-	    	    $data['speed'] = $line['groundspeed']; // speed
1573
-	    	    $data['heading'] = $line['heading']; // heading
1574
-	    	    $data['latitude'] = $line['lat']; // lat
1575
-	    	    $data['longitude'] = $line['lon']; // long
1576
-	    	    //$data['verticalrate'] = ''; // verticale rate
1577
-	    	    //$data['squawk'] = ''; // squawk
1578
-	    	    //$data['emergency'] = ''; // emergency
1579
-	    	    if (isset($value['timezone'])) {
1580
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1581
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1582
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1583
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1562
+			//print_r($line);
1563
+				$data = array();
1564
+				//$data['id'] = $line['id']; // id not usable
1565
+				$data['id'] = $line['id'];
1566
+				//$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1567
+				if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1568
+				if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1569
+				$data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1570
+				if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1571
+				$data['altitude'] = $line['altitude']; // altitude
1572
+				$data['speed'] = $line['groundspeed']; // speed
1573
+				$data['heading'] = $line['heading']; // heading
1574
+				$data['latitude'] = $line['lat']; // lat
1575
+				$data['longitude'] = $line['lon']; // long
1576
+				//$data['verticalrate'] = ''; // verticale rate
1577
+				//$data['squawk'] = ''; // squawk
1578
+				//$data['emergency'] = ''; // emergency
1579
+				if (isset($value['timezone'])) {
1580
+				$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1581
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1582
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1583
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1584 1584
 	    	    
1585
-	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1586
-	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
1587
-	    	    $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1588
-		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1589
-		    $data['registration'] = $line['bid']['aircraft']['registration'];
1585
+				$data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1586
+				$data['departure_airport_time'] = $line['bid']['deptime'];
1587
+				$data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1588
+			$data['arrival_airport_time'] = $line['bid']['arrtime'];
1589
+			$data['registration'] = $line['bid']['aircraft']['registration'];
1590 1590
 
1591
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1592
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1593
-	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1591
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1592
+			if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1593
+				$data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1594 1594
 
1595
-    		    $data['id_source'] = $id_source;
1596
-	    	    $data['format_source'] = 'vaos';
1597
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1598
-		    $SI->add($data);
1599
-		    unset($data);
1595
+				$data['id_source'] = $id_source;
1596
+				$data['format_source'] = 'vaos';
1597
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1598
+			$SI->add($data);
1599
+			unset($data);
1600 1600
 		}
1601 1601
 		if ($globalDebug) echo 'No more data...'."\n";
1602 1602
 		unset($buffer);
1603 1603
 		unset($all_data);
1604
-	    }
1605
-	    //$last_exec['phpvmacars'] = time();
1606
-	    $last_exec[$id]['last'] = time();
1604
+		}
1605
+		//$last_exec['phpvmacars'] = time();
1606
+		$last_exec[$id]['last'] = time();
1607 1607
 	} elseif ($value['format'] === 'vam' && 
1608
-	    (
1608
+		(
1609 1609
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1610 1610
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1611
-	    )
1611
+		)
1612 1612
 	) {
1613
-	    //$buffer = $Common->getData($hosts[$id]);
1614
-	    if ($globalDebug) echo 'Get Data...'."\n";
1615
-	    $buffer = $Common->getData($value['host']);
1616
-	    $all_data = json_decode($buffer,true);
1617
-	    if ($buffer != '' && is_array($all_data)) {
1613
+		//$buffer = $Common->getData($hosts[$id]);
1614
+		if ($globalDebug) echo 'Get Data...'."\n";
1615
+		$buffer = $Common->getData($value['host']);
1616
+		$all_data = json_decode($buffer,true);
1617
+		if ($buffer != '' && is_array($all_data)) {
1618 1618
 		$reset = 0;
1619 1619
 		foreach ($all_data as $line) {
1620
-	    	    $data = array();
1621
-	    	    //$data['id'] = $line['id']; // id not usable
1622
-	    	    $data['id'] = trim($line['flight_id']);
1623
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1624
-	    	    $data['pilot_name'] = $line['pilot_name'];
1625
-	    	    $data['pilot_id'] = $line['pilot_id'];
1626
-	    	    $data['ident'] = trim($line['callsign']); // ident
1627
-	    	    $data['altitude'] = $line['altitude']; // altitude
1628
-	    	    $data['speed'] = $line['gs']; // speed
1629
-	    	    $data['heading'] = $line['heading']; // heading
1630
-	    	    $data['latitude'] = $line['latitude']; // lat
1631
-	    	    $data['longitude'] = $line['longitude']; // long
1632
-	    	    $data['verticalrate'] = ''; // verticale rate
1633
-	    	    $data['squawk'] = ''; // squawk
1634
-	    	    $data['emergency'] = ''; // emergency
1635
-	    	    //$data['datetime'] = $line['lastupdate'];
1636
-	    	    $data['last_update'] = $line['last_update'];
1637
-		    $data['datetime'] = date('Y-m-d H:i:s');
1638
-	    	    $data['departure_airport_icao'] = $line['departure'];
1639
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1640
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1641
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1642
-    		    //$data['registration'] = $line['aircraft'];
1643
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1644
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1645
-    		    $data['id_source'] = $id_source;
1646
-	    	    $data['format_source'] = 'vam';
1647
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1648
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1649
-		    $SI->add($data);
1650
-		    unset($data);
1620
+				$data = array();
1621
+				//$data['id'] = $line['id']; // id not usable
1622
+				$data['id'] = trim($line['flight_id']);
1623
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1624
+				$data['pilot_name'] = $line['pilot_name'];
1625
+				$data['pilot_id'] = $line['pilot_id'];
1626
+				$data['ident'] = trim($line['callsign']); // ident
1627
+				$data['altitude'] = $line['altitude']; // altitude
1628
+				$data['speed'] = $line['gs']; // speed
1629
+				$data['heading'] = $line['heading']; // heading
1630
+				$data['latitude'] = $line['latitude']; // lat
1631
+				$data['longitude'] = $line['longitude']; // long
1632
+				$data['verticalrate'] = ''; // verticale rate
1633
+				$data['squawk'] = ''; // squawk
1634
+				$data['emergency'] = ''; // emergency
1635
+				//$data['datetime'] = $line['lastupdate'];
1636
+				$data['last_update'] = $line['last_update'];
1637
+			$data['datetime'] = date('Y-m-d H:i:s');
1638
+				$data['departure_airport_icao'] = $line['departure'];
1639
+				//$data['departure_airport_time'] = $line['departure_time'];
1640
+				$data['arrival_airport_icao'] = $line['arrival'];
1641
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1642
+				//$data['registration'] = $line['aircraft'];
1643
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1644
+				$data['aircraft_icao'] = $line['plane_type'];
1645
+				$data['id_source'] = $id_source;
1646
+				$data['format_source'] = 'vam';
1647
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1648
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1649
+			$SI->add($data);
1650
+			unset($data);
1651 1651
 		}
1652 1652
 		if ($globalDebug) echo 'No more data...'."\n";
1653 1653
 		unset($buffer);
1654 1654
 		unset($all_data);
1655
-	    }
1656
-	    //$last_exec['phpvmacars'] = time();
1657
-	    $last_exec[$id]['last'] = time();
1655
+		}
1656
+		//$last_exec['phpvmacars'] = time();
1657
+		$last_exec[$id]['last'] = time();
1658 1658
 	} elseif ($value['format'] === 'blitzortung' && 
1659
-	    (
1659
+		(
1660 1660
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1661 1661
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1662
-	    )
1662
+		)
1663 1663
 	) {
1664
-	    //$buffer = $Common->getData($hosts[$id]);
1665
-	    if ($globalDebug) echo 'Get Data...'."\n";
1666
-	    $buffer = $Common->getData($value['host']);
1667
-	    $all_data = json_decode($buffer,true);
1668
-	    if ($buffer != '') {
1664
+		//$buffer = $Common->getData($hosts[$id]);
1665
+		if ($globalDebug) echo 'Get Data...'."\n";
1666
+		$buffer = $Common->getData($value['host']);
1667
+		$all_data = json_decode($buffer,true);
1668
+		if ($buffer != '') {
1669 1669
 		$Source->deleteLocationBySource('blitzortung');
1670 1670
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1671 1671
 		$buffer = explode('\n',$buffer);
1672 1672
 		foreach ($buffer as $buffer_line) {
1673
-		    $line = json_decode($buffer_line,true);
1674
-		    if (isset($line['time'])) {
1673
+			$line = json_decode($buffer_line,true);
1674
+			if (isset($line['time'])) {
1675 1675
 			$data = array();
1676 1676
 			$data['altitude'] = $line['alt']; // altitude
1677 1677
 			$data['latitude'] = $line['lat']; // lat
@@ -1683,92 +1683,92 @@  discard block
 block discarded – undo
1683 1683
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1684 1684
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1685 1685
 			unset($data);
1686
-		    }
1686
+			}
1687 1687
 		}
1688 1688
 		if ($globalDebug) echo 'No more data...'."\n";
1689 1689
 		unset($buffer);
1690
-	    }
1691
-	    $last_exec[$id]['last'] = time();
1690
+		}
1691
+		$last_exec[$id]['last'] = time();
1692 1692
 	} elseif ($value['format'] === 'acarsjson') {
1693
-        $arr = $httpfeeds;
1694
-        $w = $e = null;
1695
-        if (isset($arr[$id])) {
1696
-            $nn = stream_select($arr,$w,$e,$timeout);
1697
-            if ($nn > 0) {
1698
-                foreach ($httpfeeds as $feed) {
1699
-                    $buffer = stream_get_line($feed,2000,"\n");
1700
-                    if ($buffer === FALSE) {
1701
-                        connect_all($globalSources);
1702
-                    }
1703
-                    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1704
-                    $buffer = explode('\n',$buffer);
1705
-                    foreach ($buffer as $line) {
1706
-                        if ($line != '') {
1707
-                            $line = json_decode($line, true);
1708
-                            if (!empty($line)) {
1709
-                                $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1710
-                                $ACARS->deleteLiveAcarsData();
1711
-                            }
1712
-                        }
1713
-                    }
1714
-                }
1715
-            } else {
1716
-                $format = $value['format'];
1717
-                if (isset($tt[$format])) $tt[$format]++;
1718
-                else $tt[$format] = 0;
1719
-                if ($tt[$format] > 30) {
1720
-                    if ($globalDebug) echo 'Reconnect...'."\n";
1721
-                    sleep(2);
1722
-                    //$sourceeen[] = $value;
1723
-                    //connect_all($sourceeen);
1724
-                    //$sourceeen = array();
1725
-                    connect_all($globalSources);
1726
-                }
1727
-            }
1728
-        }
1693
+		$arr = $httpfeeds;
1694
+		$w = $e = null;
1695
+		if (isset($arr[$id])) {
1696
+			$nn = stream_select($arr,$w,$e,$timeout);
1697
+			if ($nn > 0) {
1698
+				foreach ($httpfeeds as $feed) {
1699
+					$buffer = stream_get_line($feed,2000,"\n");
1700
+					if ($buffer === FALSE) {
1701
+						connect_all($globalSources);
1702
+					}
1703
+					$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1704
+					$buffer = explode('\n',$buffer);
1705
+					foreach ($buffer as $line) {
1706
+						if ($line != '') {
1707
+							$line = json_decode($line, true);
1708
+							if (!empty($line)) {
1709
+								$ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1710
+								$ACARS->deleteLiveAcarsData();
1711
+							}
1712
+						}
1713
+					}
1714
+				}
1715
+			} else {
1716
+				$format = $value['format'];
1717
+				if (isset($tt[$format])) $tt[$format]++;
1718
+				else $tt[$format] = 0;
1719
+				if ($tt[$format] > 30) {
1720
+					if ($globalDebug) echo 'Reconnect...'."\n";
1721
+					sleep(2);
1722
+					//$sourceeen[] = $value;
1723
+					//connect_all($sourceeen);
1724
+					//$sourceeen = array();
1725
+					connect_all($globalSources);
1726
+				}
1727
+			}
1728
+		}
1729 1729
 	//} elseif ($value === 'sbs' || $value === 'tsv' || $value === 'raw' || $value === 'aprs' || $value === 'beast') {
1730 1730
 	} elseif ($value['format'] === 'sbs' || $value['format'] === 'tsv' || $value['format'] === 'raw' || $value['format'] === 'aprs' || $value['format'] === 'famaprs' || $value['format'] === 'beast' || $value['format'] === 'flightgearmp' || $value['format'] === 'flightgearsp' || $value['format'] === 'acars' || $value['format'] === 'acarsjsonudp' || $value['format'] === 'acarssbs3' || $value['format'] === 'ais' || $value['format'] === 'vrstcp') {
1731
-	    //$last_exec[$id]['last'] = time();
1732
-	    //$read = array( $sockets[$id] );
1733
-	    $read = $sockets;
1734
-	    $write = NULL;
1735
-	    $e = NULL;
1736
-	    $n = socket_select($read, $write, $e, $timeout);
1737
-	    if ($e != NULL) var_dump($e);
1738
-	    if ($n > 0) {
1731
+		//$last_exec[$id]['last'] = time();
1732
+		//$read = array( $sockets[$id] );
1733
+		$read = $sockets;
1734
+		$write = NULL;
1735
+		$e = NULL;
1736
+		$n = socket_select($read, $write, $e, $timeout);
1737
+		if ($e != NULL) var_dump($e);
1738
+		if ($n > 0) {
1739 1739
 		$reset = 0;
1740 1740
 		foreach ($read as $nb => $r) {
1741
-		    //$value = $formats[$nb];
1742
-		    $format = $globalSources[$nb]['format'];
1743
-		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1741
+			//$value = $formats[$nb];
1742
+			$format = $globalSources[$nb]['format'];
1743
+			if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1744 1744
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1745
-		    } elseif ($format === 'vrstcp') {
1745
+			} elseif ($format === 'vrstcp') {
1746 1746
 			$buffer = @socket_read($r, 6000);
1747
-		    } else {
1747
+			} else {
1748 1748
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1749
-		    }
1750
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1751
-		    //echo $buffer."\n";
1752
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1753
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1754
-		    $error = false;
1755
-		    //$SI::del();
1756
-		    if ($buffer !== FALSE) {
1749
+			}
1750
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1751
+			//echo $buffer."\n";
1752
+			// lets play nice and handle signals such as ctrl-c/kill properly
1753
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1754
+			$error = false;
1755
+			//$SI::del();
1756
+			if ($buffer !== FALSE) {
1757 1757
 			if ($format === 'vrstcp') {
1758
-			    $buffer = explode('},{',$buffer);
1758
+				$buffer = explode('},{',$buffer);
1759 1759
 			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1760
-		    }
1761
-		    // SBS format is CSV format
1762
-		    if ($buffer !== FALSE && $buffer !== '') {
1760
+			}
1761
+			// SBS format is CSV format
1762
+			if ($buffer !== FALSE && $buffer !== '') {
1763 1763
 			$tt[$format] = 0;
1764 1764
 			if ($format === 'acarssbs3') {
1765
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1766
-			    $ACARS->add(trim($buffer));
1767
-			    $ACARS->deleteLiveAcarsData();
1765
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1766
+				$ACARS->add(trim($buffer));
1767
+				$ACARS->deleteLiveAcarsData();
1768 1768
 			} elseif ($format === 'raw') {
1769
-			    // AVR format
1770
-			    $data = $SBS->parse($buffer);
1771
-			    if (is_array($data)) {
1769
+				// AVR format
1770
+				$data = $SBS->parse($buffer);
1771
+				if (is_array($data)) {
1772 1772
 				//if (!empty($data)) print_r($data);
1773 1773
 				$data['datetime'] = date('Y-m-d H:i:s');
1774 1774
 				$data['format_source'] = 'raw';
@@ -1778,39 +1778,39 @@  discard block
 block discarded – undo
1778 1778
 				//if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1779 1779
 				$SI->add($data);
1780 1780
 				unset($data);
1781
-			    }
1781
+				}
1782 1782
 			} elseif ($format === 'ais') {
1783
-			    $ais_data = $AIS->parse_line(trim($buffer));
1784
-			    $data = array();
1785
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1786
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1787
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1788
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1789
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1790
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1791
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1792
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1793
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1794
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1795
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1796
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1797
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1798
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1799
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1800
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1783
+				$ais_data = $AIS->parse_line(trim($buffer));
1784
+				$data = array();
1785
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1786
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1787
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1788
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1789
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1790
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1791
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1792
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1793
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1794
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1795
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1796
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1797
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1798
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1799
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1800
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1801 1801
 
1802
-			    if (isset($ais_data['timestamp'])) {
1802
+				if (isset($ais_data['timestamp'])) {
1803 1803
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1804
-			    } else {
1804
+				} else {
1805 1805
 				$data['datetime'] = date('Y-m-d H:i:s');
1806
-			    }
1807
-			    $data['format_source'] = 'aisnmea';
1808
-    			    $data['id_source'] = $id_source;
1809
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1810
-			    unset($data);
1811
-                        } elseif ($format === 'flightgearsp') {
1812
-                    	    //echo $buffer."\n";
1813
-                    	    if (strlen($buffer) > 5) {
1806
+				}
1807
+				$data['format_source'] = 'aisnmea';
1808
+					$data['id_source'] = $id_source;
1809
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1810
+				unset($data);
1811
+						} elseif ($format === 'flightgearsp') {
1812
+							//echo $buffer."\n";
1813
+							if (strlen($buffer) > 5) {
1814 1814
 				$line = explode(',',$buffer);
1815 1815
 				$data = array();
1816 1816
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1827,47 +1827,47 @@  discard block
 block discarded – undo
1827 1827
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1828 1828
 				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1829 1829
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1830
-			    }
1831
-                        } elseif ($format === 'acars') {
1832
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1833
-			    $ACARS->add(trim($buffer));
1834
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1835
-			    $ACARS->deleteLiveAcarsData();
1830
+				}
1831
+						} elseif ($format === 'acars') {
1832
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1833
+				$ACARS->add(trim($buffer));
1834
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1835
+				$ACARS->deleteLiveAcarsData();
1836 1836
 			} elseif ($format === 'acarsjsonudp') {
1837
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1838
-                            $line = json_decode(trim($buffer), true);
1839
-                            if (!empty($line)) {
1837
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1838
+							$line = json_decode(trim($buffer), true);
1839
+							if (!empty($line)) {
1840 1840
 				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
1841
-                                $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1842
-                                $ACARS->deleteLiveAcarsData();
1843
-                            }
1844
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1841
+								$ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1842
+								$ACARS->deleteLiveAcarsData();
1843
+							}
1844
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1845 1845
 			} elseif ($format === 'flightgearmp') {
1846
-			    if (substr($buffer,0,1) != '#') {
1846
+				if (substr($buffer,0,1) != '#') {
1847 1847
 				$data = array();
1848 1848
 				//echo $buffer."\n";
1849 1849
 				$line = explode(' ',$buffer);
1850 1850
 				if (count($line) === 11) {
1851
-				    $userserver = explode('@',$line[0]);
1852
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1853
-				    $data['ident'] = $userserver[0];
1854
-				    $data['registration'] = $userserver[0];
1855
-				    $data['latitude'] = $line[4];
1856
-				    $data['longitude'] = $line[5];
1857
-				    $data['altitude'] = $line[6];
1858
-				    $data['datetime'] = date('Y-m-d H:i:s');
1859
-				    $aircraft_type = $line[10];
1860
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1861
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1862
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1863
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1851
+					$userserver = explode('@',$line[0]);
1852
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1853
+					$data['ident'] = $userserver[0];
1854
+					$data['registration'] = $userserver[0];
1855
+					$data['latitude'] = $line[4];
1856
+					$data['longitude'] = $line[5];
1857
+					$data['altitude'] = $line[6];
1858
+					$data['datetime'] = date('Y-m-d H:i:s');
1859
+					$aircraft_type = $line[10];
1860
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1861
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1862
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1863
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1864
+				}
1864 1865
 				}
1865
-			    }
1866 1866
 			} elseif ($format === 'beast') {
1867
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1868
-			    die;
1867
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1868
+				die;
1869 1869
 			} elseif ($format === 'vrstcp') {
1870
-			    foreach($buffer as $all_data) {
1870
+				foreach($buffer as $all_data) {
1871 1871
 				$line = json_decode('{'.$all_data.'}',true);
1872 1872
 				$data = array();
1873 1873
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1887,158 +1887,158 @@  discard block
 block discarded – undo
1887 1887
 				*/
1888 1888
 				$data['datetime'] = date('Y-m-d H:i:s');
1889 1889
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1890
-		    		$data['format_source'] = 'vrstcp';
1890
+					$data['format_source'] = 'vrstcp';
1891 1891
 				$data['id_source'] = $id_source;
1892 1892
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1893 1893
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1894 1894
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1895 1895
 				unset($data);
1896
-			    }
1896
+				}
1897 1897
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1898
-			    $line = explode("\t", $buffer);
1899
-			    for($k = 0; $k < count($line); $k=$k+2) {
1898
+				$line = explode("\t", $buffer);
1899
+				for($k = 0; $k < count($line); $k=$k+2) {
1900 1900
 				$key = $line[$k];
1901
-			        $lined[$key] = $line[$k+1];
1902
-			    }
1903
-    			    if (count($lined) > 3) {
1904
-    				$data['hex'] = $lined['hexid'];
1905
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1906
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1907
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1908
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1909
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1910
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1911
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1912
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1913
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1914
-    				$data['id_source'] = $id_source;
1915
-    				$data['format_source'] = 'tsv';
1916
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1917
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1901
+					$lined[$key] = $line[$k+1];
1902
+				}
1903
+					if (count($lined) > 3) {
1904
+					$data['hex'] = $lined['hexid'];
1905
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1906
+					$data['datetime'] = date('Y-m-d H:i:s');;
1907
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1908
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1909
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1910
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1911
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1912
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1913
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1914
+					$data['id_source'] = $id_source;
1915
+					$data['format_source'] = 'tsv';
1916
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1917
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1918 1918
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1919
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1920
-    				unset($lined);
1921
-    				unset($data);
1922
-    			    } else $error = true;
1919
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1920
+					unset($lined);
1921
+					unset($data);
1922
+					} else $error = true;
1923 1923
 			} elseif ($format === 'aprs' && $use_aprs) {
1924
-			    if ($aprs_connect === 0) {
1924
+				if ($aprs_connect === 0) {
1925 1925
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1926 1926
 				$aprs_connect = 1;
1927
-			    }
1927
+				}
1928 1928
 			    
1929
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1929
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1930 1930
 				$aprs_last_tx = time();
1931 1931
 				$data_aprs = "# Keep alive";
1932 1932
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1933
-			    }
1933
+				}
1934 1934
 			    
1935
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1936
-			    //echo 'APRS data : '.$buffer."\n";
1937
-			    $buffer = str_replace('APRS <- ','',$buffer);
1938
-			    $buffer = str_replace('APRS -> ','',$buffer);
1939
-			    //echo $buffer."\n";
1940
-			    date_default_timezone_set('UTC');
1941
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1935
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1936
+				//echo 'APRS data : '.$buffer."\n";
1937
+				$buffer = str_replace('APRS <- ','',$buffer);
1938
+				$buffer = str_replace('APRS -> ','',$buffer);
1939
+				//echo $buffer."\n";
1940
+				date_default_timezone_set('UTC');
1941
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1942 1942
 				$line = $APRS->parse($buffer);
1943 1943
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1944 1944
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1945
-				    $aprs_last_tx = time();
1946
-				    $data = array();
1947
-				    //print_r($line);
1948
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1949
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1950
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1951
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1952
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1953
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1954
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1955
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1956
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1957
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1958
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1959
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1960
-				    $data['latitude'] = $line['latitude'];
1961
-				    $data['longitude'] = $line['longitude'];
1962
-				    //$data['verticalrate'] = $line[16];
1963
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1964
-				    //else $data['speed'] = 0;
1965
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1966
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1967
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1968
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1945
+					$aprs_last_tx = time();
1946
+					$data = array();
1947
+					//print_r($line);
1948
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1949
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1950
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1951
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1952
+					if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1953
+					if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1954
+					if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1955
+					if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1956
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1957
+					else $data['datetime'] = date('Y-m-d H:i:s');
1958
+					//$data['datetime'] = date('Y-m-d H:i:s');
1959
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1960
+					$data['latitude'] = $line['latitude'];
1961
+					$data['longitude'] = $line['longitude'];
1962
+					//$data['verticalrate'] = $line[16];
1963
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1964
+					//else $data['speed'] = 0;
1965
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1966
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1967
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1968
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1969 1969
 				    
1970
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1971
-				    //else echo 'No heading...'."\n";
1972
-				    //else $data['heading'] = 0;
1973
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1974
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1975
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1976
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1977
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1978
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1979
-    				    $data['id_source'] = $id_source;
1980
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1981
-				    else $data['format_source'] = 'aprs';
1982
-				    $data['source_name'] = $line['source'];
1983
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1984
-				    else $data['source_type'] = 'flarm';
1985
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1986
-				    $currentdate = date('Y-m-d H:i:s');
1987
-				    $aprsdate = strtotime($data['datetime']);
1988
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1989
-				    // Accept data if time <= system time + 20s
1990
-				    //if (($data['source_type'] === 'modes') || isset($line['stealth']) && ($line['stealth'] === 0 || $line['stealth'] === '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1991
-				    if (
1970
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1971
+					//else echo 'No heading...'."\n";
1972
+					//else $data['heading'] = 0;
1973
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1974
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1975
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1976
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1977
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1978
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1979
+						$data['id_source'] = $id_source;
1980
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1981
+					else $data['format_source'] = 'aprs';
1982
+					$data['source_name'] = $line['source'];
1983
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1984
+					else $data['source_type'] = 'flarm';
1985
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1986
+					$currentdate = date('Y-m-d H:i:s');
1987
+					$aprsdate = strtotime($data['datetime']);
1988
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1989
+					// Accept data if time <= system time + 20s
1990
+					//if (($data['source_type'] === 'modes') || isset($line['stealth']) && ($line['stealth'] === 0 || $line['stealth'] === '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1991
+					if (
1992 1992
 					($data['source_type'] === 'modes') || 
1993 1993
 					isset($line['stealth']) && 
1994 1994
 					(!isset($data['hex']) || $data['hex'] != 'FFFFFF') && 
1995 1995
 					 ($line['stealth'] === 0 || $line['stealth'] == '') && 
1996 1996
 					 (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1997 1997
 					$send = $SI->add($data);
1998
-				    } elseif ($data['source_type'] === 'ais') {
1998
+					} elseif ($data['source_type'] === 'ais') {
1999 1999
 					$data['type'] = '';
2000 2000
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2001
-				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
2001
+					} elseif (isset($line['stealth']) && $line['stealth'] != 0) {
2002 2002
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2003
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2004
-					    //$line['symbol'] === 'Balloon' ||
2005
-					    $line['symbol'] === 'Glider' || 
2006
-					    $line['symbol'] === 'No. Plane' || 
2007
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
2008
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
2009
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2010
-					    $send = $SI->add($data);
2011
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2012
-					    $line['symbol'] === 'Yacht (Sail)' || 
2013
-					    $line['symbol'] === 'Ship (Power Boat)')) {
2014
-					    $send = $MI->add($data);
2015
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2016
-					    $line['symbol'] === 'Car' || 
2017
-					    $line['symbol'] === 'Ambulance' || 
2018
-					    $line['symbol'] === 'Van' || 
2019
-					    $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
2020
-					    $line['symbol'] === 'Motorcycle' || 
2021
-					    $line['symbol'] === 'Tractor' || 
2022
-					    $line['symbol'] === 'Police' || 
2023
-					    $line['symbol'] === 'Bike' || 
2024
-					    $line['symbol'] === 'Jogger' || 
2025
-					    $line['symbol'] === 'Horse' || 
2026
-					    $line['symbol'] === 'Bus' || 
2027
-					    $line['symbol'] === 'Jeep' || 
2028
-					    $line['symbol'] === 'Recreational Vehicle' || 
2029
-					    $line['symbol'] === 'Yacht (Sail)' || 
2030
-					    $line['symbol'] === 'Ship (Power Boat)' || 
2031
-					    $line['symbol'] === 'Firetruck' || 
2032
-					    $line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
2033
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
2034
-					    $line['symbol'] === 'SUV' ||
2035
-					    $line['symbol'] === 'Snowmobile' ||
2036
-					    $line['symbol'] === 'Mobile Satellite Station')) {
2037
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
2003
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2004
+						//$line['symbol'] === 'Balloon' ||
2005
+						$line['symbol'] === 'Glider' || 
2006
+						$line['symbol'] === 'No. Plane' || 
2007
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
2008
+						if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
2009
+						if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2010
+						$send = $SI->add($data);
2011
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2012
+						$line['symbol'] === 'Yacht (Sail)' || 
2013
+						$line['symbol'] === 'Ship (Power Boat)')) {
2014
+						$send = $MI->add($data);
2015
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2016
+						$line['symbol'] === 'Car' || 
2017
+						$line['symbol'] === 'Ambulance' || 
2018
+						$line['symbol'] === 'Van' || 
2019
+						$line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
2020
+						$line['symbol'] === 'Motorcycle' || 
2021
+						$line['symbol'] === 'Tractor' || 
2022
+						$line['symbol'] === 'Police' || 
2023
+						$line['symbol'] === 'Bike' || 
2024
+						$line['symbol'] === 'Jogger' || 
2025
+						$line['symbol'] === 'Horse' || 
2026
+						$line['symbol'] === 'Bus' || 
2027
+						$line['symbol'] === 'Jeep' || 
2028
+						$line['symbol'] === 'Recreational Vehicle' || 
2029
+						$line['symbol'] === 'Yacht (Sail)' || 
2030
+						$line['symbol'] === 'Ship (Power Boat)' || 
2031
+						$line['symbol'] === 'Firetruck' || 
2032
+						$line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
2033
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
2034
+						$line['symbol'] === 'SUV' ||
2035
+						$line['symbol'] === 'Snowmobile' ||
2036
+						$line['symbol'] === 'Mobile Satellite Station')) {
2037
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
2038 2038
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
2039 2039
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
2040 2040
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2041
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2041
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2042 2042
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
2043 2043
 					$Source->deleteOldLocationByType('gs');
2044 2044
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -2046,7 +2046,7 @@  discard block
 block discarded – undo
2046 2046
 					} else {
2047 2047
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2048 2048
 					}
2049
-				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2049
+					} elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2050 2050
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2051 2051
 					if ($globalDebug) echo '# Weather Station added'."\n";
2052 2052
 					$Source->deleteOldLocationByType('wx');
@@ -2056,7 +2056,7 @@  discard block
 block discarded – undo
2056 2056
 					} else {
2057 2057
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2058 2058
 					}
2059
-				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2059
+					} elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2060 2060
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2061 2061
 					if ($globalDebug) echo '☈ Lightning added'."\n";
2062 2062
 					$Source->deleteOldLocationByType('lightning');
@@ -2065,11 +2065,11 @@  discard block
 block discarded – undo
2065 2065
 					} else {
2066 2066
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2067 2067
 					}
2068
-				    } elseif ($globalDebug) {
2069
-				    	echo '/!\ Not added: '.$buffer."\n";
2070
-				    	print_r($line);
2071
-				    }
2072
-				    unset($data);
2068
+					} elseif ($globalDebug) {
2069
+						echo '/!\ Not added: '.$buffer."\n";
2070
+						print_r($line);
2071
+					}
2072
+					unset($data);
2073 2073
 				}
2074 2074
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2075 2075
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -2088,13 +2088,13 @@  discard block
 block discarded – undo
2088 2088
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
2089 2089
 					$globalSources[$nb]['last_weather_clean'] = time();
2090 2090
 				}
2091
-			    }
2091
+				}
2092 2092
 			} else {
2093
-			    $line = explode(',', $buffer);
2094
-			    //print_r($line);
2095
-    			    if (count($line) > 20) {
2096
-    			    	$data['hex'] = $line[4];
2097
-    				/*
2093
+				$line = explode(',', $buffer);
2094
+				//print_r($line);
2095
+					if (count($line) > 20) {
2096
+						$data['hex'] = $line[4];
2097
+					/*
2098 2098
     				$data['datetime'] = $line[6].' '.$line[7];
2099 2099
     					date_default_timezone_set($globalTimezone);
2100 2100
     					$datetime = new DateTime($data['datetime']);
@@ -2102,31 +2102,31 @@  discard block
 block discarded – undo
2102 2102
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
2103 2103
     					date_default_timezone_set('UTC');
2104 2104
     				*/
2105
-    				// Force datetime to current UTC datetime
2106
-    				date_default_timezone_set('UTC');
2107
-    				$data['datetime'] = date('Y-m-d H:i:s');
2108
-    				$data['ident'] = trim($line[10]);
2109
-    				$data['latitude'] = $line[14];
2110
-    				$data['longitude'] = $line[15];
2111
-    				$data['verticalrate'] = $line[16];
2112
-    				$data['emergency'] = $line[20];
2113
-    				$data['speed'] = $line[12];
2114
-    				$data['squawk'] = $line[17];
2115
-    				$data['altitude'] = $line[11];
2116
-    				$data['heading'] = $line[13];
2117
-    				$data['ground'] = $line[21];
2118
-    				$data['emergency'] = $line[19];
2119
-    				$data['format_source'] = 'sbs';
2105
+					// Force datetime to current UTC datetime
2106
+					date_default_timezone_set('UTC');
2107
+					$data['datetime'] = date('Y-m-d H:i:s');
2108
+					$data['ident'] = trim($line[10]);
2109
+					$data['latitude'] = $line[14];
2110
+					$data['longitude'] = $line[15];
2111
+					$data['verticalrate'] = $line[16];
2112
+					$data['emergency'] = $line[20];
2113
+					$data['speed'] = $line[12];
2114
+					$data['squawk'] = $line[17];
2115
+					$data['altitude'] = $line[11];
2116
+					$data['heading'] = $line[13];
2117
+					$data['ground'] = $line[21];
2118
+					$data['emergency'] = $line[19];
2119
+					$data['format_source'] = 'sbs';
2120 2120
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
2121 2121
 				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
2122 2122
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2123 2123
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2124
-    				$data['id_source'] = $id_source;
2125
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2126
-    				else $error = true;
2127
-    				unset($data);
2128
-    			    } else $error = true;
2129
-			    if ($error) {
2124
+					$data['id_source'] = $id_source;
2125
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2126
+					else $error = true;
2127
+					unset($data);
2128
+					} else $error = true;
2129
+				if ($error) {
2130 2130
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
2131 2131
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
2132 2132
 				} else {
@@ -2142,13 +2142,13 @@  discard block
 block discarded – undo
2142 2142
 					connect_all($sourceer);
2143 2143
 					$sourceer = array();
2144 2144
 				}
2145
-			    }
2145
+				}
2146 2146
 			}
2147 2147
 			// Sleep for xxx microseconds
2148 2148
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2149
-		    } else {
2149
+			} else {
2150 2150
 			if ($format === 'flightgearmp') {
2151
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2151
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
2152 2152
 				//@socket_close($r);
2153 2153
 				sleep($globalMinFetch);
2154 2154
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -2157,9 +2157,9 @@  discard block
 block discarded – undo
2157 2157
 				break;
2158 2158
 				
2159 2159
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
2160
-			    if (isset($tt[$format])) $tt[$format]++;
2161
-			    else $tt[$format] = 0;
2162
-			    if ($tt[$format] > 30 || $buffer === FALSE) {
2160
+				if (isset($tt[$format])) $tt[$format]++;
2161
+				else $tt[$format] = 0;
2162
+				if ($tt[$format] > 30 || $buffer === FALSE) {
2163 2163
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2164 2164
 				//@socket_close($r);
2165 2165
 				sleep(2);
@@ -2170,24 +2170,24 @@  discard block
 block discarded – undo
2170 2170
 				//connect_all($globalSources);
2171 2171
 				$tt[$format]=0;
2172 2172
 				break;
2173
-			    } 
2174
-			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
2173
+				} 
2174
+				//else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
2175
+			}
2175 2176
 			}
2176
-		    }
2177 2177
 		}
2178
-	    } else {
2178
+		} else {
2179 2179
 		$error = socket_strerror(socket_last_error());
2180 2180
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2181 2181
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2182 2182
 			if (isset($globalDebug)) echo "Restarting...\n";
2183 2183
 			// Restart the script if possible
2184 2184
 			if (is_array($sockets)) {
2185
-			    if ($globalDebug) echo "Shutdown all sockets...";
2185
+				if ($globalDebug) echo "Shutdown all sockets...";
2186 2186
 			    
2187
-			    foreach ($sockets as $sock) {
2187
+				foreach ($sockets as $sock) {
2188 2188
 				@socket_shutdown($sock,2);
2189 2189
 				@socket_close($sock);
2190
-			    }
2190
+				}
2191 2191
 			    
2192 2192
 			}
2193 2193
 			if ($globalDebug) echo "Waiting...";
@@ -2202,15 +2202,15 @@  discard block
 block discarded – undo
2202 2202
 			if ($globalDebug) echo "Restart all connections...";
2203 2203
 			connect_all($globalSources);
2204 2204
 		}
2205
-	    }
2205
+		}
2206 2206
 	}
2207 2207
 	if ($globalDaemon === false) {
2208
-	    if ($globalDebug) echo 'Check all...'."\n";
2209
-	    if (isset($SI)) $SI->checkAll();
2210
-	    if (isset($TI)) $TI->checkAll();
2211
-	    if (isset($MI)) $MI->checkAll();
2208
+		if ($globalDebug) echo 'Check all...'."\n";
2209
+		if (isset($SI)) $SI->checkAll();
2210
+		if (isset($TI)) $TI->checkAll();
2211
+		if (isset($MI)) $MI->checkAll();
2212
+	}
2212 2213
 	}
2213
-    }
2214 2214
 }
2215 2215
 
2216 2216
 ?>
Please login to merge, or discard this patch.