I've got github webhoooks set up to send a POST to a PHP script on my server when I push to a repo. (https://help.github.com/articles/post-receive-hooks)
MY PHP script logs the connecting IP, as well as the payload received:
$date = strftime('%c');
file_put_contents('log.txt', PHP_EOL.trim($date).PHP_EOL, FILE_APPEND);
try
{
$payload = json_decode($_REQUEST['payload']);
}
catch(Exception $e)
{
exit(0);
}
//LOG THE POST REQUEST
file_put_contents('log.txt', print_r($payload, TRUE), FILE_APPEND);
//EXECUTE A SCRIPT WHEN THE POST REQUEST IS INITIALIZED
if ($payload->ref === 'refs/heads/master')
{
exec('deploy.sh >> log.txt');
}
From the logs, I can see that an IP connects when I push to my repo, but no POST data is recorded. I tested with RequestBin, and confirmed that POST data present. Furthermore, if I manually put a $_GET payload variable in the URL, that is recorded (since I'm checking $_REQUEST and not just $_POST). My suspicion is that my PHP server is configured to deny POST requests from other servers. I'm using 1and1 Shared Hosting, so I don't have dedicated control, but I can SSH in, as well as configure PHP settings locally with an .ini file. Any suggestions would be greatly appreciated!
*I don't care if I do this in PHP, or some other language. If you think this might be easier using a Python or something else, that's cool too.
-Jeremy