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