1
|
|
|
#!/usr/bin/php |
2
|
|
|
<?php |
3
|
|
|
/** |
4
|
|
|
* This daemon is used to receive ACARS messages from acarsdec |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
// This is not a cron job... Use it like a daemon |
8
|
|
|
require_once(dirname(__FILE__).'/../require/class.ACARS.php'); |
9
|
|
|
|
10
|
|
|
// Check if schema is at latest version |
11
|
|
|
require_once(dirname(__FILE__).'/../require/class.Connection.php'); |
12
|
|
|
$schema = new Connection(); |
13
|
|
|
if ($schema->latest() === false) { |
14
|
|
|
echo "You MUST update to latest schema. Run install/index.php"; |
15
|
|
|
exit(); |
16
|
|
|
} |
17
|
|
|
if ($globalInstalled === FALSE) { |
18
|
|
|
echo "Install script MUST be run before this script. Use you web browser to run install/index.php"; |
19
|
|
|
die(); |
20
|
|
|
} |
21
|
|
|
if (!isset($globalACARSHost) || !isset($globalACARSPort) || $globalACARSHost == '' || $globalACARSPort == '') { |
22
|
|
|
echo 'You MUST define $globalACARSHost and $globalACARSPort in require/settings.php'; |
23
|
|
|
die(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$ACARS=new ACARS(null,true); |
27
|
|
|
date_default_timezone_set('UTC'); |
28
|
|
|
// signal handler - playing nice with sockets and dump1090 |
29
|
|
|
pcntl_signal(SIGINT, function($signo) { |
|
|
|
|
30
|
|
|
global $sock; |
31
|
|
|
echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
32
|
|
|
socket_shutdown($sock, 0); |
33
|
|
|
socket_close($sock); |
34
|
|
|
die("Bye!\n"); |
35
|
|
|
}); |
36
|
|
|
pcntl_signal_dispatch(); |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
// let's try and connect |
40
|
|
|
if ($globalDebug) echo "Listen to acarsdec ... "; |
41
|
|
|
// create our socket and set it to non-blocking |
42
|
|
|
$sock = socket_create(AF_INET, SOCK_DGRAM, 0) or die("Unable to create socket\n"); |
43
|
|
|
|
44
|
|
|
// Bind the source address |
45
|
|
|
if( !socket_bind($sock, $globalACARSHost , $globalACARSPort) ) |
46
|
|
|
{ |
47
|
|
|
$errorcode = socket_last_error(); |
48
|
|
|
$errormsg = socket_strerror($errorcode); |
49
|
|
|
|
50
|
|
|
die("Could not bind socket : [$errorcode] $errormsg \n"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($globalDebug) echo "LISTEN UDP MODE \n\n"; |
54
|
|
|
while(1) { |
55
|
|
|
$r = socket_recvfrom($sock, $buffer, 512, 0, $remote_ip, $remote_port); |
56
|
|
|
|
57
|
|
|
// lets play nice and handle signals such as ctrl-c/kill properly |
58
|
|
|
pcntl_signal_dispatch(); |
59
|
|
|
$dataFound = false; |
60
|
|
|
// (null) 2 23/02/2015 14:46:06 0 -16 X .D-AIPW ! 1L 7 M82A LH077P 010952342854:VP-MIBI+W+0)-V+(),GB1 |
61
|
|
|
if ($globalDebug) echo $buffer."\n"; |
62
|
|
|
$ACARS->add(trim($buffer)); |
63
|
|
|
socket_sendto($sock, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
64
|
|
|
$ACARS->deleteLiveAcarsData(); |
65
|
|
|
} |
66
|
|
|
pcntl_exec($_,$argv); |
67
|
|
|
?> |
68
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.