Completed
Push — master ( 3b2be2...aa3dba )
by Yannick
06:52
created
scripts/daemon-spotter.php 1 patch
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 	    die;
41 41
 	}
42 42
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
43
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
43
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
44 44
     }
45 45
 }
46 46
 
47
-$options = getopt('s::',array('source::','server','idsource::'));
47
+$options = getopt('s::', array('source::', 'server', 'idsource::'));
48 48
 //if (isset($options['s'])) $hosts = array($options['s']);
49 49
 //elseif (isset($options['source'])) $hosts = array($options['source']);
50 50
 if (isset($options['s'])) {
@@ -59,17 +59,17 @@  discard block
 block discarded – undo
59 59
 else $id_source = 1;
60 60
 if (isset($globalServer) && $globalServer) {
61 61
     if ($globalDebug) echo "Using Server Mode\n";
62
-    $SI=new SpotterServer();
63
-} else $SI=new SpotterImport($Connection->db);
62
+    $SI = new SpotterServer();
63
+} else $SI = new SpotterImport($Connection->db);
64 64
 //$APRS=new APRS($Connection->db);
65
-$SBS=new SBS();
66
-$ACARS=new ACARS($Connection->db);
67
-$Common=new Common();
65
+$SBS = new SBS();
66
+$ACARS = new ACARS($Connection->db);
67
+$Common = new Common();
68 68
 date_default_timezone_set('UTC');
69 69
 //$servertz = system('date +%Z');
70 70
 // signal handler - playing nice with sockets and dump1090
71 71
 if (function_exists('pcntl_fork')) {
72
-    pcntl_signal(SIGINT,  function() {
72
+    pcntl_signal(SIGINT, function() {
73 73
         global $sockets;
74 74
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75 75
         die("Bye!\n");
@@ -113,35 +113,35 @@  discard block
 block discarded – undo
113 113
 
114 114
 function connect_all($hosts) {
115 115
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
116
+    global $sockets, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset;
117 117
     $reset++;
118 118
     if ($globalDebug) echo 'Connect to all...'."\n";
119 119
     foreach ($hosts as $id => $value) {
120 120
 	$host = $value['host'];
121 121
 	$globalSources[$id]['last_exec'] = 0;
122 122
 	// Here we check type of source(s)
123
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
-            if (preg_match('/deltadb.txt$/i',$host)) {
123
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
+            if (preg_match('/deltadb.txt$/i', $host)) {
125 125
         	//$formats[$id] = 'deltadbtxt';
126 126
         	$globalSources[$id]['format'] = 'deltadbtxt';
127 127
         	//$last_exec['deltadbtxt'] = 0;
128 128
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
129
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
130 130
         	//$formats[$id] = 'vatsimtxt';
131 131
         	$globalSources[$id]['format'] = 'vatsimtxt';
132 132
         	//$last_exec['vatsimtxt'] = 0;
133 133
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
134
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
135 135
         	//$formats[$id] = 'aircraftlistjson';
136 136
         	$globalSources[$id]['format'] = 'aircraftlistjson';
137 137
         	//$last_exec['aircraftlistjson'] = 0;
138 138
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
-    	    } else if (preg_match('/opensky/i',$host)) {
139
+    	    } else if (preg_match('/opensky/i', $host)) {
140 140
         	//$formats[$id] = 'aircraftlistjson';
141 141
         	$globalSources[$id]['format'] = 'opensky';
142 142
         	//$last_exec['aircraftlistjson'] = 0;
143 143
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
144
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
145 145
         	//$formats[$id] = 'radarvirtueljson';
146 146
         	$globalSources[$id]['format'] = 'radarvirtueljson';
147 147
         	//$last_exec['radarvirtueljson'] = 0;
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151 151
         	    exit(0);
152 152
         	}
153
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
153
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
154 154
         	//$formats[$id] = 'planeupdatefaa';
155 155
         	$globalSources[$id]['format'] = 'planeupdatefaa';
156 156
         	//$last_exec['planeupdatefaa'] = 0;
@@ -159,26 +159,26 @@  discard block
 block discarded – undo
159 159
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160 160
         	    exit(0);
161 161
         	}
162
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
162
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
163 163
         	//$formats[$id] = 'phpvmacars';
164 164
         	$globalSources[$id]['format'] = 'phpvmacars';
165 165
         	//$last_exec['phpvmacars'] = 0;
166 166
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
167
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
168 168
         	//$formats[$id] = 'phpvmacars';
169 169
         	$globalSources[$id]['format'] = 'vam';
170 170
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
-            } else if (preg_match('/whazzup/i',$host)) {
171
+            } else if (preg_match('/whazzup/i', $host)) {
172 172
         	//$formats[$id] = 'whazzup';
173 173
         	$globalSources[$id]['format'] = 'whazzup';
174 174
         	//$last_exec['whazzup'] = 0;
175 175
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
-            } else if (preg_match('/recentpireps/i',$host)) {
176
+            } else if (preg_match('/recentpireps/i', $host)) {
177 177
         	//$formats[$id] = 'pirepsjson';
178 178
         	$globalSources[$id]['format'] = 'pirepsjson';
179 179
         	//$last_exec['pirepsjson'] = 0;
180 180
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
181
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
182 182
         	//$formats[$id] = 'fr24json';
183 183
         	$globalSources[$id]['format'] = 'fr24json';
184 184
         	//$last_exec['fr24json'] = 0;
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
         	    exit(0);
189 189
         	}
190 190
             //} else if (preg_match('/10001/',$host)) {
191
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
191
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192 192
         	//$formats[$id] = 'tsv';
193 193
         	$globalSources[$id]['format'] = 'tsv';
194 194
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195 195
             }
196
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
196
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
197 197
         	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
-	    $hostport = explode(':',$host);
198
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
199
+	    $hostport = explode(':', $host);
200 200
 	    if (isset($hostport[1])) {
201 201
 		$port = $hostport[1];
202 202
 		$hostn = $hostport[0];
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
 		$hostn = $globalSources[$id]['host'];
206 206
 	    }
207 207
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
-        	$s = create_socket($hostn,$port, $errno, $errstr);
208
+        	$s = create_socket($hostn, $port, $errno, $errstr);
209 209
     	    } else {
210
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
210
+        	$s = create_socket_udp($hostn, $port, $errno, $errstr);
211 211
 	    }
212 212
 	    if ($s) {
213 213
     	        $sockets[$id] = $s;
214 214
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
-		    if (preg_match('/aprs/',$hostn)) {
215
+		    if (preg_match('/aprs/', $hostn)) {
216 216
 			//$formats[$id] = 'aprs';
217 217
 			$globalSources[$id]['format'] = 'aprs';
218 218
 			//$aprs_connect = 0;
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
254 254
 else $timeout = 20;
255 255
 $errno = '';
256
-$errstr='';
256
+$errstr = '';
257 257
 
258 258
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
259 259
 /* Initiate connections to all the hosts simultaneously */
@@ -282,18 +282,18 @@  discard block
 block discarded – undo
282 282
 
283 283
 if ($use_aprs) {
284 284
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
285
-	$APRS=new APRS();
285
+	$APRS = new APRS();
286 286
 	$aprs_connect = 0;
287 287
 	$aprs_keep = 120;
288 288
 	$aprs_last_tx = time();
289 289
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
290
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
290
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
291 291
 	//else $aprs_version = 'Perl Example App';
292 292
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
293
-	else $aprs_ssid = 'FAM-'.str_replace(' ','_',$globalName);
293
+	else $aprs_ssid = 'FAM-'.str_replace(' ', '_', $globalName);
294 294
 	//else $aprs_ssid = 'PerlEx';
295 295
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
296
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
296
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
297 297
 	if ($aprs_full) $aprs_filter = '';
298 298
 	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} vers {$aprs_version} filter {$aprs_filter}\n";
299 299
 	else $aprs_login = "user {$aprs_ssid} vers {$aprs_version}\n";
@@ -304,12 +304,12 @@  discard block
 block discarded – undo
304 304
 sleep(1);
305 305
 if ($globalDebug) echo "SCAN MODE \n\n";
306 306
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
307
-$endtime = time()+$globalCronEnd;
307
+$endtime = time() + $globalCronEnd;
308 308
 $i = 1;
309 309
 $tt = array();
310 310
 // Delete all ATC
311 311
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
312
-	$ATC=new ATC($Connection->db);
312
+	$ATC = new ATC($Connection->db);
313 313
 }
314 314
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
315 315
 	$ATC->deleteAll();
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 
318 318
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
319 319
 while ($i > 0) {
320
-    if (!$globalDaemon) $i = $endtime-time();
320
+    if (!$globalDaemon) $i = $endtime - time();
321 321
     // Delete old ATC
322 322
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
323 323
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 	if ($max != $globalMinFetch) {
333 333
 	    if ($globalDebug) echo 'Sleeping...'."\n";
334
-	    sleep($globalMinFetch-$max+2);
334
+	    sleep($globalMinFetch - $max + 2);
335 335
 	}
336 336
     }
337 337
 
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
 	    //$buffer = $Common->getData($hosts[$id]);
345 345
 	    $buffer = $Common->getData($value['host']);
346 346
 	    if ($buffer != '') $reset = 0;
347
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
348
-	    $buffer = explode('\n',$buffer);
347
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
348
+	    $buffer = explode('\n', $buffer);
349 349
 	    foreach ($buffer as $line) {
350 350
     		if ($line != '' && count($line) > 7) {
351 351
     		    $line = explode(',', $line);
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
375 375
 	    //$buffer = $Common->getData($hosts[$id]);
376 376
 	    $buffer = $Common->getData($value['host']);
377
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
378
-	    $buffer = explode('\n',$buffer);
377
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
378
+	    $buffer = explode('\n', $buffer);
379 379
 	    $reset = 0;
380 380
 	    foreach ($buffer as $line) {
381 381
     		if ($line != '') {
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
387 387
 			$data['pilot_id'] = $line[1];
388 388
 			$data['pilot_name'] = $line[2];
389
-			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
389
+			$data['hex'] = str_pad(dechex($line[1]), 6, '000000', STR_PAD_LEFT);
390 390
 			$data['ident'] = $line[0]; // ident
391 391
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
392 392
 			$data['speed'] = $line[8]; // speed
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
403 403
 			//if (isset($line[37])) $data['last_update'] = $line[37];
404 404
 		        $data['departure_airport_icao'] = $line[11];
405
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
405
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
406 406
 		        $data['arrival_airport_icao'] = $line[13];
407 407
 			$data['frequency'] = $line[4];
408 408
 			$data['type'] = $line[18];
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
     			$data['id_source'] = $id_source;
412 412
 	    		//$data['arrival_airport_time'] = ;
413 413
 	    		if ($line[9] != '') {
414
-	    		    $aircraft_data = explode('/',$line[9]);
414
+	    		    $aircraft_data = explode('/', $line[9]);
415 415
 	    		    if (isset($aircraft_data[1])) {
416 416
 	    			$data['aircraft_icao'] = $aircraft_data[1];
417 417
 	    		    }
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
     			if ($line[3] == 'PILOT') $SI->add($data);
426 426
 			elseif ($line[3] == 'ATC') {
427 427
 				//print_r($data);
428
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
429
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
430
-				$typec = substr($data['ident'],-3);
428
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
429
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
430
+				$typec = substr($data['ident'], -3);
431 431
 				if ($typec == 'APP') $data['type'] = 'Approach';
432 432
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
433 433
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
439 439
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
440 440
 				if (!isset($data['source_name'])) $data['source_name'] = '';
441
-				echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
441
+				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']);
442 442
 			}
443 443
     			unset($data);
444 444
     		    }
@@ -449,9 +449,9 @@  discard block
 block discarded – undo
449 449
     	    $last_exec[$id]['last'] = time();
450 450
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
451 451
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
452
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
452
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
453 453
 	    if ($buffer != '') {
454
-	    $all_data = json_decode($buffer,true);
454
+	    $all_data = json_decode($buffer, true);
455 455
 	    if (isset($all_data['acList'])) {
456 456
 		$reset = 0;
457 457
 		foreach ($all_data['acList'] as $line) {
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
508 508
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
509 509
 	    $buffer = $Common->getData($value['host']);
510
-	    $all_data = json_decode($buffer,true);
510
+	    $all_data = json_decode($buffer, true);
511 511
 	    if (isset($all_data['planes'])) {
512 512
 		$reset = 0;
513 513
 		foreach ($all_data['planes'] as $key => $line) {
@@ -524,12 +524,12 @@  discard block
 block discarded – undo
524 524
 		    $data['emergency'] = ''; // emergency
525 525
 		    $data['registration'] = $line[2];
526 526
 		    $data['aircraft_icao'] = $line[0];
527
-		    $deparr = explode('-',$line[1]);
527
+		    $deparr = explode('-', $line[1]);
528 528
 		    if (count($deparr) == 2) {
529 529
 			$data['departure_airport_icao'] = $deparr[0];
530 530
 			$data['arrival_airport_icao'] = $deparr[1];
531 531
 		    }
532
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
532
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
533 533
 	    	    $data['format_source'] = 'planeupdatefaa';
534 534
     		    $data['id_source'] = $id_source;
535 535
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
     	    $last_exec[$id]['last'] = time();
542 542
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
543 543
 	    $buffer = $Common->getData($value['host']);
544
-	    $all_data = json_decode($buffer,true);
544
+	    $all_data = json_decode($buffer, true);
545 545
 	    if (isset($all_data['states'])) {
546 546
 		$reset = 0;
547 547
 		foreach ($all_data['states'] as $key => $line) {
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 		    //$data['emergency'] = ''; // emergency
559 559
 		    //$data['registration'] = $line[2];
560 560
 		    //$data['aircraft_icao'] = $line[0];
561
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
561
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
562 562
 	    	    $data['format_source'] = 'opensky';
563 563
     		    $data['id_source'] = $id_source;
564 564
 		    $SI->add($data);
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
572 572
 	    //$buffer = $Common->getData($hosts[$id]);
573 573
 	    $buffer = $Common->getData($value['host']);
574
-	    $all_data = json_decode($buffer,true);
574
+	    $all_data = json_decode($buffer, true);
575 575
 	    if (!empty($all_data)) $reset = 0;
576 576
 	    foreach ($all_data as $key => $line) {
577 577
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -603,11 +603,11 @@  discard block
 block discarded – undo
603 603
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
604 604
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
605 605
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
606
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
606
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
607 607
 	    //echo $buffer;
608
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
609
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
610
-	    $all_data = json_decode($buffer,true);
608
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
609
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
610
+	    $all_data = json_decode($buffer, true);
611 611
 	    if (json_last_error() != JSON_ERROR_NONE) {
612 612
 		die(json_last_error_msg());
613 613
 	    }
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 			//$data['departure_airport_iata'] = $line[11];
631 631
 			//$data['arrival_airport_iata'] = $line[12];
632 632
 	    		//$data['emergency'] = ''; // emergency
633
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
633
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
634 634
 	    		$data['format_source'] = 'radarvirtueljson';
635 635
     			$data['id_source'] = $id_source;
636 636
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -645,14 +645,14 @@  discard block
 block discarded – undo
645 645
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646 646
 	    //$buffer = $Common->getData($hosts[$id]);
647 647
 	    $buffer = $Common->getData($value['host'].'?'.time());
648
-	    $all_data = json_decode(utf8_encode($buffer),true);
648
+	    $all_data = json_decode(utf8_encode($buffer), true);
649 649
 	    
650 650
 	    if (isset($all_data['pireps'])) {
651 651
 		$reset = 0;
652 652
 	        foreach ($all_data['pireps'] as $line) {
653 653
 		    $data = array();
654 654
 		    $data['id'] = $line['id'];
655
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
655
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
656 656
 		    $data['ident'] = $line['callsign']; // ident
657 657
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
658 658
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -681,9 +681,9 @@  discard block
 block discarded – undo
681 681
 			$SI->add($data);
682 682
 		    //    print_r($data);
683 683
     		    } elseif ($line['icon'] == 'ct') {
684
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
685
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
686
-			$typec = substr($data['ident'],-3);
684
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
685
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
686
+			$typec = substr($data['ident'], -3);
687 687
 			$data['type'] = '';
688 688
 			if ($typec == 'APP') $data['type'] = 'Approach';
689 689
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
695 695
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
696 696
 			else $data['type'] = 'Observer';
697
-			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
697
+			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']);
698 698
 		    }
699 699
 		    unset($data);
700 700
 		}
@@ -706,14 +706,14 @@  discard block
 block discarded – undo
706 706
 	    //$buffer = $Common->getData($hosts[$id]);
707 707
 	    if ($globalDebug) echo 'Get Data...'."\n";
708 708
 	    $buffer = $Common->getData($value['host']);
709
-	    $all_data = json_decode($buffer,true);
709
+	    $all_data = json_decode($buffer, true);
710 710
 	    if ($buffer != '' && is_array($all_data)) {
711 711
 		$reset = 0;
712 712
 		foreach ($all_data as $line) {
713 713
 	    	    $data = array();
714 714
 	    	    //$data['id'] = $line['id']; // id not usable
715 715
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
716
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
716
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
717 717
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
718 718
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
719 719
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -736,12 +736,12 @@  discard block
 block discarded – undo
736 736
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
737 737
 		    if (isset($line['aircraftname'])) {
738 738
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
739
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
740
-	    		$aircraft_data = explode('-',$line['aircraftname']);
739
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
740
+	    		$aircraft_data = explode('-', $line['aircraftname']);
741 741
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
742 742
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
743 743
 	    		else {
744
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
744
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
745 745
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
746 746
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
747 747
 	    		}
@@ -763,14 +763,14 @@  discard block
 block discarded – undo
763 763
 	    //$buffer = $Common->getData($hosts[$id]);
764 764
 	    if ($globalDebug) echo 'Get Data...'."\n";
765 765
 	    $buffer = $Common->getData($value['host']);
766
-	    $all_data = json_decode($buffer,true);
766
+	    $all_data = json_decode($buffer, true);
767 767
 	    if ($buffer != '' && is_array($all_data)) {
768 768
 		$reset = 0;
769 769
 		foreach ($all_data as $line) {
770 770
 	    	    $data = array();
771 771
 	    	    //$data['id'] = $line['id']; // id not usable
772 772
 	    	    $data['id'] = trim($line['flight_id']);
773
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
773
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
774 774
 	    	    $data['pilot_name'] = $line['pilot_name'];
775 775
 	    	    $data['pilot_id'] = $line['pilot_id'];
776 776
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -821,9 +821,9 @@  discard block
 block discarded – undo
821 821
 		    //$value = $formats[$nb];
822 822
 		    $format = $globalSources[$nb]['format'];
823 823
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
824
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
824
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
825 825
         	    } else {
826
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
826
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
827 827
 	    	    }
828 828
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
829 829
         	    //echo $buffer."\n";
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
832 832
 		    $error = false;
833 833
 		    //$SI::del();
834
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
834
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
835 835
 		    // SBS format is CSV format
836 836
 		    if ($buffer != '') {
837 837
 			$tt[$format] = 0;
@@ -852,10 +852,10 @@  discard block
 block discarded – undo
852 852
                         } elseif ($format == 'flightgearsp') {
853 853
                     	    //echo $buffer."\n";
854 854
                     	    if (strlen($buffer) > 5) {
855
-				$line = explode(',',$buffer);
855
+				$line = explode(',', $buffer);
856 856
 				$data = array();
857 857
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
858
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
858
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
859 859
 				$data['ident'] = $line[6];
860 860
 				$data['aircraft_name'] = $line[7];
861 861
 				$data['longitude'] = $line[1];
@@ -866,21 +866,21 @@  discard block
 block discarded – undo
866 866
 				$data['datetime'] = date('Y-m-d H:i:s');
867 867
 				$data['format_source'] = 'flightgearsp';
868 868
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
869
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
869
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
870 870
 			    }
871 871
                         } elseif ($format == 'acars') {
872 872
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
873 873
 			    $ACARS->add(trim($buffer));
874
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
874
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
875 875
 			    $ACARS->deleteLiveAcarsData();
876 876
 			} elseif ($format == 'flightgearmp') {
877
-			    if (substr($buffer,0,1) != '#') {
877
+			    if (substr($buffer, 0, 1) != '#') {
878 878
 				$data = array();
879 879
 				//echo $buffer."\n";
880
-				$line = explode(' ',$buffer);
880
+				$line = explode(' ', $buffer);
881 881
 				if (count($line) == 11) {
882
-				    $userserver = explode('@',$line[0]);
883
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
882
+				    $userserver = explode('@', $line[0]);
883
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
884 884
 				    $data['ident'] = $userserver[0];
885 885
 				    $data['registration'] = $userserver[0];
886 886
 				    $data['latitude'] = $line[4];
@@ -888,24 +888,24 @@  discard block
 block discarded – undo
888 888
 				    $data['altitude'] = $line[6];
889 889
 				    $data['datetime'] = date('Y-m-d H:i:s');
890 890
 				    $aircraft_type = $line[10];
891
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
892
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
891
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
892
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
893 893
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
894 894
 				}
895 895
 			    }
896 896
 			} elseif ($format == 'beast') {
897 897
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
898 898
 			    die;
899
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
899
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
900 900
 			    $line = explode("\t", $buffer);
901
-			    for($k = 0; $k < count($line); $k=$k+2) {
901
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
902 902
 				$key = $line[$k];
903
-			        $lined[$key] = $line[$k+1];
903
+			        $lined[$key] = $line[$k + 1];
904 904
 			    }
905 905
     			    if (count($lined) > 3) {
906 906
     				$data['hex'] = $lined['hexid'];
907 907
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
908
-    				$data['datetime'] = date('Y-m-d H:i:s');;
908
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
909 909
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
910 910
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
911 911
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -923,27 +923,27 @@  discard block
 block discarded – undo
923 923
     			    } else $error = true;
924 924
 			} elseif ($format == 'aprs' && $use_aprs) {
925 925
 			    if ($aprs_connect == 0) {
926
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
926
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
927 927
 				$aprs_connect = 1;
928 928
 			    }
929 929
 			    
930
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
930
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
931 931
 				$aprs_last_tx = time();
932 932
 				$data_aprs = "# Keep alive";
933
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
933
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
934 934
 			    }
935 935
 			    
936 936
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
937
-			    $buffer = str_replace('APRS <- ','',$buffer);
938
-			    $buffer = str_replace('APRS -> ','',$buffer);
939
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
937
+			    $buffer = str_replace('APRS <- ', '', $buffer);
938
+			    $buffer = str_replace('APRS -> ', '', $buffer);
939
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
940 940
 				$line = $APRS->parse($buffer);
941 941
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
942 942
 				    $aprs_last_tx = time();
943 943
 				    $data = array();
944 944
 				    //print_r($line);
945 945
 				    $data['hex'] = $line['address'];
946
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
946
+				    $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
947 947
 				    //$data['datetime'] = date('Y-m-d H:i:s');
948 948
 				    $data['ident'] = $line['ident'];
949 949
 				    $data['latitude'] = $line['latitude'];
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 				    $currentdate = date('Y-m-d H:i:s');
964 964
 				    $aprsdate = strtotime($data['datetime']);
965 965
 				    // Accept data if time <= system time + 20s
966
-				    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);
966
+				    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);
967 967
 				    else {
968 968
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
969 969
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 				connect_all($sourceee);
1050 1050
 				$sourceee = array();
1051 1051
 				//connect_all($globalSources);
1052
-				$tt[$format]=0;
1052
+				$tt[$format] = 0;
1053 1053
 				break;
1054 1054
 			    }
1055 1055
 			}
@@ -1057,7 +1057,7 @@  discard block
 block discarded – undo
1057 1057
 		}
1058 1058
 	    } else {
1059 1059
 		$error = socket_strerror(socket_last_error());
1060
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1060
+		if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1061 1061
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1062 1062
 			if (isset($globalDebug)) echo "Restarting...\n";
1063 1063
 			// Restart the script if possible
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 			    if ($globalDebug) echo "Shutdown all sockets...";
1066 1066
 			    
1067 1067
 			    foreach ($sockets as $sock) {
1068
-				@socket_shutdown($sock,2);
1068
+				@socket_shutdown($sock, 2);
1069 1069
 				@socket_close($sock);
1070 1070
 			    }
1071 1071
 			    
Please login to merge, or discard this patch.