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