Created
May 17, 2013 04:06
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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