Completed
Push — master ( f218a1...9aeaea )
by Yannick
05:36
created
scripts/daemon-spotter.php 1 patch
Indentation   +693 added lines, -693 removed lines patch added patch discarded remove patch
@@ -19,47 +19,47 @@  discard block
 block discarded – undo
19 19
 // Check if schema is at latest version
20 20
 $Connection = new Connection();
21 21
 if ($Connection->latest() === false) {
22
-    echo "You MUST update to latest schema. Run install/index.php";
23
-    exit();
22
+	echo "You MUST update to latest schema. Run install/index.php";
23
+	exit();
24 24
 }
25 25
 if (PHP_SAPI != 'cli') {
26
-    echo "This script MUST be called from console, not a web browser.";
26
+	echo "This script MUST be called from console, not a web browser.";
27 27
 //    exit();
28 28
 }
29 29
 
30 30
 // This is to be compatible with old version of settings.php
31 31
 if (!isset($globalSources)) {
32
-    if (isset($globalSBS1Hosts)) {
33
-        //$hosts = $globalSBS1Hosts;
34
-        foreach ($globalSBS1Hosts as $host) {
35
-	    $globalSources[] = array('host' => $host);
36
-    	}
37
-    } else {
38
-        if (!isset($globalSBS1Host)) {
39
-	    echo '$globalSources MUST be defined !';
40
-	    die;
32
+	if (isset($globalSBS1Hosts)) {
33
+		//$hosts = $globalSBS1Hosts;
34
+		foreach ($globalSBS1Hosts as $host) {
35
+		$globalSources[] = array('host' => $host);
36
+		}
37
+	} else {
38
+		if (!isset($globalSBS1Host)) {
39
+		echo '$globalSources MUST be defined !';
40
+		die;
41 41
 	}
42 42
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
43 43
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
44
-    }
44
+	}
45 45
 }
46 46
 
47 47
 $options = getopt('s::',array('source::','server','idsource::'));
48 48
 //if (isset($options['s'])) $hosts = array($options['s']);
49 49
 //elseif (isset($options['source'])) $hosts = array($options['source']);
50 50
 if (isset($options['s'])) {
51
-    $globalSources = array();
52
-    $globalSources[] = array('host' => $options['s']);
51
+	$globalSources = array();
52
+	$globalSources[] = array('host' => $options['s']);
53 53
 } elseif (isset($options['source'])) {
54
-    $globalSources = array();
55
-    $globalSources[] = array('host' => $options['source']);
54
+	$globalSources = array();
55
+	$globalSources[] = array('host' => $options['source']);
56 56
 }
57 57
 if (isset($options['server'])) $globalServer = TRUE;
58 58
 if (isset($options['idsource'])) $id_source = $options['idsource'];
59 59
 else $id_source = 1;
60 60
 if (isset($globalServer) && $globalServer) {
61
-    if ($globalDebug) echo "Using Server Mode\n";
62
-    $SI=new SpotterServer();
61
+	if ($globalDebug) echo "Using Server Mode\n";
62
+	$SI=new SpotterServer();
63 63
 } else $SI=new SpotterImport($Connection->db);
64 64
 //$APRS=new APRS($Connection->db);
65 65
 $SBS=new SBS();
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 //$servertz = system('date +%Z');
70 70
 // signal handler - playing nice with sockets and dump1090
71 71
 if (function_exists('pcntl_fork')) {
72
-    pcntl_signal(SIGINT,  function() {
73
-        global $sockets;
74
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75
-        die("Bye!\n");
76
-    });
77
-    pcntl_signal_dispatch();
72
+	pcntl_signal(SIGINT,  function() {
73
+		global $sockets;
74
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75
+		die("Bye!\n");
76
+	});
77
+	pcntl_signal_dispatch();
78 78
 }
79 79
 
80 80
 // let's try and connect
@@ -84,162 +84,162 @@  discard block
 block discarded – undo
84 84
 $reset = 0;
85 85
 
86 86
 function create_socket($host, $port, &$errno, &$errstr) {
87
-    $ip = gethostbyname($host);
88
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
89
-    $r = @socket_connect($s, $ip, $port);
90
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
91
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92
-        return $s;
93
-    }
94
-    $errno = socket_last_error($s);
95
-    $errstr = socket_strerror($errno);
96
-    socket_close($s);
97
-    return false;
87
+	$ip = gethostbyname($host);
88
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
89
+	$r = @socket_connect($s, $ip, $port);
90
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
91
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92
+		return $s;
93
+	}
94
+	$errno = socket_last_error($s);
95
+	$errstr = socket_strerror($errno);
96
+	socket_close($s);
97
+	return false;
98 98
 }
99 99
 
100 100
 function create_socket_udp($host, $port, &$errno, &$errstr) {
101
-    echo "UDP !!";
102
-    $ip = gethostbyname($host);
103
-    $s = socket_create(AF_INET, SOCK_DGRAM, 0);
104
-    $r = @socket_bind($s, $ip, $port);
105
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
106
-        return $s;
107
-    }
108
-    $errno = socket_last_error($s);
109
-    $errstr = socket_strerror($errno);
110
-    socket_close($s);
111
-    return false;
101
+	echo "UDP !!";
102
+	$ip = gethostbyname($host);
103
+	$s = socket_create(AF_INET, SOCK_DGRAM, 0);
104
+	$r = @socket_bind($s, $ip, $port);
105
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
106
+		return $s;
107
+	}
108
+	$errno = socket_last_error($s);
109
+	$errstr = socket_strerror($errno);
110
+	socket_close($s);
111
+	return false;
112 112
 }
113 113
 
114 114
 function connect_all($hosts) {
115
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117
-    $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
119
-    foreach ($hosts as $id => $value) {
115
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
+	global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117
+	$reset++;
118
+	if ($globalDebug) echo 'Connect to all...'."\n";
119
+	foreach ($hosts as $id => $value) {
120 120
 	$host = $value['host'];
121 121
 	$globalSources[$id]['last_exec'] = 0;
122 122
 	// Here we check type of source(s)
123 123
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
-            if (preg_match('/deltadb.txt$/i',$host)) {
125
-        	//$formats[$id] = 'deltadbtxt';
126
-        	$globalSources[$id]['format'] = 'deltadbtxt';
127
-        	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
-        	//$formats[$id] = 'vatsimtxt';
131
-        	$globalSources[$id]['format'] = 'vatsimtxt';
132
-        	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135
-        	//$formats[$id] = 'aircraftlistjson';
136
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
137
-        	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
-    	    } else if (preg_match('/opensky/i',$host)) {
140
-        	//$formats[$id] = 'aircraftlistjson';
141
-        	$globalSources[$id]['format'] = 'opensky';
142
-        	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145
-        	//$formats[$id] = 'radarvirtueljson';
146
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
147
-        	//$last_exec['radarvirtueljson'] = 0;
148
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
149
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
-        	    exit(0);
152
-        	}
153
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
154
-        	//$formats[$id] = 'planeupdatefaa';
155
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
156
-        	//$last_exec['planeupdatefaa'] = 0;
157
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
158
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160
-        	    exit(0);
161
-        	}
162
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
163
-        	//$formats[$id] = 'phpvmacars';
164
-        	$globalSources[$id]['format'] = 'phpvmacars';
165
-        	//$last_exec['phpvmacars'] = 0;
166
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
168
-        	//$formats[$id] = 'phpvmacars';
169
-        	$globalSources[$id]['format'] = 'vam';
170
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
-            } else if (preg_match('/whazzup/i',$host)) {
172
-        	//$formats[$id] = 'whazzup';
173
-        	$globalSources[$id]['format'] = 'whazzup';
174
-        	//$last_exec['whazzup'] = 0;
175
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
-            } else if (preg_match('/recentpireps/i',$host)) {
177
-        	//$formats[$id] = 'pirepsjson';
178
-        	$globalSources[$id]['format'] = 'pirepsjson';
179
-        	//$last_exec['pirepsjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182
-        	//$formats[$id] = 'fr24json';
183
-        	$globalSources[$id]['format'] = 'fr24json';
184
-        	//$last_exec['fr24json'] = 0;
185
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
186
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188
-        	    exit(0);
189
-        	}
190
-            //} else if (preg_match('/10001/',$host)) {
191
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192
-        	//$formats[$id] = 'tsv';
193
-        	$globalSources[$id]['format'] = 'tsv';
194
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195
-            }
196
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
-	    $hostport = explode(':',$host);
200
-	    if (isset($hostport[1])) {
124
+			if (preg_match('/deltadb.txt$/i',$host)) {
125
+			//$formats[$id] = 'deltadbtxt';
126
+			$globalSources[$id]['format'] = 'deltadbtxt';
127
+			//$last_exec['deltadbtxt'] = 0;
128
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
+			//$formats[$id] = 'vatsimtxt';
131
+			$globalSources[$id]['format'] = 'vatsimtxt';
132
+			//$last_exec['vatsimtxt'] = 0;
133
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
135
+			//$formats[$id] = 'aircraftlistjson';
136
+			$globalSources[$id]['format'] = 'aircraftlistjson';
137
+			//$last_exec['aircraftlistjson'] = 0;
138
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
+			} else if (preg_match('/opensky/i',$host)) {
140
+			//$formats[$id] = 'aircraftlistjson';
141
+			$globalSources[$id]['format'] = 'opensky';
142
+			//$last_exec['aircraftlistjson'] = 0;
143
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145
+			//$formats[$id] = 'radarvirtueljson';
146
+			$globalSources[$id]['format'] = 'radarvirtueljson';
147
+			//$last_exec['radarvirtueljson'] = 0;
148
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
149
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
+				exit(0);
152
+			}
153
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
154
+			//$formats[$id] = 'planeupdatefaa';
155
+			$globalSources[$id]['format'] = 'planeupdatefaa';
156
+			//$last_exec['planeupdatefaa'] = 0;
157
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
158
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160
+				exit(0);
161
+			}
162
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
163
+			//$formats[$id] = 'phpvmacars';
164
+			$globalSources[$id]['format'] = 'phpvmacars';
165
+			//$last_exec['phpvmacars'] = 0;
166
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
168
+			//$formats[$id] = 'phpvmacars';
169
+			$globalSources[$id]['format'] = 'vam';
170
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
+			} else if (preg_match('/whazzup/i',$host)) {
172
+			//$formats[$id] = 'whazzup';
173
+			$globalSources[$id]['format'] = 'whazzup';
174
+			//$last_exec['whazzup'] = 0;
175
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
+			} else if (preg_match('/recentpireps/i',$host)) {
177
+			//$formats[$id] = 'pirepsjson';
178
+			$globalSources[$id]['format'] = 'pirepsjson';
179
+			//$last_exec['pirepsjson'] = 0;
180
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182
+			//$formats[$id] = 'fr24json';
183
+			$globalSources[$id]['format'] = 'fr24json';
184
+			//$last_exec['fr24json'] = 0;
185
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
186
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188
+				exit(0);
189
+			}
190
+			//} else if (preg_match('/10001/',$host)) {
191
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192
+			//$formats[$id] = 'tsv';
193
+			$globalSources[$id]['format'] = 'tsv';
194
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195
+			}
196
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
+			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
+		$hostport = explode(':',$host);
200
+		if (isset($hostport[1])) {
201 201
 		$port = $hostport[1];
202 202
 		$hostn = $hostport[0];
203
-	    } else {
203
+		} else {
204 204
 		$port = $globalSources[$id]['port'];
205 205
 		$hostn = $globalSources[$id]['host'];
206
-	    }
207
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
-        	$s = create_socket($hostn,$port, $errno, $errstr);
209
-    	    } else {
210
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
211
-	    }
212
-	    if ($s) {
213
-    	        $sockets[$id] = $s;
214
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
-		    if (preg_match('/aprs/',$hostn)) {
206
+		}
207
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
+			$s = create_socket($hostn,$port, $errno, $errstr);
209
+			} else {
210
+			$s = create_socket_udp($hostn,$port, $errno, $errstr);
211
+		}
212
+		if ($s) {
213
+				$sockets[$id] = $s;
214
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
+			if (preg_match('/aprs/',$hostn)) {
216 216
 			//$formats[$id] = 'aprs';
217 217
 			$globalSources[$id]['format'] = 'aprs';
218 218
 			//$aprs_connect = 0;
219 219
 			//$use_aprs = true;
220
-    		    } elseif ($port == '10001') {
221
-        		//$formats[$id] = 'tsv';
222
-        		$globalSources[$id]['format'] = 'tsv';
223
-		    } elseif ($port == '30002') {
224
-        		//$formats[$id] = 'raw';
225
-        		$globalSources[$id]['format'] = 'raw';
226
-		    } elseif ($port == '5001') {
227
-        		//$formats[$id] = 'raw';
228
-        		$globalSources[$id]['format'] = 'flightgearmp';
229
-		    } elseif ($port == '30005') {
220
+				} elseif ($port == '10001') {
221
+				//$formats[$id] = 'tsv';
222
+				$globalSources[$id]['format'] = 'tsv';
223
+			} elseif ($port == '30002') {
224
+				//$formats[$id] = 'raw';
225
+				$globalSources[$id]['format'] = 'raw';
226
+			} elseif ($port == '5001') {
227
+				//$formats[$id] = 'raw';
228
+				$globalSources[$id]['format'] = 'flightgearmp';
229
+			} elseif ($port == '30005') {
230 230
 			// Not yet supported
231
-        		//$formats[$id] = 'beast';
232
-        		$globalSources[$id]['format'] = 'beast';
233
-		    //} else $formats[$id] = 'sbs';
234
-		    } else $globalSources[$id]['format'] = 'sbs';
235
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
231
+				//$formats[$id] = 'beast';
232
+				$globalSources[$id]['format'] = 'beast';
233
+			//} else $formats[$id] = 'sbs';
234
+			} else $globalSources[$id]['format'] = 'sbs';
235
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
236 236
 		}
237 237
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
238
-            } else {
238
+			} else {
239 239
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
240
-    	    }
241
-        }
242
-    }
240
+			}
241
+		}
242
+	}
243 243
 }
244 244
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
245 245
 
@@ -266,18 +266,18 @@  discard block
 block discarded – undo
266 266
 	die;
267 267
 }
268 268
 foreach ($globalSources as $key => $source) {
269
-    if (!isset($source['format'])) {
270
-        $globalSources[$key]['format'] = 'auto';
271
-    }
269
+	if (!isset($source['format'])) {
270
+		$globalSources[$key]['format'] = 'auto';
271
+	}
272 272
 }
273 273
 connect_all($globalSources);
274 274
 foreach ($globalSources as $key => $source) {
275
-    if (isset($source['format']) && $source['format'] == 'aprs') {
275
+	if (isset($source['format']) && $source['format'] == 'aprs') {
276 276
 	$aprs_connect = 0;
277 277
 	$use_aprs = true;
278 278
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
279 279
 	break;
280
-    }
280
+	}
281 281
 }
282 282
 
283 283
 if ($use_aprs) {
@@ -317,69 +317,69 @@  discard block
 block discarded – undo
317 317
 
318 318
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
319 319
 while ($i > 0) {
320
-    if (!$globalDaemon) $i = $endtime-time();
321
-    // Delete old ATC
322
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
320
+	if (!$globalDaemon) $i = $endtime-time();
321
+	// Delete old ATC
322
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
323 323
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
324
-        $ATC->deleteOldATC();
325
-    }
324
+		$ATC->deleteOldATC();
325
+	}
326 326
     
327
-    if (count($last_exec) > 0) {
327
+	if (count($last_exec) > 0) {
328 328
 	$max = $globalMinFetch;
329 329
 	foreach ($last_exec as $last) {
330
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
330
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
331 331
 	}
332 332
 	if ($max != $globalMinFetch) {
333
-	    if ($globalDebug) echo 'Sleeping...'."\n";
334
-	    sleep($globalMinFetch-$max+2);
333
+		if ($globalDebug) echo 'Sleeping...'."\n";
334
+		sleep($globalMinFetch-$max+2);
335
+	}
335 336
 	}
336
-    }
337 337
 
338 338
     
339
-    //foreach ($formats as $id => $value) {
340
-    foreach ($globalSources as $id => $value) {
339
+	//foreach ($formats as $id => $value) {
340
+	foreach ($globalSources as $id => $value) {
341 341
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
342 342
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
343
-	    //$buffer = $Common->getData($hosts[$id]);
344
-	    $buffer = $Common->getData($value['host']);
345
-	    if ($buffer != '') $reset = 0;
346
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
347
-	    $buffer = explode('\n',$buffer);
348
-	    foreach ($buffer as $line) {
349
-    		if ($line != '' && count($line) > 7) {
350
-    		    $line = explode(',', $line);
351
-	            $data = array();
352
-	            $data['hex'] = $line[1]; // hex
353
-	            $data['ident'] = $line[2]; // ident
354
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
355
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
356
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
357
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
358
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
359
-	            $data['verticalrate'] = ''; // vertical rate
360
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
361
-	            $data['emergency'] = ''; // emergency
362
-		    $data['datetime'] = date('Y-m-d H:i:s');
363
-		    $data['format_source'] = 'deltadbtxt';
364
-    		    $data['id_source'] = $id_source;
365
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
366
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
367
-    		    $SI->add($data);
368
-		    unset($data);
369
-    		}
370
-    	    }
371
-    	    $last_exec[$id]['last'] = time();
343
+		//$buffer = $Common->getData($hosts[$id]);
344
+		$buffer = $Common->getData($value['host']);
345
+		if ($buffer != '') $reset = 0;
346
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
347
+		$buffer = explode('\n',$buffer);
348
+		foreach ($buffer as $line) {
349
+			if ($line != '' && count($line) > 7) {
350
+				$line = explode(',', $line);
351
+				$data = array();
352
+				$data['hex'] = $line[1]; // hex
353
+				$data['ident'] = $line[2]; // ident
354
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
355
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
356
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
357
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
358
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
359
+				$data['verticalrate'] = ''; // vertical rate
360
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
361
+				$data['emergency'] = ''; // emergency
362
+			$data['datetime'] = date('Y-m-d H:i:s');
363
+			$data['format_source'] = 'deltadbtxt';
364
+				$data['id_source'] = $id_source;
365
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
366
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
367
+				$SI->add($data);
368
+			unset($data);
369
+			}
370
+			}
371
+			$last_exec[$id]['last'] = time();
372 372
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
373 373
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
374
-	    //$buffer = $Common->getData($hosts[$id]);
375
-	    $buffer = $Common->getData($value['host']);
376
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
377
-	    $buffer = explode('\n',$buffer);
378
-	    $reset = 0;
379
-	    foreach ($buffer as $line) {
380
-    		if ($line != '') {
381
-    		    $line = explode(':', $line);
382
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
374
+		//$buffer = $Common->getData($hosts[$id]);
375
+		$buffer = $Common->getData($value['host']);
376
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
377
+		$buffer = explode('\n',$buffer);
378
+		$reset = 0;
379
+		foreach ($buffer as $line) {
380
+			if ($line != '') {
381
+				$line = explode(':', $line);
382
+				if (count($line) > 30 && $line[0] != 'callsign') {
383 383
 			$data = array();
384 384
 			$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
385 385
 			$data['pilot_id'] = $line[1];
@@ -391,36 +391,36 @@  discard block
 block discarded – undo
391 391
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
392 392
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
393 393
 			$data['latitude'] = $line[5]; // lat
394
-	        	$data['longitude'] = $line[6]; // long
395
-	        	$data['verticalrate'] = ''; // vertical rate
396
-	        	$data['squawk'] = ''; // squawk
397
-	        	$data['emergency'] = ''; // emergency
398
-	        	$data['waypoints'] = $line[30];
394
+				$data['longitude'] = $line[6]; // long
395
+				$data['verticalrate'] = ''; // vertical rate
396
+				$data['squawk'] = ''; // squawk
397
+				$data['emergency'] = ''; // emergency
398
+				$data['waypoints'] = $line[30];
399 399
 			$data['datetime'] = date('Y-m-d H:i:s');
400 400
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
401 401
 			if (isset($line[37])) $data['last_update'] = $line[37];
402
-		        $data['departure_airport_icao'] = $line[11];
403
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
404
-		        $data['arrival_airport_icao'] = $line[13];
402
+				$data['departure_airport_icao'] = $line[11];
403
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
404
+				$data['arrival_airport_icao'] = $line[13];
405 405
 			$data['frequency'] = $line[4];
406 406
 			$data['type'] = $line[18];
407 407
 			$data['range'] = $line[19];
408 408
 			if (isset($line[35])) $data['info'] = $line[35];
409
-    			$data['id_source'] = $id_source;
410
-	    		//$data['arrival_airport_time'] = ;
411
-	    		if ($line[9] != '') {
412
-	    		    $aircraft_data = explode('/',$line[9]);
413
-	    		    if (isset($aircraft_data[1])) {
414
-	    			$data['aircraft_icao'] = $aircraft_data[1];
415
-	    		    }
416
-        		}
417
-	    		/*
409
+				$data['id_source'] = $id_source;
410
+				//$data['arrival_airport_time'] = ;
411
+				if ($line[9] != '') {
412
+					$aircraft_data = explode('/',$line[9]);
413
+					if (isset($aircraft_data[1])) {
414
+					$data['aircraft_icao'] = $aircraft_data[1];
415
+					}
416
+				}
417
+				/*
418 418
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
419 419
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
420 420
 	    		*/
421
-	    		$data['format_source'] = $value['format'];
421
+				$data['format_source'] = $value['format'];
422 422
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
423
-    			if ($line[3] == 'PILOT') $SI->add($data);
423
+				if ($line[3] == 'PILOT') $SI->add($data);
424 424
 			elseif ($line[3] == 'ATC') {
425 425
 				//print_r($data);
426 426
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -438,247 +438,247 @@  discard block
 block discarded – undo
438 438
 				if (!isset($data['source_name'])) $data['source_name'] = '';
439 439
 				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']);
440 440
 			}
441
-    			unset($data);
442
-    		    }
443
-    		}
444
-    	    }
445
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
446
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
447
-    	    $last_exec[$id]['last'] = time();
448
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
449
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
450
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
451
-	    if ($buffer != '') {
452
-	    $all_data = json_decode($buffer,true);
453
-	    if (isset($all_data['acList'])) {
441
+				unset($data);
442
+				}
443
+			}
444
+			}
445
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
446
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
447
+			$last_exec[$id]['last'] = time();
448
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
449
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
450
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
451
+		if ($buffer != '') {
452
+		$all_data = json_decode($buffer,true);
453
+		if (isset($all_data['acList'])) {
454 454
 		$reset = 0;
455 455
 		foreach ($all_data['acList'] as $line) {
456
-		    $data = array();
457
-		    $data['hex'] = $line['Icao']; // hex
458
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
459
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
460
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
461
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
462
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
463
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
464
-		    //$data['verticalrate'] = $line['']; // verticale rate
465
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
466
-		    $data['emergency'] = ''; // emergency
467
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
468
-		    /*
456
+			$data = array();
457
+			$data['hex'] = $line['Icao']; // hex
458
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
459
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
460
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
461
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
462
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
463
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
464
+			//$data['verticalrate'] = $line['']; // verticale rate
465
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
466
+			$data['emergency'] = ''; // emergency
467
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
468
+			/*
469 469
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
470 470
 		    else $data['datetime'] = date('Y-m-d H:i:s');
471 471
 		    */
472
-		    $data['datetime'] = date('Y-m-d H:i:s');
473
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
474
-	    	    $data['format_source'] = 'aircraftlistjson';
475
-		    $data['id_source'] = $id_source;
476
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
477
-		    if (isset($data['datetime'])) $SI->add($data);
478
-		    unset($data);
472
+			$data['datetime'] = date('Y-m-d H:i:s');
473
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
474
+				$data['format_source'] = 'aircraftlistjson';
475
+			$data['id_source'] = $id_source;
476
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
477
+			if (isset($data['datetime'])) $SI->add($data);
478
+			unset($data);
479 479
 		}
480
-	    } else {
480
+		} else {
481 481
 		$reset = 0;
482 482
 		foreach ($all_data as $line) {
483
-		    $data = array();
484
-		    $data['hex'] = $line['hex']; // hex
485
-		    $data['ident'] = $line['flight']; // ident
486
-		    $data['altitude'] = $line['altitude']; // altitude
487
-		    $data['speed'] = $line['speed']; // speed
488
-		    $data['heading'] = $line['track']; // heading
489
-		    $data['latitude'] = $line['lat']; // lat
490
-		    $data['longitude'] = $line['lon']; // long
491
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
492
-		    $data['squawk'] = $line['squawk']; // squawk
493
-		    $data['emergency'] = ''; // emergency
494
-		    $data['datetime'] = date('Y-m-d H:i:s');
495
-	    	    $data['format_source'] = 'aircraftlistjson';
496
-    		    $data['id_source'] = $id_source;
497
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
498
-		    $SI->add($data);
499
-		    unset($data);
483
+			$data = array();
484
+			$data['hex'] = $line['hex']; // hex
485
+			$data['ident'] = $line['flight']; // ident
486
+			$data['altitude'] = $line['altitude']; // altitude
487
+			$data['speed'] = $line['speed']; // speed
488
+			$data['heading'] = $line['track']; // heading
489
+			$data['latitude'] = $line['lat']; // lat
490
+			$data['longitude'] = $line['lon']; // long
491
+			$data['verticalrate'] = $line['vrt']; // verticale rate
492
+			$data['squawk'] = $line['squawk']; // squawk
493
+			$data['emergency'] = ''; // emergency
494
+			$data['datetime'] = date('Y-m-d H:i:s');
495
+				$data['format_source'] = 'aircraftlistjson';
496
+				$data['id_source'] = $id_source;
497
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
498
+			$SI->add($data);
499
+			unset($data);
500
+		}
500 501
 		}
501
-	    }
502
-	    }
503
-    	    //$last_exec['aircraftlistjson'] = time();
504
-    	    $last_exec[$id]['last'] = time();
505
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
506
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
507
-	    $buffer = $Common->getData($value['host']);
508
-	    $all_data = json_decode($buffer,true);
509
-	    if (isset($all_data['planes'])) {
502
+		}
503
+			//$last_exec['aircraftlistjson'] = time();
504
+			$last_exec[$id]['last'] = time();
505
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
506
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
507
+		$buffer = $Common->getData($value['host']);
508
+		$all_data = json_decode($buffer,true);
509
+		if (isset($all_data['planes'])) {
510 510
 		$reset = 0;
511 511
 		foreach ($all_data['planes'] as $key => $line) {
512
-		    $data = array();
513
-		    $data['hex'] = $key; // hex
514
-		    $data['ident'] = $line[3]; // ident
515
-		    $data['altitude'] = $line[6]; // altitude
516
-		    $data['speed'] = $line[8]; // speed
517
-		    $data['heading'] = $line[7]; // heading
518
-		    $data['latitude'] = $line[4]; // lat
519
-		    $data['longitude'] = $line[5]; // long
520
-		    //$data['verticalrate'] = $line[]; // verticale rate
521
-		    $data['squawk'] = $line[10]; // squawk
522
-		    $data['emergency'] = ''; // emergency
523
-		    $data['registration'] = $line[2];
524
-		    $data['aircraft_icao'] = $line[0];
525
-		    $deparr = explode('-',$line[1]);
526
-		    if (count($deparr) == 2) {
512
+			$data = array();
513
+			$data['hex'] = $key; // hex
514
+			$data['ident'] = $line[3]; // ident
515
+			$data['altitude'] = $line[6]; // altitude
516
+			$data['speed'] = $line[8]; // speed
517
+			$data['heading'] = $line[7]; // heading
518
+			$data['latitude'] = $line[4]; // lat
519
+			$data['longitude'] = $line[5]; // long
520
+			//$data['verticalrate'] = $line[]; // verticale rate
521
+			$data['squawk'] = $line[10]; // squawk
522
+			$data['emergency'] = ''; // emergency
523
+			$data['registration'] = $line[2];
524
+			$data['aircraft_icao'] = $line[0];
525
+			$deparr = explode('-',$line[1]);
526
+			if (count($deparr) == 2) {
527 527
 			$data['departure_airport_icao'] = $deparr[0];
528 528
 			$data['arrival_airport_icao'] = $deparr[1];
529
-		    }
530
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
531
-	    	    $data['format_source'] = 'planeupdatefaa';
532
-    		    $data['id_source'] = $id_source;
533
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
534
-		    $SI->add($data);
535
-		    unset($data);
529
+			}
530
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
531
+				$data['format_source'] = 'planeupdatefaa';
532
+				$data['id_source'] = $id_source;
533
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
534
+			$SI->add($data);
535
+			unset($data);
536
+		}
536 537
 		}
537
-	    }
538
-    	    //$last_exec['planeupdatefaa'] = time();
539
-    	    $last_exec[$id]['last'] = time();
540
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
541
-	    $buffer = $Common->getData($value['host']);
542
-	    $all_data = json_decode($buffer,true);
543
-	    if (isset($all_data['states'])) {
538
+			//$last_exec['planeupdatefaa'] = time();
539
+			$last_exec[$id]['last'] = time();
540
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
541
+		$buffer = $Common->getData($value['host']);
542
+		$all_data = json_decode($buffer,true);
543
+		if (isset($all_data['states'])) {
544 544
 		$reset = 0;
545 545
 		foreach ($all_data['states'] as $key => $line) {
546
-		    $data = array();
547
-		    $data['hex'] = $line[0]; // hex
548
-		    $data['ident'] = trim($line[1]); // ident
549
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
550
-		    $data['speed'] = round($line[9]*1.94384); // speed
551
-		    $data['heading'] = round($line[10]); // heading
552
-		    $data['latitude'] = $line[5]; // lat
553
-		    $data['longitude'] = $line[6]; // long
554
-		    $data['verticalrate'] = $line[11]; // verticale rate
555
-		    //$data['squawk'] = $line[10]; // squawk
556
-		    //$data['emergency'] = ''; // emergency
557
-		    //$data['registration'] = $line[2];
558
-		    //$data['aircraft_icao'] = $line[0];
559
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
560
-	    	    $data['format_source'] = 'opensky';
561
-    		    $data['id_source'] = $id_source;
562
-		    $SI->add($data);
563
-		    unset($data);
546
+			$data = array();
547
+			$data['hex'] = $line[0]; // hex
548
+			$data['ident'] = trim($line[1]); // ident
549
+			$data['altitude'] = round($line[7]*3.28084); // altitude
550
+			$data['speed'] = round($line[9]*1.94384); // speed
551
+			$data['heading'] = round($line[10]); // heading
552
+			$data['latitude'] = $line[5]; // lat
553
+			$data['longitude'] = $line[6]; // long
554
+			$data['verticalrate'] = $line[11]; // verticale rate
555
+			//$data['squawk'] = $line[10]; // squawk
556
+			//$data['emergency'] = ''; // emergency
557
+			//$data['registration'] = $line[2];
558
+			//$data['aircraft_icao'] = $line[0];
559
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
560
+				$data['format_source'] = 'opensky';
561
+				$data['id_source'] = $id_source;
562
+			$SI->add($data);
563
+			unset($data);
564
+		}
564 565
 		}
565
-	    }
566
-    	    //$last_exec['planeupdatefaa'] = time();
567
-    	    $last_exec[$id]['last'] = time();
568
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
569
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
570
-	    //$buffer = $Common->getData($hosts[$id]);
571
-	    $buffer = $Common->getData($value['host']);
572
-	    $all_data = json_decode($buffer,true);
573
-	    if (!empty($all_data)) $reset = 0;
574
-	    foreach ($all_data as $key => $line) {
566
+			//$last_exec['planeupdatefaa'] = time();
567
+			$last_exec[$id]['last'] = time();
568
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
569
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
570
+		//$buffer = $Common->getData($hosts[$id]);
571
+		$buffer = $Common->getData($value['host']);
572
+		$all_data = json_decode($buffer,true);
573
+		if (!empty($all_data)) $reset = 0;
574
+		foreach ($all_data as $key => $line) {
575 575
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
576
-		    $data = array();
577
-		    $data['hex'] = $line[0];
578
-		    $data['ident'] = $line[16]; //$line[13]
579
-	    	    $data['altitude'] = $line[4]; // altitude
580
-	    	    $data['speed'] = $line[5]; // speed
581
-	    	    $data['heading'] = $line[3]; // heading
582
-	    	    $data['latitude'] = $line[1]; // lat
583
-	    	    $data['longitude'] = $line[2]; // long
584
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
585
-	    	    $data['squawk'] = $line[6]; // squawk
586
-	    	    $data['aircraft_icao'] = $line[8];
587
-	    	    $data['registration'] = $line[9];
588
-		    $data['departure_airport_iata'] = $line[11];
589
-		    $data['arrival_airport_iata'] = $line[12];
590
-	    	    $data['emergency'] = ''; // emergency
591
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
592
-	    	    $data['format_source'] = 'fr24json';
593
-    		    $data['id_source'] = $id_source;
594
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
595
-		    $SI->add($data);
596
-		    unset($data);
576
+			$data = array();
577
+			$data['hex'] = $line[0];
578
+			$data['ident'] = $line[16]; //$line[13]
579
+				$data['altitude'] = $line[4]; // altitude
580
+				$data['speed'] = $line[5]; // speed
581
+				$data['heading'] = $line[3]; // heading
582
+				$data['latitude'] = $line[1]; // lat
583
+				$data['longitude'] = $line[2]; // long
584
+				$data['verticalrate'] = $line[15]; // verticale rate
585
+				$data['squawk'] = $line[6]; // squawk
586
+				$data['aircraft_icao'] = $line[8];
587
+				$data['registration'] = $line[9];
588
+			$data['departure_airport_iata'] = $line[11];
589
+			$data['arrival_airport_iata'] = $line[12];
590
+				$data['emergency'] = ''; // emergency
591
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
592
+				$data['format_source'] = 'fr24json';
593
+				$data['id_source'] = $id_source;
594
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
595
+			$SI->add($data);
596
+			unset($data);
597
+		}
597 598
 		}
598
-	    }
599
-    	    //$last_exec['fr24json'] = time();
600
-    	    $last_exec[$id]['last'] = time();
601
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
602
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
603
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
604
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
605
-	    //echo $buffer;
606
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
607
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
608
-	    $all_data = json_decode($buffer,true);
609
-	    if (json_last_error() != JSON_ERROR_NONE) {
599
+			//$last_exec['fr24json'] = time();
600
+			$last_exec[$id]['last'] = time();
601
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
602
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
603
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
604
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
605
+		//echo $buffer;
606
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
607
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
608
+		$all_data = json_decode($buffer,true);
609
+		if (json_last_error() != JSON_ERROR_NONE) {
610 610
 		die(json_last_error_msg());
611
-	    }
612
-	    if (isset($all_data['mrkrs'])) {
611
+		}
612
+		if (isset($all_data['mrkrs'])) {
613 613
 		$reset = 0;
614 614
 		foreach ($all_data['mrkrs'] as $key => $line) {
615
-		    if (isset($line['inf'])) {
615
+			if (isset($line['inf'])) {
616 616
 			$data = array();
617 617
 			$data['hex'] = $line['inf']['ia'];
618 618
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
619
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
620
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
621
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
622
-	    		$data['latitude'] = $line['pt'][0]; // lat
623
-	    		$data['longitude'] = $line['pt'][1]; // long
624
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
625
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
626
-	    		//$data['aircraft_icao'] = $line[8];
627
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
619
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
620
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
621
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
622
+				$data['latitude'] = $line['pt'][0]; // lat
623
+				$data['longitude'] = $line['pt'][1]; // long
624
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
625
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
626
+				//$data['aircraft_icao'] = $line[8];
627
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
628 628
 			//$data['departure_airport_iata'] = $line[11];
629 629
 			//$data['arrival_airport_iata'] = $line[12];
630
-	    		//$data['emergency'] = ''; // emergency
630
+				//$data['emergency'] = ''; // emergency
631 631
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
632
-	    		$data['format_source'] = 'radarvirtueljson';
633
-    			$data['id_source'] = $id_source;
632
+				$data['format_source'] = 'radarvirtueljson';
633
+				$data['id_source'] = $id_source;
634 634
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
635 635
 			$SI->add($data);
636 636
 			unset($data);
637
-		    }
637
+			}
638
+		}
638 639
 		}
639
-	    }
640
-    	    //$last_exec['radarvirtueljson'] = time();
641
-    	    $last_exec[$id]['last'] = time();
642
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
643
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
644
-	    //$buffer = $Common->getData($hosts[$id]);
645
-	    $buffer = $Common->getData($value['host'].'?'.time());
646
-	    $all_data = json_decode(utf8_encode($buffer),true);
640
+			//$last_exec['radarvirtueljson'] = time();
641
+			$last_exec[$id]['last'] = time();
642
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
643
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
644
+		//$buffer = $Common->getData($hosts[$id]);
645
+		$buffer = $Common->getData($value['host'].'?'.time());
646
+		$all_data = json_decode(utf8_encode($buffer),true);
647 647
 	    
648
-	    if (isset($all_data['pireps'])) {
648
+		if (isset($all_data['pireps'])) {
649 649
 		$reset = 0;
650
-	        foreach ($all_data['pireps'] as $line) {
651
-		    $data = array();
652
-		    $data['id'] = $line['id'];
653
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
654
-		    $data['ident'] = $line['callsign']; // ident
655
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
656
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
657
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
658
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
659
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
660
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
661
-		    $data['latitude'] = $line['lat']; // lat
662
-		    $data['longitude'] = $line['lon']; // long
663
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
664
-		    //$data['squawk'] = $line['squawk']; // squawk
665
-		    //$data['emergency'] = ''; // emergency
666
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
667
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
668
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
669
-		    //$data['arrival_airport_time'] = $line['arrtime'];
670
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
671
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
672
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
673
-		    else $data['info'] = '';
674
-		    $data['format_source'] = 'pireps';
675
-    		    $data['id_source'] = $id_source;
676
-		    $data['datetime'] = date('Y-m-d H:i:s');
677
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
678
-		    if ($line['icon'] == 'plane') {
650
+			foreach ($all_data['pireps'] as $line) {
651
+			$data = array();
652
+			$data['id'] = $line['id'];
653
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
654
+			$data['ident'] = $line['callsign']; // ident
655
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
656
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
657
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
658
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
659
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
660
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
661
+			$data['latitude'] = $line['lat']; // lat
662
+			$data['longitude'] = $line['lon']; // long
663
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
664
+			//$data['squawk'] = $line['squawk']; // squawk
665
+			//$data['emergency'] = ''; // emergency
666
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
667
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
668
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
669
+			//$data['arrival_airport_time'] = $line['arrtime'];
670
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
671
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
672
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
673
+			else $data['info'] = '';
674
+			$data['format_source'] = 'pireps';
675
+				$data['id_source'] = $id_source;
676
+			$data['datetime'] = date('Y-m-d H:i:s');
677
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
678
+			if ($line['icon'] == 'plane') {
679 679
 			$SI->add($data);
680
-		    //    print_r($data);
681
-    		    } elseif ($line['icon'] == 'ct') {
680
+			//    print_r($data);
681
+				} elseif ($line['icon'] == 'ct') {
682 682
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
683 683
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
684 684
 			$typec = substr($data['ident'],-3);
@@ -693,163 +693,163 @@  discard block
 block discarded – undo
693 693
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
694 694
 			else $data['type'] = 'Observer';
695 695
 			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']);
696
-		    }
697
-		    unset($data);
696
+			}
697
+			unset($data);
698
+		}
698 699
 		}
699
-	    }
700
-    	    //$last_exec['pirepsjson'] = time();
701
-    	    $last_exec[$id]['last'] = time();
702
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
703
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
704
-	    //$buffer = $Common->getData($hosts[$id]);
705
-	    if ($globalDebug) echo 'Get Data...'."\n";
706
-	    $buffer = $Common->getData($value['host']);
707
-	    $all_data = json_decode($buffer,true);
708
-	    if ($buffer != '' && is_array($all_data)) {
700
+			//$last_exec['pirepsjson'] = time();
701
+			$last_exec[$id]['last'] = time();
702
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
703
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
704
+		//$buffer = $Common->getData($hosts[$id]);
705
+		if ($globalDebug) echo 'Get Data...'."\n";
706
+		$buffer = $Common->getData($value['host']);
707
+		$all_data = json_decode($buffer,true);
708
+		if ($buffer != '' && is_array($all_data)) {
709 709
 		$reset = 0;
710 710
 		foreach ($all_data as $line) {
711
-	    	    $data = array();
712
-	    	    //$data['id'] = $line['id']; // id not usable
713
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
714
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
715
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
716
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
717
-	    	    $data['ident'] = $line['flightnum']; // ident
718
-	    	    $data['altitude'] = $line['alt']; // altitude
719
-	    	    $data['speed'] = $line['gs']; // speed
720
-	    	    $data['heading'] = $line['heading']; // heading
721
-	    	    $data['latitude'] = $line['lat']; // lat
722
-	    	    $data['longitude'] = $line['lng']; // long
723
-	    	    $data['verticalrate'] = ''; // verticale rate
724
-	    	    $data['squawk'] = ''; // squawk
725
-	    	    $data['emergency'] = ''; // emergency
726
-	    	    //$data['datetime'] = $line['lastupdate'];
727
-	    	    $data['last_update'] = $line['lastupdate'];
728
-		    $data['datetime'] = date('Y-m-d H:i:s');
729
-	    	    $data['departure_airport_icao'] = $line['depicao'];
730
-	    	    $data['departure_airport_time'] = $line['deptime'];
731
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
732
-    		    $data['arrival_airport_time'] = $line['arrtime'];
733
-    		    $data['registration'] = $line['aircraft'];
734
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
735
-		    if (isset($line['aircraftname'])) {
711
+				$data = array();
712
+				//$data['id'] = $line['id']; // id not usable
713
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
714
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
715
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
716
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
717
+				$data['ident'] = $line['flightnum']; // ident
718
+				$data['altitude'] = $line['alt']; // altitude
719
+				$data['speed'] = $line['gs']; // speed
720
+				$data['heading'] = $line['heading']; // heading
721
+				$data['latitude'] = $line['lat']; // lat
722
+				$data['longitude'] = $line['lng']; // long
723
+				$data['verticalrate'] = ''; // verticale rate
724
+				$data['squawk'] = ''; // squawk
725
+				$data['emergency'] = ''; // emergency
726
+				//$data['datetime'] = $line['lastupdate'];
727
+				$data['last_update'] = $line['lastupdate'];
728
+			$data['datetime'] = date('Y-m-d H:i:s');
729
+				$data['departure_airport_icao'] = $line['depicao'];
730
+				$data['departure_airport_time'] = $line['deptime'];
731
+				$data['arrival_airport_icao'] = $line['arricao'];
732
+				$data['arrival_airport_time'] = $line['arrtime'];
733
+				$data['registration'] = $line['aircraft'];
734
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
735
+			if (isset($line['aircraftname'])) {
736 736
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
737 737
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
738
-	    		$aircraft_data = explode('-',$line['aircraftname']);
739
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
740
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
741
-	    		else {
742
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
743
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
744
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
745
-	    		}
746
-	    	    }
747
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
748
-    		    $data['id_source'] = $id_source;
749
-	    	    $data['format_source'] = 'phpvmacars';
750
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
751
-		    $SI->add($data);
752
-		    unset($data);
738
+				$aircraft_data = explode('-',$line['aircraftname']);
739
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
740
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
741
+				else {
742
+					$aircraft_data = explode(' ',$line['aircraftname']);
743
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
744
+					else $data['aircraft_icao'] = $line['aircraftname'];
745
+				}
746
+				}
747
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
748
+				$data['id_source'] = $id_source;
749
+				$data['format_source'] = 'phpvmacars';
750
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
751
+			$SI->add($data);
752
+			unset($data);
753 753
 		}
754 754
 		if ($globalDebug) echo 'No more data...'."\n";
755 755
 		unset($buffer);
756 756
 		unset($all_data);
757
-	    }
758
-    	    //$last_exec['phpvmacars'] = time();
759
-    	    $last_exec[$id]['last'] = time();
760
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
761
-	    //$buffer = $Common->getData($hosts[$id]);
762
-	    if ($globalDebug) echo 'Get Data...'."\n";
763
-	    $buffer = $Common->getData($value['host']);
764
-	    $all_data = json_decode($buffer,true);
765
-	    if ($buffer != '' && is_array($all_data)) {
757
+		}
758
+			//$last_exec['phpvmacars'] = time();
759
+			$last_exec[$id]['last'] = time();
760
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
761
+		//$buffer = $Common->getData($hosts[$id]);
762
+		if ($globalDebug) echo 'Get Data...'."\n";
763
+		$buffer = $Common->getData($value['host']);
764
+		$all_data = json_decode($buffer,true);
765
+		if ($buffer != '' && is_array($all_data)) {
766 766
 		$reset = 0;
767 767
 		foreach ($all_data as $line) {
768
-	    	    $data = array();
769
-	    	    //$data['id'] = $line['id']; // id not usable
770
-	    	    $data['id'] = trim($line['flight_id']);
771
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
772
-	    	    $data['pilot_name'] = $line['pilot_name'];
773
-	    	    $data['pilot_id'] = $line['pilot_id'];
774
-	    	    $data['ident'] = trim($line['callsign']); // ident
775
-	    	    $data['altitude'] = $line['altitude']; // altitude
776
-	    	    $data['speed'] = $line['gs']; // speed
777
-	    	    $data['heading'] = $line['heading']; // heading
778
-	    	    $data['latitude'] = $line['latitude']; // lat
779
-	    	    $data['longitude'] = $line['longitude']; // long
780
-	    	    $data['verticalrate'] = ''; // verticale rate
781
-	    	    $data['squawk'] = ''; // squawk
782
-	    	    $data['emergency'] = ''; // emergency
783
-	    	    //$data['datetime'] = $line['lastupdate'];
784
-	    	    $data['last_update'] = $line['last_update'];
785
-		    $data['datetime'] = date('Y-m-d H:i:s');
786
-	    	    $data['departure_airport_icao'] = $line['departure'];
787
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
788
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
789
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
790
-    		    //$data['registration'] = $line['aircraft'];
791
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
792
-	    	    $data['aircraft_icao'] = $line['plane_type'];
793
-    		    $data['id_source'] = $id_source;
794
-	    	    $data['format_source'] = 'vam';
795
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
796
-		    $SI->add($data);
797
-		    unset($data);
768
+				$data = array();
769
+				//$data['id'] = $line['id']; // id not usable
770
+				$data['id'] = trim($line['flight_id']);
771
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
772
+				$data['pilot_name'] = $line['pilot_name'];
773
+				$data['pilot_id'] = $line['pilot_id'];
774
+				$data['ident'] = trim($line['callsign']); // ident
775
+				$data['altitude'] = $line['altitude']; // altitude
776
+				$data['speed'] = $line['gs']; // speed
777
+				$data['heading'] = $line['heading']; // heading
778
+				$data['latitude'] = $line['latitude']; // lat
779
+				$data['longitude'] = $line['longitude']; // long
780
+				$data['verticalrate'] = ''; // verticale rate
781
+				$data['squawk'] = ''; // squawk
782
+				$data['emergency'] = ''; // emergency
783
+				//$data['datetime'] = $line['lastupdate'];
784
+				$data['last_update'] = $line['last_update'];
785
+			$data['datetime'] = date('Y-m-d H:i:s');
786
+				$data['departure_airport_icao'] = $line['departure'];
787
+				//$data['departure_airport_time'] = $line['departure_time'];
788
+				$data['arrival_airport_icao'] = $line['arrival'];
789
+				//$data['arrival_airport_time'] = $line['arrival_time'];
790
+				//$data['registration'] = $line['aircraft'];
791
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
792
+				$data['aircraft_icao'] = $line['plane_type'];
793
+				$data['id_source'] = $id_source;
794
+				$data['format_source'] = 'vam';
795
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
796
+			$SI->add($data);
797
+			unset($data);
798 798
 		}
799 799
 		if ($globalDebug) echo 'No more data...'."\n";
800 800
 		unset($buffer);
801 801
 		unset($all_data);
802
-	    }
803
-    	    //$last_exec['phpvmacars'] = time();
804
-    	    $last_exec[$id]['last'] = time();
802
+		}
803
+			//$last_exec['phpvmacars'] = time();
804
+			$last_exec[$id]['last'] = time();
805 805
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
806 806
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3') {
807
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
808
-    	    //$last_exec[$id]['last'] = time();
807
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
808
+			//$last_exec[$id]['last'] = time();
809 809
 
810
-	    //$read = array( $sockets[$id] );
811
-	    $read = $sockets;
812
-	    $write = NULL;
813
-	    $e = NULL;
814
-	    $n = socket_select($read, $write, $e, $timeout);
815
-	    if ($e != NULL) var_dump($e);
816
-	    if ($n > 0) {
810
+		//$read = array( $sockets[$id] );
811
+		$read = $sockets;
812
+		$write = NULL;
813
+		$e = NULL;
814
+		$n = socket_select($read, $write, $e, $timeout);
815
+		if ($e != NULL) var_dump($e);
816
+		if ($n > 0) {
817 817
 		$reset = 0;
818 818
 		foreach ($read as $nb => $r) {
819
-		    //$value = $formats[$nb];
820
-		    $format = $globalSources[$nb]['format'];
821
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
822
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
823
-        	    } else {
824
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
825
-	    	    }
826
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
827
-        	    //echo $buffer."\n";
828
-		    // lets play nice and handle signals such as ctrl-c/kill properly
829
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
830
-		    $error = false;
831
-		    //$SI::del();
832
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
833
-		    // SBS format is CSV format
834
-		    if ($buffer != '') {
819
+			//$value = $formats[$nb];
820
+			$format = $globalSources[$nb]['format'];
821
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
822
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
823
+				} else {
824
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
825
+				}
826
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
827
+				//echo $buffer."\n";
828
+			// lets play nice and handle signals such as ctrl-c/kill properly
829
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
830
+			$error = false;
831
+			//$SI::del();
832
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
833
+			// SBS format is CSV format
834
+			if ($buffer != '') {
835 835
 			$tt[$format] = 0;
836 836
 			if ($format == 'acarssbs3') {
837
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
838
-			    $ACARS->add(trim($buffer));
839
-			    $ACARS->deleteLiveAcarsData();
837
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
838
+				$ACARS->add(trim($buffer));
839
+				$ACARS->deleteLiveAcarsData();
840 840
 			} elseif ($format == 'raw') {
841
-			    // AVR format
842
-			    $data = $SBS->parse($buffer);
843
-			    if (is_array($data)) {
841
+				// AVR format
842
+				$data = $SBS->parse($buffer);
843
+				if (is_array($data)) {
844 844
 				$data['datetime'] = date('Y-m-d H:i:s');
845 845
 				$data['format_source'] = 'raw';
846 846
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
847
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
848
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
849
-                            }
850
-                        } elseif ($format == 'flightgearsp') {
851
-                    	    //echo $buffer."\n";
852
-                    	    if (strlen($buffer) > 5) {
847
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
848
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
849
+							}
850
+						} elseif ($format == 'flightgearsp') {
851
+							//echo $buffer."\n";
852
+							if (strlen($buffer) > 5) {
853 853
 				$line = explode(',',$buffer);
854 854
 				$data = array();
855 855
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -865,114 +865,114 @@  discard block
 block discarded – undo
865 865
 				$data['format_source'] = 'flightgearsp';
866 866
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
867 867
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
868
-			    }
869
-                        } elseif ($format == 'acars') {
870
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
871
-			    $ACARS->add(trim($buffer));
872
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
873
-			    $ACARS->deleteLiveAcarsData();
868
+				}
869
+						} elseif ($format == 'acars') {
870
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
871
+				$ACARS->add(trim($buffer));
872
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
873
+				$ACARS->deleteLiveAcarsData();
874 874
 			} elseif ($format == 'flightgearmp') {
875
-			    if (substr($buffer,0,1) != '#') {
875
+				if (substr($buffer,0,1) != '#') {
876 876
 				$data = array();
877 877
 				//echo $buffer."\n";
878 878
 				$line = explode(' ',$buffer);
879 879
 				if (count($line) == 11) {
880
-				    $userserver = explode('@',$line[0]);
881
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
882
-				    $data['ident'] = $userserver[0];
883
-				    $data['registration'] = $userserver[0];
884
-				    $data['latitude'] = $line[4];
885
-				    $data['longitude'] = $line[5];
886
-				    $data['altitude'] = $line[6];
887
-				    $data['datetime'] = date('Y-m-d H:i:s');
888
-				    $aircraft_type = $line[10];
889
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
890
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
891
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
880
+					$userserver = explode('@',$line[0]);
881
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
882
+					$data['ident'] = $userserver[0];
883
+					$data['registration'] = $userserver[0];
884
+					$data['latitude'] = $line[4];
885
+					$data['longitude'] = $line[5];
886
+					$data['altitude'] = $line[6];
887
+					$data['datetime'] = date('Y-m-d H:i:s');
888
+					$aircraft_type = $line[10];
889
+					$aircraft_type = preg_split(':/:',$aircraft_type);
890
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
891
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
892
+				}
892 893
 				}
893
-			    }
894 894
 			} elseif ($format == 'beast') {
895
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
896
-			    die;
895
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
896
+				die;
897 897
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
898
-			    $line = explode("\t", $buffer);
899
-			    for($k = 0; $k < count($line); $k=$k+2) {
898
+				$line = explode("\t", $buffer);
899
+				for($k = 0; $k < count($line); $k=$k+2) {
900 900
 				$key = $line[$k];
901
-			        $lined[$key] = $line[$k+1];
902
-			    }
903
-    			    if (count($lined) > 3) {
904
-    				$data['hex'] = $lined['hexid'];
905
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
906
-    				$data['datetime'] = date('Y-m-d H:i:s');;
907
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
908
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
909
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
910
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
911
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
912
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
913
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
914
-    				$data['id_source'] = $id_source;
915
-    				$data['format_source'] = 'tsv';
916
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
917
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
918
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
919
-    				unset($lined);
920
-    				unset($data);
921
-    			    } else $error = true;
901
+					$lined[$key] = $line[$k+1];
902
+				}
903
+					if (count($lined) > 3) {
904
+					$data['hex'] = $lined['hexid'];
905
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
906
+					$data['datetime'] = date('Y-m-d H:i:s');;
907
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
908
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
909
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
910
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
911
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
912
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
913
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
914
+					$data['id_source'] = $id_source;
915
+					$data['format_source'] = 'tsv';
916
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
917
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
918
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
919
+					unset($lined);
920
+					unset($data);
921
+					} else $error = true;
922 922
 			} elseif ($format == 'aprs' && $use_aprs) {
923
-			    if ($aprs_connect == 0) {
923
+				if ($aprs_connect == 0) {
924 924
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
925 925
 				$aprs_connect = 1;
926
-			    }
927
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
926
+				}
927
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
928 928
 				$aprs_last_tx = time();
929 929
 				$data_aprs = "# Keep alive";
930 930
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
931
-			    }
932
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
933
-			    $buffer = str_replace('APRS <- ','',$buffer);
934
-			    $buffer = str_replace('APRS -> ','',$buffer);
935
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
931
+				}
932
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
933
+				$buffer = str_replace('APRS <- ','',$buffer);
934
+				$buffer = str_replace('APRS -> ','',$buffer);
935
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
936 936
 				$line = $APRS->parse($buffer);
937 937
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
938
-				    $data = array();
939
-				    //print_r($line);
940
-				    $data['hex'] = $line['address'];
941
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
942
-				    //$data['datetime'] = date('Y-m-d H:i:s');
943
-				    $data['ident'] = $line['ident'];
944
-				    $data['latitude'] = $line['latitude'];
945
-				    $data['longitude'] = $line['longitude'];
946
-				    //$data['verticalrate'] = $line[16];
947
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
948
-				    else $data['speed'] = 0;
949
-				    $data['altitude'] = $line['altitude'];
950
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
951
-				    //else $data['heading'] = 0;
952
-				    $data['aircraft_type'] = $line['stealth'];
953
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
954
-    				    $data['id_source'] = $id_source;
955
-				    $data['format_source'] = 'aprs';
956
-				    $data['source_name'] = $line['source'];
957
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
958
-				    $currentdate = date('Y-m-d H:i:s');
959
-				    $aprsdate = strtotime($data['datetime']);
960
-				    // Accept data if time <= system time + 20s
961
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
962
-				    else {
938
+					$data = array();
939
+					//print_r($line);
940
+					$data['hex'] = $line['address'];
941
+					$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
942
+					//$data['datetime'] = date('Y-m-d H:i:s');
943
+					$data['ident'] = $line['ident'];
944
+					$data['latitude'] = $line['latitude'];
945
+					$data['longitude'] = $line['longitude'];
946
+					//$data['verticalrate'] = $line[16];
947
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
948
+					else $data['speed'] = 0;
949
+					$data['altitude'] = $line['altitude'];
950
+					if (isset($line['course'])) $data['heading'] = $line['course'];
951
+					//else $data['heading'] = 0;
952
+					$data['aircraft_type'] = $line['stealth'];
953
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
954
+						$data['id_source'] = $id_source;
955
+					$data['format_source'] = 'aprs';
956
+					$data['source_name'] = $line['source'];
957
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
958
+					$currentdate = date('Y-m-d H:i:s');
959
+					$aprsdate = strtotime($data['datetime']);
960
+					// Accept data if time <= system time + 20s
961
+					if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
962
+					else {
963 963
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
964 964
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
965
-				    }
966
-				    unset($data);
965
+					}
966
+					unset($data);
967 967
 				} 
968 968
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
969 969
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
970
-			    }
970
+				}
971 971
 			} else {
972
-			    $line = explode(',', $buffer);
973
-    			    if (count($line) > 20) {
974
-    			    	$data['hex'] = $line[4];
975
-    				/*
972
+				$line = explode(',', $buffer);
973
+					if (count($line) > 20) {
974
+						$data['hex'] = $line[4];
975
+					/*
976 976
     				$data['datetime'] = $line[6].' '.$line[7];
977 977
     					date_default_timezone_set($globalTimezone);
978 978
     					$datetime = new DateTime($data['datetime']);
@@ -980,29 +980,29 @@  discard block
 block discarded – undo
980 980
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
981 981
     					date_default_timezone_set('UTC');
982 982
     				*/
983
-    				// Force datetime to current UTC datetime
984
-    				date_default_timezone_set('UTC');
985
-    				$data['datetime'] = date('Y-m-d H:i:s');
986
-    				$data['ident'] = trim($line[10]);
987
-    				$data['latitude'] = $line[14];
988
-    				$data['longitude'] = $line[15];
989
-    				$data['verticalrate'] = $line[16];
990
-    				$data['emergency'] = $line[20];
991
-    				$data['speed'] = $line[12];
992
-    				$data['squawk'] = $line[17];
993
-    				$data['altitude'] = $line[11];
994
-    				$data['heading'] = $line[13];
995
-    				$data['ground'] = $line[21];
996
-    				$data['emergency'] = $line[19];
997
-    				$data['format_source'] = 'sbs';
983
+					// Force datetime to current UTC datetime
984
+					date_default_timezone_set('UTC');
985
+					$data['datetime'] = date('Y-m-d H:i:s');
986
+					$data['ident'] = trim($line[10]);
987
+					$data['latitude'] = $line[14];
988
+					$data['longitude'] = $line[15];
989
+					$data['verticalrate'] = $line[16];
990
+					$data['emergency'] = $line[20];
991
+					$data['speed'] = $line[12];
992
+					$data['squawk'] = $line[17];
993
+					$data['altitude'] = $line[11];
994
+					$data['heading'] = $line[13];
995
+					$data['ground'] = $line[21];
996
+					$data['emergency'] = $line[19];
997
+					$data['format_source'] = 'sbs';
998 998
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
999
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1000
-    				$data['id_source'] = $id_source;
1001
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1002
-    				else $error = true;
1003
-    				unset($data);
1004
-    			    } else $error = true;
1005
-			    if ($error) {
999
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1000
+					$data['id_source'] = $id_source;
1001
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1002
+					else $error = true;
1003
+					unset($data);
1004
+					} else $error = true;
1005
+				if ($error) {
1006 1006
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1007 1007
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1008 1008
 				} else {
@@ -1018,13 +1018,13 @@  discard block
 block discarded – undo
1018 1018
 					connect_all($sourceer);
1019 1019
 					$sourceer = array();
1020 1020
 				}
1021
-			    }
1021
+				}
1022 1022
 			}
1023 1023
 			// Sleep for xxx microseconds
1024 1024
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1025
-		    } else {
1025
+			} else {
1026 1026
 			if ($format == 'flightgearmp') {
1027
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1027
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1028 1028
 				//@socket_close($r);
1029 1029
 				sleep($globalMinFetch);
1030 1030
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1033,9 +1033,9 @@  discard block
 block discarded – undo
1033 1033
 				break;
1034 1034
 				
1035 1035
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1036
-			    if (isset($tt[$format])) $tt[$format]++;
1037
-			    else $tt[$format] = 0;
1038
-			    if ($tt[$format] > 30) {
1036
+				if (isset($tt[$format])) $tt[$format]++;
1037
+				else $tt[$format] = 0;
1038
+				if ($tt[$format] > 30) {
1039 1039
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1040 1040
 				//@socket_close($r);
1041 1041
 				sleep(2);
@@ -1046,23 +1046,23 @@  discard block
 block discarded – undo
1046 1046
 				//connect_all($globalSources);
1047 1047
 				$tt[$format]=0;
1048 1048
 				break;
1049
-			    }
1049
+				}
1050
+			}
1050 1051
 			}
1051
-		    }
1052 1052
 		}
1053
-	    } else {
1053
+		} else {
1054 1054
 		$error = socket_strerror(socket_last_error());
1055 1055
 		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1056 1056
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1057 1057
 			if (isset($globalDebug)) echo "Restarting...\n";
1058 1058
 			// Restart the script if possible
1059 1059
 			if (is_array($sockets)) {
1060
-			    if ($globalDebug) echo "Shutdown all sockets...";
1060
+				if ($globalDebug) echo "Shutdown all sockets...";
1061 1061
 			    
1062
-			    foreach ($sockets as $sock) {
1062
+				foreach ($sockets as $sock) {
1063 1063
 				@socket_shutdown($sock,2);
1064 1064
 				@socket_close($sock);
1065
-			    }
1065
+				}
1066 1066
 			    
1067 1067
 			}
1068 1068
 			if ($globalDebug) echo "Restart all connections...";
@@ -1073,13 +1073,13 @@  discard block
 block discarded – undo
1073 1073
 			if ($reset > 40) exit('Too many attempts...');
1074 1074
 			connect_all($globalSources);
1075 1075
 		}
1076
-	    }
1076
+		}
1077 1077
 	}
1078 1078
 	if ($globalDaemon === false) {
1079
-	    if ($globalDebug) echo 'Check all...'."\n";
1080
-	    $SI->checkAll();
1079
+		if ($globalDebug) echo 'Check all...'."\n";
1080
+		$SI->checkAll();
1081
+	}
1081 1082
 	}
1082
-    }
1083 1083
 }
1084 1084
 
1085 1085
 ?>
Please login to merge, or discard this patch.