This commit is contained in:
Ubergeek 2019-03-22 21:40:15 +00:00
parent 5714c3c5db
commit 71a11440fd
1 changed files with 4 additions and 91 deletions

View File

@ -1,89 +1,4 @@
<?php
/*
$json = '{
"secret": "01234567890",
"ref": "refs/heads/master",
"before": "197b25b76f19c73b2d58873c1b2fdab7d5a27a85",
"after": "197b25b76f19c73b2d58873c1b2fdab7d5a27a85",
"compare_url": "",
"commits": [
{
"id": "197b25b76f19c73b2d58873c1b2fdab7d5a27a85",
"message": "Ok, swap files... le sigh\n",
"url": "https://tildegit.org/thunix/www/commit/197b25b76f19c73b2d58873c1b2fdab7d5a27a85",
"author": {
"name": "Ubergeek",
"email": "ubergeek@yourtilde.com",
"username": ""
},
"committer": {
"name": "Ubergeek",
"email": "ubergeek@yourtilde.com",
"username": ""
},
"verification": null,
"timestamp": "0001-01-01T00:00:00Z"
}
],
"repository": {
"id": 318,
"owner": {
"id": 80,
"login": "thunix",
"full_name": "Thunix Phoenix Project",
"email": "",
"avatar_url": "https://tildegit.org/avatars/9c7f723c8a7fefa9e29995eade157557",
"language": "",
"username": "thunix"
},
"name": "www",
"full_name": "thunix/www",
"description": "This is the code powering the website for thunix",
"empty": false,
"private": false,
"fork": false,
"parent": null,
"mirror": false,
"size": 4997,
"html_url": "https://tildegit.org/thunix/www",
"ssh_url": "git@ttm.sh:thunix/www.git",
"clone_url": "https://tildegit.org/thunix/www.git",
"website": "",
"stars_count": 0,
"forks_count": 3,
"watchers_count": 2,
"open_issues_count": 0,
"default_branch": "master",
"archived": false,
"created_at": "2018-12-24T11:54:44-05:00",
"updated_at": "2019-03-21T20:36:37-04:00",
"permissions": {
"admin": false,
"push": false,
"pull": false
}
},
"pusher": {
"id": 33,
"login": "ubergeek",
"full_name": "",
"email": "ubergeek@yourtilde.com",
"avatar_url": "https://secure.gravatar.com/avatar/113d65c375df5e67b1430596480549a6?d=identicon",
"language": "en-US",
"username": "ubergeek"
},
"sender": {
"id": 33,
"login": "ubergeek",
"full_name": "",
"email": "ubergeek@yourtilde.com",
"avatar_url": "https://secure.gravatar.com/avatar/113d65c375df5e67b1430596480549a6?d=identicon",
"language": "en-US",
"username": "ubergeek"
}
}';
*/
/* gitea deploy webhook for thunix*/
/*
* So, this webhook current accepts hooks for www, ansible, and soon
@ -109,7 +24,6 @@ $gopher_lastrun = '/dev/shm/gopher-hook-last-run';
$gopher_dropfile = '/dev/shm/run-gopher';
$allowedip = '195.201.242.48';
$remoteip = $_SERVER['REMOTE_ADDR'];
//$allowedip = '213.239.234.117';
$ratelimit = 300;
/* get json data */
@ -119,7 +33,6 @@ $data = json_decode($json, true);
/* check our token */
$client_token = $data["secret"];
//if ((string)$client_token !== (string)$access_token)
if ( strcmp($client_token, $access_token) !== 0 )
{
http_response_code(403);
@ -128,7 +41,6 @@ if ( strcmp($client_token, $access_token) !== 0 )
}
/* check our source ip for the hook */
//if ($remoteip != $allowedip)
if ( strcmp($remoteip, $allowedip) !== 0 )
{
http_response_code(403);
@ -143,7 +55,7 @@ if ($data["repository"]["full_name"] == 'thunix/ansible') {
// overlapping. Systemd shouldn't allow it, but we'll check
// anyways
if ( time () - filemtime ( $ansible_lastrun ) > $ratelimit ) {
//touch ( $ansible_dropfile );
touch ( $ansible_dropfile );
touch ( $ansible_lastrun );
echo "HTTP 200 - Ansible webhook recieved.\n";
}
@ -160,7 +72,7 @@ if ($data["repository"]["full_name"] == 'thunix/ansible') {
elseif ($data["repository"]["full_name"] == 'thunix/www') {
syslog(LOG_INFO, 'WWW Webhook recieved.');
if ( time () - filemtime ( $www_lastrun ) > $ratelimit ) {
//touch ( $www_dropfile );
touch ( $www_dropfile );
touch ( $www_lastrun );
http_response_code(200);
echo "HTTP 200 - WWW webhook recieved.\n";
@ -176,7 +88,7 @@ elseif ($data["repository"]["full_name"] == 'thunix/www') {
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_dropfile );
touch ( $gopher_lastrun );
http_response_code(200);
echo "HTTP 200 - Gopher webhook recieved.\n";
@ -193,6 +105,7 @@ elseif ($data["repository"]["full_name"] == 'thunix/thunix_gopher') {
else {
http_response_code(418);
echo "HTTP 418 - I'm a teapot.\n";
syslog(LOG_INFO, "Tea Pot Webhook recieved.\n";
exit(0);
}
?>