Skip to content

Instantly share code, notes, and snippets.

@thefinn93
Created May 17, 2013 04:06
Show Gist options
  • Save thefinn93/5596865 to your computer and use it in GitHub Desktop.
Save thefinn93/5596865 to your computer and use it in GitHub Desktop.
A php script to pull from git whenever it is called (from approved IPs). It's meant to be a github service hook.
<?
$github_ips = array("207.97.227.253/32", "50.57.128.197/32", "108.171.174.178/32", "50.57.231.61/32", "204.232.175.64/27", "192.30.252.0/22");
function cidr_match($ip, $cidr) {
list($subnet, $mask) = explode('/', $cidr);
if ((ip2long($ip) & ~((1 << (32 - $mask)) - 1) ) == ip2long($subnet))
{
return true;
}
return false;
}
$valid = false;
foreach($github_ips as $netblock) {
if(cidr_match($_SERVER['REMOTE_ADDR'], $netblock)) {
$valid = true;
}
}
if(!$valid) {
die("Fuck off.");
}
error_log(exec("git pull"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment