-
-
Save garywu/56c60821eb5a52b63753 to your computer and use it in GitHub Desktop.
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
<?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", $output); | |
echo $output; | |
} | |
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