@@ -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(); |
@@ -54,13 +56,22 @@ discard block |
||
| 54 | 56 | $globalSources = array(); |
| 55 | 57 | $globalSources[] = array('host' => $options['source']); |
| 56 | 58 | } |
| 57 | -if (isset($options['server'])) $globalServer = TRUE; |
|
| 58 | -if (isset($options['idsource'])) $id_source = $options['idsource']; |
|
| 59 | -else $id_source = 1; |
|
| 59 | +if (isset($options['server'])) { |
|
| 60 | + $globalServer = TRUE; |
|
| 61 | +} |
|
| 62 | +if (isset($options['idsource'])) { |
|
| 63 | + $id_source = $options['idsource']; |
|
| 64 | +} else { |
|
| 65 | + $id_source = 1; |
|
| 66 | +} |
|
| 60 | 67 | if (isset($globalServer) && $globalServer) { |
| 61 | - if ($globalDebug) echo "Using Server Mode\n"; |
|
| 68 | + if ($globalDebug) { |
|
| 69 | + echo "Using Server Mode\n"; |
|
| 70 | + } |
|
| 62 | 71 | $SI=new SpotterServer(); |
| 63 | -} else $SI=new SpotterImport($Connection->db); |
|
| 72 | +} else { |
|
| 73 | + $SI=new SpotterImport($Connection->db); |
|
| 74 | +} |
|
| 64 | 75 | //$APRS=new APRS($Connection->db); |
| 65 | 76 | $SBS=new SBS(); |
| 66 | 77 | $ACARS=new ACARS($Connection->db); |
@@ -78,7 +89,9 @@ discard block |
||
| 78 | 89 | } |
| 79 | 90 | |
| 80 | 91 | // let's try and connect |
| 81 | -if ($globalDebug) echo "Connecting...\n"; |
|
| 92 | +if ($globalDebug) { |
|
| 93 | + echo "Connecting...\n"; |
|
| 94 | +} |
|
| 82 | 95 | $use_aprs = false; |
| 83 | 96 | $aprs_full = false; |
| 84 | 97 | $reset = 0; |
@@ -87,7 +100,9 @@ discard block |
||
| 87 | 100 | $ip = gethostbyname($host); |
| 88 | 101 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
| 89 | 102 | $r = @socket_connect($s, $ip, $port); |
| 90 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
| 103 | + if (!socket_set_nonblock($s)) { |
|
| 104 | + echo "Unable to set nonblock on socket\n"; |
|
| 105 | + } |
|
| 91 | 106 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
| 92 | 107 | return $s; |
| 93 | 108 | } |
@@ -115,7 +130,9 @@ discard block |
||
| 115 | 130 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
| 116 | 131 | global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset; |
| 117 | 132 | $reset++; |
| 118 | - if ($globalDebug) echo 'Connect to all...'."\n"; |
|
| 133 | + if ($globalDebug) { |
|
| 134 | + echo 'Connect to all...'."\n"; |
|
| 135 | + } |
|
| 119 | 136 | foreach ($hosts as $id => $value) { |
| 120 | 137 | $host = $value['host']; |
| 121 | 138 | $globalSources[$id]['last_exec'] = 0; |
@@ -125,27 +142,37 @@ discard block |
||
| 125 | 142 | //$formats[$id] = 'deltadbtxt'; |
| 126 | 143 | $globalSources[$id]['format'] = 'deltadbtxt'; |
| 127 | 144 | //$last_exec['deltadbtxt'] = 0; |
| 128 | - if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
| 145 | + if ($globalDebug) { |
|
| 146 | + echo "Connect to deltadb source (".$host.")...\n"; |
|
| 147 | + } |
|
| 129 | 148 | } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
| 130 | 149 | //$formats[$id] = 'vatsimtxt'; |
| 131 | 150 | $globalSources[$id]['format'] = 'vatsimtxt'; |
| 132 | 151 | //$last_exec['vatsimtxt'] = 0; |
| 133 | - if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
| 152 | + if ($globalDebug) { |
|
| 153 | + echo "Connect to vatsim source (".$host.")...\n"; |
|
| 154 | + } |
|
| 134 | 155 | } else if (preg_match('/aircraftlist.json$/i',$host)) { |
| 135 | 156 | //$formats[$id] = 'aircraftlistjson'; |
| 136 | 157 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
| 137 | 158 | //$last_exec['aircraftlistjson'] = 0; |
| 138 | - if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
| 159 | + if ($globalDebug) { |
|
| 160 | + echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
| 161 | + } |
|
| 139 | 162 | } else if (preg_match('/opensky/i',$host)) { |
| 140 | 163 | //$formats[$id] = 'aircraftlistjson'; |
| 141 | 164 | $globalSources[$id]['format'] = 'opensky'; |
| 142 | 165 | //$last_exec['aircraftlistjson'] = 0; |
| 143 | - if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
| 166 | + if ($globalDebug) { |
|
| 167 | + echo "Connect to opensky source (".$host.")...\n"; |
|
| 168 | + } |
|
| 144 | 169 | } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
| 145 | 170 | //$formats[$id] = 'radarvirtueljson'; |
| 146 | 171 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
| 147 | 172 | //$last_exec['radarvirtueljson'] = 0; |
| 148 | - if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
| 173 | + if ($globalDebug) { |
|
| 174 | + echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
| 175 | + } |
|
| 149 | 176 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
| 150 | 177 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
| 151 | 178 | exit(0); |
@@ -154,7 +181,9 @@ discard block |
||
| 154 | 181 | //$formats[$id] = 'planeupdatefaa'; |
| 155 | 182 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
| 156 | 183 | //$last_exec['planeupdatefaa'] = 0; |
| 157 | - if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
| 184 | + if ($globalDebug) { |
|
| 185 | + echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
| 186 | + } |
|
| 158 | 187 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
| 159 | 188 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
| 160 | 189 | exit(0); |
@@ -163,26 +192,36 @@ discard block |
||
| 163 | 192 | //$formats[$id] = 'phpvmacars'; |
| 164 | 193 | $globalSources[$id]['format'] = 'phpvmacars'; |
| 165 | 194 | //$last_exec['phpvmacars'] = 0; |
| 166 | - if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
| 195 | + if ($globalDebug) { |
|
| 196 | + echo "Connect to phpvmacars source (".$host.")...\n"; |
|
| 197 | + } |
|
| 167 | 198 | } else if (preg_match('/VAM-json.php$/i',$host)) { |
| 168 | 199 | //$formats[$id] = 'phpvmacars'; |
| 169 | 200 | $globalSources[$id]['format'] = 'vam'; |
| 170 | - if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
| 201 | + if ($globalDebug) { |
|
| 202 | + echo "Connect to Vam source (".$host.")...\n"; |
|
| 203 | + } |
|
| 171 | 204 | } else if (preg_match('/whazzup/i',$host)) { |
| 172 | 205 | //$formats[$id] = 'whazzup'; |
| 173 | 206 | $globalSources[$id]['format'] = 'whazzup'; |
| 174 | 207 | //$last_exec['whazzup'] = 0; |
| 175 | - if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
| 208 | + if ($globalDebug) { |
|
| 209 | + echo "Connect to whazzup source (".$host.")...\n"; |
|
| 210 | + } |
|
| 176 | 211 | } else if (preg_match('/recentpireps/i',$host)) { |
| 177 | 212 | //$formats[$id] = 'pirepsjson'; |
| 178 | 213 | $globalSources[$id]['format'] = 'pirepsjson'; |
| 179 | 214 | //$last_exec['pirepsjson'] = 0; |
| 180 | - if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
| 215 | + if ($globalDebug) { |
|
| 216 | + echo "Connect to pirepsjson source (".$host.")...\n"; |
|
| 217 | + } |
|
| 181 | 218 | } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
| 182 | 219 | //$formats[$id] = 'fr24json'; |
| 183 | 220 | $globalSources[$id]['format'] = 'fr24json'; |
| 184 | 221 | //$last_exec['fr24json'] = 0; |
| 185 | - if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
| 222 | + if ($globalDebug) { |
|
| 223 | + echo "Connect to fr24 source (".$host.")...\n"; |
|
| 224 | + } |
|
| 186 | 225 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
| 187 | 226 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
| 188 | 227 | exit(0); |
@@ -191,10 +230,14 @@ discard block |
||
| 191 | 230 | } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
| 192 | 231 | //$formats[$id] = 'tsv'; |
| 193 | 232 | $globalSources[$id]['format'] = 'tsv'; |
| 194 | - if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
| 233 | + if ($globalDebug) { |
|
| 234 | + echo "Connect to tsv source (".$host.")...\n"; |
|
| 235 | + } |
|
| 195 | 236 | } |
| 196 | 237 | } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
| 197 | - if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
| 238 | + if ($globalDebug) { |
|
| 239 | + echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
| 240 | + } |
|
| 198 | 241 | } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
| 199 | 242 | $hostport = explode(':',$host); |
| 200 | 243 | if (isset($hostport[1])) { |
@@ -231,17 +274,25 @@ discard block |
||
| 231 | 274 | //$formats[$id] = 'beast'; |
| 232 | 275 | $globalSources[$id]['format'] = 'beast'; |
| 233 | 276 | //} else $formats[$id] = 'sbs'; |
| 234 | - } else $globalSources[$id]['format'] = 'sbs'; |
|
| 277 | + } else { |
|
| 278 | + $globalSources[$id]['format'] = 'sbs'; |
|
| 279 | + } |
|
| 235 | 280 | //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
| 236 | 281 | } |
| 237 | - if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
| 282 | + if ($globalDebug) { |
|
| 283 | + echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
| 284 | + } |
|
| 238 | 285 | } else { |
| 239 | - if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
| 286 | + if ($globalDebug) { |
|
| 287 | + echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
| 288 | + } |
|
| 240 | 289 | } |
| 241 | 290 | } |
| 242 | 291 | } |
| 243 | 292 | } |
| 244 | -if (!isset($globalMinFetch)) $globalMinFetch = 15; |
|
| 293 | +if (!isset($globalMinFetch)) { |
|
| 294 | + $globalMinFetch = 15; |
|
| 295 | +} |
|
| 245 | 296 | |
| 246 | 297 | // Initialize all |
| 247 | 298 | $status = array(); |
@@ -249,13 +300,19 @@ discard block |
||
| 249 | 300 | $formats = array(); |
| 250 | 301 | $last_exec = array(); |
| 251 | 302 | $time = time(); |
| 252 | -if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut; |
|
| 253 | -else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
|
| 254 | -else $timeout = 20; |
|
| 303 | +if (isset($globalSourcesTimeout)) { |
|
| 304 | + $timeout = $globalSourcesTimeOut; |
|
| 305 | +} else if (isset($globalSBS1TimeOut)) { |
|
| 306 | + $timeout = $globalSBS1TimeOut; |
|
| 307 | +} else { |
|
| 308 | + $timeout = 20; |
|
| 309 | +} |
|
| 255 | 310 | $errno = ''; |
| 256 | 311 | $errstr=''; |
| 257 | 312 | |
| 258 | -if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
| 313 | +if (!isset($globalDaemon)) { |
|
| 314 | + $globalDaemon = TRUE; |
|
| 315 | +} |
|
| 259 | 316 | /* Initiate connections to all the hosts simultaneously */ |
| 260 | 317 | //connect_all($hosts); |
| 261 | 318 | //connect_all($globalSources); |
@@ -275,7 +332,9 @@ discard block |
||
| 275 | 332 | if (isset($source['format']) && $source['format'] == 'aprs') { |
| 276 | 333 | $aprs_connect = 0; |
| 277 | 334 | $use_aprs = true; |
| 278 | - if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true; |
|
| 335 | + if (isset($source['port']) && $source['port'] == '10152') { |
|
| 336 | + $aprs_full = true; |
|
| 337 | + } |
|
| 279 | 338 | break; |
| 280 | 339 | } |
| 281 | 340 | } |
@@ -286,23 +345,43 @@ discard block |
||
| 286 | 345 | $aprs_connect = 0; |
| 287 | 346 | $aprs_keep = 120; |
| 288 | 347 | $aprs_last_tx = time(); |
| 289 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
| 290 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
| 291 | - if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
|
| 292 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
| 293 | - if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
|
| 294 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
| 295 | - if ($aprs_full) $aprs_filter = ''; |
|
| 348 | + if (isset($globalAPRSversion)) { |
|
| 349 | + $aprs_version = $globalAPRSversion; |
|
| 350 | + } else { |
|
| 351 | + $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
| 352 | + } |
|
| 353 | + if (isset($globalAPRSssid)) { |
|
| 354 | + $aprs_ssid = $globalAPRSssid; |
|
| 355 | + } else { |
|
| 356 | + $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
| 357 | + } |
|
| 358 | + if (isset($globalAPRSfilter)) { |
|
| 359 | + $aprs_filter = $globalAPRSfilter; |
|
| 360 | + } else { |
|
| 361 | + $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
| 362 | + } |
|
| 363 | + if ($aprs_full) { |
|
| 364 | + $aprs_filter = ''; |
|
| 365 | + } |
|
| 296 | 366 | |
| 297 | - if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; |
|
| 298 | - else $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n"; |
|
| 299 | -} |
|
| 367 | + if ($aprs_filter != '') { |
|
| 368 | + $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; |
|
| 369 | + } else { |
|
| 370 | + $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n"; |
|
| 371 | + } |
|
| 372 | + } |
|
| 300 | 373 | |
| 301 | 374 | // connected - lets do some work |
| 302 | -if ($globalDebug) echo "Connected!\n"; |
|
| 375 | +if ($globalDebug) { |
|
| 376 | + echo "Connected!\n"; |
|
| 377 | +} |
|
| 303 | 378 | sleep(1); |
| 304 | -if ($globalDebug) echo "SCAN MODE \n\n"; |
|
| 305 | -if (!isset($globalCronEnd)) $globalCronEnd = 60; |
|
| 379 | +if ($globalDebug) { |
|
| 380 | + echo "SCAN MODE \n\n"; |
|
| 381 | +} |
|
| 382 | +if (!isset($globalCronEnd)) { |
|
| 383 | + $globalCronEnd = 60; |
|
| 384 | +} |
|
| 306 | 385 | $endtime = time()+$globalCronEnd; |
| 307 | 386 | $i = 1; |
| 308 | 387 | $tt = array(); |
@@ -316,20 +395,28 @@ discard block |
||
| 316 | 395 | |
| 317 | 396 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
| 318 | 397 | while ($i > 0) { |
| 319 | - if (!$globalDaemon) $i = $endtime-time(); |
|
| 398 | + if (!$globalDaemon) { |
|
| 399 | + $i = $endtime-time(); |
|
| 400 | + } |
|
| 320 | 401 | // Delete old ATC |
| 321 | 402 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
| 322 | - if ($globalDebug) echo 'Delete old ATC...'."\n"; |
|
| 403 | + if ($globalDebug) { |
|
| 404 | + echo 'Delete old ATC...'."\n"; |
|
| 405 | + } |
|
| 323 | 406 | $ATC->deleteOldATC(); |
| 324 | 407 | } |
| 325 | 408 | |
| 326 | 409 | if (count($last_exec) > 0) { |
| 327 | 410 | $max = $globalMinFetch; |
| 328 | 411 | foreach ($last_exec as $last) { |
| 329 | - if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
| 412 | + if ((time() - $last['last']) < $max) { |
|
| 413 | + $max = time() - $last['last']; |
|
| 414 | + } |
|
| 330 | 415 | } |
| 331 | 416 | if ($max != $globalMinFetch) { |
| 332 | - if ($globalDebug) echo 'Sleeping...'."\n"; |
|
| 417 | + if ($globalDebug) { |
|
| 418 | + echo 'Sleeping...'."\n"; |
|
| 419 | + } |
|
| 333 | 420 | sleep($globalMinFetch-$max+2); |
| 334 | 421 | } |
| 335 | 422 | } |
@@ -338,11 +425,15 @@ discard block |
||
| 338 | 425 | //foreach ($formats as $id => $value) { |
| 339 | 426 | foreach ($globalSources as $id => $value) { |
| 340 | 427 | date_default_timezone_set('UTC'); |
| 341 | - if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0; |
|
| 428 | + if (!isset($last_exec[$id]['last'])) { |
|
| 429 | + $last_exec[$id]['last'] = 0; |
|
| 430 | + } |
|
| 342 | 431 | if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
| 343 | 432 | //$buffer = $Common->getData($hosts[$id]); |
| 344 | 433 | $buffer = $Common->getData($value['host']); |
| 345 | - if ($buffer != '') $reset = 0; |
|
| 434 | + if ($buffer != '') { |
|
| 435 | + $reset = 0; |
|
| 436 | + } |
|
| 346 | 437 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
| 347 | 438 | $buffer = explode('\n',$buffer); |
| 348 | 439 | foreach ($buffer as $line) { |
@@ -351,19 +442,38 @@ discard block |
||
| 351 | 442 | $data = array(); |
| 352 | 443 | $data['hex'] = $line[1]; // hex |
| 353 | 444 | $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 |
|
| 445 | + if (isset($line[3])) { |
|
| 446 | + $data['altitude'] = $line[3]; |
|
| 447 | + } |
|
| 448 | + // altitude |
|
| 449 | + if (isset($line[4])) { |
|
| 450 | + $data['speed'] = $line[4]; |
|
| 451 | + } |
|
| 452 | + // speed |
|
| 453 | + if (isset($line[5])) { |
|
| 454 | + $data['heading'] = $line[5]; |
|
| 455 | + } |
|
| 456 | + // heading |
|
| 457 | + if (isset($line[6])) { |
|
| 458 | + $data['latitude'] = $line[6]; |
|
| 459 | + } |
|
| 460 | + // lat |
|
| 461 | + if (isset($line[7])) { |
|
| 462 | + $data['longitude'] = $line[7]; |
|
| 463 | + } |
|
| 464 | + // long |
|
| 359 | 465 | $data['verticalrate'] = ''; // vertical rate |
| 360 | 466 | //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
| 361 | 467 | $data['emergency'] = ''; // emergency |
| 362 | 468 | $data['datetime'] = date('Y-m-d H:i:s'); |
| 363 | 469 | $data['format_source'] = 'deltadbtxt'; |
| 364 | 470 | $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']; |
|
| 471 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 472 | + $data['source_name'] = $value['name']; |
|
| 473 | + } |
|
| 474 | + if (isset($value['sourcestats'])) { |
|
| 475 | + $data['sourcestats'] = $value['sourcestats']; |
|
| 476 | + } |
|
| 367 | 477 | $SI->add($data); |
| 368 | 478 | unset($data); |
| 369 | 479 | } |
@@ -381,16 +491,28 @@ discard block |
||
| 381 | 491 | $line = explode(':', $line); |
| 382 | 492 | if (count($line) > 30 && $line[0] != 'callsign') { |
| 383 | 493 | $data = array(); |
| 384 | - if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
| 385 | - else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
| 494 | + if (isset($line[37]) && $line[37] != '') { |
|
| 495 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
| 496 | + } else { |
|
| 497 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
| 498 | + } |
|
| 386 | 499 | $data['pilot_id'] = $line[1]; |
| 387 | 500 | $data['pilot_name'] = $line[2]; |
| 388 | 501 | $data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT); |
| 389 | 502 | $data['ident'] = $line[0]; // ident |
| 390 | - if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
|
| 503 | + if ($line[7] != '' && $line[7] != 0) { |
|
| 504 | + $data['altitude'] = $line[7]; |
|
| 505 | + } |
|
| 506 | + // altitude |
|
| 391 | 507 | $data['speed'] = $line[8]; // speed |
| 392 | - if (isset($line[45])) $data['heading'] = $line[45]; // heading |
|
| 393 | - elseif (isset($line[38])) $data['heading'] = $line[38]; // heading |
|
| 508 | + if (isset($line[45])) { |
|
| 509 | + $data['heading'] = $line[45]; |
|
| 510 | + } |
|
| 511 | + // heading |
|
| 512 | + elseif (isset($line[38])) { |
|
| 513 | + $data['heading'] = $line[38]; |
|
| 514 | + } |
|
| 515 | + // heading |
|
| 394 | 516 | $data['latitude'] = $line[5]; // lat |
| 395 | 517 | $data['longitude'] = $line[6]; // long |
| 396 | 518 | $data['verticalrate'] = ''; // vertical rate |
@@ -406,7 +528,9 @@ discard block |
||
| 406 | 528 | $data['frequency'] = $line[4]; |
| 407 | 529 | $data['type'] = $line[18]; |
| 408 | 530 | $data['range'] = $line[19]; |
| 409 | - if (isset($line[35])) $data['info'] = $line[35]; |
|
| 531 | + if (isset($line[35])) { |
|
| 532 | + $data['info'] = $line[35]; |
|
| 533 | + } |
|
| 410 | 534 | $data['id_source'] = $id_source; |
| 411 | 535 | //$data['arrival_airport_time'] = ; |
| 412 | 536 | if ($line[9] != '') { |
@@ -420,23 +544,38 @@ discard block |
||
| 420 | 544 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt'; |
| 421 | 545 | */ |
| 422 | 546 | $data['format_source'] = $value['format']; |
| 423 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 424 | - if ($line[3] == 'PILOT') $SI->add($data); |
|
| 425 | - elseif ($line[3] == 'ATC') { |
|
| 547 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 548 | + $data['source_name'] = $value['name']; |
|
| 549 | + } |
|
| 550 | + if ($line[3] == 'PILOT') { |
|
| 551 | + $SI->add($data); |
|
| 552 | + } elseif ($line[3] == 'ATC') { |
|
| 426 | 553 | //print_r($data); |
| 427 | 554 | $data['info'] = str_replace('^§','<br />',$data['info']); |
| 428 | 555 | $data['info'] = str_replace('&sect;','',$data['info']); |
| 429 | 556 | $typec = substr($data['ident'],-3); |
| 430 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
| 431 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
| 432 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
| 433 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
| 434 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
| 435 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
| 436 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
| 437 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
| 438 | - elseif ($data['type'] == '') $data['type'] = 'Observer'; |
|
| 439 | - if (!isset($data['source_name'])) $data['source_name'] = ''; |
|
| 557 | + if ($typec == 'APP') { |
|
| 558 | + $data['type'] = 'Approach'; |
|
| 559 | + } elseif ($typec == 'TWR') { |
|
| 560 | + $data['type'] = 'Tower'; |
|
| 561 | + } elseif ($typec == 'OBS') { |
|
| 562 | + $data['type'] = 'Observer'; |
|
| 563 | + } elseif ($typec == 'GND') { |
|
| 564 | + $data['type'] = 'Ground'; |
|
| 565 | + } elseif ($typec == 'DEL') { |
|
| 566 | + $data['type'] = 'Delivery'; |
|
| 567 | + } elseif ($typec == 'DEP') { |
|
| 568 | + $data['type'] = 'Departure'; |
|
| 569 | + } elseif ($typec == 'FSS') { |
|
| 570 | + $data['type'] = 'Flight Service Station'; |
|
| 571 | + } elseif ($typec == 'CTR') { |
|
| 572 | + $data['type'] = 'Control Radar or Centre'; |
|
| 573 | + } elseif ($data['type'] == '') { |
|
| 574 | + $data['type'] = 'Observer'; |
|
| 575 | + } |
|
| 576 | + if (!isset($data['source_name'])) { |
|
| 577 | + $data['source_name'] = ''; |
|
| 578 | + } |
|
| 440 | 579 | 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']); |
| 441 | 580 | } |
| 442 | 581 | unset($data); |
@@ -456,26 +595,55 @@ discard block |
||
| 456 | 595 | foreach ($all_data['acList'] as $line) { |
| 457 | 596 | $data = array(); |
| 458 | 597 | $data['hex'] = $line['Icao']; // hex |
| 459 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
| 460 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
| 461 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
| 462 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
| 463 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
| 464 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
| 598 | + if (isset($line['Call'])) { |
|
| 599 | + $data['ident'] = $line['Call']; |
|
| 600 | + } |
|
| 601 | + // ident |
|
| 602 | + if (isset($line['Alt'])) { |
|
| 603 | + $data['altitude'] = $line['Alt']; |
|
| 604 | + } |
|
| 605 | + // altitude |
|
| 606 | + if (isset($line['Spd'])) { |
|
| 607 | + $data['speed'] = $line['Spd']; |
|
| 608 | + } |
|
| 609 | + // speed |
|
| 610 | + if (isset($line['Trak'])) { |
|
| 611 | + $data['heading'] = $line['Trak']; |
|
| 612 | + } |
|
| 613 | + // heading |
|
| 614 | + if (isset($line['Lat'])) { |
|
| 615 | + $data['latitude'] = $line['Lat']; |
|
| 616 | + } |
|
| 617 | + // lat |
|
| 618 | + if (isset($line['Long'])) { |
|
| 619 | + $data['longitude'] = $line['Long']; |
|
| 620 | + } |
|
| 621 | + // long |
|
| 465 | 622 | //$data['verticalrate'] = $line['']; // verticale rate |
| 466 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
| 623 | + if (isset($line['Sqk'])) { |
|
| 624 | + $data['squawk'] = $line['Sqk']; |
|
| 625 | + } |
|
| 626 | + // squawk |
|
| 467 | 627 | $data['emergency'] = ''; // emergency |
| 468 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
| 628 | + if (isset($line['Reg'])) { |
|
| 629 | + $data['registration'] = $line['Reg']; |
|
| 630 | + } |
|
| 469 | 631 | /* |
| 470 | 632 | if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); |
| 471 | 633 | else $data['datetime'] = date('Y-m-d H:i:s'); |
| 472 | 634 | */ |
| 473 | 635 | $data['datetime'] = date('Y-m-d H:i:s'); |
| 474 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
| 636 | + if (isset($line['Type'])) { |
|
| 637 | + $data['aircraft_icao'] = $line['Type']; |
|
| 638 | + } |
|
| 475 | 639 | $data['format_source'] = 'aircraftlistjson'; |
| 476 | 640 | $data['id_source'] = $id_source; |
| 477 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 478 | - if (isset($data['datetime'])) $SI->add($data); |
|
| 641 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 642 | + $data['source_name'] = $value['name']; |
|
| 643 | + } |
|
| 644 | + if (isset($data['datetime'])) { |
|
| 645 | + $SI->add($data); |
|
| 646 | + } |
|
| 479 | 647 | unset($data); |
| 480 | 648 | } |
| 481 | 649 | } else { |
@@ -495,7 +663,9 @@ discard block |
||
| 495 | 663 | $data['datetime'] = date('Y-m-d H:i:s'); |
| 496 | 664 | $data['format_source'] = 'aircraftlistjson'; |
| 497 | 665 | $data['id_source'] = $id_source; |
| 498 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 666 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 667 | + $data['source_name'] = $value['name']; |
|
| 668 | + } |
|
| 499 | 669 | $SI->add($data); |
| 500 | 670 | unset($data); |
| 501 | 671 | } |
@@ -531,7 +701,9 @@ discard block |
||
| 531 | 701 | $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
| 532 | 702 | $data['format_source'] = 'planeupdatefaa'; |
| 533 | 703 | $data['id_source'] = $id_source; |
| 534 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 704 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 705 | + $data['source_name'] = $value['name']; |
|
| 706 | + } |
|
| 535 | 707 | $SI->add($data); |
| 536 | 708 | unset($data); |
| 537 | 709 | } |
@@ -571,7 +743,9 @@ discard block |
||
| 571 | 743 | //$buffer = $Common->getData($hosts[$id]); |
| 572 | 744 | $buffer = $Common->getData($value['host']); |
| 573 | 745 | $all_data = json_decode($buffer,true); |
| 574 | - if (!empty($all_data)) $reset = 0; |
|
| 746 | + if (!empty($all_data)) { |
|
| 747 | + $reset = 0; |
|
| 748 | + } |
|
| 575 | 749 | foreach ($all_data as $key => $line) { |
| 576 | 750 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
| 577 | 751 | $data = array(); |
@@ -592,7 +766,9 @@ discard block |
||
| 592 | 766 | $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
| 593 | 767 | $data['format_source'] = 'fr24json'; |
| 594 | 768 | $data['id_source'] = $id_source; |
| 595 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 769 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 770 | + $data['source_name'] = $value['name']; |
|
| 771 | + } |
|
| 596 | 772 | $SI->add($data); |
| 597 | 773 | unset($data); |
| 598 | 774 | } |
@@ -616,23 +792,39 @@ discard block |
||
| 616 | 792 | if (isset($line['inf'])) { |
| 617 | 793 | $data = array(); |
| 618 | 794 | $data['hex'] = $line['inf']['ia']; |
| 619 | - if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13] |
|
| 795 | + if (isset($line['inf']['cs'])) { |
|
| 796 | + $data['ident'] = $line['inf']['cs']; |
|
| 797 | + } |
|
| 798 | + //$line[13] |
|
| 620 | 799 | $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
| 621 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
| 622 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
| 800 | + if (isset($line['inf']['gs'])) { |
|
| 801 | + $data['speed'] = round($line['inf']['gs']*0.539957); |
|
| 802 | + } |
|
| 803 | + // speed |
|
| 804 | + if (isset($line['inf']['tr'])) { |
|
| 805 | + $data['heading'] = $line['inf']['tr']; |
|
| 806 | + } |
|
| 807 | + // heading |
|
| 623 | 808 | $data['latitude'] = $line['pt'][0]; // lat |
| 624 | 809 | $data['longitude'] = $line['pt'][1]; // long |
| 625 | 810 | //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
| 626 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
| 811 | + if (isset($line['inf']['sq'])) { |
|
| 812 | + $data['squawk'] = $line['inf']['sq']; |
|
| 813 | + } |
|
| 814 | + // squawk |
|
| 627 | 815 | //$data['aircraft_icao'] = $line[8]; |
| 628 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
| 816 | + if (isset($line['inf']['rc'])) { |
|
| 817 | + $data['registration'] = $line['inf']['rc']; |
|
| 818 | + } |
|
| 629 | 819 | //$data['departure_airport_iata'] = $line[11]; |
| 630 | 820 | //$data['arrival_airport_iata'] = $line[12]; |
| 631 | 821 | //$data['emergency'] = ''; // emergency |
| 632 | 822 | $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
| 633 | 823 | $data['format_source'] = 'radarvirtueljson'; |
| 634 | 824 | $data['id_source'] = $id_source; |
| 635 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 825 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 826 | + $data['source_name'] = $value['name']; |
|
| 827 | + } |
|
| 636 | 828 | $SI->add($data); |
| 637 | 829 | unset($data); |
| 638 | 830 | } |
@@ -653,29 +845,62 @@ discard block |
||
| 653 | 845 | $data['id'] = $line['id']; |
| 654 | 846 | $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
| 655 | 847 | $data['ident'] = $line['callsign']; // ident |
| 656 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
| 657 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
| 658 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
| 659 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
| 660 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
| 661 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
| 848 | + if (isset($line['pilotid'])) { |
|
| 849 | + $data['pilot_id'] = $line['pilotid']; |
|
| 850 | + } |
|
| 851 | + // pilot id |
|
| 852 | + if (isset($line['name'])) { |
|
| 853 | + $data['pilot_name'] = $line['name']; |
|
| 854 | + } |
|
| 855 | + // pilot name |
|
| 856 | + if (isset($line['alt'])) { |
|
| 857 | + $data['altitude'] = $line['alt']; |
|
| 858 | + } |
|
| 859 | + // altitude |
|
| 860 | + if (isset($line['gs'])) { |
|
| 861 | + $data['speed'] = $line['gs']; |
|
| 862 | + } |
|
| 863 | + // speed |
|
| 864 | + if (isset($line['heading'])) { |
|
| 865 | + $data['heading'] = $line['heading']; |
|
| 866 | + } |
|
| 867 | + // heading |
|
| 868 | + if (isset($line['route'])) { |
|
| 869 | + $data['waypoints'] = $line['route']; |
|
| 870 | + } |
|
| 871 | + // route |
|
| 662 | 872 | $data['latitude'] = $line['lat']; // lat |
| 663 | 873 | $data['longitude'] = $line['lon']; // long |
| 664 | 874 | //$data['verticalrate'] = $line['vrt']; // verticale rate |
| 665 | 875 | //$data['squawk'] = $line['squawk']; // squawk |
| 666 | 876 | //$data['emergency'] = ''; // emergency |
| 667 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
| 668 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
| 669 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
| 877 | + if (isset($line['depicao'])) { |
|
| 878 | + $data['departure_airport_icao'] = $line['depicao']; |
|
| 879 | + } |
|
| 880 | + if (isset($line['deptime'])) { |
|
| 881 | + $data['departure_airport_time'] = $line['deptime']; |
|
| 882 | + } |
|
| 883 | + if (isset($line['arricao'])) { |
|
| 884 | + $data['arrival_airport_icao'] = $line['arricao']; |
|
| 885 | + } |
|
| 670 | 886 | //$data['arrival_airport_time'] = $line['arrtime']; |
| 671 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
| 672 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
| 673 | - if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
| 674 | - else $data['info'] = ''; |
|
| 887 | + if (isset($line['aircraft'])) { |
|
| 888 | + $data['aircraft_icao'] = $line['aircraft']; |
|
| 889 | + } |
|
| 890 | + if (isset($line['transponder'])) { |
|
| 891 | + $data['squawk'] = $line['transponder']; |
|
| 892 | + } |
|
| 893 | + if (isset($line['atis'])) { |
|
| 894 | + $data['info'] = $line['atis']; |
|
| 895 | + } else { |
|
| 896 | + $data['info'] = ''; |
|
| 897 | + } |
|
| 675 | 898 | $data['format_source'] = 'pireps'; |
| 676 | 899 | $data['id_source'] = $id_source; |
| 677 | 900 | $data['datetime'] = date('Y-m-d H:i:s'); |
| 678 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 901 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 902 | + $data['source_name'] = $value['name']; |
|
| 903 | + } |
|
| 679 | 904 | if ($line['icon'] == 'plane') { |
| 680 | 905 | $SI->add($data); |
| 681 | 906 | // print_r($data); |
@@ -684,15 +909,25 @@ discard block |
||
| 684 | 909 | $data['info'] = str_replace('&sect;','',$data['info']); |
| 685 | 910 | $typec = substr($data['ident'],-3); |
| 686 | 911 | $data['type'] = ''; |
| 687 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
| 688 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
| 689 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
| 690 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
| 691 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
| 692 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
| 693 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
| 694 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
| 695 | - else $data['type'] = 'Observer'; |
|
| 912 | + if ($typec == 'APP') { |
|
| 913 | + $data['type'] = 'Approach'; |
|
| 914 | + } elseif ($typec == 'TWR') { |
|
| 915 | + $data['type'] = 'Tower'; |
|
| 916 | + } elseif ($typec == 'OBS') { |
|
| 917 | + $data['type'] = 'Observer'; |
|
| 918 | + } elseif ($typec == 'GND') { |
|
| 919 | + $data['type'] = 'Ground'; |
|
| 920 | + } elseif ($typec == 'DEL') { |
|
| 921 | + $data['type'] = 'Delivery'; |
|
| 922 | + } elseif ($typec == 'DEP') { |
|
| 923 | + $data['type'] = 'Departure'; |
|
| 924 | + } elseif ($typec == 'FSS') { |
|
| 925 | + $data['type'] = 'Flight Service Station'; |
|
| 926 | + } elseif ($typec == 'CTR') { |
|
| 927 | + $data['type'] = 'Control Radar or Centre'; |
|
| 928 | + } else { |
|
| 929 | + $data['type'] = 'Observer'; |
|
| 930 | + } |
|
| 696 | 931 | 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']); |
| 697 | 932 | } |
| 698 | 933 | unset($data); |
@@ -703,7 +938,9 @@ discard block |
||
| 703 | 938 | //} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { |
| 704 | 939 | } elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
| 705 | 940 | //$buffer = $Common->getData($hosts[$id]); |
| 706 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
| 941 | + if ($globalDebug) { |
|
| 942 | + echo 'Get Data...'."\n"; |
|
| 943 | + } |
|
| 707 | 944 | $buffer = $Common->getData($value['host']); |
| 708 | 945 | $all_data = json_decode($buffer,true); |
| 709 | 946 | if ($buffer != '' && is_array($all_data)) { |
@@ -711,10 +948,16 @@ discard block |
||
| 711 | 948 | foreach ($all_data as $line) { |
| 712 | 949 | $data = array(); |
| 713 | 950 | //$data['id'] = $line['id']; // id not usable |
| 714 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
| 951 | + if (isset($line['pilotid'])) { |
|
| 952 | + $data['id'] = $line['pilotid'].$line['flightnum']; |
|
| 953 | + } |
|
| 715 | 954 | $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
| 716 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
| 717 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
| 955 | + if (isset($line['pilotname'])) { |
|
| 956 | + $data['pilot_name'] = $line['pilotname']; |
|
| 957 | + } |
|
| 958 | + if (isset($line['pilotid'])) { |
|
| 959 | + $data['pilot_id'] = $line['pilotid']; |
|
| 960 | + } |
|
| 718 | 961 | $data['ident'] = $line['flightnum']; // ident |
| 719 | 962 | $data['altitude'] = $line['alt']; // altitude |
| 720 | 963 | $data['speed'] = $line['gs']; // speed |
@@ -732,27 +975,41 @@ discard block |
||
| 732 | 975 | $data['arrival_airport_icao'] = $line['arricao']; |
| 733 | 976 | $data['arrival_airport_time'] = $line['arrtime']; |
| 734 | 977 | $data['registration'] = $line['aircraft']; |
| 735 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
| 978 | + if (isset($line['route'])) { |
|
| 979 | + $data['waypoints'] = $line['route']; |
|
| 980 | + } |
|
| 981 | + // route |
|
| 736 | 982 | if (isset($line['aircraftname'])) { |
| 737 | 983 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
| 738 | 984 | $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
| 739 | 985 | $aircraft_data = explode('-',$line['aircraftname']); |
| 740 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
|
| 741 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
|
| 742 | - else { |
|
| 986 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) { |
|
| 987 | + $data['aircraft_icao'] = $aircraft_data[0]; |
|
| 988 | + } elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) { |
|
| 989 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
| 990 | + } else { |
|
| 743 | 991 | $aircraft_data = explode(' ',$line['aircraftname']); |
| 744 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
|
| 745 | - else $data['aircraft_icao'] = $line['aircraftname']; |
|
| 992 | + if (isset($aircraft_data[1])) { |
|
| 993 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
| 994 | + } else { |
|
| 995 | + $data['aircraft_icao'] = $line['aircraftname']; |
|
| 996 | + } |
|
| 746 | 997 | } |
| 747 | 998 | } |
| 748 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
| 999 | + if (isset($line['route'])) { |
|
| 1000 | + $data['waypoints'] = $line['route']; |
|
| 1001 | + } |
|
| 749 | 1002 | $data['id_source'] = $id_source; |
| 750 | 1003 | $data['format_source'] = 'phpvmacars'; |
| 751 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 1004 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 1005 | + $data['source_name'] = $value['name']; |
|
| 1006 | + } |
|
| 752 | 1007 | $SI->add($data); |
| 753 | 1008 | unset($data); |
| 754 | 1009 | } |
| 755 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
| 1010 | + if ($globalDebug) { |
|
| 1011 | + echo 'No more data...'."\n"; |
|
| 1012 | + } |
|
| 756 | 1013 | unset($buffer); |
| 757 | 1014 | unset($all_data); |
| 758 | 1015 | } |
@@ -760,7 +1017,9 @@ discard block |
||
| 760 | 1017 | $last_exec[$id]['last'] = time(); |
| 761 | 1018 | } elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
| 762 | 1019 | //$buffer = $Common->getData($hosts[$id]); |
| 763 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
| 1020 | + if ($globalDebug) { |
|
| 1021 | + echo 'Get Data...'."\n"; |
|
| 1022 | + } |
|
| 764 | 1023 | $buffer = $Common->getData($value['host']); |
| 765 | 1024 | $all_data = json_decode($buffer,true); |
| 766 | 1025 | if ($buffer != '' && is_array($all_data)) { |
@@ -789,15 +1048,22 @@ discard block |
||
| 789 | 1048 | $data['arrival_airport_icao'] = $line['arrival']; |
| 790 | 1049 | //$data['arrival_airport_time'] = $line['arrival_time']; |
| 791 | 1050 | //$data['registration'] = $line['aircraft']; |
| 792 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
| 1051 | + if (isset($line['route'])) { |
|
| 1052 | + $data['waypoints'] = $line['route']; |
|
| 1053 | + } |
|
| 1054 | + // route |
|
| 793 | 1055 | $data['aircraft_icao'] = $line['plane_type']; |
| 794 | 1056 | $data['id_source'] = $id_source; |
| 795 | 1057 | $data['format_source'] = 'vam'; |
| 796 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
| 1058 | + if (isset($value['name']) && $value['name'] != '') { |
|
| 1059 | + $data['source_name'] = $value['name']; |
|
| 1060 | + } |
|
| 797 | 1061 | $SI->add($data); |
| 798 | 1062 | unset($data); |
| 799 | 1063 | } |
| 800 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
| 1064 | + if ($globalDebug) { |
|
| 1065 | + echo 'No more data...'."\n"; |
|
| 1066 | + } |
|
| 801 | 1067 | unset($buffer); |
| 802 | 1068 | unset($all_data); |
| 803 | 1069 | } |
@@ -805,7 +1071,9 @@ discard block |
||
| 805 | 1071 | $last_exec[$id]['last'] = time(); |
| 806 | 1072 | //} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { |
| 807 | 1073 | } 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') { |
| 808 | - if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
| 1074 | + if (function_exists('pcntl_fork')) { |
|
| 1075 | + pcntl_signal_dispatch(); |
|
| 1076 | + } |
|
| 809 | 1077 | //$last_exec[$id]['last'] = time(); |
| 810 | 1078 | |
| 811 | 1079 | //$read = array( $sockets[$id] ); |
@@ -813,7 +1081,9 @@ discard block |
||
| 813 | 1081 | $write = NULL; |
| 814 | 1082 | $e = NULL; |
| 815 | 1083 | $n = socket_select($read, $write, $e, $timeout); |
| 816 | - if ($e != NULL) var_dump($e); |
|
| 1084 | + if ($e != NULL) { |
|
| 1085 | + var_dump($e); |
|
| 1086 | + } |
|
| 817 | 1087 | if ($n > 0) { |
| 818 | 1088 | $reset = 0; |
| 819 | 1089 | foreach ($read as $nb => $r) { |
@@ -835,7 +1105,9 @@ discard block |
||
| 835 | 1105 | if ($buffer != '') { |
| 836 | 1106 | $tt[$format] = 0; |
| 837 | 1107 | if ($format == 'acarssbs3') { |
| 838 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
| 1108 | + if ($globalDebug) { |
|
| 1109 | + echo 'ACARS : '.$buffer."\n"; |
|
| 1110 | + } |
|
| 839 | 1111 | $ACARS->add(trim($buffer)); |
| 840 | 1112 | $ACARS->deleteLiveAcarsData(); |
| 841 | 1113 | } elseif ($format == 'raw') { |
@@ -844,9 +1116,15 @@ discard block |
||
| 844 | 1116 | if (is_array($data)) { |
| 845 | 1117 | $data['datetime'] = date('Y-m-d H:i:s'); |
| 846 | 1118 | $data['format_source'] = 'raw'; |
| 847 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
| 848 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
| 849 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
| 1119 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
| 1120 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
| 1121 | + } |
|
| 1122 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
| 1123 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
| 1124 | + } |
|
| 1125 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
| 1126 | + $SI->add($data); |
|
| 1127 | + } |
|
| 850 | 1128 | } |
| 851 | 1129 | } elseif ($format == 'flightgearsp') { |
| 852 | 1130 | //echo $buffer."\n"; |
@@ -864,11 +1142,15 @@ discard block |
||
| 864 | 1142 | $data['speed'] = round($line[5]*1.94384); |
| 865 | 1143 | $data['datetime'] = date('Y-m-d H:i:s'); |
| 866 | 1144 | $data['format_source'] = 'flightgearsp'; |
| 867 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
| 1145 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
| 1146 | + $SI->add($data); |
|
| 1147 | + } |
|
| 868 | 1148 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
| 869 | 1149 | } |
| 870 | 1150 | } elseif ($format == 'acars') { |
| 871 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
| 1151 | + if ($globalDebug) { |
|
| 1152 | + echo 'ACARS : '.$buffer."\n"; |
|
| 1153 | + } |
|
| 872 | 1154 | $ACARS->add(trim($buffer)); |
| 873 | 1155 | socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
| 874 | 1156 | $ACARS->deleteLiveAcarsData(); |
@@ -889,7 +1171,9 @@ discard block |
||
| 889 | 1171 | $aircraft_type = $line[10]; |
| 890 | 1172 | $aircraft_type = preg_split(':/:',$aircraft_type); |
| 891 | 1173 | $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
| 892 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
| 1174 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
| 1175 | + $SI->add($data); |
|
| 1176 | + } |
|
| 893 | 1177 | } |
| 894 | 1178 | } |
| 895 | 1179 | } elseif ($format == 'beast') { |
@@ -905,21 +1189,43 @@ discard block |
||
| 905 | 1189 | $data['hex'] = $lined['hexid']; |
| 906 | 1190 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
| 907 | 1191 | $data['datetime'] = date('Y-m-d H:i:s');; |
| 908 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
| 909 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
| 910 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
| 911 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
| 912 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
| 913 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
| 914 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
| 1192 | + if (isset($lined['ident'])) { |
|
| 1193 | + $data['ident'] = $lined['ident']; |
|
| 1194 | + } |
|
| 1195 | + if (isset($lined['lat'])) { |
|
| 1196 | + $data['latitude'] = $lined['lat']; |
|
| 1197 | + } |
|
| 1198 | + if (isset($lined['lon'])) { |
|
| 1199 | + $data['longitude'] = $lined['lon']; |
|
| 1200 | + } |
|
| 1201 | + if (isset($lined['speed'])) { |
|
| 1202 | + $data['speed'] = $lined['speed']; |
|
| 1203 | + } |
|
| 1204 | + if (isset($lined['squawk'])) { |
|
| 1205 | + $data['squawk'] = $lined['squawk']; |
|
| 1206 | + } |
|
| 1207 | + if (isset($lined['alt'])) { |
|
| 1208 | + $data['altitude'] = $lined['alt']; |
|
| 1209 | + } |
|
| 1210 | + if (isset($lined['heading'])) { |
|
| 1211 | + $data['heading'] = $lined['heading']; |
|
| 1212 | + } |
|
| 915 | 1213 | $data['id_source'] = $id_source; |
| 916 | 1214 | $data['format_source'] = 'tsv'; |
| 917 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
| 918 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
| 919 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
| 1215 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
| 1216 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
| 1217 | + } |
|
| 1218 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
| 1219 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
| 1220 | + } |
|
| 1221 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
| 1222 | + $SI->add($data); |
|
| 1223 | + } |
|
| 920 | 1224 | unset($lined); |
| 921 | 1225 | unset($data); |
| 922 | - } else $error = true; |
|
| 1226 | + } else { |
|
| 1227 | + $error = true; |
|
| 1228 | + } |
|
| 923 | 1229 | } elseif ($format == 'aprs' && $use_aprs) { |
| 924 | 1230 | if ($aprs_connect == 0) { |
| 925 | 1231 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
@@ -950,29 +1256,40 @@ discard block |
||
| 950 | 1256 | $data['latitude'] = $line['latitude']; |
| 951 | 1257 | $data['longitude'] = $line['longitude']; |
| 952 | 1258 | //$data['verticalrate'] = $line[16]; |
| 953 | - if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
| 954 | - else $data['speed'] = 0; |
|
| 1259 | + if (isset($line['speed'])) { |
|
| 1260 | + $data['speed'] = $line['speed']; |
|
| 1261 | + } else { |
|
| 1262 | + $data['speed'] = 0; |
|
| 1263 | + } |
|
| 955 | 1264 | $data['altitude'] = $line['altitude']; |
| 956 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; |
|
| 1265 | + if (isset($line['heading'])) { |
|
| 1266 | + $data['heading'] = $line['heading']; |
|
| 1267 | + } |
|
| 957 | 1268 | //else $data['heading'] = 0; |
| 958 | 1269 | $data['aircraft_type'] = $line['stealth']; |
| 959 | - if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true; |
|
| 1270 | + if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) { |
|
| 1271 | + $data['noarchive'] = true; |
|
| 1272 | + } |
|
| 960 | 1273 | $data['id_source'] = $id_source; |
| 961 | 1274 | $data['format_source'] = 'aprs'; |
| 962 | 1275 | $data['source_name'] = $line['source']; |
| 963 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
| 1276 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
| 1277 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
| 1278 | + } |
|
| 964 | 1279 | $currentdate = date('Y-m-d H:i:s'); |
| 965 | 1280 | $aprsdate = strtotime($data['datetime']); |
| 966 | 1281 | // Accept data if time <= system time + 20s |
| 967 | 1282 | if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
| 968 | 1283 | $send = $SI->add($data); |
| 969 | 1284 | } else { |
| 970 | - if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
| 971 | - else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
| 1285 | + if ($line['stealth'] != 0) { |
|
| 1286 | + echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
| 1287 | + } else { |
|
| 1288 | + echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
| 1289 | + } |
|
| 972 | 1290 | } |
| 973 | 1291 | unset($data); |
| 974 | - } |
|
| 975 | - elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
| 1292 | + } elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
| 976 | 1293 | echo '!! Weather Station not yet supported'."\n"; |
| 977 | 1294 | } |
| 978 | 1295 | //elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; |
@@ -1005,25 +1322,42 @@ discard block |
||
| 1005 | 1322 | $data['ground'] = $line[21]; |
| 1006 | 1323 | $data['emergency'] = $line[19]; |
| 1007 | 1324 | $data['format_source'] = 'sbs'; |
| 1008 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
| 1009 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
| 1325 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
| 1326 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
| 1327 | + } |
|
| 1328 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
| 1329 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
| 1330 | + } |
|
| 1010 | 1331 | $data['id_source'] = $id_source; |
| 1011 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
| 1012 | - else $error = true; |
|
| 1332 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
| 1333 | + $send = $SI->add($data); |
|
| 1334 | + } else { |
|
| 1335 | + $error = true; |
|
| 1336 | + } |
|
| 1013 | 1337 | unset($data); |
| 1014 | - } else $error = true; |
|
| 1338 | + } else { |
|
| 1339 | + $error = true; |
|
| 1340 | + } |
|
| 1015 | 1341 | if ($error) { |
| 1016 | 1342 | if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { |
| 1017 | - if ($globalDebug) echo "Not a message. Ignoring... \n"; |
|
| 1343 | + if ($globalDebug) { |
|
| 1344 | + echo "Not a message. Ignoring... \n"; |
|
| 1345 | + } |
|
| 1018 | 1346 | } else { |
| 1019 | - if ($globalDebug) echo "Wrong line format. Ignoring... \n"; |
|
| 1347 | + if ($globalDebug) { |
|
| 1348 | + echo "Wrong line format. Ignoring... \n"; |
|
| 1349 | + } |
|
| 1020 | 1350 | if ($globalDebug) { |
| 1021 | 1351 | echo $buffer; |
| 1022 | 1352 | print_r($line); |
| 1023 | 1353 | } |
| 1024 | 1354 | //socket_close($r); |
| 1025 | - if ($globalDebug) echo "Reconnect after an error...\n"; |
|
| 1026 | - if ($format == 'aprs') $aprs_connect = 0; |
|
| 1355 | + if ($globalDebug) { |
|
| 1356 | + echo "Reconnect after an error...\n"; |
|
| 1357 | + } |
|
| 1358 | + if ($format == 'aprs') { |
|
| 1359 | + $aprs_connect = 0; |
|
| 1360 | + } |
|
| 1027 | 1361 | $sourceer[$nb] = $globalSources[$nb]; |
| 1028 | 1362 | connect_all($sourceer); |
| 1029 | 1363 | $sourceer = array(); |
@@ -1031,10 +1365,14 @@ discard block |
||
| 1031 | 1365 | } |
| 1032 | 1366 | } |
| 1033 | 1367 | // Sleep for xxx microseconds |
| 1034 | - if (isset($globalSBSSleep)) usleep($globalSBSSleep); |
|
| 1368 | + if (isset($globalSBSSleep)) { |
|
| 1369 | + usleep($globalSBSSleep); |
|
| 1370 | + } |
|
| 1035 | 1371 | } else { |
| 1036 | 1372 | if ($format == 'flightgearmp') { |
| 1037 | - if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
| 1373 | + if ($globalDebug) { |
|
| 1374 | + echo "Reconnect FlightGear MP..."; |
|
| 1375 | + } |
|
| 1038 | 1376 | //@socket_close($r); |
| 1039 | 1377 | sleep($globalMinFetch); |
| 1040 | 1378 | $sourcefg[$nb] = $globalSources[$nb]; |
@@ -1043,10 +1381,15 @@ discard block |
||
| 1043 | 1381 | break; |
| 1044 | 1382 | |
| 1045 | 1383 | } elseif ($format != 'acars' && $format != 'flightgearsp') { |
| 1046 | - if (isset($tt[$format])) $tt[$format]++; |
|
| 1047 | - else $tt[$format] = 0; |
|
| 1384 | + if (isset($tt[$format])) { |
|
| 1385 | + $tt[$format]++; |
|
| 1386 | + } else { |
|
| 1387 | + $tt[$format] = 0; |
|
| 1388 | + } |
|
| 1048 | 1389 | if ($tt[$format] > 30) { |
| 1049 | - if ($globalDebug) echo "ERROR : Reconnect ".$format."..."; |
|
| 1390 | + if ($globalDebug) { |
|
| 1391 | + echo "ERROR : Reconnect ".$format."..."; |
|
| 1392 | + } |
|
| 1050 | 1393 | //@socket_close($r); |
| 1051 | 1394 | sleep(2); |
| 1052 | 1395 | $aprs_connect = 0; |
@@ -1062,12 +1405,18 @@ discard block |
||
| 1062 | 1405 | } |
| 1063 | 1406 | } else { |
| 1064 | 1407 | $error = socket_strerror(socket_last_error()); |
| 1065 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
| 1408 | + if ($globalDebug) { |
|
| 1409 | + echo "ERROR : socket_select give this error ".$error . "\n"; |
|
| 1410 | + } |
|
| 1066 | 1411 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) { |
| 1067 | - if (isset($globalDebug)) echo "Restarting...\n"; |
|
| 1412 | + if (isset($globalDebug)) { |
|
| 1413 | + echo "Restarting...\n"; |
|
| 1414 | + } |
|
| 1068 | 1415 | // Restart the script if possible |
| 1069 | 1416 | if (is_array($sockets)) { |
| 1070 | - if ($globalDebug) echo "Shutdown all sockets..."; |
|
| 1417 | + if ($globalDebug) { |
|
| 1418 | + echo "Shutdown all sockets..."; |
|
| 1419 | + } |
|
| 1071 | 1420 | |
| 1072 | 1421 | foreach ($sockets as $sock) { |
| 1073 | 1422 | @socket_shutdown($sock,2); |
@@ -1075,18 +1424,24 @@ discard block |
||
| 1075 | 1424 | } |
| 1076 | 1425 | |
| 1077 | 1426 | } |
| 1078 | - if ($globalDebug) echo "Restart all connections..."; |
|
| 1427 | + if ($globalDebug) { |
|
| 1428 | + echo "Restart all connections..."; |
|
| 1429 | + } |
|
| 1079 | 1430 | sleep(2); |
| 1080 | 1431 | $time = time(); |
| 1081 | 1432 | //connect_all($hosts); |
| 1082 | 1433 | $aprs_connect = 0; |
| 1083 | - if ($reset > 40) exit('Too many attempts...'); |
|
| 1434 | + if ($reset > 40) { |
|
| 1435 | + exit('Too many attempts...'); |
|
| 1436 | + } |
|
| 1084 | 1437 | connect_all($globalSources); |
| 1085 | 1438 | } |
| 1086 | 1439 | } |
| 1087 | 1440 | } |
| 1088 | 1441 | if ($globalDaemon === false) { |
| 1089 | - if ($globalDebug) echo 'Check all...'."\n"; |
|
| 1442 | + if ($globalDebug) { |
|
| 1443 | + echo 'Check all...'."\n"; |
|
| 1444 | + } |
|
| 1090 | 1445 | $SI->checkAll(); |
| 1091 | 1446 | } |
| 1092 | 1447 | } |
@@ -102,7 +102,9 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | /* Check that end was found and body has at least one byte. */ |
| 104 | 104 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
| 105 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
| 105 | + if ($globalDebug) { |
|
| 106 | + echo '!!! APRS invalid : '.$input."\n"; |
|
| 107 | + } |
|
| 106 | 108 | return false; |
| 107 | 109 | } |
| 108 | 110 | |
@@ -111,16 +113,22 @@ discard block |
||
| 111 | 113 | $body_len = strlen($body); |
| 112 | 114 | $header = substr($input,0,$splitpos); |
| 113 | 115 | //$header_len = strlen($header); |
| 114 | - if ($debug) echo 'header : '.$header."\n"; |
|
| 116 | + if ($debug) { |
|
| 117 | + echo 'header : '.$header."\n"; |
|
| 118 | + } |
|
| 115 | 119 | |
| 116 | 120 | /* Parse source, target and path. */ |
| 117 | 121 | //FLRDF0A52>APRS,qAS,LSTB |
| 118 | 122 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
| 119 | 123 | $ident = $matches[1]; |
| 120 | 124 | $all_elements = $matches[2]; |
| 121 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
| 125 | + if ($debug) { |
|
| 126 | + echo 'ident : '.$ident."\n"; |
|
| 127 | + } |
|
| 122 | 128 | $result['ident'] = $ident; |
| 123 | - } else return false; |
|
| 129 | + } else { |
|
| 130 | + return false; |
|
| 131 | + } |
|
| 124 | 132 | $elements = explode(',',$all_elements); |
| 125 | 133 | $source = end($elements); |
| 126 | 134 | $result['source'] = $source; |
@@ -202,7 +210,9 @@ discard block |
||
| 202 | 210 | //$symbol_table = $matches[4]; |
| 203 | 211 | $lat = intval($lat_deg); |
| 204 | 212 | $lon = intval($lon_deg); |
| 205 | - if ($lat > 89 || $lon > 179) return false; |
|
| 213 | + if ($lat > 89 || $lon > 179) { |
|
| 214 | + return false; |
|
| 215 | + } |
|
| 206 | 216 | |
| 207 | 217 | /* |
| 208 | 218 | $tmp_5b = str_replace('.','',$lat_min); |
@@ -212,8 +222,12 @@ discard block |
||
| 212 | 222 | */ |
| 213 | 223 | $latitude = $lat + floatval($lat_min)/60; |
| 214 | 224 | $longitude = $lon + floatval($lon_min)/60; |
| 215 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
| 216 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
| 225 | + if ($sind == 'S') { |
|
| 226 | + $latitude = 0-$latitude; |
|
| 227 | + } |
|
| 228 | + if ($wind == 'W') { |
|
| 229 | + $longitude = 0-$longitude; |
|
| 230 | + } |
|
| 217 | 231 | $result['latitude'] = $latitude; |
| 218 | 232 | $result['longitude'] = $longitude; |
| 219 | 233 | $body_parse = substr($body_parse,18); |
@@ -245,7 +259,9 @@ discard block |
||
| 245 | 259 | //} |
| 246 | 260 | //echo $body_parse; |
| 247 | 261 | $result['symbol_code'] = $symbol_code; |
| 248 | - if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
|
| 262 | + if (isset($this->symbols[$symbol_code])) { |
|
| 263 | + $result['symbol'] = $this->symbols[$symbol_code]; |
|
| 264 | + } |
|
| 249 | 265 | if ($symbol_code != '_') { |
| 250 | 266 | //$body_parse = substr($body_parse,1); |
| 251 | 267 | //$body_parse = trim($body_parse); |
@@ -255,7 +271,9 @@ discard block |
||
| 255 | 271 | if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
| 256 | 272 | $course = substr($body_parse,0,3); |
| 257 | 273 | $tmp_s = intval($course); |
| 258 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
| 274 | + if ($tmp_s >= 1 && $tmp_s <= 360) { |
|
| 275 | + $result['heading'] = intval($course); |
|
| 276 | + } |
|
| 259 | 277 | $speed = substr($body_parse,4,3); |
| 260 | 278 | $result['speed'] = round($speed*1.852); |
| 261 | 279 | $body_parse = substr($body_parse,7); |
@@ -290,10 +308,16 @@ discard block |
||
| 290 | 308 | $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
| 291 | 309 | $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
| 292 | 310 | |
| 293 | - if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
|
| 294 | - else $result['latitude'] += $lat_off; |
|
| 295 | - if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
|
| 296 | - else $result['longitude'] += $lon_off; |
|
| 311 | + if ($result['latitude'] < 0) { |
|
| 312 | + $result['latitude'] -= $lat_off; |
|
| 313 | + } else { |
|
| 314 | + $result['latitude'] += $lat_off; |
|
| 315 | + } |
|
| 316 | + if ($result['longitude'] < 0) { |
|
| 317 | + $result['longitude'] -= $lon_off; |
|
| 318 | + } else { |
|
| 319 | + $result['longitude'] += $lon_off; |
|
| 320 | + } |
|
| 297 | 321 | } |
| 298 | 322 | $body_parse = substr($body_parse,6); |
| 299 | 323 | } |
@@ -307,27 +331,48 @@ discard block |
||
| 307 | 331 | $address = substr($id,2); |
| 308 | 332 | //print_r($matches); |
| 309 | 333 | $addressType = (intval(substr($id,0,2),16))&3; |
| 310 | - if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
|
| 311 | - elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
|
| 312 | - elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
|
| 313 | - elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
|
| 334 | + if ($addressType == 0) { |
|
| 335 | + $result['addresstype'] = "RANDOM"; |
|
| 336 | + } elseif ($addressType == 1) { |
|
| 337 | + $result['addresstype'] = "ICAO"; |
|
| 338 | + } elseif ($addressType == 2) { |
|
| 339 | + $result['addresstype'] = "FLARM"; |
|
| 340 | + } elseif ($addressType == 3) { |
|
| 341 | + $result['addresstype'] = "OGN"; |
|
| 342 | + } |
|
| 314 | 343 | $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
| 315 | 344 | $result['aircrafttype_code'] = $aircraftType; |
| 316 | - if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
|
| 317 | - elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
|
| 318 | - elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE"; |
|
| 319 | - elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
| 320 | - elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE"; |
|
| 321 | - elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE"; |
|
| 322 | - elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER"; |
|
| 323 | - elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER"; |
|
| 324 | - elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
| 325 | - elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
| 326 | - elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO"; |
|
| 327 | - elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON"; |
|
| 328 | - elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
|
| 329 | - elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
|
| 330 | - elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
|
| 345 | + if ($aircraftType == 0) { |
|
| 346 | + $result['aircrafttype'] = "UNKNOWN"; |
|
| 347 | + } elseif ($aircraftType == 1) { |
|
| 348 | + $result['aircrafttype'] = "GLIDER"; |
|
| 349 | + } elseif ($aircraftType == 2) { |
|
| 350 | + $result['aircrafttype'] = "TOW_PLANE"; |
|
| 351 | + } elseif ($aircraftType == 3) { |
|
| 352 | + $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
| 353 | + } elseif ($aircraftType == 4) { |
|
| 354 | + $result['aircrafttype'] = "PARACHUTE"; |
|
| 355 | + } elseif ($aircraftType == 5) { |
|
| 356 | + $result['aircrafttype'] = "DROP_PLANE"; |
|
| 357 | + } elseif ($aircraftType == 6) { |
|
| 358 | + $result['aircrafttype'] = "HANG_GLIDER"; |
|
| 359 | + } elseif ($aircraftType == 7) { |
|
| 360 | + $result['aircrafttype'] = "PARA_GLIDER"; |
|
| 361 | + } elseif ($aircraftType == 8) { |
|
| 362 | + $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
| 363 | + } elseif ($aircraftType == 9) { |
|
| 364 | + $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
| 365 | + } elseif ($aircraftType == 10) { |
|
| 366 | + $result['aircrafttype'] = "UFO"; |
|
| 367 | + } elseif ($aircraftType == 11) { |
|
| 368 | + $result['aircrafttype'] = "BALLOON"; |
|
| 369 | + } elseif ($aircraftType == 12) { |
|
| 370 | + $result['aircrafttype'] = "AIRSHIP"; |
|
| 371 | + } elseif ($aircraftType == 13) { |
|
| 372 | + $result['aircrafttype'] = "UAV"; |
|
| 373 | + } elseif ($aircraftType == 15) { |
|
| 374 | + $result['aircrafttype'] = "STATIC_OBJECT"; |
|
| 375 | + } |
|
| 331 | 376 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
| 332 | 377 | $result['stealth'] = $stealth; |
| 333 | 378 | $result['address'] = $address; |
@@ -367,12 +412,18 @@ discard block |
||
| 367 | 412 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
| 368 | 413 | } |
| 369 | 414 | } |
| 370 | - } else $result['comment'] = trim($body_parse); |
|
| 415 | + } else { |
|
| 416 | + $result['comment'] = trim($body_parse); |
|
| 417 | + } |
|
| 371 | 418 | |
| 372 | 419 | } |
| 373 | 420 | //} |
| 374 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
| 375 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
| 421 | + if (isset($result['latitude'])) { |
|
| 422 | + $result['latitude'] = round($result['latitude'],4); |
|
| 423 | + } |
|
| 424 | + if (isset($result['longitude'])) { |
|
| 425 | + $result['longitude'] = round($result['longitude'],4); |
|
| 426 | + } |
|
| 376 | 427 | //print_r($result); |
| 377 | 428 | return $result; |
| 378 | 429 | } |