adding logging to webhook php

This commit is contained in:
Peter Molnar 2018-10-17 11:37:16 +01:00
parent 2dcf04d632
commit d82be675c7

View file

@ -1,15 +1,27 @@
<?php
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}" );
}
$raw = file_get_contents("php://input");
try {
$payload = json_decode($raw, TRUE);
} catch (Exception $e) {
header('HTTP/1.1 422 Unprocessable Entity');
_syslog('[webhook] json_decode failed on:' . $raw);
die('Unprocessable Entity');
}
if(! isset($payload['secret']) || $payload['secret'] != '{{ callback_secret }}' ) {
header('HTTP/1.1 400 Bad Request');
_syslog('[webhook] bad request:' . $raw);
die('Bad Request');
}