2018-08-08 09:42:42 +01:00
|
|
|
<?php
|
|
|
|
|
2018-10-17 11:37:16 +01:00
|
|
|
function _syslog($msg) {
|
|
|
|
$trace = debug_backtrace();
|
|
|
|
$caller = $trace[1];
|
|
|
|
$parent = $caller['function'];
|
|
|
|
if (isset($caller['class']))
|
|
|
|
$parent = $caller['class'] . '::' . $parent;
|
|
|
|
|
|
|
|
return error_log( "{$parent}: {$msg}" );
|
|
|
|
}
|
|
|
|
|
2018-08-08 09:42:42 +01:00
|
|
|
$raw = file_get_contents("php://input");
|
|
|
|
try {
|
2018-11-03 09:48:37 +00:00
|
|
|
$payload = json_decode($raw, TRUE);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
2018-08-08 09:42:42 +01:00
|
|
|
header('HTTP/1.1 422 Unprocessable Entity');
|
2018-10-17 11:37:16 +01:00
|
|
|
_syslog('[webhook] json_decode failed on:' . $raw);
|
2018-08-08 09:42:42 +01:00
|
|
|
die('Unprocessable Entity');
|
|
|
|
}
|
|
|
|
|
2018-11-03 09:48:37 +00:00
|
|
|
if(isset($payload['secret']) && $payload['secret'] == '{{ webmentionio.secret }}' ) {
|
|
|
|
$msg = sprintf('
|
2018-08-15 11:02:59 +01:00
|
|
|
Type: %s
|
|
|
|
Source: %s
|
|
|
|
Target: %s
|
|
|
|
From: %s
|
|
|
|
|
|
|
|
%s
|
|
|
|
',
|
2018-11-03 09:48:37 +00:00
|
|
|
$payload['post']['wm-property'],
|
|
|
|
$payload['source'],
|
|
|
|
$payload['target'],
|
|
|
|
$payload['post']['author']['name'],
|
|
|
|
$payload['post']['content']['text']
|
|
|
|
);
|
|
|
|
|
|
|
|
_syslog('[webhook] accepted from webmention.io');
|
|
|
|
mail("{{ author.email }}", "[webmention] {$payload['source']}", $msg);
|
|
|
|
header('HTTP/1.1 202 Accepted');
|
|
|
|
exit(0);
|
|
|
|
}
|
2018-08-15 11:02:59 +01:00
|
|
|
|
2018-11-03 09:48:37 +00:00
|
|
|
header('HTTP/1.1 400 Bad Request');
|
|
|
|
_syslog('[webhook] bad request:' . $raw);
|
|
|
|
die('Bad Request');
|