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