Skip to content

Instantly share code, notes, and snippets.

@slavcodev
Forked from samdark/github-post-receive.php
Created May 19, 2014 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slavcodev/3dbd7f8ea4644f0c57f7 to your computer and use it in GitHub Desktop.
Save slavcodev/3dbd7f8ea4644f0c57f7 to your computer and use it in GitHub Desktop.
<?php
function cidr_match($ip, $ranges)
{
$ranges = (array)$ranges;
foreach($ranges as $range) {
list($subnet, $mask) = explode('/', $range);
if((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) {
return true;
}
}
return false;
}
$github_ips = array('207.97.227.253', '50.57.128.197', '108.171.174.178', '50.57.231.61');
$github_cidrs = array('204.232.175.64/27', '192.30.252.0/22');
if(in_array($_SERVER['REMOTE_ADDR'], $github_ips) || cidr_match($_SERVER['REMOTE_ADDR'], $github_cidrs)) {
$dir = '/var/www/path/to/your/git/root';
exec("cd $dir && git pull");
echo 'Done.';
}
else {
header('HTTP/1.1 404 Not Found');
echo '404 Not Found.';
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment