Updating the githook, and adding teapot easter egg.
This commit is contained in:
parent
b79a0c921d
commit
341f879c71
58
githook.php
58
githook.php
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
/* gitea deploy webhook */
|
/* gitea deploy webhook */
|
||||||
|
|
||||||
/* security */
|
/* security and environment*/
|
||||||
$access_token = '1234567890';
|
$access_token = '1234567890';
|
||||||
$lastrun = '/dev/shm/ansible-hook-last-run';
|
$ansible_lastrun = '/dev/shm/ansible-hook-last-run';
|
||||||
$dropfile = '/dev/shm/run-ansible';
|
$ansible_dropfile = '/dev/shm/run-ansible';
|
||||||
|
$www_lastrun = '/dev/shm/www-hook-last-run';
|
||||||
|
$www_dropfile = '/dev/shm/run-www';
|
||||||
|
$remoteip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
$allowedip = '195.201.242.48';
|
||||||
|
$ratelimit = 300;
|
||||||
|
|
||||||
/* get json data */
|
/* get json data */
|
||||||
$json = file_get_contents('php://input');
|
$json = file_get_contents('php://input');
|
||||||
|
@ -15,23 +20,50 @@ $client_token = $data["secret"];
|
||||||
if ($client_token !== $access_token)
|
if ($client_token !== $access_token)
|
||||||
{
|
{
|
||||||
http_response_code(403);
|
http_response_code(403);
|
||||||
|
echo "HTTP 403 - Forbidden.";
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog(LOG_INFO, 'Ansible Webhook recieved.');
|
if ($remoteip !== $allowedip)
|
||||||
|
{
|
||||||
|
http_repsonse_code(403);
|
||||||
|
echo "HTTP 403 - Forbidden.";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
//* if you need get full json input */
|
//* if you need get full json input */
|
||||||
//fwrite($fs, 'DATA: '.print_r($data, true).PHP_EOL);
|
//fwrite($fs, 'DATA: '.print_r($data, true).PHP_EOL);
|
||||||
|
|
||||||
|
if ($data["repository"]["full_name"] == 'thunix/ansible') {
|
||||||
if ( time () - filemtime ( $lastrun ) > 300 ) {
|
syslog(LOG_INFO, 'Ansible Webhook recieved.');
|
||||||
touch ( $dropfile );
|
if ( time () - filemtime ( $ansible_lastrun ) > $ratelimit ) {
|
||||||
touch ( $lastrun );
|
touch ( $ansible_dropfile );
|
||||||
echo "HTTP 200 - Ansible webhook recieved.";
|
touch ( $ansible_lastrun );
|
||||||
}
|
echo "HTTP 200 - Ansible webhook recieved.";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
http_response_code(429);
|
http_response_code(429);
|
||||||
echo "HTTP 429 - Rate Limited.";
|
echo "HTTP 429 - Rate Limited.";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($data["repository"]["full_name"] == 'thunix/www') {
|
||||||
|
syslog(LOG_INFO, 'WWW Webhook recieved.');
|
||||||
|
if ( time () - filemtime ( $www_lastrun ) > $ratelimit ) {
|
||||||
|
touch ( $www_dropfile );
|
||||||
|
touch ( $www_lastrun );
|
||||||
|
http_response_code(200);
|
||||||
|
echo "HTTP 200 - WWW webhook recieved.";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
http_response_code(429);
|
||||||
|
echo "HTTP 429 - Rate Limited.";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
http_response_code(418);
|
||||||
|
echo "HTTP 418 - I'm a teapot.";
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
http_response_code(418);
|
||||||
|
echo "HTTP 418 - I'm a teapot.";
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue