forked from thunix/www
Adding githook
This commit is contained in:
parent
0b2fbbd6a0
commit
52de48e5f3
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/* gitea deploy webhook */
|
||||||
|
|
||||||
|
/* security */
|
||||||
|
$access_token = '1234567890';
|
||||||
|
$lastrun = '/tmp/ansible-hook-last-run';
|
||||||
|
|
||||||
|
/* get json data */
|
||||||
|
$json = file_get_contents('php://input');
|
||||||
|
$data = json_decode($json, true);
|
||||||
|
|
||||||
|
$client_token = $data["secret"];
|
||||||
|
if ($client_token !== $access_token)
|
||||||
|
{
|
||||||
|
http_response_code(403);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
syslog(LOG_INFO, 'Ansible Webhook recieved.');
|
||||||
|
|
||||||
|
//* if you need get full json input */
|
||||||
|
//fwrite($fs, 'DATA: '.print_r($data, true).PHP_EOL);
|
||||||
|
|
||||||
|
|
||||||
|
if (time()-filemtime($lastrun) > 300) {
|
||||||
|
exec("/etc/cron.hourly/ansible-pull");
|
||||||
|
touch ($lastrun);
|
||||||
|
echo "Ansible webhook recieved.";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
http_response_code(429);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
Loading…
Reference in New Issue