Completed
Push — master ( d388e5...86df70 )
by Yannick
06:31
created
scripts/daemon-spotter.php 1 patch
Indentation   +867 added lines, -867 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,42 +24,42 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
-    else $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
+	else $globalSources[] = array('host' => $options['s']);
59 59
 } elseif (isset($options['source'])) {
60
-    $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
-    else $globalSources[] = array('host' => $options['source']);
60
+	$globalSources = array();
61
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
+	else $globalSources[] = array('host' => $options['source']);
63 63
 }
64 64
 if (isset($options['aprsserverhost'])) {
65 65
 	$globalServerAPRS = TRUE;
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 if (isset($options['idsource'])) $id_source = $options['idsource'];
75 75
 else $id_source = 1;
76 76
 if (isset($globalServer) && $globalServer) {
77
-    if ($globalDebug) echo "Using Server Mode\n";
78
-    $SI=new SpotterServer();
77
+	if ($globalDebug) echo "Using Server Mode\n";
78
+	$SI=new SpotterServer();
79 79
 /*
80 80
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
81 81
     $SI = new adsb2aprs();
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 } else $SI=new SpotterImport($Connection->db);
85 85
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
86 86
 if (isset($globalMarine) && $globalMarine) {
87
-    $AIS = new AIS();
88
-    $MI = new MarineImport($Connection->db);
87
+	$AIS = new AIS();
88
+	$MI = new MarineImport($Connection->db);
89 89
 }
90 90
 //$APRS=new APRS($Connection->db);
91 91
 $SBS=new SBS();
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
 //$servertz = system('date +%Z');
96 96
 // signal handler - playing nice with sockets and dump1090
97 97
 if (function_exists('pcntl_fork')) {
98
-    pcntl_signal(SIGINT,  function() {
99
-        global $sockets;
100
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
101
-        die("Bye!\n");
102
-    });
103
-    pcntl_signal_dispatch();
98
+	pcntl_signal(SIGINT,  function() {
99
+		global $sockets;
100
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
101
+		die("Bye!\n");
102
+	});
103
+	pcntl_signal_dispatch();
104 104
 }
105 105
 
106 106
 // let's try and connect
@@ -110,153 +110,153 @@  discard block
 block discarded – undo
110 110
 $reset = 0;
111 111
 
112 112
 function connect_all($hosts) {
113
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
114
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
115
-    $reset++;
116
-    if ($globalDebug) echo 'Connect to all...'."\n";
117
-    foreach ($hosts as $id => $value) {
113
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
114
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
115
+	$reset++;
116
+	if ($globalDebug) echo 'Connect to all...'."\n";
117
+	foreach ($hosts as $id => $value) {
118 118
 	$host = $value['host'];
119 119
 	$globalSources[$id]['last_exec'] = 0;
120 120
 	// Here we check type of source(s)
121 121
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
122
-            if (preg_match('/deltadb.txt$/i',$host)) {
123
-        	//$formats[$id] = 'deltadbtxt';
124
-        	$globalSources[$id]['format'] = 'deltadbtxt';
125
-        	//$last_exec['deltadbtxt'] = 0;
126
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
127
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
128
-        	//$formats[$id] = 'vatsimtxt';
129
-        	$globalSources[$id]['format'] = 'vatsimtxt';
130
-        	//$last_exec['vatsimtxt'] = 0;
131
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
132
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
133
-        	//$formats[$id] = 'aircraftlistjson';
134
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
135
-        	//$last_exec['aircraftlistjson'] = 0;
136
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
137
-    	    } else if (preg_match('/opensky/i',$host)) {
138
-        	//$formats[$id] = 'aircraftlistjson';
139
-        	$globalSources[$id]['format'] = 'opensky';
140
-        	//$last_exec['aircraftlistjson'] = 0;
141
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
142
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143
-        	//$formats[$id] = 'radarvirtueljson';
144
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
145
-        	//$last_exec['radarvirtueljson'] = 0;
146
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
147
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149
-        	    exit(0);
150
-        	}
151
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
152
-        	//$formats[$id] = 'planeupdatefaa';
153
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
154
-        	//$last_exec['planeupdatefaa'] = 0;
155
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
156
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158
-        	    exit(0);
159
-        	}
160
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
161
-        	//$formats[$id] = 'phpvmacars';
162
-        	$globalSources[$id]['format'] = 'phpvmacars';
163
-        	//$last_exec['phpvmacars'] = 0;
164
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
165
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
166
-        	//$formats[$id] = 'phpvmacars';
167
-        	$globalSources[$id]['format'] = 'vam';
168
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
169
-            } else if (preg_match('/whazzup/i',$host)) {
170
-        	//$formats[$id] = 'whazzup';
171
-        	$globalSources[$id]['format'] = 'whazzup';
172
-        	//$last_exec['whazzup'] = 0;
173
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
174
-            } else if (preg_match('/recentpireps/i',$host)) {
175
-        	//$formats[$id] = 'pirepsjson';
176
-        	$globalSources[$id]['format'] = 'pirepsjson';
177
-        	//$last_exec['pirepsjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
179
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180
-        	//$formats[$id] = 'fr24json';
181
-        	$globalSources[$id]['format'] = 'fr24json';
182
-        	//$last_exec['fr24json'] = 0;
183
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
184
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186
-        	    exit(0);
187
-        	}
188
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
189
-        	//$formats[$id] = 'fr24json';
190
-        	$globalSources[$id]['format'] = 'myshiptracking';
191
-        	//$last_exec['fr24json'] = 0;
192
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
193
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
194
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
195
-        	    exit(0);
196
-        	}
197
-            //} else if (preg_match('/10001/',$host)) {
198
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
199
-        	//$formats[$id] = 'tsv';
200
-        	$globalSources[$id]['format'] = 'tsv';
201
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
202
-            }
203
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
204
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
205
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
206
-    		    if ($idf !== false) {
207
-    			$httpfeeds[$id] = $idf;
208
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
209
-    		    }
210
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
211
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
213
-	    $hostport = explode(':',$host);
214
-	    if (isset($hostport[1])) {
122
+			if (preg_match('/deltadb.txt$/i',$host)) {
123
+			//$formats[$id] = 'deltadbtxt';
124
+			$globalSources[$id]['format'] = 'deltadbtxt';
125
+			//$last_exec['deltadbtxt'] = 0;
126
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
127
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
128
+			//$formats[$id] = 'vatsimtxt';
129
+			$globalSources[$id]['format'] = 'vatsimtxt';
130
+			//$last_exec['vatsimtxt'] = 0;
131
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
132
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
133
+			//$formats[$id] = 'aircraftlistjson';
134
+			$globalSources[$id]['format'] = 'aircraftlistjson';
135
+			//$last_exec['aircraftlistjson'] = 0;
136
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
137
+			} else if (preg_match('/opensky/i',$host)) {
138
+			//$formats[$id] = 'aircraftlistjson';
139
+			$globalSources[$id]['format'] = 'opensky';
140
+			//$last_exec['aircraftlistjson'] = 0;
141
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
142
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143
+			//$formats[$id] = 'radarvirtueljson';
144
+			$globalSources[$id]['format'] = 'radarvirtueljson';
145
+			//$last_exec['radarvirtueljson'] = 0;
146
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
147
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149
+				exit(0);
150
+			}
151
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
152
+			//$formats[$id] = 'planeupdatefaa';
153
+			$globalSources[$id]['format'] = 'planeupdatefaa';
154
+			//$last_exec['planeupdatefaa'] = 0;
155
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
156
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158
+				exit(0);
159
+			}
160
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
161
+			//$formats[$id] = 'phpvmacars';
162
+			$globalSources[$id]['format'] = 'phpvmacars';
163
+			//$last_exec['phpvmacars'] = 0;
164
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
165
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
166
+			//$formats[$id] = 'phpvmacars';
167
+			$globalSources[$id]['format'] = 'vam';
168
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
169
+			} else if (preg_match('/whazzup/i',$host)) {
170
+			//$formats[$id] = 'whazzup';
171
+			$globalSources[$id]['format'] = 'whazzup';
172
+			//$last_exec['whazzup'] = 0;
173
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
174
+			} else if (preg_match('/recentpireps/i',$host)) {
175
+			//$formats[$id] = 'pirepsjson';
176
+			$globalSources[$id]['format'] = 'pirepsjson';
177
+			//$last_exec['pirepsjson'] = 0;
178
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
179
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180
+			//$formats[$id] = 'fr24json';
181
+			$globalSources[$id]['format'] = 'fr24json';
182
+			//$last_exec['fr24json'] = 0;
183
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
184
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186
+				exit(0);
187
+			}
188
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
189
+			//$formats[$id] = 'fr24json';
190
+			$globalSources[$id]['format'] = 'myshiptracking';
191
+			//$last_exec['fr24json'] = 0;
192
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
193
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
194
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
195
+				exit(0);
196
+			}
197
+			//} else if (preg_match('/10001/',$host)) {
198
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
199
+			//$formats[$id] = 'tsv';
200
+			$globalSources[$id]['format'] = 'tsv';
201
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
202
+			}
203
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
204
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
205
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
206
+				if ($idf !== false) {
207
+				$httpfeeds[$id] = $idf;
208
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
209
+				}
210
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
211
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
213
+		$hostport = explode(':',$host);
214
+		if (isset($hostport[1])) {
215 215
 		$port = $hostport[1];
216 216
 		$hostn = $hostport[0];
217
-	    } else {
217
+		} else {
218 218
 		$port = $globalSources[$id]['port'];
219 219
 		$hostn = $globalSources[$id]['host'];
220
-	    }
221
-	    $Common = new Common();
222
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
223
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
224
-    	    } else {
225
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
226
-	    }
227
-	    if ($s) {
228
-    	        $sockets[$id] = $s;
229
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
230
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220
+		}
221
+		$Common = new Common();
222
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
223
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
224
+			} else {
225
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
226
+		}
227
+		if ($s) {
228
+				$sockets[$id] = $s;
229
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
230
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
231 231
 			//$formats[$id] = 'aprs';
232 232
 			$globalSources[$id]['format'] = 'aprs';
233 233
 			//$aprs_connect = 0;
234 234
 			//$use_aprs = true;
235
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
235
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
236 236
 			$globalSources[$id]['format'] = 'vrstcp';
237
-    		    } elseif ($port == '10001') {
238
-        		//$formats[$id] = 'tsv';
239
-        		$globalSources[$id]['format'] = 'tsv';
240
-		    } elseif ($port == '30002') {
241
-        		//$formats[$id] = 'raw';
242
-        		$globalSources[$id]['format'] = 'raw';
243
-		    } elseif ($port == '5001') {
244
-        		//$formats[$id] = 'raw';
245
-        		$globalSources[$id]['format'] = 'flightgearmp';
246
-		    } elseif ($port == '30005') {
237
+				} elseif ($port == '10001') {
238
+				//$formats[$id] = 'tsv';
239
+				$globalSources[$id]['format'] = 'tsv';
240
+			} elseif ($port == '30002') {
241
+				//$formats[$id] = 'raw';
242
+				$globalSources[$id]['format'] = 'raw';
243
+			} elseif ($port == '5001') {
244
+				//$formats[$id] = 'raw';
245
+				$globalSources[$id]['format'] = 'flightgearmp';
246
+			} elseif ($port == '30005') {
247 247
 			// Not yet supported
248
-        		//$formats[$id] = 'beast';
249
-        		$globalSources[$id]['format'] = 'beast';
250
-		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
252
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
248
+				//$formats[$id] = 'beast';
249
+				$globalSources[$id]['format'] = 'beast';
250
+			//} else $formats[$id] = 'sbs';
251
+			} else $globalSources[$id]['format'] = 'sbs';
252
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 253
 		}
254 254
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
255
-            } else {
255
+			} else {
256 256
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
257
-    	    }
258
-        }
259
-    }
257
+			}
258
+		}
259
+	}
260 260
 }
261 261
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
262 262
 
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 //connect_all($globalSources);
280 280
 
281 281
 if (isset($globalProxy) && $globalProxy) {
282
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
282
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
283 283
 } else {
284
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
284
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
285 285
 }
286 286
 
287 287
 // APRS Configuration
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
 	die;
291 291
 }
292 292
 foreach ($globalSources as $key => $source) {
293
-    if (!isset($source['format'])) {
294
-        $globalSources[$key]['format'] = 'auto';
295
-    }
293
+	if (!isset($source['format'])) {
294
+		$globalSources[$key]['format'] = 'auto';
295
+	}
296 296
 }
297 297
 connect_all($globalSources);
298 298
 foreach ($globalSources as $key => $source) {
299
-    if (isset($source['format']) && $source['format'] == 'aprs') {
299
+	if (isset($source['format']) && $source['format'] == 'aprs') {
300 300
 	$aprs_connect = 0;
301 301
 	$use_aprs = true;
302 302
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
303 303
 	break;
304
-    }
304
+	}
305 305
 }
306 306
 
307 307
 if ($use_aprs) {
@@ -342,116 +342,116 @@  discard block
 block discarded – undo
342 342
 
343 343
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
344 344
 while ($i > 0) {
345
-    if (!$globalDaemon) $i = $endtime-time();
346
-    // Delete old ATC
347
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
345
+	if (!$globalDaemon) $i = $endtime-time();
346
+	// Delete old ATC
347
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
348 348
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
349
-        $ATC->deleteOldATC();
350
-    }
349
+		$ATC->deleteOldATC();
350
+	}
351 351
     
352
-    //if (count($last_exec) > 0) {
353
-    if (count($last_exec) == count($globalSources)) {
352
+	//if (count($last_exec) > 0) {
353
+	if (count($last_exec) == count($globalSources)) {
354 354
 	$max = $globalMinFetch;
355 355
 	foreach ($last_exec as $last) {
356
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
356
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
357 357
 	}
358 358
 	if ($max != $globalMinFetch) {
359
-	    if ($globalDebug) echo 'Sleeping...'."\n";
360
-	    sleep($globalMinFetch-$max+2);
359
+		if ($globalDebug) echo 'Sleeping...'."\n";
360
+		sleep($globalMinFetch-$max+2);
361
+	}
361 362
 	}
362
-    }
363 363
 
364 364
     
365
-    //foreach ($formats as $id => $value) {
366
-    foreach ($globalSources as $id => $value) {
365
+	//foreach ($formats as $id => $value) {
366
+	foreach ($globalSources as $id => $value) {
367 367
 	date_default_timezone_set('UTC');
368 368
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
369 369
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
370
-	    //$buffer = $Common->getData($hosts[$id]);
371
-	    $buffer = $Common->getData($value['host']);
372
-	    if ($buffer != '') $reset = 0;
373
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374
-	    $buffer = explode('\n',$buffer);
375
-	    foreach ($buffer as $line) {
376
-    		if ($line != '' && count($line) > 7) {
377
-    		    $line = explode(',', $line);
378
-	            $data = array();
379
-	            $data['hex'] = $line[1]; // hex
380
-	            $data['ident'] = $line[2]; // ident
381
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
382
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
383
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
384
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
385
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
386
-	            $data['verticalrate'] = ''; // vertical rate
387
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
388
-	            $data['emergency'] = ''; // emergency
389
-		    $data['datetime'] = date('Y-m-d H:i:s');
390
-		    $data['format_source'] = 'deltadbtxt';
391
-    		    $data['id_source'] = $id_source;
392
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
393
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
394
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
395
-    		    $SI->add($data);
396
-		    unset($data);
397
-    		}
398
-    	    }
399
-    	    $last_exec[$id]['last'] = time();
370
+		//$buffer = $Common->getData($hosts[$id]);
371
+		$buffer = $Common->getData($value['host']);
372
+		if ($buffer != '') $reset = 0;
373
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374
+		$buffer = explode('\n',$buffer);
375
+		foreach ($buffer as $line) {
376
+			if ($line != '' && count($line) > 7) {
377
+				$line = explode(',', $line);
378
+				$data = array();
379
+				$data['hex'] = $line[1]; // hex
380
+				$data['ident'] = $line[2]; // ident
381
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
382
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
383
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
384
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
385
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
386
+				$data['verticalrate'] = ''; // vertical rate
387
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
388
+				$data['emergency'] = ''; // emergency
389
+			$data['datetime'] = date('Y-m-d H:i:s');
390
+			$data['format_source'] = 'deltadbtxt';
391
+				$data['id_source'] = $id_source;
392
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
393
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
394
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
395
+				$SI->add($data);
396
+			unset($data);
397
+			}
398
+			}
399
+			$last_exec[$id]['last'] = time();
400 400
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
401
-	    date_default_timezone_set('CET');
402
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
403
-	    date_default_timezone_set('UTC');
404
-	    if ($buffer != '') $reset = 0;
405
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
406
-	    $buffer = explode('\n',$buffer);
407
-	    foreach ($buffer as $line) {
401
+		date_default_timezone_set('CET');
402
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
403
+		date_default_timezone_set('UTC');
404
+		if ($buffer != '') $reset = 0;
405
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
406
+		$buffer = explode('\n',$buffer);
407
+		foreach ($buffer as $line) {
408 408
 		if ($line != '') {
409
-		    echo "'".$line."'\n";
410
-		    $add = false;
411
-		    $ais_data = $AIS->parse_line(trim($line));
412
-		    $data = array();
413
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
414
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
415
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
416
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
417
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
418
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
419
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
420
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
421
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
422
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
423
-		    if (isset($ais_data['timestamp'])) {
409
+			echo "'".$line."'\n";
410
+			$add = false;
411
+			$ais_data = $AIS->parse_line(trim($line));
412
+			$data = array();
413
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
414
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
415
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
416
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
417
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
418
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
419
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
420
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
421
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
422
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
423
+			if (isset($ais_data['timestamp'])) {
424 424
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
425 425
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
426
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
427
-			    $add = true;
426
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
427
+				$add = true;
428 428
 			}
429
-		    } else {
429
+			} else {
430 430
 			$data['datetime'] = date('Y-m-d H:i:s');
431 431
 			$add = true;
432
-		    }
433
-		    $data['format_source'] = 'aisnmeatxt';
434
-    		    $data['id_source'] = $id_source;
435
-		    //print_r($data);
436
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
437
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
438
-		    unset($data);
432
+			}
433
+			$data['format_source'] = 'aisnmeatxt';
434
+				$data['id_source'] = $id_source;
435
+			//print_r($data);
436
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
437
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
438
+			unset($data);
439 439
 		}
440
-    	    }
441
-    	    $last_exec[$id]['last'] = time();
440
+			}
441
+			$last_exec[$id]['last'] = time();
442 442
 	} elseif ($value['format'] == 'aisnmeahttp') {
443
-	    $arr = $httpfeeds;
444
-	    $w = $e = null;
443
+		$arr = $httpfeeds;
444
+		$w = $e = null;
445 445
 	    
446
-	    if (isset($arr[$id])) {
446
+		if (isset($arr[$id])) {
447 447
 		$nn = stream_select($arr,$w,$e,$timeout);
448 448
 		if ($nn > 0) {
449
-		    foreach ($httpfeeds as $feed) {
449
+			foreach ($httpfeeds as $feed) {
450 450
 			$buffer = stream_get_line($feed,2000,"\n");
451 451
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
452 452
 			$buffer = explode('\n',$buffer);
453 453
 			foreach ($buffer as $line) {
454
-			    if ($line != '') {
454
+				if ($line != '') {
455 455
 				$ais_data = $AIS->parse_line(trim($line));
456 456
 				$data = array();
457 457
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -469,40 +469,40 @@  discard block
 block discarded – undo
469 469
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
470 470
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
471 471
 				if (isset($ais_data['timestamp'])) {
472
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
472
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
473 473
 				} else {
474
-				    $data['datetime'] = date('Y-m-d H:i:s');
474
+					$data['datetime'] = date('Y-m-d H:i:s');
475 475
 				}
476 476
 				$data['format_source'] = 'aisnmeahttp';
477 477
 				$data['id_source'] = $id_source;
478 478
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
479 479
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
480 480
 				unset($data);
481
-			    }
481
+				}
482
+			}
482 483
 			}
483
-		    }
484 484
 		} else {
485
-		    $format = $value['format'];
486
-		    if (isset($tt[$format])) $tt[$format]++;
487
-		    else $tt[$format] = 0;
488
-		    if ($tt[$format] > 30) {
485
+			$format = $value['format'];
486
+			if (isset($tt[$format])) $tt[$format]++;
487
+			else $tt[$format] = 0;
488
+			if ($tt[$format] > 30) {
489 489
 			if ($globalDebug) echo 'Reconnect...'."\n";
490 490
 			sleep(2);
491 491
 			$sourceeen[] = $value;
492 492
 			connect_all($sourceeen);
493 493
 			$sourceeen = array();
494
-		    }
494
+			}
495
+		}
495 496
 		}
496
-	    }
497 497
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
498
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
499
-	    if ($buffer != '') {
498
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
499
+		if ($buffer != '') {
500 500
 		//echo $buffer;
501 501
 		$all_data = json_decode($buffer,true);
502 502
 		//print_r($all_data);
503 503
 		if (isset($all_data[0]['DATA'])) {
504 504
 		foreach ($all_data[0]['DATA'] as $line) {
505
-		    if ($line != '') {
505
+			if ($line != '') {
506 506
 			$data = array();
507 507
 			$data['ident'] = $line['NAME'];
508 508
 			$data['mmsi'] = $line['MMSI'];
@@ -519,89 +519,89 @@  discard block
 block discarded – undo
519 519
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
520 520
 			$MI->add($data);
521 521
 			unset($data);
522
-		    }
522
+			}
523 523
 		}
524 524
 		}
525 525
 		
526
-	    }
527
-    	    $last_exec[$id]['last'] = time();
526
+		}
527
+			$last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
529
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
530
-	    if ($buffer != '') {
529
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
530
+		if ($buffer != '') {
531 531
 		$all_data = json_decode($buffer,true);
532 532
 		if (isset($all_data[0]['mmsi'])) {
533
-		    foreach ($all_data as $line) {
533
+			foreach ($all_data as $line) {
534 534
 			if ($line != '') {
535
-			    $data = array();
536
-			    $data['ident'] = $line['shipname'];
537
-			    $data['callsign'] = $line['callsign'];
538
-			    $data['mmsi'] = $line['mmsi'];
539
-			    $data['speed'] = $line['sog'];
540
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
541
-			    $data['latitude'] = $line['latitude'];
542
-			    $data['longitude'] = $line['longitude'];
543
-			    $data['type_id'] = $line['shiptype'];
544
-			    $data['arrival_code'] = $line['destination'];
545
-			    $data['datetime'] = $line['time'];
546
-			    $data['format_source'] = 'boatbeaconapp';
547
-			    $data['id_source'] = $id_source;
548
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
549
-			    $MI->add($data);
550
-			    unset($data);
535
+				$data = array();
536
+				$data['ident'] = $line['shipname'];
537
+				$data['callsign'] = $line['callsign'];
538
+				$data['mmsi'] = $line['mmsi'];
539
+				$data['speed'] = $line['sog'];
540
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
541
+				$data['latitude'] = $line['latitude'];
542
+				$data['longitude'] = $line['longitude'];
543
+				$data['type_id'] = $line['shiptype'];
544
+				$data['arrival_code'] = $line['destination'];
545
+				$data['datetime'] = $line['time'];
546
+				$data['format_source'] = 'boatbeaconapp';
547
+				$data['id_source'] = $id_source;
548
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
549
+				$MI->add($data);
550
+				unset($data);
551
+			}
551 552
 			}
552
-		    }
553 553
 		}
554 554
 		
555
-	    }
556
-    	    $last_exec[$id]['last'] = time();
555
+		}
556
+			$last_exec[$id]['last'] = time();
557 557
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
558
-	    echo 'download...';
559
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
560
-	    echo 'done !'."\n";
561
-	    if ($buffer != '') $reset = 0;
562
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
563
-	    $buffer = explode('\n',$buffer);
564
-	    foreach ($buffer as $line) {
558
+		echo 'download...';
559
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
560
+		echo 'done !'."\n";
561
+		if ($buffer != '') $reset = 0;
562
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
563
+		$buffer = explode('\n',$buffer);
564
+		foreach ($buffer as $line) {
565 565
 		if ($line != '') {
566
-		    $data = array();
567
-		    $data['mmsi'] = (int)substr($line,0,9);
568
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
569
-		    //$data['status'] = substr($line,21,2);
570
-		    //$data['type'] = substr($line,24,3);
571
-		    $data['latitude'] = substr($line,29,9);
572
-		    $data['longitude'] = substr($line,41,9);
573
-		    $data['speed'] = round(substr($line,51,5));
574
-		    //$data['course'] = substr($line,57,5);
575
-		    $data['heading'] = round(substr($line,63,3));
576
-		    //$data['draft'] = substr($line,67,4);
577
-		    //$data['length'] = substr($line,72,3);
578
-		    //$data['beam'] = substr($line,76,2);
579
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
580
-		    //$data['callsign'] = trim(substr($line,100,7);
581
-		    //$data['dest'] = substr($line,108,20);
582
-		    //$data['etaDate'] = substr($line,129,5);
583
-		    //$data['etaTime'] = substr($line,135,5);
584
-		    $data['format_source'] = 'shipplotter';
585
-    		    $data['id_source'] = $id_source;
586
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
587
-		    //print_r($data);
588
-		    echo 'Add...'."\n";
589
-		    $MI->add($data);
590
-		    unset($data);
566
+			$data = array();
567
+			$data['mmsi'] = (int)substr($line,0,9);
568
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
569
+			//$data['status'] = substr($line,21,2);
570
+			//$data['type'] = substr($line,24,3);
571
+			$data['latitude'] = substr($line,29,9);
572
+			$data['longitude'] = substr($line,41,9);
573
+			$data['speed'] = round(substr($line,51,5));
574
+			//$data['course'] = substr($line,57,5);
575
+			$data['heading'] = round(substr($line,63,3));
576
+			//$data['draft'] = substr($line,67,4);
577
+			//$data['length'] = substr($line,72,3);
578
+			//$data['beam'] = substr($line,76,2);
579
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
580
+			//$data['callsign'] = trim(substr($line,100,7);
581
+			//$data['dest'] = substr($line,108,20);
582
+			//$data['etaDate'] = substr($line,129,5);
583
+			//$data['etaTime'] = substr($line,135,5);
584
+			$data['format_source'] = 'shipplotter';
585
+				$data['id_source'] = $id_source;
586
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
587
+			//print_r($data);
588
+			echo 'Add...'."\n";
589
+			$MI->add($data);
590
+			unset($data);
591 591
 		}
592
-    	    }
593
-    	    $last_exec[$id]['last'] = time();
592
+			}
593
+			$last_exec[$id]['last'] = time();
594 594
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
595 595
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
596
-	    //$buffer = $Common->getData($hosts[$id]);
597
-	    $buffer = $Common->getData($value['host']);
598
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
599
-	    $buffer = explode('\n',$buffer);
600
-	    $reset = 0;
601
-	    foreach ($buffer as $line) {
602
-    		if ($line != '') {
603
-    		    $line = explode(':', $line);
604
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
596
+		//$buffer = $Common->getData($hosts[$id]);
597
+		$buffer = $Common->getData($value['host']);
598
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
599
+		$buffer = explode('\n',$buffer);
600
+		$reset = 0;
601
+		foreach ($buffer as $line) {
602
+			if ($line != '') {
603
+				$line = explode(':', $line);
604
+				if (count($line) > 30 && $line[0] != 'callsign') {
605 605
 			$data = array();
606 606
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
607 607
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -614,37 +614,37 @@  discard block
 block discarded – undo
614 614
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
615 615
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
616 616
 			$data['latitude'] = $line[5]; // lat
617
-	        	$data['longitude'] = $line[6]; // long
618
-	        	$data['verticalrate'] = ''; // vertical rate
619
-	        	$data['squawk'] = ''; // squawk
620
-	        	$data['emergency'] = ''; // emergency
621
-	        	$data['waypoints'] = $line[30];
617
+				$data['longitude'] = $line[6]; // long
618
+				$data['verticalrate'] = ''; // vertical rate
619
+				$data['squawk'] = ''; // squawk
620
+				$data['emergency'] = ''; // emergency
621
+				$data['waypoints'] = $line[30];
622 622
 			$data['datetime'] = date('Y-m-d H:i:s');
623 623
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
624 624
 			//if (isset($line[37])) $data['last_update'] = $line[37];
625
-		        $data['departure_airport_icao'] = $line[11];
626
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
627
-		        $data['arrival_airport_icao'] = $line[13];
625
+				$data['departure_airport_icao'] = $line[11];
626
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
627
+				$data['arrival_airport_icao'] = $line[13];
628 628
 			$data['frequency'] = $line[4];
629 629
 			$data['type'] = $line[18];
630 630
 			$data['range'] = $line[19];
631 631
 			if (isset($line[35])) $data['info'] = $line[35];
632
-    			$data['id_source'] = $id_source;
633
-	    		//$data['arrival_airport_time'] = ;
634
-	    		if ($line[9] != '') {
635
-	    		    $aircraft_data = explode('/',$line[9]);
636
-	    		    if (isset($aircraft_data[1])) {
637
-	    			$data['aircraft_icao'] = $aircraft_data[1];
638
-	    		    }
639
-        		}
640
-	    		/*
632
+				$data['id_source'] = $id_source;
633
+				//$data['arrival_airport_time'] = ;
634
+				if ($line[9] != '') {
635
+					$aircraft_data = explode('/',$line[9]);
636
+					if (isset($aircraft_data[1])) {
637
+					$data['aircraft_icao'] = $aircraft_data[1];
638
+					}
639
+				}
640
+				/*
641 641
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
642 642
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
643 643
 	    		*/
644
-	    		$data['format_source'] = $value['format'];
644
+				$data['format_source'] = $value['format'];
645 645
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
646 646
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
647
-    			if ($line[3] == 'PILOT') $SI->add($data);
647
+				if ($line[3] == 'PILOT') $SI->add($data);
648 648
 			elseif ($line[3] == 'ATC') {
649 649
 				//print_r($data);
650 650
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -662,255 +662,255 @@  discard block
 block discarded – undo
662 662
 				if (!isset($data['source_name'])) $data['source_name'] = '';
663 663
 				if (isset($ATC)) 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']);
664 664
 			}
665
-    			unset($data);
666
-    		    }
667
-    		}
668
-    	    }
669
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
670
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
671
-    	    $last_exec[$id]['last'] = time();
672
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
673
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
674
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
675
-	    if ($buffer != '') {
676
-	    $all_data = json_decode($buffer,true);
677
-	    if (isset($all_data['acList'])) {
665
+				unset($data);
666
+				}
667
+			}
668
+			}
669
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
670
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
671
+			$last_exec[$id]['last'] = time();
672
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
673
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
674
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
675
+		if ($buffer != '') {
676
+		$all_data = json_decode($buffer,true);
677
+		if (isset($all_data['acList'])) {
678 678
 		$reset = 0;
679 679
 		foreach ($all_data['acList'] as $line) {
680
-		    $data = array();
681
-		    $data['hex'] = $line['Icao']; // hex
682
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
683
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
684
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
685
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
686
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
687
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
688
-		    //$data['verticalrate'] = $line['']; // verticale rate
689
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
690
-		    $data['emergency'] = ''; // emergency
691
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
680
+			$data = array();
681
+			$data['hex'] = $line['Icao']; // hex
682
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
683
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
684
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
685
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
686
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
687
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
688
+			//$data['verticalrate'] = $line['']; // verticale rate
689
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
690
+			$data['emergency'] = ''; // emergency
691
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
692 692
 		    
693
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
694
-		    else $data['datetime'] = date('Y-m-d H:i:s');
693
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
694
+			else $data['datetime'] = date('Y-m-d H:i:s');
695 695
 		    
696
-		    //$data['datetime'] = date('Y-m-d H:i:s');
697
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
698
-	    	    $data['format_source'] = 'aircraftlistjson';
699
-		    $data['id_source'] = $id_source;
700
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
701
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
-		    if (isset($data['latitude'])) $SI->add($data);
703
-		    unset($data);
696
+			//$data['datetime'] = date('Y-m-d H:i:s');
697
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
698
+				$data['format_source'] = 'aircraftlistjson';
699
+			$data['id_source'] = $id_source;
700
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
701
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
+			if (isset($data['latitude'])) $SI->add($data);
703
+			unset($data);
704 704
 		}
705
-	    } elseif (is_array($all_data)) {
705
+		} elseif (is_array($all_data)) {
706 706
 		$reset = 0;
707 707
 		foreach ($all_data as $line) {
708
-		    $data = array();
709
-		    $data['hex'] = $line['hex']; // hex
710
-		    $data['ident'] = $line['flight']; // ident
711
-		    $data['altitude'] = $line['altitude']; // altitude
712
-		    $data['speed'] = $line['speed']; // speed
713
-		    $data['heading'] = $line['track']; // heading
714
-		    $data['latitude'] = $line['lat']; // lat
715
-		    $data['longitude'] = $line['lon']; // long
716
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
717
-		    $data['squawk'] = $line['squawk']; // squawk
718
-		    $data['emergency'] = ''; // emergency
719
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
720
-		    else $data['datetime'] = date('Y-m-d H:i:s');
721
-	    	    $data['format_source'] = 'aircraftlistjson';
722
-    		    $data['id_source'] = $id_source;
723
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
724
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
725
-		    $SI->add($data);
726
-		    unset($data);
708
+			$data = array();
709
+			$data['hex'] = $line['hex']; // hex
710
+			$data['ident'] = $line['flight']; // ident
711
+			$data['altitude'] = $line['altitude']; // altitude
712
+			$data['speed'] = $line['speed']; // speed
713
+			$data['heading'] = $line['track']; // heading
714
+			$data['latitude'] = $line['lat']; // lat
715
+			$data['longitude'] = $line['lon']; // long
716
+			$data['verticalrate'] = $line['vrt']; // verticale rate
717
+			$data['squawk'] = $line['squawk']; // squawk
718
+			$data['emergency'] = ''; // emergency
719
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
720
+			else $data['datetime'] = date('Y-m-d H:i:s');
721
+				$data['format_source'] = 'aircraftlistjson';
722
+				$data['id_source'] = $id_source;
723
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
724
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
725
+			$SI->add($data);
726
+			unset($data);
727
+		}
727 728
 		}
728
-	    }
729
-	    }
730
-    	    //$last_exec['aircraftlistjson'] = time();
731
-    	    $last_exec[$id]['last'] = time();
732
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
733
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734
-	    $buffer = $Common->getData($value['host']);
735
-	    $all_data = json_decode($buffer,true);
736
-	    if (isset($all_data['planes'])) {
729
+		}
730
+			//$last_exec['aircraftlistjson'] = time();
731
+			$last_exec[$id]['last'] = time();
732
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
733
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734
+		$buffer = $Common->getData($value['host']);
735
+		$all_data = json_decode($buffer,true);
736
+		if (isset($all_data['planes'])) {
737 737
 		$reset = 0;
738 738
 		foreach ($all_data['planes'] as $key => $line) {
739
-		    $data = array();
740
-		    $data['hex'] = $key; // hex
741
-		    $data['ident'] = $line[3]; // ident
742
-		    $data['altitude'] = $line[6]; // altitude
743
-		    $data['speed'] = $line[8]; // speed
744
-		    $data['heading'] = $line[7]; // heading
745
-		    $data['latitude'] = $line[4]; // lat
746
-		    $data['longitude'] = $line[5]; // long
747
-		    //$data['verticalrate'] = $line[]; // verticale rate
748
-		    $data['squawk'] = $line[10]; // squawk
749
-		    $data['emergency'] = ''; // emergency
750
-		    $data['registration'] = $line[2];
751
-		    $data['aircraft_icao'] = $line[0];
752
-		    $deparr = explode('-',$line[1]);
753
-		    if (count($deparr) == 2) {
739
+			$data = array();
740
+			$data['hex'] = $key; // hex
741
+			$data['ident'] = $line[3]; // ident
742
+			$data['altitude'] = $line[6]; // altitude
743
+			$data['speed'] = $line[8]; // speed
744
+			$data['heading'] = $line[7]; // heading
745
+			$data['latitude'] = $line[4]; // lat
746
+			$data['longitude'] = $line[5]; // long
747
+			//$data['verticalrate'] = $line[]; // verticale rate
748
+			$data['squawk'] = $line[10]; // squawk
749
+			$data['emergency'] = ''; // emergency
750
+			$data['registration'] = $line[2];
751
+			$data['aircraft_icao'] = $line[0];
752
+			$deparr = explode('-',$line[1]);
753
+			if (count($deparr) == 2) {
754 754
 			$data['departure_airport_icao'] = $deparr[0];
755 755
 			$data['arrival_airport_icao'] = $deparr[1];
756
-		    }
757
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
758
-	    	    $data['format_source'] = 'planeupdatefaa';
759
-    		    $data['id_source'] = $id_source;
760
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
761
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
762
-		    $SI->add($data);
763
-		    unset($data);
756
+			}
757
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
758
+				$data['format_source'] = 'planeupdatefaa';
759
+				$data['id_source'] = $id_source;
760
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
761
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
762
+			$SI->add($data);
763
+			unset($data);
764
+		}
764 765
 		}
765
-	    }
766
-    	    //$last_exec['planeupdatefaa'] = time();
767
-    	    $last_exec[$id]['last'] = time();
768
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
769
-	    $buffer = $Common->getData($value['host']);
770
-	    $all_data = json_decode($buffer,true);
771
-	    if (isset($all_data['states'])) {
766
+			//$last_exec['planeupdatefaa'] = time();
767
+			$last_exec[$id]['last'] = time();
768
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
769
+		$buffer = $Common->getData($value['host']);
770
+		$all_data = json_decode($buffer,true);
771
+		if (isset($all_data['states'])) {
772 772
 		$reset = 0;
773 773
 		foreach ($all_data['states'] as $key => $line) {
774
-		    $data = array();
775
-		    $data['hex'] = $line[0]; // hex
776
-		    $data['ident'] = trim($line[1]); // ident
777
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
778
-		    $data['speed'] = round($line[9]*1.94384); // speed
779
-		    $data['heading'] = round($line[10]); // heading
780
-		    $data['latitude'] = $line[5]; // lat
781
-		    $data['longitude'] = $line[6]; // long
782
-		    $data['verticalrate'] = $line[11]; // verticale rate
783
-		    //$data['squawk'] = $line[10]; // squawk
784
-		    //$data['emergency'] = ''; // emergency
785
-		    //$data['registration'] = $line[2];
786
-		    //$data['aircraft_icao'] = $line[0];
787
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
788
-	    	    $data['format_source'] = 'opensky';
789
-    		    $data['id_source'] = $id_source;
790
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
791
-		    $SI->add($data);
792
-		    unset($data);
774
+			$data = array();
775
+			$data['hex'] = $line[0]; // hex
776
+			$data['ident'] = trim($line[1]); // ident
777
+			$data['altitude'] = round($line[7]*3.28084); // altitude
778
+			$data['speed'] = round($line[9]*1.94384); // speed
779
+			$data['heading'] = round($line[10]); // heading
780
+			$data['latitude'] = $line[5]; // lat
781
+			$data['longitude'] = $line[6]; // long
782
+			$data['verticalrate'] = $line[11]; // verticale rate
783
+			//$data['squawk'] = $line[10]; // squawk
784
+			//$data['emergency'] = ''; // emergency
785
+			//$data['registration'] = $line[2];
786
+			//$data['aircraft_icao'] = $line[0];
787
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
788
+				$data['format_source'] = 'opensky';
789
+				$data['id_source'] = $id_source;
790
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
791
+			$SI->add($data);
792
+			unset($data);
793
+		}
793 794
 		}
794
-	    }
795
-    	    //$last_exec['planeupdatefaa'] = time();
796
-    	    $last_exec[$id]['last'] = time();
797
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
798
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
-	    //$buffer = $Common->getData($hosts[$id]);
800
-	    $buffer = $Common->getData($value['host']);
801
-	    $all_data = json_decode($buffer,true);
802
-	    if (!empty($all_data)) $reset = 0;
803
-	    foreach ($all_data as $key => $line) {
795
+			//$last_exec['planeupdatefaa'] = time();
796
+			$last_exec[$id]['last'] = time();
797
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
798
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
+		//$buffer = $Common->getData($hosts[$id]);
800
+		$buffer = $Common->getData($value['host']);
801
+		$all_data = json_decode($buffer,true);
802
+		if (!empty($all_data)) $reset = 0;
803
+		foreach ($all_data as $key => $line) {
804 804
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
805
-		    $data = array();
806
-		    $data['hex'] = $line[0];
807
-		    $data['ident'] = $line[16]; //$line[13]
808
-	    	    $data['altitude'] = $line[4]; // altitude
809
-	    	    $data['speed'] = $line[5]; // speed
810
-	    	    $data['heading'] = $line[3]; // heading
811
-	    	    $data['latitude'] = $line[1]; // lat
812
-	    	    $data['longitude'] = $line[2]; // long
813
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
814
-	    	    $data['squawk'] = $line[6]; // squawk
815
-	    	    $data['aircraft_icao'] = $line[8];
816
-	    	    $data['registration'] = $line[9];
817
-		    $data['departure_airport_iata'] = $line[11];
818
-		    $data['arrival_airport_iata'] = $line[12];
819
-	    	    $data['emergency'] = ''; // emergency
820
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
821
-	    	    $data['format_source'] = 'fr24json';
822
-    		    $data['id_source'] = $id_source;
823
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
824
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
825
-		    $SI->add($data);
826
-		    unset($data);
805
+			$data = array();
806
+			$data['hex'] = $line[0];
807
+			$data['ident'] = $line[16]; //$line[13]
808
+				$data['altitude'] = $line[4]; // altitude
809
+				$data['speed'] = $line[5]; // speed
810
+				$data['heading'] = $line[3]; // heading
811
+				$data['latitude'] = $line[1]; // lat
812
+				$data['longitude'] = $line[2]; // long
813
+				$data['verticalrate'] = $line[15]; // verticale rate
814
+				$data['squawk'] = $line[6]; // squawk
815
+				$data['aircraft_icao'] = $line[8];
816
+				$data['registration'] = $line[9];
817
+			$data['departure_airport_iata'] = $line[11];
818
+			$data['arrival_airport_iata'] = $line[12];
819
+				$data['emergency'] = ''; // emergency
820
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
821
+				$data['format_source'] = 'fr24json';
822
+				$data['id_source'] = $id_source;
823
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
824
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
825
+			$SI->add($data);
826
+			unset($data);
827
+		}
827 828
 		}
828
-	    }
829
-    	    //$last_exec['fr24json'] = time();
830
-    	    $last_exec[$id]['last'] = time();
831
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
832
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
833
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
834
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
835
-	    //echo $buffer;
836
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
837
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
838
-	    $all_data = json_decode($buffer,true);
839
-	    if (json_last_error() != JSON_ERROR_NONE) {
829
+			//$last_exec['fr24json'] = time();
830
+			$last_exec[$id]['last'] = time();
831
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
832
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
833
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
834
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
835
+		//echo $buffer;
836
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
837
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
838
+		$all_data = json_decode($buffer,true);
839
+		if (json_last_error() != JSON_ERROR_NONE) {
840 840
 		die(json_last_error_msg());
841
-	    }
842
-	    if (isset($all_data['mrkrs'])) {
841
+		}
842
+		if (isset($all_data['mrkrs'])) {
843 843
 		$reset = 0;
844 844
 		foreach ($all_data['mrkrs'] as $key => $line) {
845
-		    if (isset($line['inf'])) {
845
+			if (isset($line['inf'])) {
846 846
 			$data = array();
847 847
 			$data['hex'] = $line['inf']['ia'];
848 848
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
849
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
850
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
851
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
852
-	    		$data['latitude'] = $line['pt'][0]; // lat
853
-	    		$data['longitude'] = $line['pt'][1]; // long
854
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
855
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
856
-	    		//$data['aircraft_icao'] = $line[8];
857
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
849
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
850
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
851
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
852
+				$data['latitude'] = $line['pt'][0]; // lat
853
+				$data['longitude'] = $line['pt'][1]; // long
854
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
855
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
856
+				//$data['aircraft_icao'] = $line[8];
857
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
858 858
 			//$data['departure_airport_iata'] = $line[11];
859 859
 			//$data['arrival_airport_iata'] = $line[12];
860
-	    		//$data['emergency'] = ''; // emergency
860
+				//$data['emergency'] = ''; // emergency
861 861
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
862
-	    		$data['format_source'] = 'radarvirtueljson';
863
-    			$data['id_source'] = $id_source;
862
+				$data['format_source'] = 'radarvirtueljson';
863
+				$data['id_source'] = $id_source;
864 864
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
865 865
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
866 866
 			$SI->add($data);
867 867
 			unset($data);
868
-		    }
868
+			}
869
+		}
869 870
 		}
870
-	    }
871
-    	    //$last_exec['radarvirtueljson'] = time();
872
-    	    $last_exec[$id]['last'] = time();
873
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
874
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
875
-	    //$buffer = $Common->getData($hosts[$id]);
876
-	    $buffer = $Common->getData($value['host'].'?'.time());
877
-	    $all_data = json_decode(utf8_encode($buffer),true);
871
+			//$last_exec['radarvirtueljson'] = time();
872
+			$last_exec[$id]['last'] = time();
873
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
874
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
875
+		//$buffer = $Common->getData($hosts[$id]);
876
+		$buffer = $Common->getData($value['host'].'?'.time());
877
+		$all_data = json_decode(utf8_encode($buffer),true);
878 878
 	    
879
-	    if (isset($all_data['pireps'])) {
879
+		if (isset($all_data['pireps'])) {
880 880
 		$reset = 0;
881
-	        foreach ($all_data['pireps'] as $line) {
882
-		    $data = array();
883
-		    $data['id'] = $line['id'];
884
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
885
-		    $data['ident'] = $line['callsign']; // ident
886
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
887
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
888
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
889
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
890
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
891
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
892
-		    $data['latitude'] = $line['lat']; // lat
893
-		    $data['longitude'] = $line['lon']; // long
894
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
895
-		    //$data['squawk'] = $line['squawk']; // squawk
896
-		    //$data['emergency'] = ''; // emergency
897
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
898
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
899
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
900
-		    //$data['arrival_airport_time'] = $line['arrtime'];
901
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
902
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
903
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
904
-		    else $data['info'] = '';
905
-		    $data['format_source'] = 'pireps';
906
-    		    $data['id_source'] = $id_source;
907
-		    $data['datetime'] = date('Y-m-d H:i:s');
908
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
909
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
910
-		    if ($line['icon'] == 'plane') {
881
+			foreach ($all_data['pireps'] as $line) {
882
+			$data = array();
883
+			$data['id'] = $line['id'];
884
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
885
+			$data['ident'] = $line['callsign']; // ident
886
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
887
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
888
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
889
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
890
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
891
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
892
+			$data['latitude'] = $line['lat']; // lat
893
+			$data['longitude'] = $line['lon']; // long
894
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
895
+			//$data['squawk'] = $line['squawk']; // squawk
896
+			//$data['emergency'] = ''; // emergency
897
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
898
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
899
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
900
+			//$data['arrival_airport_time'] = $line['arrtime'];
901
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
902
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
903
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
904
+			else $data['info'] = '';
905
+			$data['format_source'] = 'pireps';
906
+				$data['id_source'] = $id_source;
907
+			$data['datetime'] = date('Y-m-d H:i:s');
908
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
909
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
910
+			if ($line['icon'] == 'plane') {
911 911
 			$SI->add($data);
912
-		    //    print_r($data);
913
-    		    } elseif ($line['icon'] == 'ct') {
912
+			//    print_r($data);
913
+				} elseif ($line['icon'] == 'ct') {
914 914
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
915 915
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
916 916
 			$typec = substr($data['ident'],-3);
@@ -925,197 +925,197 @@  discard block
 block discarded – undo
925 925
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
926 926
 			else $data['type'] = 'Observer';
927 927
 			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']);
928
-		    }
929
-		    unset($data);
928
+			}
929
+			unset($data);
930 930
 		}
931
-	    }
932
-    	    //$last_exec['pirepsjson'] = time();
933
-    	    $last_exec[$id]['last'] = time();
934
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
935
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
936
-	    //$buffer = $Common->getData($hosts[$id]);
937
-	    if ($globalDebug) echo 'Get Data...'."\n";
938
-	    $buffer = $Common->getData($value['host']);
939
-	    $all_data = json_decode($buffer,true);
940
-	    if ($buffer != '' && is_array($all_data)) {
931
+		}
932
+			//$last_exec['pirepsjson'] = time();
933
+			$last_exec[$id]['last'] = time();
934
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
935
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
936
+		//$buffer = $Common->getData($hosts[$id]);
937
+		if ($globalDebug) echo 'Get Data...'."\n";
938
+		$buffer = $Common->getData($value['host']);
939
+		$all_data = json_decode($buffer,true);
940
+		if ($buffer != '' && is_array($all_data)) {
941 941
 		$reset = 0;
942 942
 		foreach ($all_data as $line) {
943
-	    	    $data = array();
944
-	    	    //$data['id'] = $line['id']; // id not usable
945
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
946
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
947
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
948
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
949
-	    	    $data['ident'] = $line['flightnum']; // ident
950
-	    	    $data['altitude'] = $line['alt']; // altitude
951
-	    	    $data['speed'] = $line['gs']; // speed
952
-	    	    $data['heading'] = $line['heading']; // heading
953
-	    	    $data['latitude'] = $line['lat']; // lat
954
-	    	    $data['longitude'] = $line['lng']; // long
955
-	    	    $data['verticalrate'] = ''; // verticale rate
956
-	    	    $data['squawk'] = ''; // squawk
957
-	    	    $data['emergency'] = ''; // emergency
958
-	    	    //$data['datetime'] = $line['lastupdate'];
959
-	    	    $data['last_update'] = $line['lastupdate'];
960
-		    $data['datetime'] = date('Y-m-d H:i:s');
961
-	    	    $data['departure_airport_icao'] = $line['depicao'];
962
-	    	    $data['departure_airport_time'] = $line['deptime'];
963
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
964
-    		    $data['arrival_airport_time'] = $line['arrtime'];
965
-    		    $data['registration'] = $line['aircraft'];
966
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
967
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
968
-		    if (isset($line['aircraftname'])) {
943
+				$data = array();
944
+				//$data['id'] = $line['id']; // id not usable
945
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
946
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
947
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
948
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
949
+				$data['ident'] = $line['flightnum']; // ident
950
+				$data['altitude'] = $line['alt']; // altitude
951
+				$data['speed'] = $line['gs']; // speed
952
+				$data['heading'] = $line['heading']; // heading
953
+				$data['latitude'] = $line['lat']; // lat
954
+				$data['longitude'] = $line['lng']; // long
955
+				$data['verticalrate'] = ''; // verticale rate
956
+				$data['squawk'] = ''; // squawk
957
+				$data['emergency'] = ''; // emergency
958
+				//$data['datetime'] = $line['lastupdate'];
959
+				$data['last_update'] = $line['lastupdate'];
960
+			$data['datetime'] = date('Y-m-d H:i:s');
961
+				$data['departure_airport_icao'] = $line['depicao'];
962
+				$data['departure_airport_time'] = $line['deptime'];
963
+				$data['arrival_airport_icao'] = $line['arricao'];
964
+				$data['arrival_airport_time'] = $line['arrtime'];
965
+				$data['registration'] = $line['aircraft'];
966
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
967
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
968
+			if (isset($line['aircraftname'])) {
969 969
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
970 970
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
971
-	    		$aircraft_data = explode('-',$line['aircraftname']);
972
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
973
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
974
-	    		else {
975
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
976
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
977
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
978
-	    		}
979
-	    	    }
980
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
981
-    		    $data['id_source'] = $id_source;
982
-	    	    $data['format_source'] = 'phpvmacars';
983
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
984
-		    $SI->add($data);
985
-		    unset($data);
971
+				$aircraft_data = explode('-',$line['aircraftname']);
972
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
973
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
974
+				else {
975
+					$aircraft_data = explode(' ',$line['aircraftname']);
976
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
977
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
978
+				}
979
+				}
980
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
981
+				$data['id_source'] = $id_source;
982
+				$data['format_source'] = 'phpvmacars';
983
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
984
+			$SI->add($data);
985
+			unset($data);
986 986
 		}
987 987
 		if ($globalDebug) echo 'No more data...'."\n";
988 988
 		unset($buffer);
989 989
 		unset($all_data);
990
-	    }
991
-    	    //$last_exec['phpvmacars'] = time();
992
-    	    $last_exec[$id]['last'] = time();
993
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
994
-	    //$buffer = $Common->getData($hosts[$id]);
995
-	    if ($globalDebug) echo 'Get Data...'."\n";
996
-	    $buffer = $Common->getData($value['host']);
997
-	    $all_data = json_decode($buffer,true);
998
-	    if ($buffer != '' && is_array($all_data)) {
990
+		}
991
+			//$last_exec['phpvmacars'] = time();
992
+			$last_exec[$id]['last'] = time();
993
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
994
+		//$buffer = $Common->getData($hosts[$id]);
995
+		if ($globalDebug) echo 'Get Data...'."\n";
996
+		$buffer = $Common->getData($value['host']);
997
+		$all_data = json_decode($buffer,true);
998
+		if ($buffer != '' && is_array($all_data)) {
999 999
 		$reset = 0;
1000 1000
 		foreach ($all_data as $line) {
1001
-	    	    $data = array();
1002
-	    	    //$data['id'] = $line['id']; // id not usable
1003
-	    	    $data['id'] = trim($line['flight_id']);
1004
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1005
-	    	    $data['pilot_name'] = $line['pilot_name'];
1006
-	    	    $data['pilot_id'] = $line['pilot_id'];
1007
-	    	    $data['ident'] = trim($line['callsign']); // ident
1008
-	    	    $data['altitude'] = $line['altitude']; // altitude
1009
-	    	    $data['speed'] = $line['gs']; // speed
1010
-	    	    $data['heading'] = $line['heading']; // heading
1011
-	    	    $data['latitude'] = $line['latitude']; // lat
1012
-	    	    $data['longitude'] = $line['longitude']; // long
1013
-	    	    $data['verticalrate'] = ''; // verticale rate
1014
-	    	    $data['squawk'] = ''; // squawk
1015
-	    	    $data['emergency'] = ''; // emergency
1016
-	    	    //$data['datetime'] = $line['lastupdate'];
1017
-	    	    $data['last_update'] = $line['last_update'];
1018
-		    $data['datetime'] = date('Y-m-d H:i:s');
1019
-	    	    $data['departure_airport_icao'] = $line['departure'];
1020
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1021
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1022
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1023
-    		    //$data['registration'] = $line['aircraft'];
1024
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1025
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1026
-    		    $data['id_source'] = $id_source;
1027
-	    	    $data['format_source'] = 'vam';
1028
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
-		    $SI->add($data);
1031
-		    unset($data);
1001
+				$data = array();
1002
+				//$data['id'] = $line['id']; // id not usable
1003
+				$data['id'] = trim($line['flight_id']);
1004
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1005
+				$data['pilot_name'] = $line['pilot_name'];
1006
+				$data['pilot_id'] = $line['pilot_id'];
1007
+				$data['ident'] = trim($line['callsign']); // ident
1008
+				$data['altitude'] = $line['altitude']; // altitude
1009
+				$data['speed'] = $line['gs']; // speed
1010
+				$data['heading'] = $line['heading']; // heading
1011
+				$data['latitude'] = $line['latitude']; // lat
1012
+				$data['longitude'] = $line['longitude']; // long
1013
+				$data['verticalrate'] = ''; // verticale rate
1014
+				$data['squawk'] = ''; // squawk
1015
+				$data['emergency'] = ''; // emergency
1016
+				//$data['datetime'] = $line['lastupdate'];
1017
+				$data['last_update'] = $line['last_update'];
1018
+			$data['datetime'] = date('Y-m-d H:i:s');
1019
+				$data['departure_airport_icao'] = $line['departure'];
1020
+				//$data['departure_airport_time'] = $line['departure_time'];
1021
+				$data['arrival_airport_icao'] = $line['arrival'];
1022
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1023
+				//$data['registration'] = $line['aircraft'];
1024
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1025
+				$data['aircraft_icao'] = $line['plane_type'];
1026
+				$data['id_source'] = $id_source;
1027
+				$data['format_source'] = 'vam';
1028
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
+			$SI->add($data);
1031
+			unset($data);
1032 1032
 		}
1033 1033
 		if ($globalDebug) echo 'No more data...'."\n";
1034 1034
 		unset($buffer);
1035 1035
 		unset($all_data);
1036
-	    }
1037
-    	    //$last_exec['phpvmacars'] = time();
1038
-    	    $last_exec[$id]['last'] = time();
1036
+		}
1037
+			//$last_exec['phpvmacars'] = time();
1038
+			$last_exec[$id]['last'] = time();
1039 1039
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1040 1040
 	} 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') {
1041
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1042
-    	    //$last_exec[$id]['last'] = time();
1041
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1042
+			//$last_exec[$id]['last'] = time();
1043 1043
 
1044
-	    //$read = array( $sockets[$id] );
1045
-	    $read = $sockets;
1046
-	    $write = NULL;
1047
-	    $e = NULL;
1048
-	    $n = socket_select($read, $write, $e, $timeout);
1049
-	    if ($e != NULL) var_dump($e);
1050
-	    if ($n > 0) {
1044
+		//$read = array( $sockets[$id] );
1045
+		$read = $sockets;
1046
+		$write = NULL;
1047
+		$e = NULL;
1048
+		$n = socket_select($read, $write, $e, $timeout);
1049
+		if ($e != NULL) var_dump($e);
1050
+		if ($n > 0) {
1051 1051
 		$reset = 0;
1052 1052
 		foreach ($read as $nb => $r) {
1053
-		    //$value = $formats[$nb];
1054
-		    $format = $globalSources[$nb]['format'];
1055
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1053
+			//$value = $formats[$nb];
1054
+			$format = $globalSources[$nb]['format'];
1055
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1056 1056
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1057
-		    } elseif ($format == 'vrstcp') {
1057
+			} elseif ($format == 'vrstcp') {
1058 1058
 			$buffer = @socket_read($r, 6000);
1059
-		    } else {
1059
+			} else {
1060 1060
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1061
-		    }
1062
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1063
-		    //echo $buffer."\n";
1064
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1065
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1066
-		    $error = false;
1067
-		    //$SI::del();
1068
-		    if ($format == 'vrstcp') {
1061
+			}
1062
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1063
+			//echo $buffer."\n";
1064
+			// lets play nice and handle signals such as ctrl-c/kill properly
1065
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1066
+			$error = false;
1067
+			//$SI::del();
1068
+			if ($format == 'vrstcp') {
1069 1069
 			$buffer = explode('},{',$buffer);
1070
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1071
-		    // SBS format is CSV format
1072
-		    if ($buffer !== FALSE && $buffer != '') {
1070
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1071
+			// SBS format is CSV format
1072
+			if ($buffer !== FALSE && $buffer != '') {
1073 1073
 			$tt[$format] = 0;
1074 1074
 			if ($format == 'acarssbs3') {
1075
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1076
-			    $ACARS->add(trim($buffer));
1077
-			    $ACARS->deleteLiveAcarsData();
1075
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1076
+				$ACARS->add(trim($buffer));
1077
+				$ACARS->deleteLiveAcarsData();
1078 1078
 			} elseif ($format == 'raw') {
1079
-			    // AVR format
1080
-			    $data = $SBS->parse($buffer);
1081
-			    if (is_array($data)) {
1079
+				// AVR format
1080
+				$data = $SBS->parse($buffer);
1081
+				if (is_array($data)) {
1082 1082
 				$data['datetime'] = date('Y-m-d H:i:s');
1083 1083
 				$data['format_source'] = 'raw';
1084 1084
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1085 1085
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1086 1086
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1087 1087
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1088
-			    }
1088
+				}
1089 1089
 			} elseif ($format == 'ais') {
1090
-			    $ais_data = $AIS->parse_line(trim($buffer));
1091
-			    $data = array();
1092
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1093
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1094
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1095
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1096
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1097
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1098
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1099
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1100
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1101
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1102
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1103
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1104
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1105
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1090
+				$ais_data = $AIS->parse_line(trim($buffer));
1091
+				$data = array();
1092
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1093
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1094
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1095
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1096
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1097
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1098
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1099
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1100
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1101
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1102
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1103
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1104
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1105
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1106 1106
 
1107
-			    if (isset($ais_data['timestamp'])) {
1107
+				if (isset($ais_data['timestamp'])) {
1108 1108
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1109
-			    } else {
1109
+				} else {
1110 1110
 				$data['datetime'] = date('Y-m-d H:i:s');
1111
-			    }
1112
-			    $data['format_source'] = 'aisnmea';
1113
-    			    $data['id_source'] = $id_source;
1114
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1115
-			    unset($data);
1116
-                        } elseif ($format == 'flightgearsp') {
1117
-                    	    //echo $buffer."\n";
1118
-                    	    if (strlen($buffer) > 5) {
1111
+				}
1112
+				$data['format_source'] = 'aisnmea';
1113
+					$data['id_source'] = $id_source;
1114
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1115
+				unset($data);
1116
+						} elseif ($format == 'flightgearsp') {
1117
+							//echo $buffer."\n";
1118
+							if (strlen($buffer) > 5) {
1119 1119
 				$line = explode(',',$buffer);
1120 1120
 				$data = array();
1121 1121
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1132,38 +1132,38 @@  discard block
 block discarded – undo
1132 1132
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1133 1133
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1134 1134
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1135
-			    }
1136
-                        } elseif ($format == 'acars') {
1137
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1138
-			    $ACARS->add(trim($buffer));
1139
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1140
-			    $ACARS->deleteLiveAcarsData();
1135
+				}
1136
+						} elseif ($format == 'acars') {
1137
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1138
+				$ACARS->add(trim($buffer));
1139
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1140
+				$ACARS->deleteLiveAcarsData();
1141 1141
 			} elseif ($format == 'flightgearmp') {
1142
-			    if (substr($buffer,0,1) != '#') {
1142
+				if (substr($buffer,0,1) != '#') {
1143 1143
 				$data = array();
1144 1144
 				//echo $buffer."\n";
1145 1145
 				$line = explode(' ',$buffer);
1146 1146
 				if (count($line) == 11) {
1147
-				    $userserver = explode('@',$line[0]);
1148
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1149
-				    $data['ident'] = $userserver[0];
1150
-				    $data['registration'] = $userserver[0];
1151
-				    $data['latitude'] = $line[4];
1152
-				    $data['longitude'] = $line[5];
1153
-				    $data['altitude'] = $line[6];
1154
-				    $data['datetime'] = date('Y-m-d H:i:s');
1155
-				    $aircraft_type = $line[10];
1156
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1157
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1158
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1159
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1147
+					$userserver = explode('@',$line[0]);
1148
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1149
+					$data['ident'] = $userserver[0];
1150
+					$data['registration'] = $userserver[0];
1151
+					$data['latitude'] = $line[4];
1152
+					$data['longitude'] = $line[5];
1153
+					$data['altitude'] = $line[6];
1154
+					$data['datetime'] = date('Y-m-d H:i:s');
1155
+					$aircraft_type = $line[10];
1156
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1157
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1158
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1159
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1160
+				}
1160 1161
 				}
1161
-			    }
1162 1162
 			} elseif ($format == 'beast') {
1163
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1164
-			    die;
1163
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1164
+				die;
1165 1165
 			} elseif ($format == 'vrstcp') {
1166
-			    foreach($buffer as $all_data) {
1166
+				foreach($buffer as $all_data) {
1167 1167
 				$line = json_decode('{'.$all_data.'}',true);
1168 1168
 				$data = array();
1169 1169
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1183,113 +1183,113 @@  discard block
 block discarded – undo
1183 1183
 				*/
1184 1184
 				$data['datetime'] = date('Y-m-d H:i:s');
1185 1185
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1186
-		    		$data['format_source'] = 'vrstcp';
1186
+					$data['format_source'] = 'vrstcp';
1187 1187
 				$data['id_source'] = $id_source;
1188 1188
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1189 1189
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1190 1190
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1191 1191
 				unset($data);
1192
-			    }
1192
+				}
1193 1193
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1194
-			    $line = explode("\t", $buffer);
1195
-			    for($k = 0; $k < count($line); $k=$k+2) {
1194
+				$line = explode("\t", $buffer);
1195
+				for($k = 0; $k < count($line); $k=$k+2) {
1196 1196
 				$key = $line[$k];
1197
-			        $lined[$key] = $line[$k+1];
1198
-			    }
1199
-    			    if (count($lined) > 3) {
1200
-    				$data['hex'] = $lined['hexid'];
1201
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1202
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1203
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1204
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1205
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1206
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1207
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1208
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1209
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1210
-    				$data['id_source'] = $id_source;
1211
-    				$data['format_source'] = 'tsv';
1212
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1213
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1197
+					$lined[$key] = $line[$k+1];
1198
+				}
1199
+					if (count($lined) > 3) {
1200
+					$data['hex'] = $lined['hexid'];
1201
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1202
+					$data['datetime'] = date('Y-m-d H:i:s');;
1203
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1204
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1205
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1206
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1207
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1208
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1209
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1210
+					$data['id_source'] = $id_source;
1211
+					$data['format_source'] = 'tsv';
1212
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1213
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1214 1214
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1215
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1216
-    				unset($lined);
1217
-    				unset($data);
1218
-    			    } else $error = true;
1215
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1216
+					unset($lined);
1217
+					unset($data);
1218
+					} else $error = true;
1219 1219
 			} elseif ($format == 'aprs' && $use_aprs) {
1220
-			    if ($aprs_connect == 0) {
1220
+				if ($aprs_connect == 0) {
1221 1221
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1222 1222
 				$aprs_connect = 1;
1223
-			    }
1223
+				}
1224 1224
 			    
1225
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1225
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1226 1226
 				$aprs_last_tx = time();
1227 1227
 				$data_aprs = "# Keep alive";
1228 1228
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1229
-			    }
1229
+				}
1230 1230
 			    
1231
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1232
-			    //echo 'APRS data : '.$buffer."\n";
1233
-			    $buffer = str_replace('APRS <- ','',$buffer);
1234
-			    $buffer = str_replace('APRS -> ','',$buffer);
1235
-			    //echo $buffer."\n";
1236
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1231
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1232
+				//echo 'APRS data : '.$buffer."\n";
1233
+				$buffer = str_replace('APRS <- ','',$buffer);
1234
+				$buffer = str_replace('APRS -> ','',$buffer);
1235
+				//echo $buffer."\n";
1236
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1237 1237
 				$line = $APRS->parse($buffer);
1238 1238
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1239 1239
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1240
-				    $aprs_last_tx = time();
1241
-				    $data = array();
1242
-				    //print_r($line);
1243
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1244
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1245
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1246
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1247
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1248
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1249
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1250
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1251
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1252
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1253
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1254
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1255
-				    $data['latitude'] = $line['latitude'];
1256
-				    $data['longitude'] = $line['longitude'];
1257
-				    //$data['verticalrate'] = $line[16];
1258
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1259
-				    else $data['speed'] = 0;
1260
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1261
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1262
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1263
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1264
-				    //else $data['heading'] = 0;
1265
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1266
-				    if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1267
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1268
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1269
-    				    $data['id_source'] = $id_source;
1270
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1271
-				    else $data['format_source'] = 'aprs';
1272
-				    $data['source_name'] = $line['source'];
1273
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1274
-				    else $data['source_type'] = 'flarm';
1275
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1276
-				    $currentdate = date('Y-m-d H:i:s');
1277
-				    $aprsdate = strtotime($data['datetime']);
1278
-				    // Accept data if time <= system time + 20s
1279
-				    //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'])))) {
1280
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1240
+					$aprs_last_tx = time();
1241
+					$data = array();
1242
+					//print_r($line);
1243
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1244
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1245
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1246
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1247
+					if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1248
+					if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1249
+					if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1250
+					if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1251
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1252
+					else $data['datetime'] = date('Y-m-d H:i:s');
1253
+					//$data['datetime'] = date('Y-m-d H:i:s');
1254
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1255
+					$data['latitude'] = $line['latitude'];
1256
+					$data['longitude'] = $line['longitude'];
1257
+					//$data['verticalrate'] = $line[16];
1258
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1259
+					else $data['speed'] = 0;
1260
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1261
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1262
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1263
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1264
+					//else $data['heading'] = 0;
1265
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1266
+					if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1267
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1268
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1269
+						$data['id_source'] = $id_source;
1270
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1271
+					else $data['format_source'] = 'aprs';
1272
+					$data['source_name'] = $line['source'];
1273
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1274
+					else $data['source_type'] = 'flarm';
1275
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1276
+					$currentdate = date('Y-m-d H:i:s');
1277
+					$aprsdate = strtotime($data['datetime']);
1278
+					// Accept data if time <= system time + 20s
1279
+					//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'])))) {
1280
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1281 1281
 					$send = $SI->add($data);
1282
-				    } elseif ($data['source_type'] == 'ais') {
1282
+					} elseif ($data['source_type'] == 'ais') {
1283 1283
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1284
-				    } elseif (isset($line['stealth'])) {
1284
+					} elseif (isset($line['stealth'])) {
1285 1285
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1286 1286
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1287
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1288
-				    } 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') {
1287
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1288
+					} 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') {
1289 1289
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1290 1290
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1291
-				    }
1292
-				    unset($data);
1291
+					}
1292
+					unset($data);
1293 1293
 				} 
1294 1294
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1295 1295
 					echo '!! Weather Station not yet supported'."\n";
@@ -1299,12 +1299,12 @@  discard block
 block discarded – undo
1299 1299
 				}
1300 1300
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1301 1301
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1302
-			    }
1302
+				}
1303 1303
 			} else {
1304
-			    $line = explode(',', $buffer);
1305
-    			    if (count($line) > 20) {
1306
-    			    	$data['hex'] = $line[4];
1307
-    				/*
1304
+				$line = explode(',', $buffer);
1305
+					if (count($line) > 20) {
1306
+						$data['hex'] = $line[4];
1307
+					/*
1308 1308
     				$data['datetime'] = $line[6].' '.$line[7];
1309 1309
     					date_default_timezone_set($globalTimezone);
1310 1310
     					$datetime = new DateTime($data['datetime']);
@@ -1312,30 +1312,30 @@  discard block
 block discarded – undo
1312 1312
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1313 1313
     					date_default_timezone_set('UTC');
1314 1314
     				*/
1315
-    				// Force datetime to current UTC datetime
1316
-    				date_default_timezone_set('UTC');
1317
-    				$data['datetime'] = date('Y-m-d H:i:s');
1318
-    				$data['ident'] = trim($line[10]);
1319
-    				$data['latitude'] = $line[14];
1320
-    				$data['longitude'] = $line[15];
1321
-    				$data['verticalrate'] = $line[16];
1322
-    				$data['emergency'] = $line[20];
1323
-    				$data['speed'] = $line[12];
1324
-    				$data['squawk'] = $line[17];
1325
-    				$data['altitude'] = $line[11];
1326
-    				$data['heading'] = $line[13];
1327
-    				$data['ground'] = $line[21];
1328
-    				$data['emergency'] = $line[19];
1329
-    				$data['format_source'] = 'sbs';
1315
+					// Force datetime to current UTC datetime
1316
+					date_default_timezone_set('UTC');
1317
+					$data['datetime'] = date('Y-m-d H:i:s');
1318
+					$data['ident'] = trim($line[10]);
1319
+					$data['latitude'] = $line[14];
1320
+					$data['longitude'] = $line[15];
1321
+					$data['verticalrate'] = $line[16];
1322
+					$data['emergency'] = $line[20];
1323
+					$data['speed'] = $line[12];
1324
+					$data['squawk'] = $line[17];
1325
+					$data['altitude'] = $line[11];
1326
+					$data['heading'] = $line[13];
1327
+					$data['ground'] = $line[21];
1328
+					$data['emergency'] = $line[19];
1329
+					$data['format_source'] = 'sbs';
1330 1330
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1331
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1331
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1332 1332
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1333
-    				$data['id_source'] = $id_source;
1334
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1335
-    				else $error = true;
1336
-    				unset($data);
1337
-    			    } else $error = true;
1338
-			    if ($error) {
1333
+					$data['id_source'] = $id_source;
1334
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1335
+					else $error = true;
1336
+					unset($data);
1337
+					} else $error = true;
1338
+				if ($error) {
1339 1339
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1340 1340
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1341 1341
 				} else {
@@ -1351,13 +1351,13 @@  discard block
 block discarded – undo
1351 1351
 					connect_all($sourceer);
1352 1352
 					$sourceer = array();
1353 1353
 				}
1354
-			    }
1354
+				}
1355 1355
 			}
1356 1356
 			// Sleep for xxx microseconds
1357 1357
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1358
-		    } else {
1358
+			} else {
1359 1359
 			if ($format == 'flightgearmp') {
1360
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1360
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1361 1361
 				//@socket_close($r);
1362 1362
 				sleep($globalMinFetch);
1363 1363
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1366,9 +1366,9 @@  discard block
 block discarded – undo
1366 1366
 				break;
1367 1367
 				
1368 1368
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1369
-			    if (isset($tt[$format])) $tt[$format]++;
1370
-			    else $tt[$format] = 0;
1371
-			    if ($tt[$format] > 30) {
1369
+				if (isset($tt[$format])) $tt[$format]++;
1370
+				else $tt[$format] = 0;
1371
+				if ($tt[$format] > 30) {
1372 1372
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1373 1373
 				//@socket_close($r);
1374 1374
 				sleep(2);
@@ -1379,23 +1379,23 @@  discard block
 block discarded – undo
1379 1379
 				//connect_all($globalSources);
1380 1380
 				$tt[$format]=0;
1381 1381
 				break;
1382
-			    }
1382
+				}
1383
+			}
1383 1384
 			}
1384
-		    }
1385 1385
 		}
1386
-	    } else {
1386
+		} else {
1387 1387
 		$error = socket_strerror(socket_last_error());
1388 1388
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1389 1389
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1390 1390
 			if (isset($globalDebug)) echo "Restarting...\n";
1391 1391
 			// Restart the script if possible
1392 1392
 			if (is_array($sockets)) {
1393
-			    if ($globalDebug) echo "Shutdown all sockets...";
1393
+				if ($globalDebug) echo "Shutdown all sockets...";
1394 1394
 			    
1395
-			    foreach ($sockets as $sock) {
1395
+				foreach ($sockets as $sock) {
1396 1396
 				@socket_shutdown($sock,2);
1397 1397
 				@socket_close($sock);
1398
-			    }
1398
+				}
1399 1399
 			    
1400 1400
 			}
1401 1401
 			if ($globalDebug) echo "Waiting...";
@@ -1410,13 +1410,13 @@  discard block
 block discarded – undo
1410 1410
 			if ($globalDebug) echo "Restart all connections...";
1411 1411
 			connect_all($globalSources);
1412 1412
 		}
1413
-	    }
1413
+		}
1414 1414
 	}
1415 1415
 	if ($globalDaemon === false) {
1416
-	    if ($globalDebug) echo 'Check all...'."\n";
1417
-	    $SI->checkAll();
1416
+		if ($globalDebug) echo 'Check all...'."\n";
1417
+		$SI->checkAll();
1418
+	}
1418 1419
 	}
1419
-    }
1420 1420
 }
1421 1421
 
1422 1422
 ?>
Please login to merge, or discard this patch.