$ratelimit ) {
touch ( $ansible_dropfile );
touch ( $ansible_lastrun );
echo "HTTP 200 - Ansible webhook recieved.\n";
}
else {
http_response_code(429);
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/30 ) {
touch ( $www_dropfile );
touch ( $www_lastrun );
http_response_code(200);
echo "HTTP 200 - WWW webhook recieved.\n";
}
else {
http_response_code(429);
echo "HTTP 429 - Rate Limited.\n";
exit(0);
}
}
// Hook for gopher. Not implemented on the backend yet.
elseif ($data["repository"]["full_name"] == 'thunix/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);
}
}
//Wiki webhook
elseif ($data["repository"]["full_name"] == 'thunix/wiki') {
syslog(LOG_INFO, 'Wiki Webhook recieved.');
if ( time () - filemtime ( $wiki_lastrun ) > $ratelimit/30 ) {
touch ( $wiki_dropfile );
touch ( $wiki_lastrun );
http_response_code(200);
echo "HTTP 200 - Wiki 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.\n";
syslog(LOG_INFO, "Tea Pot Webhook recieved.\n");
exit(0);
}
/*$fp = pfsockopen( "tcp://127.0.0.1", 1234, $errno, $errstr );
if (!$fp)
{
echo "ERROR: $errno - $errstr
\n";
}
socket_set_timeout ($fp, 10);
$msg = "Commit '".$data['commits'][0]["message"]."' was pushed to ".$data["repository"]["full_name"].' by '.$data["pusher"]["login"];
$msg = trim(preg_replace('/\s+/', ' ', $msg));
$write = fwrite ($fp, $msg);
fclose($fp);
if (!$write) {
echo "error writing to port.
";
next;
}
*/
?>