@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | require_once(dirname(__FILE__).'/../require/class.Connection.php'); |
15 | 15 | require_once(dirname(__FILE__).'/../require/class.Common.php'); |
16 | 16 | |
17 | -if (!isset($globalDebug)) $globalDebug = FALSE; |
|
17 | +if (!isset($globalDebug)) { |
|
18 | + $globalDebug = FALSE; |
|
19 | +} |
|
18 | 20 | |
19 | 21 | // Check if schema is at latest version |
20 | 22 | $Connection = new Connection(); |
@@ -51,13 +53,22 @@ discard block |
||
51 | 53 | $globalSources = array(); |
52 | 54 | $globalSources[] = array('host' => $options['source']); |
53 | 55 | } |
54 | -if (isset($options['server'])) $globalServer = TRUE; |
|
55 | -if (isset($options['idsource'])) $id_source = $options['idsource']; |
|
56 | -else $id_source = 1; |
|
56 | +if (isset($options['server'])) { |
|
57 | + $globalServer = TRUE; |
|
58 | +} |
|
59 | +if (isset($options['idsource'])) { |
|
60 | + $id_source = $options['idsource']; |
|
61 | +} else { |
|
62 | + $id_source = 1; |
|
63 | +} |
|
57 | 64 | if (isset($globalServer) && $globalServer) { |
58 | - if ($globalDebug) echo "Using Server Mode\n"; |
|
65 | + if ($globalDebug) { |
|
66 | + echo "Using Server Mode\n"; |
|
67 | + } |
|
59 | 68 | $SI=new SpotterServer(); |
60 | -} else $SI=new SpotterImport($Connection->db); |
|
69 | +} else { |
|
70 | + $SI=new SpotterImport($Connection->db); |
|
71 | +} |
|
61 | 72 | //$APRS=new APRS($Connection->db); |
62 | 73 | $SBS=new SBS(); |
63 | 74 | $ACARS=new ACARS($Connection->db); |
@@ -75,7 +86,9 @@ discard block |
||
75 | 86 | } |
76 | 87 | |
77 | 88 | // let's try and connect |
78 | -if ($globalDebug) echo "Connecting...\n"; |
|
89 | +if ($globalDebug) { |
|
90 | + echo "Connecting...\n"; |
|
91 | +} |
|
79 | 92 | $use_aprs = false; |
80 | 93 | $aprs_full = false; |
81 | 94 | |
@@ -83,7 +96,9 @@ discard block |
||
83 | 96 | $ip = gethostbyname($host); |
84 | 97 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
85 | 98 | $r = @socket_connect($s, $ip, $port); |
86 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
99 | + if (!socket_set_nonblock($s)) { |
|
100 | + echo "Unable to set nonblock on socket\n"; |
|
101 | + } |
|
87 | 102 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
88 | 103 | return $s; |
89 | 104 | } |
@@ -110,7 +125,9 @@ discard block |
||
110 | 125 | function connect_all($hosts) { |
111 | 126 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
112 | 127 | global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
113 | - if ($globalDebug) echo 'Connect to all...'."\n"; |
|
128 | + if ($globalDebug) { |
|
129 | + echo 'Connect to all...'."\n"; |
|
130 | + } |
|
114 | 131 | foreach ($hosts as $id => $value) { |
115 | 132 | $host = $value['host']; |
116 | 133 | $globalSources[$id]['last_exec'] = 0; |
@@ -120,27 +137,37 @@ discard block |
||
120 | 137 | //$formats[$id] = 'deltadbtxt'; |
121 | 138 | $globalSources[$id]['format'] = 'deltadbtxt'; |
122 | 139 | //$last_exec['deltadbtxt'] = 0; |
123 | - if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
140 | + if ($globalDebug) { |
|
141 | + echo "Connect to deltadb source (".$host.")...\n"; |
|
142 | + } |
|
124 | 143 | } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
125 | 144 | //$formats[$id] = 'vatsimtxt'; |
126 | 145 | $globalSources[$id]['format'] = 'vatsimtxt'; |
127 | 146 | //$last_exec['vatsimtxt'] = 0; |
128 | - if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
147 | + if ($globalDebug) { |
|
148 | + echo "Connect to vatsim source (".$host.")...\n"; |
|
149 | + } |
|
129 | 150 | } else if (preg_match('/aircraftlist.json$/i',$host)) { |
130 | 151 | //$formats[$id] = 'aircraftlistjson'; |
131 | 152 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
132 | 153 | //$last_exec['aircraftlistjson'] = 0; |
133 | - if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
154 | + if ($globalDebug) { |
|
155 | + echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
156 | + } |
|
134 | 157 | } else if (preg_match('/opensky/i',$host)) { |
135 | 158 | //$formats[$id] = 'aircraftlistjson'; |
136 | 159 | $globalSources[$id]['format'] = 'opensky'; |
137 | 160 | //$last_exec['aircraftlistjson'] = 0; |
138 | - if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
161 | + if ($globalDebug) { |
|
162 | + echo "Connect to opensky source (".$host.")...\n"; |
|
163 | + } |
|
139 | 164 | } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
140 | 165 | //$formats[$id] = 'radarvirtueljson'; |
141 | 166 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
142 | 167 | //$last_exec['radarvirtueljson'] = 0; |
143 | - if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
168 | + if ($globalDebug) { |
|
169 | + echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
170 | + } |
|
144 | 171 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
145 | 172 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
146 | 173 | exit(0); |
@@ -149,7 +176,9 @@ discard block |
||
149 | 176 | //$formats[$id] = 'planeupdatefaa'; |
150 | 177 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
151 | 178 | //$last_exec['planeupdatefaa'] = 0; |
152 | - if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
179 | + if ($globalDebug) { |
|
180 | + echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
181 | + } |
|
153 | 182 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
154 | 183 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
155 | 184 | exit(0); |
@@ -158,22 +187,30 @@ discard block |
||
158 | 187 | //$formats[$id] = 'phpvmacars'; |
159 | 188 | $globalSources[$id]['format'] = 'phpvmacars'; |
160 | 189 | //$last_exec['phpvmacars'] = 0; |
161 | - if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
190 | + if ($globalDebug) { |
|
191 | + echo "Connect to phpvmacars source (".$host.")...\n"; |
|
192 | + } |
|
162 | 193 | } else if (preg_match('/whazzup/i',$host)) { |
163 | 194 | //$formats[$id] = 'whazzup'; |
164 | 195 | $globalSources[$id]['format'] = 'whazzup'; |
165 | 196 | //$last_exec['whazzup'] = 0; |
166 | - if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
197 | + if ($globalDebug) { |
|
198 | + echo "Connect to whazzup source (".$host.")...\n"; |
|
199 | + } |
|
167 | 200 | } else if (preg_match('/recentpireps/i',$host)) { |
168 | 201 | //$formats[$id] = 'pirepsjson'; |
169 | 202 | $globalSources[$id]['format'] = 'pirepsjson'; |
170 | 203 | //$last_exec['pirepsjson'] = 0; |
171 | - if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
204 | + if ($globalDebug) { |
|
205 | + echo "Connect to pirepsjson source (".$host.")...\n"; |
|
206 | + } |
|
172 | 207 | } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
173 | 208 | //$formats[$id] = 'fr24json'; |
174 | 209 | $globalSources[$id]['format'] = 'fr24json'; |
175 | 210 | //$last_exec['fr24json'] = 0; |
176 | - if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
211 | + if ($globalDebug) { |
|
212 | + echo "Connect to fr24 source (".$host.")...\n"; |
|
213 | + } |
|
177 | 214 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
178 | 215 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
179 | 216 | exit(0); |
@@ -182,10 +219,14 @@ discard block |
||
182 | 219 | } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
183 | 220 | //$formats[$id] = 'tsv'; |
184 | 221 | $globalSources[$id]['format'] = 'tsv'; |
185 | - if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
222 | + if ($globalDebug) { |
|
223 | + echo "Connect to tsv source (".$host.")...\n"; |
|
224 | + } |
|
186 | 225 | } |
187 | 226 | } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
188 | - if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
227 | + if ($globalDebug) { |
|
228 | + echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
229 | + } |
|
189 | 230 | } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
190 | 231 | $hostport = explode(':',$host); |
191 | 232 | if (isset($hostport[1])) { |
@@ -222,17 +263,25 @@ discard block |
||
222 | 263 | //$formats[$id] = 'beast'; |
223 | 264 | $globalSources[$id]['format'] = 'beast'; |
224 | 265 | //} else $formats[$id] = 'sbs'; |
225 | - } else $globalSources[$id]['format'] = 'sbs'; |
|
266 | + } else { |
|
267 | + $globalSources[$id]['format'] = 'sbs'; |
|
268 | + } |
|
226 | 269 | //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
227 | 270 | } |
228 | - if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
271 | + if ($globalDebug) { |
|
272 | + echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
273 | + } |
|
229 | 274 | } else { |
230 | - if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
275 | + if ($globalDebug) { |
|
276 | + echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
277 | + } |
|
231 | 278 | } |
232 | 279 | } |
233 | 280 | } |
234 | 281 | } |
235 | -if (!isset($globalMinFetch)) $globalMinFetch = 15; |
|
282 | +if (!isset($globalMinFetch)) { |
|
283 | + $globalMinFetch = 15; |
|
284 | +} |
|
236 | 285 | |
237 | 286 | // Initialize all |
238 | 287 | $status = array(); |
@@ -240,13 +289,19 @@ discard block |
||
240 | 289 | $formats = array(); |
241 | 290 | $last_exec = array(); |
242 | 291 | $time = time(); |
243 | -if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut; |
|
244 | -else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
|
245 | -else $timeout = 20; |
|
292 | +if (isset($globalSourcesTimeout)) { |
|
293 | + $timeout = $globalSourcesTimeOut; |
|
294 | +} else if (isset($globalSBS1TimeOut)) { |
|
295 | + $timeout = $globalSBS1TimeOut; |
|
296 | +} else { |
|
297 | + $timeout = 20; |
|
298 | +} |
|
246 | 299 | $errno = ''; |
247 | 300 | $errstr=''; |
248 | 301 | |
249 | -if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
302 | +if (!isset($globalDaemon)) { |
|
303 | + $globalDaemon = TRUE; |
|
304 | +} |
|
250 | 305 | /* Initiate connections to all the hosts simultaneously */ |
251 | 306 | //connect_all($hosts); |
252 | 307 | //connect_all($globalSources); |
@@ -266,7 +321,9 @@ discard block |
||
266 | 321 | if (isset($source['format']) && $source['format'] == 'aprs') { |
267 | 322 | $aprs_connect = 0; |
268 | 323 | $use_aprs = true; |
269 | - if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true; |
|
324 | + if (isset($source['port']) && $source['port'] == '10152') { |
|
325 | + $aprs_full = true; |
|
326 | + } |
|
270 | 327 | break; |
271 | 328 | } |
272 | 329 | } |
@@ -277,24 +334,44 @@ discard block |
||
277 | 334 | $aprs_connect = 0; |
278 | 335 | $aprs_keep = 120; |
279 | 336 | $aprs_last_tx = time(); |
280 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
281 | - else $aprs_version = $globalName.' using FlightAirMap'; |
|
337 | + if (isset($globalAPRSversion)) { |
|
338 | + $aprs_version = $globalAPRSversion; |
|
339 | + } else { |
|
340 | + $aprs_version = $globalName.' using FlightAirMap'; |
|
341 | + } |
|
282 | 342 | //else $aprs_version = 'Perl Example App'; |
283 | - if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
|
284 | - else $aprs_ssid = 'FAM'; |
|
343 | + if (isset($globalAPRSssid)) { |
|
344 | + $aprs_ssid = $globalAPRSssid; |
|
345 | + } else { |
|
346 | + $aprs_ssid = 'FAM'; |
|
347 | + } |
|
285 | 348 | //else $aprs_ssid = 'PerlEx'; |
286 | - if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
|
287 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
288 | - if ($aprs_full) $aprs_filter = ''; |
|
289 | - if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n"; |
|
290 | - else $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n"; |
|
291 | -} |
|
349 | + if (isset($globalAPRSfilter)) { |
|
350 | + $aprs_filter = $globalAPRSfilter; |
|
351 | + } else { |
|
352 | + $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
353 | + } |
|
354 | + if ($aprs_full) { |
|
355 | + $aprs_filter = ''; |
|
356 | + } |
|
357 | + if ($aprs_filter != '') { |
|
358 | + $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n"; |
|
359 | + } else { |
|
360 | + $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n"; |
|
361 | + } |
|
362 | + } |
|
292 | 363 | |
293 | 364 | // connected - lets do some work |
294 | -if ($globalDebug) echo "Connected!\n"; |
|
365 | +if ($globalDebug) { |
|
366 | + echo "Connected!\n"; |
|
367 | +} |
|
295 | 368 | sleep(1); |
296 | -if ($globalDebug) echo "SCAN MODE \n\n"; |
|
297 | -if (!isset($globalCronEnd)) $globalCronEnd = 60; |
|
369 | +if ($globalDebug) { |
|
370 | + echo "SCAN MODE \n\n"; |
|
371 | +} |
|
372 | +if (!isset($globalCronEnd)) { |
|
373 | + $globalCronEnd = 60; |
|
374 | +} |
|
298 | 375 | $endtime = time()+$globalCronEnd; |
299 | 376 | $i = 1; |
300 | 377 | $tt = array(); |
@@ -308,20 +385,28 @@ discard block |
||
308 | 385 | |
309 | 386 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
310 | 387 | while ($i > 0) { |
311 | - if (!$globalDaemon) $i = $endtime-time(); |
|
388 | + if (!$globalDaemon) { |
|
389 | + $i = $endtime-time(); |
|
390 | + } |
|
312 | 391 | // Delete old ATC |
313 | 392 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
314 | - if ($globalDebug) echo 'Delete old ATC...'."\n"; |
|
393 | + if ($globalDebug) { |
|
394 | + echo 'Delete old ATC...'."\n"; |
|
395 | + } |
|
315 | 396 | $ATC->deleteOldATC(); |
316 | 397 | } |
317 | 398 | |
318 | 399 | if (count($last_exec) > 0) { |
319 | 400 | $max = $globalMinFetch; |
320 | 401 | foreach ($last_exec as $last) { |
321 | - if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
402 | + if ((time() - $last['last']) < $max) { |
|
403 | + $max = time() - $last['last']; |
|
404 | + } |
|
322 | 405 | } |
323 | 406 | if ($max != $globalMinFetch) { |
324 | - if ($globalDebug) echo 'Sleeping...'."\n"; |
|
407 | + if ($globalDebug) { |
|
408 | + echo 'Sleeping...'."\n"; |
|
409 | + } |
|
325 | 410 | sleep($globalMinFetch-$max+2); |
326 | 411 | } |
327 | 412 | } |
@@ -329,7 +414,9 @@ discard block |
||
329 | 414 | |
330 | 415 | //foreach ($formats as $id => $value) { |
331 | 416 | foreach ($globalSources as $id => $value) { |
332 | - if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0; |
|
417 | + if (!isset($last_exec[$id]['last'])) { |
|
418 | + $last_exec[$id]['last'] = 0; |
|
419 | + } |
|
333 | 420 | if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
334 | 421 | //$buffer = $Common->getData($hosts[$id]); |
335 | 422 | $buffer = $Common->getData($value['host']); |
@@ -352,8 +439,12 @@ discard block |
||
352 | 439 | $data['datetime'] = date('Y-m-d H:i:s'); |
353 | 440 | $data['format_source'] = 'deltadbtxt'; |
354 | 441 | $data['id_source'] = $id_source; |
355 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
356 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
442 | + if (isset($value['name']) && $value['name'] != '') { |
|
443 | + $data['source_name'] = $value['name']; |
|
444 | + } |
|
445 | + if (isset($value['sourcestats'])) { |
|
446 | + $data['sourcestats'] = $value['sourcestats']; |
|
447 | + } |
|
357 | 448 | $SI->add($data); |
358 | 449 | unset($data); |
359 | 450 | } |
@@ -375,10 +466,19 @@ discard block |
||
375 | 466 | $data['pilot_name'] = $line[2]; |
376 | 467 | $data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT); |
377 | 468 | $data['ident'] = $line[0]; // ident |
378 | - if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
|
469 | + if ($line[7] != '' && $line[7] != 0) { |
|
470 | + $data['altitude'] = $line[7]; |
|
471 | + } |
|
472 | + // altitude |
|
379 | 473 | $data['speed'] = $line[8]; // speed |
380 | - if (isset($line[45])) $data['heading'] = $line[45]; // heading |
|
381 | - elseif (isset($line[38])) $data['heading'] = $line[38]; // heading |
|
474 | + if (isset($line[45])) { |
|
475 | + $data['heading'] = $line[45]; |
|
476 | + } |
|
477 | + // heading |
|
478 | + elseif (isset($line[38])) { |
|
479 | + $data['heading'] = $line[38]; |
|
480 | + } |
|
481 | + // heading |
|
382 | 482 | $data['latitude'] = $line[5]; // lat |
383 | 483 | $data['longitude'] = $line[6]; // long |
384 | 484 | $data['verticalrate'] = ''; // vertical rate |
@@ -387,14 +487,18 @@ discard block |
||
387 | 487 | $data['waypoints'] = $line[30]; |
388 | 488 | $data['datetime'] = date('Y-m-d H:i:s'); |
389 | 489 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37])); |
390 | - if (isset($line[37])) $data['last_update'] = $line[37] |
|
490 | + if (isset($line[37])) { |
|
491 | + $data['last_update'] = $line[37] |
|
391 | 492 | $data['departure_airport_icao'] = $line[11]; |
493 | + } |
|
392 | 494 | $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
393 | 495 | $data['arrival_airport_icao'] = $line[13]; |
394 | 496 | $data['frequency'] = $line[4]; |
395 | 497 | $data['type'] = $line[18]; |
396 | 498 | $data['range'] = $line[19]; |
397 | - if (isset($line[35])) $data['info'] = $line[35]; |
|
499 | + if (isset($line[35])) { |
|
500 | + $data['info'] = $line[35]; |
|
501 | + } |
|
398 | 502 | $data['id_source'] = $id_source; |
399 | 503 | //$data['arrival_airport_time'] = ; |
400 | 504 | if ($line[9] != '') { |
@@ -408,22 +512,35 @@ discard block |
||
408 | 512 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt'; |
409 | 513 | */ |
410 | 514 | $data['format_source'] = $value['format']; |
411 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
412 | - if ($line[3] == 'PILOT') $SI->add($data); |
|
413 | - elseif ($line[3] == 'ATC') { |
|
515 | + if (isset($value['name']) && $value['name'] != '') { |
|
516 | + $data['source_name'] = $value['name']; |
|
517 | + } |
|
518 | + if ($line[3] == 'PILOT') { |
|
519 | + $SI->add($data); |
|
520 | + } elseif ($line[3] == 'ATC') { |
|
414 | 521 | //print_r($data); |
415 | 522 | $data['info'] = str_replace('^§','<br />',$data['info']); |
416 | 523 | $data['info'] = str_replace('&sect;','',$data['info']); |
417 | 524 | $typec = substr($data['ident'],-3); |
418 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
419 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
420 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
421 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
422 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
423 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
424 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
425 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
426 | - elseif ($data['type'] == '') $data['type'] = 'Observer'; |
|
525 | + if ($typec == 'APP') { |
|
526 | + $data['type'] = 'Approach'; |
|
527 | + } elseif ($typec == 'TWR') { |
|
528 | + $data['type'] = 'Tower'; |
|
529 | + } elseif ($typec == 'OBS') { |
|
530 | + $data['type'] = 'Observer'; |
|
531 | + } elseif ($typec == 'GND') { |
|
532 | + $data['type'] = 'Ground'; |
|
533 | + } elseif ($typec == 'DEL') { |
|
534 | + $data['type'] = 'Delivery'; |
|
535 | + } elseif ($typec == 'DEP') { |
|
536 | + $data['type'] = 'Departure'; |
|
537 | + } elseif ($typec == 'FSS') { |
|
538 | + $data['type'] = 'Flight Service Station'; |
|
539 | + } elseif ($typec == 'CTR') { |
|
540 | + $data['type'] = 'Control Radar or Centre'; |
|
541 | + } elseif ($data['type'] == '') { |
|
542 | + $data['type'] = 'Observer'; |
|
543 | + } |
|
427 | 544 | |
428 | 545 | 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']); |
429 | 546 | } |
@@ -443,26 +560,55 @@ discard block |
||
443 | 560 | foreach ($all_data['acList'] as $line) { |
444 | 561 | $data = array(); |
445 | 562 | $data['hex'] = $line['Icao']; // hex |
446 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
447 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
448 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
449 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
450 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
451 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
563 | + if (isset($line['Call'])) { |
|
564 | + $data['ident'] = $line['Call']; |
|
565 | + } |
|
566 | + // ident |
|
567 | + if (isset($line['Alt'])) { |
|
568 | + $data['altitude'] = $line['Alt']; |
|
569 | + } |
|
570 | + // altitude |
|
571 | + if (isset($line['Spd'])) { |
|
572 | + $data['speed'] = $line['Spd']; |
|
573 | + } |
|
574 | + // speed |
|
575 | + if (isset($line['Trak'])) { |
|
576 | + $data['heading'] = $line['Trak']; |
|
577 | + } |
|
578 | + // heading |
|
579 | + if (isset($line['Lat'])) { |
|
580 | + $data['latitude'] = $line['Lat']; |
|
581 | + } |
|
582 | + // lat |
|
583 | + if (isset($line['Long'])) { |
|
584 | + $data['longitude'] = $line['Long']; |
|
585 | + } |
|
586 | + // long |
|
452 | 587 | //$data['verticalrate'] = $line['']; // verticale rate |
453 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
588 | + if (isset($line['Sqk'])) { |
|
589 | + $data['squawk'] = $line['Sqk']; |
|
590 | + } |
|
591 | + // squawk |
|
454 | 592 | $data['emergency'] = ''; // emergency |
455 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
593 | + if (isset($line['Reg'])) { |
|
594 | + $data['registration'] = $line['Reg']; |
|
595 | + } |
|
456 | 596 | /* |
457 | 597 | if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); |
458 | 598 | else $data['datetime'] = date('Y-m-d H:i:s'); |
459 | 599 | */ |
460 | 600 | $data['datetime'] = date('Y-m-d H:i:s'); |
461 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
601 | + if (isset($line['Type'])) { |
|
602 | + $data['aircraft_icao'] = $line['Type']; |
|
603 | + } |
|
462 | 604 | $data['format_source'] = 'aircraftlistjson'; |
463 | 605 | $data['id_source'] = $id_source; |
464 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
465 | - if (isset($data['datetime'])) $SI->add($data); |
|
606 | + if (isset($value['name']) && $value['name'] != '') { |
|
607 | + $data['source_name'] = $value['name']; |
|
608 | + } |
|
609 | + if (isset($data['datetime'])) { |
|
610 | + $SI->add($data); |
|
611 | + } |
|
466 | 612 | unset($data); |
467 | 613 | } |
468 | 614 | } else { |
@@ -481,7 +627,9 @@ discard block |
||
481 | 627 | $data['datetime'] = date('Y-m-d H:i:s'); |
482 | 628 | $data['format_source'] = 'aircraftlistjson'; |
483 | 629 | $data['id_source'] = $id_source; |
484 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
630 | + if (isset($value['name']) && $value['name'] != '') { |
|
631 | + $data['source_name'] = $value['name']; |
|
632 | + } |
|
485 | 633 | $SI->add($data); |
486 | 634 | unset($data); |
487 | 635 | } |
@@ -516,7 +664,9 @@ discard block |
||
516 | 664 | $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
517 | 665 | $data['format_source'] = 'planeupdatefaa'; |
518 | 666 | $data['id_source'] = $id_source; |
519 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
667 | + if (isset($value['name']) && $value['name'] != '') { |
|
668 | + $data['source_name'] = $value['name']; |
|
669 | + } |
|
520 | 670 | $SI->add($data); |
521 | 671 | unset($data); |
522 | 672 | } |
@@ -575,7 +725,9 @@ discard block |
||
575 | 725 | $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
576 | 726 | $data['format_source'] = 'fr24json'; |
577 | 727 | $data['id_source'] = $id_source; |
578 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
728 | + if (isset($value['name']) && $value['name'] != '') { |
|
729 | + $data['source_name'] = $value['name']; |
|
730 | + } |
|
579 | 731 | $SI->add($data); |
580 | 732 | unset($data); |
581 | 733 | } |
@@ -598,23 +750,39 @@ discard block |
||
598 | 750 | if (isset($line['inf'])) { |
599 | 751 | $data = array(); |
600 | 752 | $data['hex'] = $line['inf']['ia']; |
601 | - if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13] |
|
753 | + if (isset($line['inf']['cs'])) { |
|
754 | + $data['ident'] = $line['inf']['cs']; |
|
755 | + } |
|
756 | + //$line[13] |
|
602 | 757 | $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
603 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
604 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
758 | + if (isset($line['inf']['gs'])) { |
|
759 | + $data['speed'] = round($line['inf']['gs']*0.539957); |
|
760 | + } |
|
761 | + // speed |
|
762 | + if (isset($line['inf']['tr'])) { |
|
763 | + $data['heading'] = $line['inf']['tr']; |
|
764 | + } |
|
765 | + // heading |
|
605 | 766 | $data['latitude'] = $line['pt'][0]; // lat |
606 | 767 | $data['longitude'] = $line['pt'][1]; // long |
607 | 768 | //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
608 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
769 | + if (isset($line['inf']['sq'])) { |
|
770 | + $data['squawk'] = $line['inf']['sq']; |
|
771 | + } |
|
772 | + // squawk |
|
609 | 773 | //$data['aircraft_icao'] = $line[8]; |
610 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
774 | + if (isset($line['inf']['rc'])) { |
|
775 | + $data['registration'] = $line['inf']['rc']; |
|
776 | + } |
|
611 | 777 | //$data['departure_airport_iata'] = $line[11]; |
612 | 778 | //$data['arrival_airport_iata'] = $line[12]; |
613 | 779 | //$data['emergency'] = ''; // emergency |
614 | 780 | $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
615 | 781 | $data['format_source'] = 'radarvirtueljson'; |
616 | 782 | $data['id_source'] = $id_source; |
617 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
783 | + if (isset($value['name']) && $value['name'] != '') { |
|
784 | + $data['source_name'] = $value['name']; |
|
785 | + } |
|
618 | 786 | $SI->add($data); |
619 | 787 | unset($data); |
620 | 788 | } |
@@ -634,29 +802,62 @@ discard block |
||
634 | 802 | $data['id'] = $line['id']; |
635 | 803 | $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
636 | 804 | $data['ident'] = $line['callsign']; // ident |
637 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
638 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
639 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
640 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
641 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
642 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
805 | + if (isset($line['pilotid'])) { |
|
806 | + $data['pilot_id'] = $line['pilotid']; |
|
807 | + } |
|
808 | + // pilot id |
|
809 | + if (isset($line['name'])) { |
|
810 | + $data['pilot_name'] = $line['name']; |
|
811 | + } |
|
812 | + // pilot name |
|
813 | + if (isset($line['alt'])) { |
|
814 | + $data['altitude'] = $line['alt']; |
|
815 | + } |
|
816 | + // altitude |
|
817 | + if (isset($line['gs'])) { |
|
818 | + $data['speed'] = $line['gs']; |
|
819 | + } |
|
820 | + // speed |
|
821 | + if (isset($line['heading'])) { |
|
822 | + $data['heading'] = $line['heading']; |
|
823 | + } |
|
824 | + // heading |
|
825 | + if (isset($line['route'])) { |
|
826 | + $data['waypoints'] = $line['route']; |
|
827 | + } |
|
828 | + // route |
|
643 | 829 | $data['latitude'] = $line['lat']; // lat |
644 | 830 | $data['longitude'] = $line['lon']; // long |
645 | 831 | //$data['verticalrate'] = $line['vrt']; // verticale rate |
646 | 832 | //$data['squawk'] = $line['squawk']; // squawk |
647 | 833 | //$data['emergency'] = ''; // emergency |
648 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
649 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
650 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
834 | + if (isset($line['depicao'])) { |
|
835 | + $data['departure_airport_icao'] = $line['depicao']; |
|
836 | + } |
|
837 | + if (isset($line['deptime'])) { |
|
838 | + $data['departure_airport_time'] = $line['deptime']; |
|
839 | + } |
|
840 | + if (isset($line['arricao'])) { |
|
841 | + $data['arrival_airport_icao'] = $line['arricao']; |
|
842 | + } |
|
651 | 843 | //$data['arrival_airport_time'] = $line['arrtime']; |
652 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
653 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
654 | - if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
655 | - else $data['info'] = ''; |
|
844 | + if (isset($line['aircraft'])) { |
|
845 | + $data['aircraft_icao'] = $line['aircraft']; |
|
846 | + } |
|
847 | + if (isset($line['transponder'])) { |
|
848 | + $data['squawk'] = $line['transponder']; |
|
849 | + } |
|
850 | + if (isset($line['atis'])) { |
|
851 | + $data['info'] = $line['atis']; |
|
852 | + } else { |
|
853 | + $data['info'] = ''; |
|
854 | + } |
|
656 | 855 | $data['format_source'] = 'pireps'; |
657 | 856 | $data['id_source'] = $id_source; |
658 | 857 | $data['datetime'] = date('Y-m-d H:i:s'); |
659 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
858 | + if (isset($value['name']) && $value['name'] != '') { |
|
859 | + $data['source_name'] = $value['name']; |
|
860 | + } |
|
660 | 861 | if ($line['icon'] == 'plane') { |
661 | 862 | $SI->add($data); |
662 | 863 | // print_r($data); |
@@ -665,15 +866,25 @@ discard block |
||
665 | 866 | $data['info'] = str_replace('&sect;','',$data['info']); |
666 | 867 | $typec = substr($data['ident'],-3); |
667 | 868 | $data['type'] = ''; |
668 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
669 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
670 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
671 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
672 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
673 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
674 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
675 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
676 | - else $data['type'] = 'Observer'; |
|
869 | + if ($typec == 'APP') { |
|
870 | + $data['type'] = 'Approach'; |
|
871 | + } elseif ($typec == 'TWR') { |
|
872 | + $data['type'] = 'Tower'; |
|
873 | + } elseif ($typec == 'OBS') { |
|
874 | + $data['type'] = 'Observer'; |
|
875 | + } elseif ($typec == 'GND') { |
|
876 | + $data['type'] = 'Ground'; |
|
877 | + } elseif ($typec == 'DEL') { |
|
878 | + $data['type'] = 'Delivery'; |
|
879 | + } elseif ($typec == 'DEP') { |
|
880 | + $data['type'] = 'Departure'; |
|
881 | + } elseif ($typec == 'FSS') { |
|
882 | + $data['type'] = 'Flight Service Station'; |
|
883 | + } elseif ($typec == 'CTR') { |
|
884 | + $data['type'] = 'Control Radar or Centre'; |
|
885 | + } else { |
|
886 | + $data['type'] = 'Observer'; |
|
887 | + } |
|
677 | 888 | echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name']); |
678 | 889 | } |
679 | 890 | unset($data); |
@@ -684,17 +895,25 @@ discard block |
||
684 | 895 | //} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { |
685 | 896 | } elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
686 | 897 | //$buffer = $Common->getData($hosts[$id]); |
687 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
898 | + if ($globalDebug) { |
|
899 | + echo 'Get Data...'."\n"; |
|
900 | + } |
|
688 | 901 | $buffer = $Common->getData($value['host']); |
689 | 902 | $all_data = json_decode($buffer,true); |
690 | 903 | if ($buffer != '' && is_array($all_data)) { |
691 | 904 | foreach ($all_data as $line) { |
692 | 905 | $data = array(); |
693 | 906 | //$data['id'] = $line['id']; // id not usable |
694 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
907 | + if (isset($line['pilotid'])) { |
|
908 | + $data['id'] = $line['pilotid'].$line['flightnum']; |
|
909 | + } |
|
695 | 910 | $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
696 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
697 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
911 | + if (isset($line['pilotname'])) { |
|
912 | + $data['pilot_name'] = $line['pilotname']; |
|
913 | + } |
|
914 | + if (isset($line['pilotid'])) { |
|
915 | + $data['pilot_id'] = $line['pilotid']; |
|
916 | + } |
|
698 | 917 | $data['ident'] = $line['flightnum']; // ident |
699 | 918 | $data['altitude'] = $line['alt']; // altitude |
700 | 919 | $data['speed'] = $line['gs']; // speed |
@@ -712,27 +931,41 @@ discard block |
||
712 | 931 | $data['arrival_airport_icao'] = $line['arricao']; |
713 | 932 | $data['arrival_airport_time'] = $line['arrtime']; |
714 | 933 | $data['registration'] = $line['aircraft']; |
715 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
934 | + if (isset($line['route'])) { |
|
935 | + $data['waypoints'] = $line['route']; |
|
936 | + } |
|
937 | + // route |
|
716 | 938 | if (isset($line['aircraftname'])) { |
717 | 939 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
718 | 940 | $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
719 | 941 | $aircraft_data = explode('-',$line['aircraftname']); |
720 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
|
721 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
|
722 | - else { |
|
942 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) { |
|
943 | + $data['aircraft_icao'] = $aircraft_data[0]; |
|
944 | + } elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) { |
|
945 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
946 | + } else { |
|
723 | 947 | $aircraft_data = explode(' ',$line['aircraftname']); |
724 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
|
725 | - else $data['aircraft_icao'] = $line['aircraftname']; |
|
948 | + if (isset($aircraft_data[1])) { |
|
949 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
950 | + } else { |
|
951 | + $data['aircraft_icao'] = $line['aircraftname']; |
|
952 | + } |
|
726 | 953 | } |
727 | 954 | } |
728 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
955 | + if (isset($line['route'])) { |
|
956 | + $data['waypoints'] = $line['route']; |
|
957 | + } |
|
729 | 958 | $data['id_source'] = $id_source; |
730 | 959 | $data['format_source'] = 'phpvmacars'; |
731 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
960 | + if (isset($value['name']) && $value['name'] != '') { |
|
961 | + $data['source_name'] = $value['name']; |
|
962 | + } |
|
732 | 963 | $SI->add($data); |
733 | 964 | unset($data); |
734 | 965 | } |
735 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
966 | + if ($globalDebug) { |
|
967 | + echo 'No more data...'."\n"; |
|
968 | + } |
|
736 | 969 | unset($buffer); |
737 | 970 | unset($all_data); |
738 | 971 | } |
@@ -740,7 +973,9 @@ discard block |
||
740 | 973 | $last_exec[$id]['last'] = time(); |
741 | 974 | //} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { |
742 | 975 | } 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') { |
743 | - if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
976 | + if (function_exists('pcntl_fork')) { |
|
977 | + pcntl_signal_dispatch(); |
|
978 | + } |
|
744 | 979 | //$last_exec[$id]['last'] = time(); |
745 | 980 | |
746 | 981 | //$read = array( $sockets[$id] ); |
@@ -748,7 +983,9 @@ discard block |
||
748 | 983 | $write = NULL; |
749 | 984 | $e = NULL; |
750 | 985 | $n = socket_select($read, $write, $e, $timeout); |
751 | - if ($e != NULL) var_dump($e); |
|
986 | + if ($e != NULL) { |
|
987 | + var_dump($e); |
|
988 | + } |
|
752 | 989 | if ($n > 0) { |
753 | 990 | foreach ($read as $nb => $r) { |
754 | 991 | //$value = $formats[$nb]; |
@@ -776,9 +1013,15 @@ discard block |
||
776 | 1013 | if (is_array($data)) { |
777 | 1014 | $data['datetime'] = date('Y-m-d H:i:s'); |
778 | 1015 | $data['format_source'] = 'raw'; |
779 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
780 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
781 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1016 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1017 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1018 | + } |
|
1019 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1020 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1021 | + } |
|
1022 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1023 | + $SI->add($data); |
|
1024 | + } |
|
782 | 1025 | } |
783 | 1026 | } elseif ($format == 'flightgearsp') { |
784 | 1027 | //echo $buffer."\n"; |
@@ -796,11 +1039,15 @@ discard block |
||
796 | 1039 | $data['speed'] = round($line[5]*1.94384); |
797 | 1040 | $data['datetime'] = date('Y-m-d H:i:s'); |
798 | 1041 | $data['format_source'] = 'flightgearsp'; |
799 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1042 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1043 | + $SI->add($data); |
|
1044 | + } |
|
800 | 1045 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
801 | 1046 | } |
802 | 1047 | } elseif ($format == 'acars') { |
803 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1048 | + if ($globalDebug) { |
|
1049 | + echo 'ACARS : '.$buffer."\n"; |
|
1050 | + } |
|
804 | 1051 | $ACARS->add(trim($buffer)); |
805 | 1052 | socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
806 | 1053 | $ACARS->deleteLiveAcarsData(); |
@@ -821,7 +1068,9 @@ discard block |
||
821 | 1068 | $aircraft_type = $line[10]; |
822 | 1069 | $aircraft_type = preg_split(':/:',$aircraft_type); |
823 | 1070 | $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
824 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1071 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1072 | + $SI->add($data); |
|
1073 | + } |
|
825 | 1074 | } |
826 | 1075 | } |
827 | 1076 | } elseif ($format == 'beast') { |
@@ -837,21 +1086,43 @@ discard block |
||
837 | 1086 | $data['hex'] = $lined['hexid']; |
838 | 1087 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
839 | 1088 | $data['datetime'] = date('Y-m-d H:i:s');; |
840 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
841 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
842 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
843 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
844 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
845 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
846 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
1089 | + if (isset($lined['ident'])) { |
|
1090 | + $data['ident'] = $lined['ident']; |
|
1091 | + } |
|
1092 | + if (isset($lined['lat'])) { |
|
1093 | + $data['latitude'] = $lined['lat']; |
|
1094 | + } |
|
1095 | + if (isset($lined['lon'])) { |
|
1096 | + $data['longitude'] = $lined['lon']; |
|
1097 | + } |
|
1098 | + if (isset($lined['speed'])) { |
|
1099 | + $data['speed'] = $lined['speed']; |
|
1100 | + } |
|
1101 | + if (isset($lined['squawk'])) { |
|
1102 | + $data['squawk'] = $lined['squawk']; |
|
1103 | + } |
|
1104 | + if (isset($lined['alt'])) { |
|
1105 | + $data['altitude'] = $lined['alt']; |
|
1106 | + } |
|
1107 | + if (isset($lined['heading'])) { |
|
1108 | + $data['heading'] = $lined['heading']; |
|
1109 | + } |
|
847 | 1110 | $data['id_source'] = $id_source; |
848 | 1111 | $data['format_source'] = 'tsv'; |
849 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
850 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
851 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1112 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1113 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1114 | + } |
|
1115 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1116 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1117 | + } |
|
1118 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1119 | + $SI->add($data); |
|
1120 | + } |
|
852 | 1121 | unset($lined); |
853 | 1122 | unset($data); |
854 | - } else $error = true; |
|
1123 | + } else { |
|
1124 | + $error = true; |
|
1125 | + } |
|
855 | 1126 | } elseif ($format == 'aprs' && $use_aprs) { |
856 | 1127 | if ($aprs_connect == 0) { |
857 | 1128 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
@@ -877,29 +1148,44 @@ discard block |
||
877 | 1148 | $data['latitude'] = $line['latitude']; |
878 | 1149 | $data['longitude'] = $line['longitude']; |
879 | 1150 | //$data['verticalrate'] = $line[16]; |
880 | - if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
881 | - else $data['speed'] = 0; |
|
1151 | + if (isset($line['speed'])) { |
|
1152 | + $data['speed'] = $line['speed']; |
|
1153 | + } else { |
|
1154 | + $data['speed'] = 0; |
|
1155 | + } |
|
882 | 1156 | $data['altitude'] = $line['altitude']; |
883 | - if (isset($line['course'])) $data['heading'] = $line['course']; |
|
1157 | + if (isset($line['course'])) { |
|
1158 | + $data['heading'] = $line['course']; |
|
1159 | + } |
|
884 | 1160 | //else $data['heading'] = 0; |
885 | 1161 | $data['aircraft_type'] = $line['stealth']; |
886 | - if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true; |
|
1162 | + if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) { |
|
1163 | + $data['noarchive'] = true; |
|
1164 | + } |
|
887 | 1165 | $data['id_source'] = $id_source; |
888 | 1166 | $data['format_source'] = 'aprs'; |
889 | 1167 | $data['source_name'] = $line['source']; |
890 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1168 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1169 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1170 | + } |
|
891 | 1171 | $currentdate = date('Y-m-d H:i:s'); |
892 | 1172 | $aprsdate = strtotime($data['datetime']); |
893 | 1173 | // Accept data if time <= system time + 20s |
894 | - 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); |
|
895 | - else { |
|
896 | - if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
897 | - else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
1174 | + if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
1175 | + $send = $SI->add($data); |
|
1176 | + } else { |
|
1177 | + if ($line['stealth'] != 0) { |
|
1178 | + echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
1179 | + } else { |
|
1180 | + echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
1181 | + } |
|
898 | 1182 | } |
899 | 1183 | unset($data); |
900 | 1184 | } |
901 | 1185 | //elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; |
902 | - elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n"; |
|
1186 | + elseif ($line == true && $globalDebug) { |
|
1187 | + echo '!! Failed : '.$buffer."!!\n"; |
|
1188 | + } |
|
903 | 1189 | } |
904 | 1190 | } else { |
905 | 1191 | $line = explode(',', $buffer); |
@@ -927,25 +1213,42 @@ discard block |
||
927 | 1213 | $data['ground'] = $line[21]; |
928 | 1214 | $data['emergency'] = $line[19]; |
929 | 1215 | $data['format_source'] = 'sbs'; |
930 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
931 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1216 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1217 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1218 | + } |
|
1219 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1220 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1221 | + } |
|
932 | 1222 | $data['id_source'] = $id_source; |
933 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
934 | - else $error = true; |
|
1223 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1224 | + $send = $SI->add($data); |
|
1225 | + } else { |
|
1226 | + $error = true; |
|
1227 | + } |
|
935 | 1228 | unset($data); |
936 | - } else $error = true; |
|
1229 | + } else { |
|
1230 | + $error = true; |
|
1231 | + } |
|
937 | 1232 | if ($error) { |
938 | 1233 | if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { |
939 | - if ($globalDebug) echo "Not a message. Ignoring... \n"; |
|
1234 | + if ($globalDebug) { |
|
1235 | + echo "Not a message. Ignoring... \n"; |
|
1236 | + } |
|
940 | 1237 | } else { |
941 | - if ($globalDebug) echo "Wrong line format. Ignoring... \n"; |
|
1238 | + if ($globalDebug) { |
|
1239 | + echo "Wrong line format. Ignoring... \n"; |
|
1240 | + } |
|
942 | 1241 | if ($globalDebug) { |
943 | 1242 | echo $buffer; |
944 | 1243 | print_r($line); |
945 | 1244 | } |
946 | 1245 | //socket_close($r); |
947 | - if ($globalDebug) echo "Reconnect after an error...\n"; |
|
948 | - if ($format == 'aprs') $aprs_connect = 0; |
|
1246 | + if ($globalDebug) { |
|
1247 | + echo "Reconnect after an error...\n"; |
|
1248 | + } |
|
1249 | + if ($format == 'aprs') { |
|
1250 | + $aprs_connect = 0; |
|
1251 | + } |
|
949 | 1252 | $sourceer[$nb] = $globalSources[$nb]; |
950 | 1253 | connect_all($sourceer); |
951 | 1254 | $sourceer = array(); |
@@ -953,10 +1256,14 @@ discard block |
||
953 | 1256 | } |
954 | 1257 | } |
955 | 1258 | // Sleep for xxx microseconds |
956 | - if (isset($globalSBSSleep)) usleep($globalSBSSleep); |
|
1259 | + if (isset($globalSBSSleep)) { |
|
1260 | + usleep($globalSBSSleep); |
|
1261 | + } |
|
957 | 1262 | } else { |
958 | 1263 | if ($format == 'flightgearmp') { |
959 | - if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
1264 | + if ($globalDebug) { |
|
1265 | + echo "Reconnect FlightGear MP..."; |
|
1266 | + } |
|
960 | 1267 | //@socket_close($r); |
961 | 1268 | sleep($globalMinFetch); |
962 | 1269 | $sourcefg[$nb] = $globalSources[$nb]; |
@@ -965,10 +1272,15 @@ discard block |
||
965 | 1272 | break; |
966 | 1273 | |
967 | 1274 | } elseif ($format != 'acars' && $format != 'flightgearsp') { |
968 | - if (isset($tt[$format])) $tt[$format]++; |
|
969 | - else $tt[$format] = 0; |
|
1275 | + if (isset($tt[$format])) { |
|
1276 | + $tt[$format]++; |
|
1277 | + } else { |
|
1278 | + $tt[$format] = 0; |
|
1279 | + } |
|
970 | 1280 | if ($tt[$format] > 30) { |
971 | - if ($globalDebug) echo "ERROR : Reconnect ".$format."..."; |
|
1281 | + if ($globalDebug) { |
|
1282 | + echo "ERROR : Reconnect ".$format."..."; |
|
1283 | + } |
|
972 | 1284 | //@socket_close($r); |
973 | 1285 | sleep(2); |
974 | 1286 | $aprs_connect = 0; |
@@ -984,12 +1296,18 @@ discard block |
||
984 | 1296 | } |
985 | 1297 | } else { |
986 | 1298 | $error = socket_strerror(socket_last_error()); |
987 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1299 | + if ($globalDebug) { |
|
1300 | + echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1301 | + } |
|
988 | 1302 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) || time() - $time >= $timeout) { |
989 | - if (isset($globalDebug)) echo "Restarting...\n"; |
|
1303 | + if (isset($globalDebug)) { |
|
1304 | + echo "Restarting...\n"; |
|
1305 | + } |
|
990 | 1306 | // Restart the script if possible |
991 | 1307 | if (is_array($sockets)) { |
992 | - if ($globalDebug) echo "Shutdown all sockets..."; |
|
1308 | + if ($globalDebug) { |
|
1309 | + echo "Shutdown all sockets..."; |
|
1310 | + } |
|
993 | 1311 | |
994 | 1312 | foreach ($sockets as $sock) { |
995 | 1313 | @socket_shutdown($sock,2); |
@@ -997,7 +1315,9 @@ discard block |
||
997 | 1315 | } |
998 | 1316 | |
999 | 1317 | } |
1000 | - if ($globalDebug) echo "Restart all connections..."; |
|
1318 | + if ($globalDebug) { |
|
1319 | + echo "Restart all connections..."; |
|
1320 | + } |
|
1001 | 1321 | sleep(2); |
1002 | 1322 | $time = time(); |
1003 | 1323 | //connect_all($hosts); |
@@ -1008,7 +1328,9 @@ discard block |
||
1008 | 1328 | } |
1009 | 1329 | } |
1010 | 1330 | if ($globalDaemon === false) { |
1011 | - if ($globalDebug) echo 'Check all...'."\n"; |
|
1331 | + if ($globalDebug) { |
|
1332 | + echo 'Check all...'."\n"; |
|
1333 | + } |
|
1012 | 1334 | $SI->checkAll(); |
1013 | 1335 | } |
1014 | 1336 | } |