@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | die; |
41 | 41 | } |
42 | 42 | //$hosts = array($globalSBS1Host.':'.$globalSBS1Port); |
43 | - $globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port); |
|
43 | + $globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | -$options = getopt('s::',array('source::','server','idsource::')); |
|
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'])) { |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | else $id_source = 1; |
60 | 60 | if (isset($globalServer) && $globalServer) { |
61 | 61 | if ($globalDebug) echo "Using Server Mode\n"; |
62 | - $SI=new SpotterServer(); |
|
63 | -} else $SI=new SpotterImport($Connection->db); |
|
62 | + $SI = new SpotterServer(); |
|
63 | +} else $SI = new SpotterImport($Connection->db); |
|
64 | 64 | //$APRS=new APRS($Connection->db); |
65 | -$SBS=new SBS(); |
|
66 | -$ACARS=new ACARS($Connection->db); |
|
67 | -$Common=new Common(); |
|
65 | +$SBS = new SBS(); |
|
66 | +$ACARS = new ACARS($Connection->db); |
|
67 | +$Common = new Common(); |
|
68 | 68 | date_default_timezone_set('UTC'); |
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() { |
|
72 | + pcntl_signal(SIGINT, function() { |
|
73 | 73 | global $sockets; |
74 | 74 | echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
75 | 75 | die("Bye!\n"); |
@@ -113,35 +113,35 @@ discard block |
||
113 | 113 | |
114 | 114 | function connect_all($hosts) { |
115 | 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; |
|
116 | + global $sockets, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset; |
|
117 | 117 | $reset++; |
118 | 118 | if ($globalDebug) echo 'Connect to all...'."\n"; |
119 | 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 | - if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
124 | - if (preg_match('/deltadb.txt$/i',$host)) { |
|
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 | 125 | //$formats[$id] = 'deltadbtxt'; |
126 | 126 | $globalSources[$id]['format'] = 'deltadbtxt'; |
127 | 127 | //$last_exec['deltadbtxt'] = 0; |
128 | 128 | if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
129 | - } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
129 | + } else if (preg_match('/vatsim-data.txt$/i', $host)) { |
|
130 | 130 | //$formats[$id] = 'vatsimtxt'; |
131 | 131 | $globalSources[$id]['format'] = 'vatsimtxt'; |
132 | 132 | //$last_exec['vatsimtxt'] = 0; |
133 | 133 | if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
134 | - } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
134 | + } else if (preg_match('/aircraftlist.json$/i', $host)) { |
|
135 | 135 | //$formats[$id] = 'aircraftlistjson'; |
136 | 136 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
137 | 137 | //$last_exec['aircraftlistjson'] = 0; |
138 | 138 | if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
139 | - } else if (preg_match('/opensky/i',$host)) { |
|
139 | + } else if (preg_match('/opensky/i', $host)) { |
|
140 | 140 | //$formats[$id] = 'aircraftlistjson'; |
141 | 141 | $globalSources[$id]['format'] = 'opensky'; |
142 | 142 | //$last_exec['aircraftlistjson'] = 0; |
143 | 143 | if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
144 | - } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
|
144 | + } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) { |
|
145 | 145 | //$formats[$id] = 'radarvirtueljson'; |
146 | 146 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
147 | 147 | //$last_exec['radarvirtueljson'] = 0; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
151 | 151 | exit(0); |
152 | 152 | } |
153 | - } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
153 | + } else if (preg_match('/planeUpdateFAA.php$/i', $host)) { |
|
154 | 154 | //$formats[$id] = 'planeupdatefaa'; |
155 | 155 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
156 | 156 | //$last_exec['planeupdatefaa'] = 0; |
@@ -159,26 +159,26 @@ discard block |
||
159 | 159 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
160 | 160 | exit(0); |
161 | 161 | } |
162 | - } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
162 | + } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) { |
|
163 | 163 | //$formats[$id] = 'phpvmacars'; |
164 | 164 | $globalSources[$id]['format'] = 'phpvmacars'; |
165 | 165 | //$last_exec['phpvmacars'] = 0; |
166 | 166 | if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
167 | - } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
167 | + } else if (preg_match('/VAM-json.php$/i', $host)) { |
|
168 | 168 | //$formats[$id] = 'phpvmacars'; |
169 | 169 | $globalSources[$id]['format'] = 'vam'; |
170 | 170 | if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
171 | - } else if (preg_match('/whazzup/i',$host)) { |
|
171 | + } else if (preg_match('/whazzup/i', $host)) { |
|
172 | 172 | //$formats[$id] = 'whazzup'; |
173 | 173 | $globalSources[$id]['format'] = 'whazzup'; |
174 | 174 | //$last_exec['whazzup'] = 0; |
175 | 175 | if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
176 | - } else if (preg_match('/recentpireps/i',$host)) { |
|
176 | + } else if (preg_match('/recentpireps/i', $host)) { |
|
177 | 177 | //$formats[$id] = 'pirepsjson'; |
178 | 178 | $globalSources[$id]['format'] = 'pirepsjson'; |
179 | 179 | //$last_exec['pirepsjson'] = 0; |
180 | 180 | if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
181 | - } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
181 | + } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) { |
|
182 | 182 | //$formats[$id] = 'fr24json'; |
183 | 183 | $globalSources[$id]['format'] = 'fr24json'; |
184 | 184 | //$last_exec['fr24json'] = 0; |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | exit(0); |
189 | 189 | } |
190 | 190 | //} else if (preg_match('/10001/',$host)) { |
191 | - } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
191 | + } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
192 | 192 | //$formats[$id] = 'tsv'; |
193 | 193 | $globalSources[$id]['format'] = 'tsv'; |
194 | 194 | if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
195 | 195 | } |
196 | - } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
196 | + } elseif (filter_var($host, FILTER_VALIDATE_URL)) { |
|
197 | 197 | if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
198 | - } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
199 | - $hostport = explode(':',$host); |
|
198 | + } elseif (!filter_var($host, FILTER_VALIDATE_URL)) { |
|
199 | + $hostport = explode(':', $host); |
|
200 | 200 | if (isset($hostport[1])) { |
201 | 201 | $port = $hostport[1]; |
202 | 202 | $hostn = $hostport[0]; |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | $hostn = $globalSources[$id]['host']; |
206 | 206 | } |
207 | 207 | if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
208 | - $s = create_socket($hostn,$port, $errno, $errstr); |
|
208 | + $s = create_socket($hostn, $port, $errno, $errstr); |
|
209 | 209 | } else { |
210 | - $s = create_socket_udp($hostn,$port, $errno, $errstr); |
|
210 | + $s = create_socket_udp($hostn, $port, $errno, $errstr); |
|
211 | 211 | } |
212 | 212 | if ($s) { |
213 | 213 | $sockets[$id] = $s; |
214 | 214 | if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
215 | - if (preg_match('/aprs/',$hostn)) { |
|
215 | + if (preg_match('/aprs/', $hostn)) { |
|
216 | 216 | //$formats[$id] = 'aprs'; |
217 | 217 | $globalSources[$id]['format'] = 'aprs'; |
218 | 218 | //$aprs_connect = 0; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
254 | 254 | else $timeout = 20; |
255 | 255 | $errno = ''; |
256 | -$errstr=''; |
|
256 | +$errstr = ''; |
|
257 | 257 | |
258 | 258 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
259 | 259 | /* Initiate connections to all the hosts simultaneously */ |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | |
283 | 283 | if ($use_aprs) { |
284 | 284 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
285 | - $APRS=new APRS(); |
|
285 | + $APRS = new APRS(); |
|
286 | 286 | $aprs_connect = 0; |
287 | 287 | $aprs_keep = 120; |
288 | 288 | $aprs_last_tx = time(); |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | else $aprs_ssid = 'FAM'; |
294 | 294 | //else $aprs_ssid = 'PerlEx'; |
295 | 295 | if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
296 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
296 | + else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
297 | 297 | if ($aprs_full) $aprs_filter = ''; |
298 | 298 | if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n"; |
299 | 299 | else $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n"; |
@@ -304,12 +304,12 @@ discard block |
||
304 | 304 | sleep(1); |
305 | 305 | if ($globalDebug) echo "SCAN MODE \n\n"; |
306 | 306 | if (!isset($globalCronEnd)) $globalCronEnd = 60; |
307 | -$endtime = time()+$globalCronEnd; |
|
307 | +$endtime = time() + $globalCronEnd; |
|
308 | 308 | $i = 1; |
309 | 309 | $tt = array(); |
310 | 310 | // Delete all ATC |
311 | 311 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) { |
312 | - $ATC=new ATC($Connection->db); |
|
312 | + $ATC = new ATC($Connection->db); |
|
313 | 313 | } |
314 | 314 | if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
315 | 315 | $ATC->deleteAll(); |
@@ -317,7 +317,7 @@ discard block |
||
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(); |
|
320 | + if (!$globalDaemon) $i = $endtime - time(); |
|
321 | 321 | // Delete old ATC |
322 | 322 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
323 | 323 | if ($globalDebug) echo 'Delete old ATC...'."\n"; |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | } |
332 | 332 | if ($max != $globalMinFetch) { |
333 | 333 | if ($globalDebug) echo 'Sleeping...'."\n"; |
334 | - sleep($globalMinFetch-$max+2); |
|
334 | + sleep($globalMinFetch - $max + 2); |
|
335 | 335 | } |
336 | 336 | } |
337 | 337 | |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | //$buffer = $Common->getData($hosts[$id]); |
344 | 344 | $buffer = $Common->getData($value['host']); |
345 | 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); |
|
346 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
347 | + $buffer = explode('\n', $buffer); |
|
348 | 348 | foreach ($buffer as $line) { |
349 | 349 | if ($line != '' && count($line) > 7) { |
350 | 350 | $line = explode(',', $line); |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | } elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) { |
374 | 374 | //$buffer = $Common->getData($hosts[$id]); |
375 | 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); |
|
376 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
377 | + $buffer = explode('\n', $buffer); |
|
378 | 378 | $reset = 0; |
379 | 379 | foreach ($buffer as $line) { |
380 | 380 | if ($line != '') { |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
385 | 385 | $data['pilot_id'] = $line[1]; |
386 | 386 | $data['pilot_name'] = $line[2]; |
387 | - $data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT); |
|
387 | + $data['hex'] = str_pad(dechex($line[1]), 6, '000000', STR_PAD_LEFT); |
|
388 | 388 | $data['ident'] = $line[0]; // ident |
389 | 389 | if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
390 | 390 | $data['speed'] = $line[8]; // speed |
@@ -400,7 +400,7 @@ discard block |
||
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 | 402 | $data['departure_airport_icao'] = $line[11]; |
403 | - $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
403 | + $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':'); |
|
404 | 404 | $data['arrival_airport_icao'] = $line[13]; |
405 | 405 | $data['frequency'] = $line[4]; |
406 | 406 | $data['type'] = $line[18]; |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | $data['id_source'] = $id_source; |
410 | 410 | //$data['arrival_airport_time'] = ; |
411 | 411 | if ($line[9] != '') { |
412 | - $aircraft_data = explode('/',$line[9]); |
|
412 | + $aircraft_data = explode('/', $line[9]); |
|
413 | 413 | if (isset($aircraft_data[1])) { |
414 | 414 | $data['aircraft_icao'] = $aircraft_data[1]; |
415 | 415 | } |
@@ -423,9 +423,9 @@ discard block |
||
423 | 423 | if ($line[3] == 'PILOT') $SI->add($data); |
424 | 424 | elseif ($line[3] == 'ATC') { |
425 | 425 | //print_r($data); |
426 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
427 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
428 | - $typec = substr($data['ident'],-3); |
|
426 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
427 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
428 | + $typec = substr($data['ident'], -3); |
|
429 | 429 | if ($typec == 'APP') $data['type'] = 'Approach'; |
430 | 430 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
431 | 431 | elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
437 | 437 | elseif ($data['type'] == '') $data['type'] = 'Observer'; |
438 | 438 | if (!isset($data['source_name'])) $data['source_name'] = ''; |
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']); |
|
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 | 441 | unset($data); |
442 | 442 | } |
@@ -447,9 +447,9 @@ discard block |
||
447 | 447 | $last_exec[$id]['last'] = time(); |
448 | 448 | //} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) { |
449 | 449 | } elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
450 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
450 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20'); |
|
451 | 451 | if ($buffer != '') { |
452 | - $all_data = json_decode($buffer,true); |
|
452 | + $all_data = json_decode($buffer, true); |
|
453 | 453 | if (isset($all_data['acList'])) { |
454 | 454 | $reset = 0; |
455 | 455 | foreach ($all_data['acList'] as $line) { |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
506 | 506 | } elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
507 | 507 | $buffer = $Common->getData($value['host']); |
508 | - $all_data = json_decode($buffer,true); |
|
508 | + $all_data = json_decode($buffer, true); |
|
509 | 509 | if (isset($all_data['planes'])) { |
510 | 510 | $reset = 0; |
511 | 511 | foreach ($all_data['planes'] as $key => $line) { |
@@ -522,12 +522,12 @@ discard block |
||
522 | 522 | $data['emergency'] = ''; // emergency |
523 | 523 | $data['registration'] = $line[2]; |
524 | 524 | $data['aircraft_icao'] = $line[0]; |
525 | - $deparr = explode('-',$line[1]); |
|
525 | + $deparr = explode('-', $line[1]); |
|
526 | 526 | if (count($deparr) == 2) { |
527 | 527 | $data['departure_airport_icao'] = $deparr[0]; |
528 | 528 | $data['arrival_airport_icao'] = $deparr[1]; |
529 | 529 | } |
530 | - $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
530 | + $data['datetime'] = date('Y-m-d H:i:s', $line[9]); |
|
531 | 531 | $data['format_source'] = 'planeupdatefaa'; |
532 | 532 | $data['id_source'] = $id_source; |
533 | 533 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | $last_exec[$id]['last'] = time(); |
540 | 540 | } elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
541 | 541 | $buffer = $Common->getData($value['host']); |
542 | - $all_data = json_decode($buffer,true); |
|
542 | + $all_data = json_decode($buffer, true); |
|
543 | 543 | if (isset($all_data['states'])) { |
544 | 544 | $reset = 0; |
545 | 545 | foreach ($all_data['states'] as $key => $line) { |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | //$data['emergency'] = ''; // emergency |
557 | 557 | //$data['registration'] = $line[2]; |
558 | 558 | //$data['aircraft_icao'] = $line[0]; |
559 | - $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
559 | + $data['datetime'] = date('Y-m-d H:i:s', $line[3]); |
|
560 | 560 | $data['format_source'] = 'opensky'; |
561 | 561 | $data['id_source'] = $id_source; |
562 | 562 | $SI->add($data); |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | } elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
570 | 570 | //$buffer = $Common->getData($hosts[$id]); |
571 | 571 | $buffer = $Common->getData($value['host']); |
572 | - $all_data = json_decode($buffer,true); |
|
572 | + $all_data = json_decode($buffer, true); |
|
573 | 573 | if (!empty($all_data)) $reset = 0; |
574 | 574 | foreach ($all_data as $key => $line) { |
575 | 575 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
@@ -601,11 +601,11 @@ discard block |
||
601 | 601 | //} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { |
602 | 602 | } elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
603 | 603 | //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
604 | - $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
604 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150'); |
|
605 | 605 | //echo $buffer; |
606 | - $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
607 | - $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
608 | - $all_data = json_decode($buffer,true); |
|
606 | + $buffer = str_replace(array("\n", "\r"), "", $buffer); |
|
607 | + $buffer = preg_replace('/,"num":(.+)/', '}', $buffer); |
|
608 | + $all_data = json_decode($buffer, true); |
|
609 | 609 | if (json_last_error() != JSON_ERROR_NONE) { |
610 | 610 | die(json_last_error_msg()); |
611 | 611 | } |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | //$data['departure_airport_iata'] = $line[11]; |
629 | 629 | //$data['arrival_airport_iata'] = $line[12]; |
630 | 630 | //$data['emergency'] = ''; // emergency |
631 | - $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
|
631 | + $data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10] |
|
632 | 632 | $data['format_source'] = 'radarvirtueljson'; |
633 | 633 | $data['id_source'] = $id_source; |
634 | 634 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
@@ -643,14 +643,14 @@ discard block |
||
643 | 643 | } elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
644 | 644 | //$buffer = $Common->getData($hosts[$id]); |
645 | 645 | $buffer = $Common->getData($value['host'].'?'.time()); |
646 | - $all_data = json_decode(utf8_encode($buffer),true); |
|
646 | + $all_data = json_decode(utf8_encode($buffer), true); |
|
647 | 647 | |
648 | 648 | if (isset($all_data['pireps'])) { |
649 | 649 | $reset = 0; |
650 | 650 | foreach ($all_data['pireps'] as $line) { |
651 | 651 | $data = array(); |
652 | 652 | $data['id'] = $line['id']; |
653 | - $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
653 | + $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
654 | 654 | $data['ident'] = $line['callsign']; // ident |
655 | 655 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
656 | 656 | if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
@@ -679,9 +679,9 @@ discard block |
||
679 | 679 | $SI->add($data); |
680 | 680 | // print_r($data); |
681 | 681 | } elseif ($line['icon'] == 'ct') { |
682 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
683 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
684 | - $typec = substr($data['ident'],-3); |
|
682 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
683 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
684 | + $typec = substr($data['ident'], -3); |
|
685 | 685 | $data['type'] = ''; |
686 | 686 | if ($typec == 'APP') $data['type'] = 'Approach'; |
687 | 687 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
693 | 693 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
694 | 694 | else $data['type'] = 'Observer'; |
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']); |
|
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 | 696 | } |
697 | 697 | unset($data); |
698 | 698 | } |
@@ -704,14 +704,14 @@ discard block |
||
704 | 704 | //$buffer = $Common->getData($hosts[$id]); |
705 | 705 | if ($globalDebug) echo 'Get Data...'."\n"; |
706 | 706 | $buffer = $Common->getData($value['host']); |
707 | - $all_data = json_decode($buffer,true); |
|
707 | + $all_data = json_decode($buffer, true); |
|
708 | 708 | if ($buffer != '' && is_array($all_data)) { |
709 | 709 | $reset = 0; |
710 | 710 | foreach ($all_data as $line) { |
711 | 711 | $data = array(); |
712 | 712 | //$data['id'] = $line['id']; // id not usable |
713 | 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 |
|
714 | + $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
715 | 715 | if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
716 | 716 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
717 | 717 | $data['ident'] = $line['flightnum']; // ident |
@@ -734,12 +734,12 @@ discard block |
||
734 | 734 | if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
735 | 735 | if (isset($line['aircraftname'])) { |
736 | 736 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
737 | - $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
|
738 | - $aircraft_data = explode('-',$line['aircraftname']); |
|
737 | + $line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']); |
|
738 | + $aircraft_data = explode('-', $line['aircraftname']); |
|
739 | 739 | if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
740 | 740 | elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
741 | 741 | else { |
742 | - $aircraft_data = explode(' ',$line['aircraftname']); |
|
742 | + $aircraft_data = explode(' ', $line['aircraftname']); |
|
743 | 743 | if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
744 | 744 | else $data['aircraft_icao'] = $line['aircraftname']; |
745 | 745 | } |
@@ -761,14 +761,14 @@ discard block |
||
761 | 761 | //$buffer = $Common->getData($hosts[$id]); |
762 | 762 | if ($globalDebug) echo 'Get Data...'."\n"; |
763 | 763 | $buffer = $Common->getData($value['host']); |
764 | - $all_data = json_decode($buffer,true); |
|
764 | + $all_data = json_decode($buffer, true); |
|
765 | 765 | if ($buffer != '' && is_array($all_data)) { |
766 | 766 | $reset = 0; |
767 | 767 | foreach ($all_data as $line) { |
768 | 768 | $data = array(); |
769 | 769 | //$data['id'] = $line['id']; // id not usable |
770 | 770 | $data['id'] = trim($line['flight_id']); |
771 | - $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
771 | + $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
772 | 772 | $data['pilot_name'] = $line['pilot_name']; |
773 | 773 | $data['pilot_id'] = $line['pilot_id']; |
774 | 774 | $data['ident'] = trim($line['callsign']); // ident |
@@ -819,9 +819,9 @@ discard block |
||
819 | 819 | //$value = $formats[$nb]; |
820 | 820 | $format = $globalSources[$nb]['format']; |
821 | 821 | if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
822 | - $buffer = socket_read($r, 6000,PHP_NORMAL_READ); |
|
822 | + $buffer = socket_read($r, 6000, PHP_NORMAL_READ); |
|
823 | 823 | } else { |
824 | - $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port); |
|
824 | + $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port); |
|
825 | 825 | } |
826 | 826 | //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
827 | 827 | //echo $buffer."\n"; |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
830 | 830 | $error = false; |
831 | 831 | //$SI::del(); |
832 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
832 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer)); |
|
833 | 833 | // SBS format is CSV format |
834 | 834 | if ($buffer != '') { |
835 | 835 | $tt[$format] = 0; |
@@ -850,10 +850,10 @@ discard block |
||
850 | 850 | } elseif ($format == 'flightgearsp') { |
851 | 851 | //echo $buffer."\n"; |
852 | 852 | if (strlen($buffer) > 5) { |
853 | - $line = explode(',',$buffer); |
|
853 | + $line = explode(',', $buffer); |
|
854 | 854 | $data = array(); |
855 | 855 | //XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p |
856 | - $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6); |
|
856 | + $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
857 | 857 | $data['ident'] = $line[6]; |
858 | 858 | $data['aircraft_name'] = $line[7]; |
859 | 859 | $data['longitude'] = $line[1]; |
@@ -864,21 +864,21 @@ discard block |
||
864 | 864 | $data['datetime'] = date('Y-m-d H:i:s'); |
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 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
867 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
868 | 868 | } |
869 | 869 | } elseif ($format == 'acars') { |
870 | 870 | if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
871 | 871 | $ACARS->add(trim($buffer)); |
872 | - socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
872 | + socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port); |
|
873 | 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 | - $line = explode(' ',$buffer); |
|
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 |
|
880 | + $userserver = explode('@', $line[0]); |
|
881 | + $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex |
|
882 | 882 | $data['ident'] = $userserver[0]; |
883 | 883 | $data['registration'] = $userserver[0]; |
884 | 884 | $data['latitude'] = $line[4]; |
@@ -886,24 +886,24 @@ discard block |
||
886 | 886 | $data['altitude'] = $line[6]; |
887 | 887 | $data['datetime'] = date('Y-m-d H:i:s'); |
888 | 888 | $aircraft_type = $line[10]; |
889 | - $aircraft_type = preg_split(':/:',$aircraft_type); |
|
890 | - $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
889 | + $aircraft_type = preg_split(':/:', $aircraft_type); |
|
890 | + $data['aircraft_name'] = substr(end($aircraft_type), 0, -4); |
|
891 | 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 | 895 | echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
896 | 896 | die; |
897 | - } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
|
897 | + } elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') { |
|
898 | 898 | $line = explode("\t", $buffer); |
899 | - for($k = 0; $k < count($line); $k=$k+2) { |
|
899 | + for ($k = 0; $k < count($line); $k = $k + 2) { |
|
900 | 900 | $key = $line[$k]; |
901 | - $lined[$key] = $line[$k+1]; |
|
901 | + $lined[$key] = $line[$k + 1]; |
|
902 | 902 | } |
903 | 903 | if (count($lined) > 3) { |
904 | 904 | $data['hex'] = $lined['hexid']; |
905 | 905 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
906 | - $data['datetime'] = date('Y-m-d H:i:s');; |
|
906 | + $data['datetime'] = date('Y-m-d H:i:s'); ; |
|
907 | 907 | if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
908 | 908 | if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
909 | 909 | if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
@@ -921,24 +921,24 @@ discard block |
||
921 | 921 | } else $error = true; |
922 | 922 | } elseif ($format == 'aprs' && $use_aprs) { |
923 | 923 | if ($aprs_connect == 0) { |
924 | - $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
|
924 | + $send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0); |
|
925 | 925 | $aprs_connect = 1; |
926 | 926 | } |
927 | - if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
927 | + if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) { |
|
928 | 928 | $aprs_last_tx = time(); |
929 | 929 | $data_aprs = "# Keep alive"; |
930 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
930 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
931 | 931 | } |
932 | 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 ') { |
|
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 | 938 | $data = array(); |
939 | 939 | //print_r($line); |
940 | 940 | $data['hex'] = $line['address']; |
941 | - $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
941 | + $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']); |
|
942 | 942 | //$data['datetime'] = date('Y-m-d H:i:s'); |
943 | 943 | $data['ident'] = $line['ident']; |
944 | 944 | $data['latitude'] = $line['latitude']; |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | $currentdate = date('Y-m-d H:i:s'); |
959 | 959 | $aprsdate = strtotime($data['datetime']); |
960 | 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); |
|
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 | 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"; |
@@ -1044,7 +1044,7 @@ discard block |
||
1044 | 1044 | connect_all($sourceee); |
1045 | 1045 | $sourceee = array(); |
1046 | 1046 | //connect_all($globalSources); |
1047 | - $tt[$format]=0; |
|
1047 | + $tt[$format] = 0; |
|
1048 | 1048 | break; |
1049 | 1049 | } |
1050 | 1050 | } |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | } |
1053 | 1053 | } else { |
1054 | 1054 | $error = socket_strerror(socket_last_error()); |
1055 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
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 |
@@ -1060,7 +1060,7 @@ discard block |
||
1060 | 1060 | if ($globalDebug) echo "Shutdown all sockets..."; |
1061 | 1061 | |
1062 | 1062 | foreach ($sockets as $sock) { |
1063 | - @socket_shutdown($sock,2); |
|
1063 | + @socket_shutdown($sock, 2); |
|
1064 | 1064 | @socket_close($sock); |
1065 | 1065 | } |
1066 | 1066 |