forked from moztw/www.moztw.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-received.php
More file actions
41 lines (36 loc) · 1.27 KB
/
Copy pathgit-received.php
File metadata and controls
41 lines (36 loc) · 1.27 KB
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
40
41
<?php
$isInStage = (strpos($_SERVER["SCRIPT_FILENAME"], 'www-stage') != false);
// Github We’ll hit these URLs with POST requests when you push to us,
// passing along information about the push. More information can be found in the Post-Receive Guide.
//
// The Public IP addresses for these hooks are: 204.232.175.64/27, 192.30.252.0/22.
// FIXME: counting CIDR is too complicated. DO NOT UNMARK FOLLOWING TWO LINES UNLESS YOU WROTE CODE FOR COUNTING IP RANGE.
//$whitelist = array('204.232.175.64/27', '192.30.252.0/22');
//$isGithub = (in_array($_SERVER['REMOTE_ADDR'], $whitelist) === true);
$isGithub = isset($_POST["payload"]) && (strpos($_SERVER["HTTP_USER_AGENT"], 'GitHub') !== false);
if($isGithub){
$payload = json_decode($_POST["payload"]);
$cmd = '/home/moztw/repo/base/autoupdate/update.sh';
$opt = '';
if($payload->ref==="refs/heads/production"){
//production
$opt .= ' www';
}elseif($payload->ref==="refs/heads/master"){
//stage
$opt .= ' stage';
}else{
die("!!!Wrong payload.");
}
$opt .= ' md5';
$opt .= ' cache';
$cmd .= $opt;
$cmd .= ' 2>&1';
error_log(print_r($cmd,TRUE));
ob_flush();
flush();
$handle = popen("" . $cmd, "r");
pclose($handle);
} else {
die("!!!Invalid arguments given or not from Github.");
}
?>