-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_hook.php
More file actions
39 lines (29 loc) · 805 Bytes
/
github_hook.php
File metadata and controls
39 lines (29 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// GitHub hook will POST to this endpoint in order to trigger auto pull
function cidr_match($ip, $cidr)
{
list($subnet, $mask) = explode('/', $cidr);
if ((ip2long($ip) & ~((1 << (32 - $mask)) - 1) ) == ip2long($subnet))
{
return true;
}
return false;
}
function exec_background($cmd) {
// http://php.net/manual/en/function.exec.php#86329
// This will run shell command in background
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
// Make sure request comes from GitHub hook
if(cidr_match($_SERVER['REMOTE_ADDR'], '192.30.252.0/22')){
exec_background('github_hook.bat');
}else{
header('HTTP/1.1 401 Unauthorized');
echo 'Access Denined';
}
?>