|
1
|
|
|
<?php |
|
2
|
|
|
require '/var/www/common/libs/aws/aws-autoloader.php'; |
|
3
|
|
|
use Aws\Sns\MessageValidator\Message; |
|
4
|
|
|
use Aws\Sns\MessageValidator\MessageValidator; |
|
5
|
|
|
use Aws\S3\S3Client; |
|
6
|
|
|
use Guzzle\Http\Client; |
|
7
|
|
|
|
|
8
|
|
|
function aws() |
|
9
|
|
|
{ |
|
10
|
|
|
global $app; |
|
11
|
|
|
$app->post('/snsEndpoint', 'snsEndpoint'); |
|
12
|
|
|
$app->post('/test', 'testX'); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
function sendToBackend($function, $payload) |
|
16
|
|
|
{ |
|
17
|
|
|
$context = new ZMQContext(); |
|
18
|
|
|
$queue = new ZMQSocket($context, ZMQ::SOCKET_REQ); |
|
19
|
|
|
|
|
20
|
|
|
$queue->connect('tcp://127.0.0.1:55555'); |
|
21
|
|
|
$message = base64_encode(serialize($payload)); |
|
22
|
|
|
$queue->send($function.':', ZMQ::MODE_SNDMORE); |
|
23
|
|
|
$queue->send($message); |
|
24
|
|
|
return $queue->recv(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function testX() |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
global $app; |
|
30
|
|
|
$array = $app->getJSONBody(true); |
|
31
|
|
|
|
|
32
|
|
|
echo sendToBackend('testX', $array); |
|
33
|
|
|
die(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function snsEndpoint() |
|
37
|
|
|
{ |
|
38
|
|
|
global $app; |
|
39
|
|
|
$array = $app->getJSONBody(true); |
|
40
|
|
|
|
|
41
|
|
|
try |
|
42
|
|
|
{ |
|
43
|
|
|
$message = Message::fromArray($array); |
|
44
|
|
|
|
|
45
|
|
|
// Validate the message |
|
46
|
|
|
$validator = new MessageValidator(); |
|
47
|
|
|
$validator->validate($message); |
|
48
|
|
|
} |
|
49
|
|
|
catch(\Exception $e) |
|
50
|
|
|
{ |
|
51
|
|
|
$app->notFound(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$type = $message->get('Type'); |
|
55
|
|
|
switch($type) |
|
56
|
|
|
{ |
|
57
|
|
|
case 'SubscriptionConfirmation': |
|
58
|
|
|
(new Client)->get($message->get('SubscribeURL'))->send(); |
|
59
|
|
|
break; |
|
60
|
|
|
case 'Notification': |
|
61
|
|
|
$arn = $message->get('TopicArn'); |
|
62
|
|
|
if($arn !== false) |
|
63
|
|
|
{ |
|
64
|
|
|
$pos = strpos($arn, 'Listserv'); |
|
65
|
|
|
if($pos !== false) |
|
66
|
|
|
{ |
|
67
|
|
|
sendToBackend('processListServMessage', $message->get('Message')); |
|
68
|
|
|
echo 'true'; |
|
69
|
|
|
return; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
default: |
|
73
|
|
|
file_put_contents('/var/www/profiles/tmp/log.log', print_r($message, true), FILE_APPEND); |
|
74
|
|
|
break; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
function endswith($string, $test) |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
$strlen = strlen($string); |
|
81
|
|
|
$testlen = strlen($test); |
|
82
|
|
|
if($testlen > $strlen) |
|
83
|
|
|
{ |
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
function getDestinationsForID($id) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
if(strcasecmp($id, 'pboyd') === 0) |
|
92
|
|
|
{ |
|
93
|
|
|
return array('[email protected]'); |
|
94
|
|
|
} |
|
95
|
|
|
else |
|
96
|
|
|
{ |
|
97
|
|
|
return false; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
View Code Duplication |
function getActualDestinations($originals) |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
$ret = array(); |
|
104
|
|
|
$count = count($originals); |
|
105
|
|
|
for($i = 0; $i < $count; $i++) |
|
106
|
|
|
{ |
|
107
|
|
|
$dest = $originals[$i]; |
|
108
|
|
|
if(endswith($dest, 'burningflipside.com')) |
|
109
|
|
|
{ |
|
110
|
|
|
$parts = explode('@', $dest); |
|
111
|
|
|
if(count($parts) === 2) |
|
112
|
|
|
{ |
|
113
|
|
|
$dests = getDestinationsForID($parts[0]); |
|
114
|
|
|
if($dests === false) |
|
115
|
|
|
{ |
|
116
|
|
|
file_put_contents('/var/www/profiles/tmp/log.log', "getActualDestinations: Invalid destination id $parts[0]\n", FILE_APPEND); |
|
117
|
|
|
} |
|
118
|
|
|
else |
|
119
|
|
|
{ |
|
120
|
|
|
$ret = array_merge($ret, $dests); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
else |
|
124
|
|
|
{ |
|
125
|
|
|
file_put_contents('/var/www/profiles/tmp/log.log', "getActualDestinations: Invalid destination format $dest\n", FILE_APPEND); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
return $ret; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
function getRawMessage($action) |
|
|
|
|
|
|
133
|
|
|
{ |
|
134
|
|
|
$s3Client = S3Client::factory(); |
|
135
|
|
|
$object = $s3Client->getObject(array('Bucket'=>$action['bucketName'], 'Key'=>$action['objectKey'])); |
|
136
|
|
|
file_put_contents('/var/www/profiles/tmp/log.log', print_r($object, true), FILE_APPEND); |
|
137
|
|
|
return $object; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
function processListServMessage($message) |
|
|
|
|
|
|
141
|
|
|
{ |
|
142
|
|
|
$message = json_decode($message); |
|
143
|
|
|
$dests = getActualDestinations($message->mail->destination); |
|
144
|
|
|
file_put_contents('/var/www/profiles/tmp/log.log', print_r($dests, true), FILE_APPEND); |
|
145
|
|
|
$rawMessage = getRawMessage($message['action']); |
|
|
|
|
|
|
146
|
|
|
//file_put_contents('/var/www/profiles/tmp/log.log', print_r($message, true), FILE_APPEND); |
|
|
|
|
|
|
147
|
|
|
file_put_contents('/var/www/profiles/tmp/log.log', "processListServMessage: Exited\n", FILE_APPEND); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
?> |
|
|
|
|
|
|
151
|
|
|
|
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignoreannotation.See also the PhpDoc documentation for @ignore.