From 1920355074726796ba1bfd8e477a47257f43f9a2 Mon Sep 17 00:00:00 2001 From: Ubergeek Date: Fri, 22 Mar 2019 16:52:54 +0000 Subject: [PATCH] Ok, pretty sure I got it now --- githook.php | 82 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/githook.php b/githook.php index 7c9bf4c..7f2a717 100644 --- a/githook.php +++ b/githook.php @@ -1,14 +1,28 @@ $ratelimit ) { touch ( $ansible_dropfile ); touch ( $ansible_lastrun ); - echo "HTTP 200 - Ansible webhook recieved."; + echo "HTTP 200 - Ansible webhook recieved.\n"; } else { http_response_code(429); - echo "HTTP 429 - Rate Limited."; + echo "HTTP 429 - Rate Limited.\n"; exit(0); } } + +// Hook for www repo here. Same rules apply, as above, for www. We +// could probably make it able to run more frequently. Backend job is +// just a git pull, and is quick. 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."; + echo "HTTP 200 - WWW webhook recieved.\n"; } else { http_response_code(429); - echo "HTTP 429 - Rate Limited."; + echo "HTTP 429 - Rate Limited.\n"; exit(0); } - } +} + +// Hook for gopher. Not implemented on the backend yet. +elseif ($data["repository"]["full_name"] == 'thunix/gopher') { + syslog(LOG_INFO, 'Gopher Webhook recieved.'); + if ( time () - filemtime ( $gopher_lastrun ) > $ratelimit ) { + touch ( $gopher_dropfile ); + touch ( $gopher_lastrun ); + http_response_code(200); + echo "HTTP 200 - Gopher webhook recieved.\n"; + } + else { + http_response_code(429); + echo "HTTP 429 - Rate Limited.\n"; + exit(0); + } +} + +// Easter egg for anyone probing the hook. Enjoy. We're a coffee maker +// and not a teapot :) else { http_response_code(418); - echo "HTTP 418 - I'm a teapot."; + echo "HTTP 418 - I'm a teapot.\n"; exit(0); } ?>