@@ -89,6 +89,10 @@ discard block |
||
89 | 89 | 'y' => 'Yagi At QTH'); |
90 | 90 | |
91 | 91 | |
92 | + /** |
|
93 | + * @param integer $n |
|
94 | + * @param integer $s |
|
95 | + */ |
|
92 | 96 | private function urshift($n, $s) { |
93 | 97 | return ($n >= 0) ? ($n >> $s) : |
94 | 98 | (($n & 0x7fffffff) >> $s) | |
@@ -462,6 +466,9 @@ discard block |
||
462 | 466 | } |
463 | 467 | } |
464 | 468 | |
469 | + /** |
|
470 | + * @param string $data |
|
471 | + */ |
|
465 | 472 | function send($data) { |
466 | 473 | if ($this->connected === false) $this->connect(); |
467 | 474 | $send = socket_send( $this->socket , $data , strlen($data),0); |
@@ -90,8 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | |
92 | 92 | private function urshift($n, $s) { |
93 | - return ($n >= 0) ? ($n >> $s) : |
|
94 | - (($n & 0x7fffffff) >> $s) | |
|
93 | + return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| |
|
95 | 94 | (0x40000000 >> ($s - 1)); |
96 | 95 | } |
97 | 96 | |
@@ -103,7 +102,7 @@ discard block |
||
103 | 102 | //$split_input = str_split($input); |
104 | 103 | |
105 | 104 | /* Find the end of header checking for NULL bytes while doing it. */ |
106 | - $splitpos = strpos($input,':'); |
|
105 | + $splitpos = strpos($input, ':'); |
|
107 | 106 | |
108 | 107 | /* Check that end was found and body has at least one byte. */ |
109 | 108 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
@@ -113,15 +112,15 @@ discard block |
||
113 | 112 | |
114 | 113 | if ($debug) echo 'input : '.$input."\n"; |
115 | 114 | /* Save header and body. */ |
116 | - $body = substr($input,$splitpos+1,$input_len); |
|
115 | + $body = substr($input, $splitpos + 1, $input_len); |
|
117 | 116 | $body_len = strlen($body); |
118 | - $header = substr($input,0,$splitpos); |
|
117 | + $header = substr($input, 0, $splitpos); |
|
119 | 118 | //$header_len = strlen($header); |
120 | 119 | if ($debug) echo 'header : '.$header."\n"; |
121 | 120 | |
122 | 121 | /* Parse source, target and path. */ |
123 | 122 | //FLRDF0A52>APRS,qAS,LSTB |
124 | - if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
|
123 | + if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) { |
|
125 | 124 | $ident = $matches[1]; |
126 | 125 | if ($ident == 'AIRCRAFT') { |
127 | 126 | $result['format_source'] = 'famaprs'; |
@@ -134,14 +133,14 @@ discard block |
||
134 | 133 | if ($debug) echo 'ident : '.$ident."\n"; |
135 | 134 | $result['ident'] = $ident; |
136 | 135 | } else return false; |
137 | - $elements = explode(',',$all_elements); |
|
136 | + $elements = explode(',', $all_elements); |
|
138 | 137 | $source = end($elements); |
139 | 138 | $result['source'] = $source; |
140 | 139 | foreach ($elements as $element) { |
141 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
140 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) { |
|
142 | 141 | //echo "ok"; |
143 | 142 | //if ($element == 'TCPIP*') return false; |
144 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
143 | + } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) { |
|
145 | 144 | if ($debug) echo 'element : '.$element."\n"; |
146 | 145 | return false; |
147 | 146 | } |
@@ -154,10 +153,10 @@ discard block |
||
154 | 153 | */ |
155 | 154 | } |
156 | 155 | |
157 | - $type = substr($body,0,1); |
|
156 | + $type = substr($body, 0, 1); |
|
158 | 157 | if ($debug) echo 'type : '.$type."\n"; |
159 | 158 | if ($type == ';') { |
160 | - $result['ident'] = trim(substr($body,1,9)); |
|
159 | + $result['ident'] = trim(substr($body, 1, 9)); |
|
161 | 160 | } elseif ($type == ',') { |
162 | 161 | // Invalid data or test data |
163 | 162 | return false; |
@@ -165,24 +164,24 @@ discard block |
||
165 | 164 | |
166 | 165 | // Check for Timestamp |
167 | 166 | $find = false; |
168 | - $body_parse = substr($body,1); |
|
167 | + $body_parse = substr($body, 1); |
|
169 | 168 | //echo 'Body : '.$body."\n"; |
170 | - if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
|
171 | - $body_parse = substr($body_parse,10); |
|
169 | + if (preg_match('/^;(.){9}\*/', $body, $matches)) { |
|
170 | + $body_parse = substr($body_parse, 10); |
|
172 | 171 | $find = true; |
173 | 172 | //echo $body_parse."\n"; |
174 | 173 | } |
175 | - if (preg_match('/^`(.*)\//',$body,$matches)) { |
|
176 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
174 | + if (preg_match('/^`(.*)\//', $body, $matches)) { |
|
175 | + $body_parse = substr($body_parse, strlen($matches[1]) - 1); |
|
177 | 176 | $find = true; |
178 | 177 | //echo $body_parse."\n"; |
179 | 178 | } |
180 | - if (preg_match("/^'(.*)\//",$body,$matches)) { |
|
181 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
179 | + if (preg_match("/^'(.*)\//", $body, $matches)) { |
|
180 | + $body_parse = substr($body_parse, strlen($matches[1]) - 1); |
|
182 | 181 | $find = true; |
183 | 182 | //echo $body_parse."\n"; |
184 | 183 | } |
185 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
|
184 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) { |
|
186 | 185 | $find = true; |
187 | 186 | //print_r($matches); |
188 | 187 | $timestamp = $matches[0]; |
@@ -197,19 +196,19 @@ discard block |
||
197 | 196 | // This work or not ? |
198 | 197 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
199 | 198 | } |
200 | - $body_parse = substr($body_parse,7); |
|
199 | + $body_parse = substr($body_parse, 7); |
|
201 | 200 | $result['timestamp'] = $timestamp; |
202 | 201 | //echo date('Ymd H:i:s',$timestamp); |
203 | 202 | } |
204 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
|
203 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) { |
|
205 | 204 | $find = true; |
206 | 205 | $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
207 | - $body_parse = substr($body_parse,8); |
|
206 | + $body_parse = substr($body_parse, 8); |
|
208 | 207 | $result['timestamp'] = $timestamp; |
209 | 208 | //echo date('Ymd H:i:s',$timestamp); |
210 | 209 | } |
211 | 210 | //if (strlen($body_parse) > 19) { |
212 | - 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)) { |
|
211 | + 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)) { |
|
213 | 212 | $find = true; |
214 | 213 | // 4658.70N/00707.78Ez |
215 | 214 | //print_r(str_split($body_parse)); |
@@ -235,11 +234,11 @@ discard block |
||
235 | 234 | */ |
236 | 235 | $latitude = $lat + floatval($lat_min)/60; |
237 | 236 | $longitude = $lon + floatval($lon_min)/60; |
238 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
239 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
237 | + if ($sind == 'S') $latitude = 0 - $latitude; |
|
238 | + if ($wind == 'W') $longitude = 0 - $longitude; |
|
240 | 239 | $result['latitude'] = $latitude; |
241 | 240 | $result['longitude'] = $longitude; |
242 | - $body_parse = substr($body_parse,18); |
|
241 | + $body_parse = substr($body_parse, 18); |
|
243 | 242 | $body_parse_len = strlen($body_parse); |
244 | 243 | } |
245 | 244 | $body_parse_len = strlen($body_parse); |
@@ -266,7 +265,7 @@ discard block |
||
266 | 265 | //} |
267 | 266 | //echo $body_parse; |
268 | 267 | if ($type != ';' && $type != '>') { |
269 | - $body_parse = substr($body_parse,1); |
|
268 | + $body_parse = substr($body_parse, 1); |
|
270 | 269 | $body_parse_len = strlen($body_parse); |
271 | 270 | $result['symbol_code'] = $symbol_code; |
272 | 271 | if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
@@ -277,15 +276,15 @@ discard block |
||
277 | 276 | //$body_parse_len = strlen($body_parse); |
278 | 277 | if ($body_parse_len >= 7) { |
279 | 278 | |
280 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
281 | - $course = substr($body_parse,0,3); |
|
279 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) { |
|
280 | + $course = substr($body_parse, 0, 3); |
|
282 | 281 | $tmp_s = intval($course); |
283 | 282 | if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
284 | - $speed = substr($body_parse,4,3); |
|
283 | + $speed = substr($body_parse, 4, 3); |
|
285 | 284 | if ($speed != '...') { |
286 | 285 | $result['speed'] = round($speed*1.852); |
287 | 286 | } |
288 | - $body_parse = substr($body_parse,7); |
|
287 | + $body_parse = substr($body_parse, 7); |
|
289 | 288 | } |
290 | 289 | // Check PHGR, PHG, RNG |
291 | 290 | } |
@@ -295,12 +294,12 @@ discard block |
||
295 | 294 | } |
296 | 295 | */ |
297 | 296 | if (strlen($body_parse) > 0) { |
298 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
297 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) { |
|
299 | 298 | $altitude = intval($matches[1]); |
300 | 299 | //$result['altitude'] = round($altitude*0.3048); |
301 | 300 | $result['altitude'] = $altitude; |
302 | 301 | //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
303 | - $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
302 | + $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/', '', $body_parse)); |
|
304 | 303 | } |
305 | 304 | } |
306 | 305 | |
@@ -311,56 +310,56 @@ discard block |
||
311 | 310 | } |
312 | 311 | */ |
313 | 312 | // DAO |
314 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
313 | + if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) { |
|
315 | 314 | $dao = $matches[1]; |
316 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
315 | + if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) { |
|
317 | 316 | $dao_split = str_split($dao); |
318 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
319 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
317 | + $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0; |
|
318 | + $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0; |
|
320 | 319 | |
321 | 320 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
322 | 321 | else $result['latitude'] += $lat_off; |
323 | 322 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
324 | 323 | else $result['longitude'] += $lon_off; |
325 | 324 | } |
326 | - $body_parse = substr($body_parse,6); |
|
325 | + $body_parse = substr($body_parse, 6); |
|
327 | 326 | } |
328 | 327 | |
329 | - if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
328 | + if (preg_match('/CS=([0-9A-Z]*)/', $body_parse, $matches)) { |
|
330 | 329 | $result['callsign'] = $matches[1]; |
331 | 330 | } |
332 | - if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
|
331 | + if (preg_match('/SQ=([0-9]{4})/', $body_parse, $matches)) { |
|
333 | 332 | $result['squawk'] = $matches[1]; |
334 | 333 | } |
335 | - if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
|
334 | + if (preg_match('/AI=([0-9A-Z]{4})/', $body_parse, $matches)) { |
|
336 | 335 | $result['aircraft_icao'] = $matches[1]; |
337 | 336 | } |
338 | - if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
|
337 | + if (preg_match('/TI=([0-9]*)/', $body_parse, $matches)) { |
|
339 | 338 | $result['typeid'] = $matches[1]; |
340 | 339 | } |
341 | - if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
340 | + if (preg_match('/IMO=([0-9]{7})/', $body_parse, $matches)) { |
|
342 | 341 | $result['imo'] = $matches[1]; |
343 | 342 | } |
344 | - if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
343 | + if (preg_match('/AD=([0-9]*)/', $body_parse, $matches)) { |
|
345 | 344 | $result['arrival_date'] = $matches[1]; |
346 | 345 | } |
347 | - if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
346 | + if (preg_match('/AC=([0-9A-Z]*)/', $body_parse, $matches)) { |
|
348 | 347 | $result['arrival_code'] = $matches[1]; |
349 | 348 | } |
350 | 349 | // OGN comment |
351 | 350 | // echo "Before OGN : ".$body_parse."\n"; |
352 | 351 | //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
353 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
352 | + if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) { |
|
354 | 353 | $id = $matches[1]; |
355 | 354 | //$mode = substr($id,0,2); |
356 | - $address = substr($id,2); |
|
355 | + $address = substr($id, 2); |
|
357 | 356 | //print_r($matches); |
358 | - $addressType = (intval(substr($id,0,2),16))&3; |
|
357 | + $addressType = (intval(substr($id, 0, 2), 16))&3; |
|
359 | 358 | if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
360 | 359 | elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
361 | 360 | elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
362 | 361 | elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
363 | - $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
|
362 | + $aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2); |
|
364 | 363 | $result['aircrafttype_code'] = $aircraftType; |
365 | 364 | if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
366 | 365 | elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
@@ -377,7 +376,7 @@ discard block |
||
377 | 376 | elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
378 | 377 | elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
379 | 378 | elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
380 | - $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
|
379 | + $stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0; |
|
381 | 380 | $result['stealth'] = $stealth; |
382 | 381 | $result['address'] = $address; |
383 | 382 | } |
@@ -389,72 +388,72 @@ discard block |
||
389 | 388 | //$body_parse = substr($body_parse,1); |
390 | 389 | //$body_parse_len = strlen($body_parse); |
391 | 390 | |
392 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
391 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
393 | 392 | $result['wind_dir'] = intval($matches[1]); |
394 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
395 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
396 | - $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
397 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
398 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
393 | + $result['wind_speed'] = round(intval($matches[2])*1.60934, 1); |
|
394 | + $result['wind_gust'] = round(intval($matches[3])*1.60934, 1); |
|
395 | + $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1); |
|
396 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
397 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
399 | 398 | $result['wind_dir'] = intval($matches[1]); |
400 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
401 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
402 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
403 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
404 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
399 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
400 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
401 | + $result['temp'] = round(5/9*(($matches[4]) - 32), 1); |
|
402 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
403 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
405 | 404 | $result['wind_dir'] = intval($matches[1]); |
406 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
407 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
408 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
409 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
405 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
406 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
407 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
408 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) { |
|
410 | 409 | $result['wind_dir'] = intval($matches[1]); |
411 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
412 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
413 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
410 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
411 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
412 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
414 | 413 | } |
415 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
416 | - $result['temp'] = round(5/9*(($matches[1])-32),1); |
|
414 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) { |
|
415 | + $result['temp'] = round(5/9*(($matches[1]) - 32), 1); |
|
417 | 416 | } |
418 | 417 | } |
419 | 418 | } else $result['comment'] = trim($body_parse); |
420 | 419 | |
421 | 420 | } |
422 | 421 | //} |
423 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
424 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
422 | + if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4); |
|
423 | + if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4); |
|
425 | 424 | if ($debug) print_r($result); |
426 | 425 | return $result; |
427 | 426 | } |
428 | 427 | |
429 | 428 | function connect() { |
430 | - global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport; |
|
429 | + global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass, $globalName, $globalServerAPRShost, $globalServerAPRSport; |
|
431 | 430 | $aprs_connect = 0; |
432 | 431 | $aprs_keep = 120; |
433 | 432 | $aprs_last_tx = time(); |
434 | 433 | if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
435 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
434 | + else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName); |
|
436 | 435 | if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid; |
437 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
436 | + else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8); |
|
438 | 437 | if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass; |
439 | 438 | else $aprs_pass = '-1'; |
440 | 439 | |
441 | - $aprs_filter = ''; |
|
440 | + $aprs_filter = ''; |
|
442 | 441 | $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
443 | 442 | $Common = new Common(); |
444 | - $s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr); |
|
443 | + $s = $Common->create_socket($globalServerAPRShost, $globalServerAPRSport, $errno, $errstr); |
|
445 | 444 | if ($s !== false) { |
446 | 445 | echo 'Connected to APRS server! '."\n"; |
447 | 446 | $authstart = time(); |
448 | 447 | $this->socket = $s; |
449 | - $send = socket_send( $this->socket , $aprs_login , strlen($aprs_login) , 0 ); |
|
450 | - while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) { |
|
448 | + $send = socket_send($this->socket, $aprs_login, strlen($aprs_login), 0); |
|
449 | + while ($msgin = socket_read($this->socket, 1000, PHP_NORMAL_READ)) { |
|
451 | 450 | if (strpos($msgin, "$aprs_ssid verified") !== FALSE) { |
452 | 451 | echo 'APRS user verified !'."\n"; |
453 | 452 | $this->connected = true; |
454 | 453 | return true; |
455 | 454 | break; |
456 | 455 | } |
457 | - if (time()-$authstart > 5) { |
|
456 | + if (time() - $authstart > 5) { |
|
458 | 457 | echo 'APRS timeout'."\n"; |
459 | 458 | break; |
460 | 459 | } |
@@ -464,20 +463,20 @@ discard block |
||
464 | 463 | |
465 | 464 | function send($data) { |
466 | 465 | if ($this->connected === false) $this->connect(); |
467 | - $send = socket_send( $this->socket , $data , strlen($data),0); |
|
466 | + $send = socket_send($this->socket, $data, strlen($data), 0); |
|
468 | 467 | if ($send === FALSE) $this->connect(); |
469 | 468 | } |
470 | 469 | } |
471 | 470 | |
472 | 471 | class APRSSpotter extends APRS { |
473 | - function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) { |
|
472 | + function addLiveSpotterData($id, $ident, $aircraft_icao, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $altitude_real, $heading, $speed, $datetime, $departure_airport_time, $arrival_airport_time, $squawk, $route_stop, $hex, $putinarchive, $registration, $pilot_id, $pilot_name, $verticalrate, $noarchive, $ground, $format_source, $source_name, $over_country) { |
|
474 | 473 | $Common = new Common(); |
475 | 474 | if ($latitude != '' && $longitude != '') { |
476 | - $latitude = $Common->convertDM($latitude,'latitude'); |
|
477 | - $longitude = $Common->convertDM($longitude,'longitude'); |
|
478 | - $coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW']; |
|
479 | - $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000)); |
|
480 | - $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000)); |
|
475 | + $latitude = $Common->convertDM($latitude, 'latitude'); |
|
476 | + $longitude = $Common->convertDM($longitude, 'longitude'); |
|
477 | + $coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW']; |
|
478 | + $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000)); |
|
479 | + $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000)); |
|
481 | 480 | $w = $w1.$w2; |
482 | 481 | //$w = '00'; |
483 | 482 | $custom = ''; |
@@ -494,19 +493,19 @@ discard block |
||
494 | 493 | $custom .= 'AI='.$aircraft_icao; |
495 | 494 | } |
496 | 495 | if ($custom != '') $custom = ' '.$custom; |
497 | - $this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.' *'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
|
496 | + $this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.' *'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude_real, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
|
498 | 497 | } |
499 | 498 | } |
500 | 499 | } |
501 | 500 | class APRSMarine extends APRS { |
502 | - function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) { |
|
501 | + function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed, $datetime, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $noarchive, $format_source, $source_name, $over_country) { |
|
503 | 502 | $Common = new Common(); |
504 | 503 | if ($latitude != '' && $longitude != '') { |
505 | - $latitude = $Common->convertDM($latitude,'latitude'); |
|
506 | - $longitude = $Common->convertDM($longitude,'longitude'); |
|
507 | - $coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW']; |
|
508 | - $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000)); |
|
509 | - $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000)); |
|
504 | + $latitude = $Common->convertDM($latitude, 'latitude'); |
|
505 | + $longitude = $Common->convertDM($longitude, 'longitude'); |
|
506 | + $coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW']; |
|
507 | + $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000)); |
|
508 | + $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000)); |
|
510 | 509 | $w = $w1.$w2; |
511 | 510 | //$w = '00'; |
512 | 511 | $custom = ''; |
@@ -532,7 +531,7 @@ discard block |
||
532 | 531 | } |
533 | 532 | if ($custom != '') $custom = ' '.$custom; |
534 | 533 | $altitude = 0; |
535 | - $this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
|
534 | + $this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
|
536 | 535 | } |
537 | 536 | } |
538 | 537 | } |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | die; |
46 | 46 | } |
47 | 47 | //$hosts = array($globalSBS1Host.':'.$globalSBS1Port); |
48 | - $globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port); |
|
48 | + $globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | -$options = getopt('s::',array('source::','server','idsource::')); |
|
52 | +$options = getopt('s::', array('source::', 'server', 'idsource::')); |
|
53 | 53 | //if (isset($options['s'])) $hosts = array($options['s']); |
54 | 54 | //elseif (isset($options['source'])) $hosts = array($options['source']); |
55 | 55 | if (isset($options['s'])) { |
@@ -64,27 +64,27 @@ discard block |
||
64 | 64 | else $id_source = 1; |
65 | 65 | if (isset($globalServer) && $globalServer) { |
66 | 66 | if ($globalDebug) echo "Using Server Mode\n"; |
67 | - $SI=new SpotterServer(); |
|
67 | + $SI = new SpotterServer(); |
|
68 | 68 | /* |
69 | 69 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
70 | 70 | $SI = new adsb2aprs(); |
71 | 71 | $SI->connect(); |
72 | 72 | */ |
73 | -} else $SI=new SpotterImport($Connection->db); |
|
73 | +} else $SI = new SpotterImport($Connection->db); |
|
74 | 74 | if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db); |
75 | 75 | if (isset($globalMarine) && $globalMarine) { |
76 | 76 | $AIS = new AIS(); |
77 | 77 | $MI = new MarineImport($Connection->db); |
78 | 78 | } |
79 | 79 | //$APRS=new APRS($Connection->db); |
80 | -$SBS=new SBS(); |
|
81 | -$ACARS=new ACARS($Connection->db); |
|
82 | -$Common=new Common(); |
|
80 | +$SBS = new SBS(); |
|
81 | +$ACARS = new ACARS($Connection->db); |
|
82 | +$Common = new Common(); |
|
83 | 83 | date_default_timezone_set('UTC'); |
84 | 84 | //$servertz = system('date +%Z'); |
85 | 85 | // signal handler - playing nice with sockets and dump1090 |
86 | 86 | if (function_exists('pcntl_fork')) { |
87 | - pcntl_signal(SIGINT, function() { |
|
87 | + pcntl_signal(SIGINT, function() { |
|
88 | 88 | global $sockets; |
89 | 89 | echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
90 | 90 | die("Bye!\n"); |
@@ -100,35 +100,35 @@ discard block |
||
100 | 100 | |
101 | 101 | function connect_all($hosts) { |
102 | 102 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
103 | - global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context; |
|
103 | + global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context; |
|
104 | 104 | $reset++; |
105 | 105 | if ($globalDebug) echo 'Connect to all...'."\n"; |
106 | 106 | foreach ($hosts as $id => $value) { |
107 | 107 | $host = $value['host']; |
108 | 108 | $globalSources[$id]['last_exec'] = 0; |
109 | 109 | // Here we check type of source(s) |
110 | - if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
111 | - if (preg_match('/deltadb.txt$/i',$host)) { |
|
110 | + if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
111 | + if (preg_match('/deltadb.txt$/i', $host)) { |
|
112 | 112 | //$formats[$id] = 'deltadbtxt'; |
113 | 113 | $globalSources[$id]['format'] = 'deltadbtxt'; |
114 | 114 | //$last_exec['deltadbtxt'] = 0; |
115 | 115 | if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
116 | - } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
116 | + } else if (preg_match('/vatsim-data.txt$/i', $host)) { |
|
117 | 117 | //$formats[$id] = 'vatsimtxt'; |
118 | 118 | $globalSources[$id]['format'] = 'vatsimtxt'; |
119 | 119 | //$last_exec['vatsimtxt'] = 0; |
120 | 120 | if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
121 | - } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
121 | + } else if (preg_match('/aircraftlist.json$/i', $host)) { |
|
122 | 122 | //$formats[$id] = 'aircraftlistjson'; |
123 | 123 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
124 | 124 | //$last_exec['aircraftlistjson'] = 0; |
125 | 125 | if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
126 | - } else if (preg_match('/opensky/i',$host)) { |
|
126 | + } else if (preg_match('/opensky/i', $host)) { |
|
127 | 127 | //$formats[$id] = 'aircraftlistjson'; |
128 | 128 | $globalSources[$id]['format'] = 'opensky'; |
129 | 129 | //$last_exec['aircraftlistjson'] = 0; |
130 | 130 | if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
131 | - } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
|
131 | + } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) { |
|
132 | 132 | //$formats[$id] = 'radarvirtueljson'; |
133 | 133 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
134 | 134 | //$last_exec['radarvirtueljson'] = 0; |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
138 | 138 | exit(0); |
139 | 139 | } |
140 | - } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
140 | + } else if (preg_match('/planeUpdateFAA.php$/i', $host)) { |
|
141 | 141 | //$formats[$id] = 'planeupdatefaa'; |
142 | 142 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
143 | 143 | //$last_exec['planeupdatefaa'] = 0; |
@@ -146,26 +146,26 @@ discard block |
||
146 | 146 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
147 | 147 | exit(0); |
148 | 148 | } |
149 | - } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
149 | + } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) { |
|
150 | 150 | //$formats[$id] = 'phpvmacars'; |
151 | 151 | $globalSources[$id]['format'] = 'phpvmacars'; |
152 | 152 | //$last_exec['phpvmacars'] = 0; |
153 | 153 | if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
154 | - } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
154 | + } else if (preg_match('/VAM-json.php$/i', $host)) { |
|
155 | 155 | //$formats[$id] = 'phpvmacars'; |
156 | 156 | $globalSources[$id]['format'] = 'vam'; |
157 | 157 | if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
158 | - } else if (preg_match('/whazzup/i',$host)) { |
|
158 | + } else if (preg_match('/whazzup/i', $host)) { |
|
159 | 159 | //$formats[$id] = 'whazzup'; |
160 | 160 | $globalSources[$id]['format'] = 'whazzup'; |
161 | 161 | //$last_exec['whazzup'] = 0; |
162 | 162 | if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
163 | - } else if (preg_match('/recentpireps/i',$host)) { |
|
163 | + } else if (preg_match('/recentpireps/i', $host)) { |
|
164 | 164 | //$formats[$id] = 'pirepsjson'; |
165 | 165 | $globalSources[$id]['format'] = 'pirepsjson'; |
166 | 166 | //$last_exec['pirepsjson'] = 0; |
167 | 167 | if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
168 | - } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
168 | + } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) { |
|
169 | 169 | //$formats[$id] = 'fr24json'; |
170 | 170 | $globalSources[$id]['format'] = 'fr24json'; |
171 | 171 | //$last_exec['fr24json'] = 0; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
175 | 175 | exit(0); |
176 | 176 | } |
177 | - } else if (preg_match(':myshiptracking.com/:i',$host)) { |
|
177 | + } else if (preg_match(':myshiptracking.com/:i', $host)) { |
|
178 | 178 | //$formats[$id] = 'fr24json'; |
179 | 179 | $globalSources[$id]['format'] = 'myshiptracking'; |
180 | 180 | //$last_exec['fr24json'] = 0; |
@@ -184,22 +184,22 @@ discard block |
||
184 | 184 | exit(0); |
185 | 185 | } |
186 | 186 | //} else if (preg_match('/10001/',$host)) { |
187 | - } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
187 | + } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
188 | 188 | //$formats[$id] = 'tsv'; |
189 | 189 | $globalSources[$id]['format'] = 'tsv'; |
190 | 190 | if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
191 | 191 | } |
192 | - } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
192 | + } elseif (filter_var($host, FILTER_VALIDATE_URL)) { |
|
193 | 193 | if ($globalSources[$id]['format'] == 'aisnmeahttp') { |
194 | - $idf = fopen($globalSources[$id]['host'],'r',false,$context); |
|
194 | + $idf = fopen($globalSources[$id]['host'], 'r', false, $context); |
|
195 | 195 | if ($idf !== false) { |
196 | 196 | $httpfeeds[$id] = $idf; |
197 | 197 | if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
198 | 198 | } |
199 | 199 | elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
200 | 200 | } elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
201 | - } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
202 | - $hostport = explode(':',$host); |
|
201 | + } elseif (!filter_var($host, FILTER_VALIDATE_URL)) { |
|
202 | + $hostport = explode(':', $host); |
|
203 | 203 | if (isset($hostport[1])) { |
204 | 204 | $port = $hostport[1]; |
205 | 205 | $hostn = $hostport[0]; |
@@ -209,14 +209,14 @@ discard block |
||
209 | 209 | } |
210 | 210 | $Common = new Common(); |
211 | 211 | if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
212 | - $s = $Common->create_socket($hostn,$port, $errno, $errstr); |
|
212 | + $s = $Common->create_socket($hostn, $port, $errno, $errstr); |
|
213 | 213 | } else { |
214 | - $s = $Common->create_socket_udp($hostn,$port, $errno, $errstr); |
|
214 | + $s = $Common->create_socket_udp($hostn, $port, $errno, $errstr); |
|
215 | 215 | } |
216 | 216 | if ($s) { |
217 | 217 | $sockets[$id] = $s; |
218 | 218 | if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
219 | - if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') { |
|
219 | + if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') { |
|
220 | 220 | //$formats[$id] = 'aprs'; |
221 | 221 | $globalSources[$id]['format'] = 'aprs'; |
222 | 222 | //$aprs_connect = 0; |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
259 | 259 | else $timeout = 20; |
260 | 260 | $errno = ''; |
261 | -$errstr=''; |
|
261 | +$errstr = ''; |
|
262 | 262 | |
263 | 263 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
264 | 264 | /* Initiate connections to all the hosts simultaneously */ |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | //connect_all($globalSources); |
267 | 267 | |
268 | 268 | if (isset($globalProxy) && $globalProxy) { |
269 | - $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true))); |
|
269 | + $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true))); |
|
270 | 270 | } else { |
271 | 271 | $context = stream_context_create(array('http' => array('timeout' => $timeout))); |
272 | 272 | } |
@@ -293,16 +293,16 @@ discard block |
||
293 | 293 | |
294 | 294 | if ($use_aprs) { |
295 | 295 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
296 | - $APRS=new APRS(); |
|
296 | + $APRS = new APRS(); |
|
297 | 297 | $aprs_connect = 0; |
298 | 298 | $aprs_keep = 120; |
299 | 299 | $aprs_last_tx = time(); |
300 | 300 | if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
301 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
301 | + else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName); |
|
302 | 302 | if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
303 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
303 | + else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8); |
|
304 | 304 | if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
305 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
305 | + else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
306 | 306 | if ($aprs_full) $aprs_filter = ''; |
307 | 307 | if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass; |
308 | 308 | else $aprs_pass = '-1'; |
@@ -317,12 +317,12 @@ discard block |
||
317 | 317 | sleep(1); |
318 | 318 | if ($globalDebug) echo "SCAN MODE \n\n"; |
319 | 319 | if (!isset($globalCronEnd)) $globalCronEnd = 60; |
320 | -$endtime = time()+$globalCronEnd; |
|
320 | +$endtime = time() + $globalCronEnd; |
|
321 | 321 | $i = 1; |
322 | 322 | $tt = array(); |
323 | 323 | // Delete all ATC |
324 | 324 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) { |
325 | - $ATC=new ATC($Connection->db); |
|
325 | + $ATC = new ATC($Connection->db); |
|
326 | 326 | } |
327 | 327 | if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
328 | 328 | $ATC->deleteAll(); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | |
331 | 331 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
332 | 332 | while ($i > 0) { |
333 | - if (!$globalDaemon) $i = $endtime-time(); |
|
333 | + if (!$globalDaemon) $i = $endtime - time(); |
|
334 | 334 | // Delete old ATC |
335 | 335 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
336 | 336 | if ($globalDebug) echo 'Delete old ATC...'."\n"; |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | } |
346 | 346 | if ($max != $globalMinFetch) { |
347 | 347 | if ($globalDebug) echo 'Sleeping...'."\n"; |
348 | - sleep($globalMinFetch-$max+2); |
|
348 | + sleep($globalMinFetch - $max + 2); |
|
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | //$buffer = $Common->getData($hosts[$id]); |
359 | 359 | $buffer = $Common->getData($value['host']); |
360 | 360 | if ($buffer != '') $reset = 0; |
361 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
362 | - $buffer = explode('\n',$buffer); |
|
361 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
362 | + $buffer = explode('\n', $buffer); |
|
363 | 363 | foreach ($buffer as $line) { |
364 | 364 | if ($line != '' && count($line) > 7) { |
365 | 365 | $line = explode(',', $line); |
@@ -386,11 +386,11 @@ discard block |
||
386 | 386 | $last_exec[$id]['last'] = time(); |
387 | 387 | } elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) { |
388 | 388 | date_default_timezone_set('CET'); |
389 | - $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host'])); |
|
389 | + $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host'])); |
|
390 | 390 | date_default_timezone_set('UTC'); |
391 | 391 | if ($buffer != '') $reset = 0; |
392 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
393 | - $buffer = explode('\n',$buffer); |
|
392 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
393 | + $buffer = explode('\n', $buffer); |
|
394 | 394 | foreach ($buffer as $line) { |
395 | 395 | if ($line != '') { |
396 | 396 | echo "'".$line."'\n"; |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
409 | 409 | if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
410 | 410 | if (isset($ais_data['timestamp'])) { |
411 | - $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
|
411 | + $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']); |
|
412 | 412 | if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) { |
413 | 413 | $last_exec[$id]['timestamp'] = $ais_data['timestamp']; |
414 | 414 | $add = true; |
@@ -431,12 +431,12 @@ discard block |
||
431 | 431 | $w = $e = null; |
432 | 432 | |
433 | 433 | if (isset($arr[$id])) { |
434 | - $nn = stream_select($arr,$w,$e,$timeout); |
|
434 | + $nn = stream_select($arr, $w, $e, $timeout); |
|
435 | 435 | if ($nn > 0) { |
436 | 436 | foreach ($httpfeeds as $feed) { |
437 | - $buffer = stream_get_line($feed,2000,"\n"); |
|
438 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
439 | - $buffer = explode('\n',$buffer); |
|
437 | + $buffer = stream_get_line($feed, 2000, "\n"); |
|
438 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
439 | + $buffer = explode('\n', $buffer); |
|
440 | 440 | foreach ($buffer as $line) { |
441 | 441 | if ($line != '') { |
442 | 442 | $ais_data = $AIS->parse_line(trim($line)); |
@@ -452,9 +452,9 @@ discard block |
||
452 | 452 | if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
453 | 453 | if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
454 | 454 | if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
455 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
455 | + if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']); |
|
456 | 456 | if (isset($ais_data['timestamp'])) { |
457 | - $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
|
457 | + $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']); |
|
458 | 458 | } else { |
459 | 459 | $data['datetime'] = date('Y-m-d H:i:s'); |
460 | 460 | } |
@@ -468,10 +468,10 @@ discard block |
||
468 | 468 | } |
469 | 469 | } |
470 | 470 | } elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) { |
471 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
471 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20'); |
|
472 | 472 | if ($buffer != '') { |
473 | 473 | //echo $buffer; |
474 | - $all_data = json_decode($buffer,true); |
|
474 | + $all_data = json_decode($buffer, true); |
|
475 | 475 | //print_r($all_data); |
476 | 476 | if (isset($all_data[0]['DATA'])) { |
477 | 477 | foreach ($all_data[0]['DATA'] as $line) { |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | // if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
487 | 487 | $data['imo'] = $line['IMO']; |
488 | 488 | //$data['arrival_code'] = $ais_data['destination']; |
489 | - $data['datetime'] = date('Y-m-d H:i:s',$line['T']); |
|
489 | + $data['datetime'] = date('Y-m-d H:i:s', $line['T']); |
|
490 | 490 | $data['format_source'] = 'myshiptracking'; |
491 | 491 | $data['id_source'] = $id_source; |
492 | 492 | $MI->add($data); |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | } |
499 | 499 | $last_exec[$id]['last'] = time(); |
500 | 500 | } elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) { |
501 | - $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host'])); |
|
501 | + $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host'])); |
|
502 | 502 | if ($buffer != '') { |
503 | - $all_data = json_decode($buffer,true); |
|
503 | + $all_data = json_decode($buffer, true); |
|
504 | 504 | if (isset($all_data[0]['mmsi'])) { |
505 | 505 | foreach ($all_data as $line) { |
506 | 506 | if ($line != '') { |
@@ -527,27 +527,27 @@ discard block |
||
527 | 527 | $last_exec[$id]['last'] = time(); |
528 | 528 | } elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) { |
529 | 529 | echo 'download...'; |
530 | - $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter'); |
|
530 | + $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter'); |
|
531 | 531 | echo 'done !'."\n"; |
532 | 532 | if ($buffer != '') $reset = 0; |
533 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
534 | - $buffer = explode('\n',$buffer); |
|
533 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
534 | + $buffer = explode('\n', $buffer); |
|
535 | 535 | foreach ($buffer as $line) { |
536 | 536 | if ($line != '') { |
537 | 537 | $data = array(); |
538 | - $data['mmsi'] = (int)substr($line,0,9); |
|
539 | - $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10)); |
|
538 | + $data['mmsi'] = (int) substr($line, 0, 9); |
|
539 | + $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10)); |
|
540 | 540 | //$data['status'] = substr($line,21,2); |
541 | 541 | //$data['type'] = substr($line,24,3); |
542 | - $data['latitude'] = substr($line,29,9); |
|
543 | - $data['longitude'] = substr($line,41,9); |
|
544 | - $data['speed'] = round(substr($line,51,5)); |
|
542 | + $data['latitude'] = substr($line, 29, 9); |
|
543 | + $data['longitude'] = substr($line, 41, 9); |
|
544 | + $data['speed'] = round(substr($line, 51, 5)); |
|
545 | 545 | //$data['course'] = substr($line,57,5); |
546 | - $data['heading'] = round(substr($line,63,3)); |
|
546 | + $data['heading'] = round(substr($line, 63, 3)); |
|
547 | 547 | //$data['draft'] = substr($line,67,4); |
548 | 548 | //$data['length'] = substr($line,72,3); |
549 | 549 | //$data['beam'] = substr($line,76,2); |
550 | - $data['ident'] = trim(utf8_encode(substr($line,79,20))); |
|
550 | + $data['ident'] = trim(utf8_encode(substr($line, 79, 20))); |
|
551 | 551 | //$data['callsign'] = trim(substr($line,100,7); |
552 | 552 | //$data['dest'] = substr($line,108,20); |
553 | 553 | //$data['etaDate'] = substr($line,129,5); |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | } elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) { |
566 | 566 | //$buffer = $Common->getData($hosts[$id]); |
567 | 567 | $buffer = $Common->getData($value['host']); |
568 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
569 | - $buffer = explode('\n',$buffer); |
|
568 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
569 | + $buffer = explode('\n', $buffer); |
|
570 | 570 | $reset = 0; |
571 | 571 | foreach ($buffer as $line) { |
572 | 572 | if ($line != '') { |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
578 | 578 | $data['pilot_id'] = $line[1]; |
579 | 579 | $data['pilot_name'] = $line[2]; |
580 | - $data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT); |
|
580 | + $data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT); |
|
581 | 581 | $data['ident'] = $line[0]; // ident |
582 | 582 | if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
583 | 583 | $data['speed'] = $line[8]; // speed |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37])); |
594 | 594 | //if (isset($line[37])) $data['last_update'] = $line[37]; |
595 | 595 | $data['departure_airport_icao'] = $line[11]; |
596 | - $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
596 | + $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':'); |
|
597 | 597 | $data['arrival_airport_icao'] = $line[13]; |
598 | 598 | $data['frequency'] = $line[4]; |
599 | 599 | $data['type'] = $line[18]; |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | $data['id_source'] = $id_source; |
603 | 603 | //$data['arrival_airport_time'] = ; |
604 | 604 | if ($line[9] != '') { |
605 | - $aircraft_data = explode('/',$line[9]); |
|
605 | + $aircraft_data = explode('/', $line[9]); |
|
606 | 606 | if (isset($aircraft_data[1])) { |
607 | 607 | $data['aircraft_icao'] = $aircraft_data[1]; |
608 | 608 | } |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | if ($line[3] == 'PILOT') $SI->add($data); |
617 | 617 | elseif ($line[3] == 'ATC') { |
618 | 618 | //print_r($data); |
619 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
620 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
621 | - $typec = substr($data['ident'],-3); |
|
619 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
620 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
621 | + $typec = substr($data['ident'], -3); |
|
622 | 622 | if ($typec == 'APP') $data['type'] = 'Approach'; |
623 | 623 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
624 | 624 | elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
630 | 630 | elseif ($data['type'] == '') $data['type'] = 'Observer'; |
631 | 631 | if (!isset($data['source_name'])) $data['source_name'] = ''; |
632 | - if (isset($ATC)) 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']); |
|
632 | + if (isset($ATC)) 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']); |
|
633 | 633 | } |
634 | 634 | unset($data); |
635 | 635 | } |
@@ -640,9 +640,9 @@ discard block |
||
640 | 640 | $last_exec[$id]['last'] = time(); |
641 | 641 | //} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) { |
642 | 642 | } elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
643 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
643 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20'); |
|
644 | 644 | if ($buffer != '') { |
645 | - $all_data = json_decode($buffer,true); |
|
645 | + $all_data = json_decode($buffer, true); |
|
646 | 646 | if (isset($all_data['acList'])) { |
647 | 647 | $reset = 0; |
648 | 648 | foreach ($all_data['acList'] as $line) { |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
699 | 699 | } elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
700 | 700 | $buffer = $Common->getData($value['host']); |
701 | - $all_data = json_decode($buffer,true); |
|
701 | + $all_data = json_decode($buffer, true); |
|
702 | 702 | if (isset($all_data['planes'])) { |
703 | 703 | $reset = 0; |
704 | 704 | foreach ($all_data['planes'] as $key => $line) { |
@@ -715,12 +715,12 @@ discard block |
||
715 | 715 | $data['emergency'] = ''; // emergency |
716 | 716 | $data['registration'] = $line[2]; |
717 | 717 | $data['aircraft_icao'] = $line[0]; |
718 | - $deparr = explode('-',$line[1]); |
|
718 | + $deparr = explode('-', $line[1]); |
|
719 | 719 | if (count($deparr) == 2) { |
720 | 720 | $data['departure_airport_icao'] = $deparr[0]; |
721 | 721 | $data['arrival_airport_icao'] = $deparr[1]; |
722 | 722 | } |
723 | - $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
723 | + $data['datetime'] = date('Y-m-d H:i:s', $line[9]); |
|
724 | 724 | $data['format_source'] = 'planeupdatefaa'; |
725 | 725 | $data['id_source'] = $id_source; |
726 | 726 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | $last_exec[$id]['last'] = time(); |
733 | 733 | } elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
734 | 734 | $buffer = $Common->getData($value['host']); |
735 | - $all_data = json_decode($buffer,true); |
|
735 | + $all_data = json_decode($buffer, true); |
|
736 | 736 | if (isset($all_data['states'])) { |
737 | 737 | $reset = 0; |
738 | 738 | foreach ($all_data['states'] as $key => $line) { |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | //$data['emergency'] = ''; // emergency |
750 | 750 | //$data['registration'] = $line[2]; |
751 | 751 | //$data['aircraft_icao'] = $line[0]; |
752 | - $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
752 | + $data['datetime'] = date('Y-m-d H:i:s', $line[3]); |
|
753 | 753 | $data['format_source'] = 'opensky'; |
754 | 754 | $data['id_source'] = $id_source; |
755 | 755 | $SI->add($data); |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | } elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
763 | 763 | //$buffer = $Common->getData($hosts[$id]); |
764 | 764 | $buffer = $Common->getData($value['host']); |
765 | - $all_data = json_decode($buffer,true); |
|
765 | + $all_data = json_decode($buffer, true); |
|
766 | 766 | if (!empty($all_data)) $reset = 0; |
767 | 767 | foreach ($all_data as $key => $line) { |
768 | 768 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
@@ -794,11 +794,11 @@ discard block |
||
794 | 794 | //} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { |
795 | 795 | } elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
796 | 796 | //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
797 | - $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
797 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150'); |
|
798 | 798 | //echo $buffer; |
799 | - $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
800 | - $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
801 | - $all_data = json_decode($buffer,true); |
|
799 | + $buffer = str_replace(array("\n", "\r"), "", $buffer); |
|
800 | + $buffer = preg_replace('/,"num":(.+)/', '}', $buffer); |
|
801 | + $all_data = json_decode($buffer, true); |
|
802 | 802 | if (json_last_error() != JSON_ERROR_NONE) { |
803 | 803 | die(json_last_error_msg()); |
804 | 804 | } |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | //$data['departure_airport_iata'] = $line[11]; |
822 | 822 | //$data['arrival_airport_iata'] = $line[12]; |
823 | 823 | //$data['emergency'] = ''; // emergency |
824 | - $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
|
824 | + $data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10] |
|
825 | 825 | $data['format_source'] = 'radarvirtueljson'; |
826 | 826 | $data['id_source'] = $id_source; |
827 | 827 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
@@ -836,14 +836,14 @@ discard block |
||
836 | 836 | } elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
837 | 837 | //$buffer = $Common->getData($hosts[$id]); |
838 | 838 | $buffer = $Common->getData($value['host'].'?'.time()); |
839 | - $all_data = json_decode(utf8_encode($buffer),true); |
|
839 | + $all_data = json_decode(utf8_encode($buffer), true); |
|
840 | 840 | |
841 | 841 | if (isset($all_data['pireps'])) { |
842 | 842 | $reset = 0; |
843 | 843 | foreach ($all_data['pireps'] as $line) { |
844 | 844 | $data = array(); |
845 | 845 | $data['id'] = $line['id']; |
846 | - $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
846 | + $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
847 | 847 | $data['ident'] = $line['callsign']; // ident |
848 | 848 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
849 | 849 | if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
@@ -872,9 +872,9 @@ discard block |
||
872 | 872 | $SI->add($data); |
873 | 873 | // print_r($data); |
874 | 874 | } elseif ($line['icon'] == 'ct') { |
875 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
876 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
877 | - $typec = substr($data['ident'],-3); |
|
875 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
876 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
877 | + $typec = substr($data['ident'], -3); |
|
878 | 878 | $data['type'] = ''; |
879 | 879 | if ($typec == 'APP') $data['type'] = 'Approach'; |
880 | 880 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
886 | 886 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
887 | 887 | else $data['type'] = 'Observer'; |
888 | - if (isset($ATC)) 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']); |
|
888 | + if (isset($ATC)) 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']); |
|
889 | 889 | } |
890 | 890 | unset($data); |
891 | 891 | } |
@@ -897,14 +897,14 @@ discard block |
||
897 | 897 | //$buffer = $Common->getData($hosts[$id]); |
898 | 898 | if ($globalDebug) echo 'Get Data...'."\n"; |
899 | 899 | $buffer = $Common->getData($value['host']); |
900 | - $all_data = json_decode($buffer,true); |
|
900 | + $all_data = json_decode($buffer, true); |
|
901 | 901 | if ($buffer != '' && is_array($all_data)) { |
902 | 902 | $reset = 0; |
903 | 903 | foreach ($all_data as $line) { |
904 | 904 | $data = array(); |
905 | 905 | //$data['id'] = $line['id']; // id not usable |
906 | 906 | if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
907 | - $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
907 | + $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
908 | 908 | if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
909 | 909 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
910 | 910 | $data['ident'] = $line['flightnum']; // ident |
@@ -927,12 +927,12 @@ discard block |
||
927 | 927 | if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
928 | 928 | if (isset($line['aircraftname'])) { |
929 | 929 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
930 | - $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
|
931 | - $aircraft_data = explode('-',$line['aircraftname']); |
|
930 | + $line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']); |
|
931 | + $aircraft_data = explode('-', $line['aircraftname']); |
|
932 | 932 | if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
933 | 933 | elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
934 | 934 | else { |
935 | - $aircraft_data = explode(' ',$line['aircraftname']); |
|
935 | + $aircraft_data = explode(' ', $line['aircraftname']); |
|
936 | 936 | if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
937 | 937 | else $data['aircraft_icao'] = $line['aircraftname']; |
938 | 938 | } |
@@ -954,14 +954,14 @@ discard block |
||
954 | 954 | //$buffer = $Common->getData($hosts[$id]); |
955 | 955 | if ($globalDebug) echo 'Get Data...'."\n"; |
956 | 956 | $buffer = $Common->getData($value['host']); |
957 | - $all_data = json_decode($buffer,true); |
|
957 | + $all_data = json_decode($buffer, true); |
|
958 | 958 | if ($buffer != '' && is_array($all_data)) { |
959 | 959 | $reset = 0; |
960 | 960 | foreach ($all_data as $line) { |
961 | 961 | $data = array(); |
962 | 962 | //$data['id'] = $line['id']; // id not usable |
963 | 963 | $data['id'] = trim($line['flight_id']); |
964 | - $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
964 | + $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
965 | 965 | $data['pilot_name'] = $line['pilot_name']; |
966 | 966 | $data['pilot_id'] = $line['pilot_id']; |
967 | 967 | $data['ident'] = trim($line['callsign']); // ident |
@@ -1012,9 +1012,9 @@ discard block |
||
1012 | 1012 | //$value = $formats[$nb]; |
1013 | 1013 | $format = $globalSources[$nb]['format']; |
1014 | 1014 | if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
1015 | - $buffer = socket_read($r, 6000,PHP_NORMAL_READ); |
|
1015 | + $buffer = socket_read($r, 6000, PHP_NORMAL_READ); |
|
1016 | 1016 | } else { |
1017 | - $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port); |
|
1017 | + $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port); |
|
1018 | 1018 | } |
1019 | 1019 | //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
1020 | 1020 | //echo $buffer."\n"; |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
1023 | 1023 | $error = false; |
1024 | 1024 | //$SI::del(); |
1025 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
1025 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer)); |
|
1026 | 1026 | // SBS format is CSV format |
1027 | 1027 | if ($buffer != '') { |
1028 | 1028 | $tt[$format] = 0; |
@@ -1054,10 +1054,10 @@ discard block |
||
1054 | 1054 | if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
1055 | 1055 | if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
1056 | 1056 | if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
1057 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
1057 | + if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']); |
|
1058 | 1058 | |
1059 | 1059 | if (isset($ais_data['timestamp'])) { |
1060 | - $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
|
1060 | + $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']); |
|
1061 | 1061 | } else { |
1062 | 1062 | $data['datetime'] = date('Y-m-d H:i:s'); |
1063 | 1063 | } |
@@ -1068,10 +1068,10 @@ discard block |
||
1068 | 1068 | } elseif ($format == 'flightgearsp') { |
1069 | 1069 | //echo $buffer."\n"; |
1070 | 1070 | if (strlen($buffer) > 5) { |
1071 | - $line = explode(',',$buffer); |
|
1071 | + $line = explode(',', $buffer); |
|
1072 | 1072 | $data = array(); |
1073 | 1073 | //XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p |
1074 | - $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6); |
|
1074 | + $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
1075 | 1075 | $data['ident'] = $line[6]; |
1076 | 1076 | $data['aircraft_name'] = $line[7]; |
1077 | 1077 | $data['longitude'] = $line[1]; |
@@ -1082,21 +1082,21 @@ discard block |
||
1082 | 1082 | $data['datetime'] = date('Y-m-d H:i:s'); |
1083 | 1083 | $data['format_source'] = 'flightgearsp'; |
1084 | 1084 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
1085 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
1085 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
1086 | 1086 | } |
1087 | 1087 | } elseif ($format == 'acars') { |
1088 | 1088 | if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
1089 | 1089 | $ACARS->add(trim($buffer)); |
1090 | - socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
1090 | + socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port); |
|
1091 | 1091 | $ACARS->deleteLiveAcarsData(); |
1092 | 1092 | } elseif ($format == 'flightgearmp') { |
1093 | - if (substr($buffer,0,1) != '#') { |
|
1093 | + if (substr($buffer, 0, 1) != '#') { |
|
1094 | 1094 | $data = array(); |
1095 | 1095 | //echo $buffer."\n"; |
1096 | - $line = explode(' ',$buffer); |
|
1096 | + $line = explode(' ', $buffer); |
|
1097 | 1097 | if (count($line) == 11) { |
1098 | - $userserver = explode('@',$line[0]); |
|
1099 | - $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex |
|
1098 | + $userserver = explode('@', $line[0]); |
|
1099 | + $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex |
|
1100 | 1100 | $data['ident'] = $userserver[0]; |
1101 | 1101 | $data['registration'] = $userserver[0]; |
1102 | 1102 | $data['latitude'] = $line[4]; |
@@ -1104,24 +1104,24 @@ discard block |
||
1104 | 1104 | $data['altitude'] = $line[6]; |
1105 | 1105 | $data['datetime'] = date('Y-m-d H:i:s'); |
1106 | 1106 | $aircraft_type = $line[10]; |
1107 | - $aircraft_type = preg_split(':/:',$aircraft_type); |
|
1108 | - $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
1107 | + $aircraft_type = preg_split(':/:', $aircraft_type); |
|
1108 | + $data['aircraft_name'] = substr(end($aircraft_type), 0, -4); |
|
1109 | 1109 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
1110 | 1110 | } |
1111 | 1111 | } |
1112 | 1112 | } elseif ($format == 'beast') { |
1113 | 1113 | echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
1114 | 1114 | die; |
1115 | - } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
|
1115 | + } elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') { |
|
1116 | 1116 | $line = explode("\t", $buffer); |
1117 | - for($k = 0; $k < count($line); $k=$k+2) { |
|
1117 | + for ($k = 0; $k < count($line); $k = $k + 2) { |
|
1118 | 1118 | $key = $line[$k]; |
1119 | - $lined[$key] = $line[$k+1]; |
|
1119 | + $lined[$key] = $line[$k + 1]; |
|
1120 | 1120 | } |
1121 | 1121 | if (count($lined) > 3) { |
1122 | 1122 | $data['hex'] = $lined['hexid']; |
1123 | 1123 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
1124 | - $data['datetime'] = date('Y-m-d H:i:s');; |
|
1124 | + $data['datetime'] = date('Y-m-d H:i:s'); ; |
|
1125 | 1125 | if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
1126 | 1126 | if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
1127 | 1127 | if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
@@ -1139,22 +1139,22 @@ discard block |
||
1139 | 1139 | } else $error = true; |
1140 | 1140 | } elseif ($format == 'aprs' && $use_aprs) { |
1141 | 1141 | if ($aprs_connect == 0) { |
1142 | - $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
|
1142 | + $send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0); |
|
1143 | 1143 | $aprs_connect = 1; |
1144 | 1144 | } |
1145 | 1145 | |
1146 | - if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
1146 | + if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) { |
|
1147 | 1147 | $aprs_last_tx = time(); |
1148 | 1148 | $data_aprs = "# Keep alive"; |
1149 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
1149 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | //echo 'Connect : '.$aprs_connect.' '.$buffer."\n"; |
1153 | 1153 | //echo 'APRS data : '.$buffer."\n"; |
1154 | - $buffer = str_replace('APRS <- ','',$buffer); |
|
1155 | - $buffer = str_replace('APRS -> ','',$buffer); |
|
1154 | + $buffer = str_replace('APRS <- ', '', $buffer); |
|
1155 | + $buffer = str_replace('APRS -> ', '', $buffer); |
|
1156 | 1156 | //echo $buffer."\n"; |
1157 | - if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { |
|
1157 | + if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') { |
|
1158 | 1158 | $line = $APRS->parse($buffer); |
1159 | 1159 | //print_r($line); |
1160 | 1160 | //if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) { |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | $data = array(); |
1164 | 1164 | //print_r($line); |
1165 | 1165 | if (isset($line['address'])) $data['hex'] = $line['address']; |
1166 | - if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1166 | + if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']); |
|
1167 | 1167 | else $data['datetime'] = date('Y-m-d H:i:s'); |
1168 | 1168 | //$data['datetime'] = date('Y-m-d H:i:s'); |
1169 | 1169 | $data['ident'] = $line['ident']; |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | $currentdate = date('Y-m-d H:i:s'); |
1190 | 1190 | $aprsdate = strtotime($data['datetime']); |
1191 | 1191 | // Accept data if time <= system time + 20s |
1192 | - if (($data['source_type'] == 'sbs') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
1192 | + if (($data['source_type'] == 'sbs') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
1193 | 1193 | $send = $SI->add($data); |
1194 | 1194 | } elseif (isset($line['stealth'])) { |
1195 | 1195 | if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
@@ -1286,7 +1286,7 @@ discard block |
||
1286 | 1286 | connect_all($sourceee); |
1287 | 1287 | $sourceee = array(); |
1288 | 1288 | //connect_all($globalSources); |
1289 | - $tt[$format]=0; |
|
1289 | + $tt[$format] = 0; |
|
1290 | 1290 | break; |
1291 | 1291 | } |
1292 | 1292 | } |
@@ -1295,14 +1295,14 @@ discard block |
||
1295 | 1295 | } else { |
1296 | 1296 | $error = socket_strerror(socket_last_error()); |
1297 | 1297 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) { |
1298 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1298 | + if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n"; |
|
1299 | 1299 | if (isset($globalDebug)) echo "Restarting...\n"; |
1300 | 1300 | // Restart the script if possible |
1301 | 1301 | if (is_array($sockets)) { |
1302 | 1302 | if ($globalDebug) echo "Shutdown all sockets..."; |
1303 | 1303 | |
1304 | 1304 | foreach ($sockets as $sock) { |
1305 | - @socket_shutdown($sock,2); |
|
1305 | + @socket_shutdown($sock, 2); |
|
1306 | 1306 | @socket_close($sock); |
1307 | 1307 | } |
1308 | 1308 |