-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebhook.php
More file actions
65 lines (60 loc) · 2.81 KB
/
webhook.php
File metadata and controls
65 lines (60 loc) · 2.81 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
$hookSecret = trim(file_get_contents("/var/www/html/.webhook_secret"));
if($hookSecret !== NULL)
{
if(!isset($_SERVER["HTTP_X_HUB_SIGNATURE"]))
{
exit("HTTP header 'X-Hub-Signature' is missing.");
}
else if(!extension_loaded("hash"))
{
exit("Missing 'hash' extension to check the secret code validity.");
}
list($algo, $hash) = explode("=", $_SERVER["HTTP_X_HUB_SIGNATURE"], 2) + array("", "");
if(!in_array($algo, hash_algos(), TRUE))
{
exit("Hash algorithm '$algo' is not supported.");
}
$rawPost = file_get_contents("php://input");
if($hash !== hash_hmac($algo, $rawPost, $hookSecret))
{
exit("Hook secret does not match.....");
}
};
switch(strtolower($_SERVER["HTTP_X_GITHUB_EVENT"]))
{
case "ping":
echo "pong.....";
break;
case "push":
// Get the current user. Pull the repo, kill node and start it again
$user = $_SERVER["USER"];
if($user == "mathdev"){
system("cd /var/www/html/dev/MathNetClient && /usr/bin/git checkout dev && /usr/bin/git fetch && /usr/bin/git reset --hard origin/dev", $dummy);
system("cd /var/www/html/dev/MathNetServer && /usr/bin/git checkout dev && /usr/bin/git fetch && /usr/bin/git reset --hard origin/dev", $dummy2);
system("killall node", $dummy3);
system("/usr/bin/node /var/www/html/dev/MathNetServer/server.js 8887 > /dev/null 2>&1 &", $dummy4);
echo "Ran DEV commands " . $dummy . "\n" . $dummy2 . "\n" . $dummy3 . "\n" . $dummy4;
}
if($user == "mathtest") {
system("cd /var/www/html/test/MathNetClient && /usr/bin/git checkout test && /usr/bin/git fetch && /usr/bin/git reset --hard origin/test", $dummy);
system("cd /var/www/html/test/MathNetServer && /usr/bin/git checkout test && /usr/bin/git fetch && /usr/bin/git reset --hard origin/test", $dummy2);
system("killall node", $dummy3);
system("/usr/bin/node /var/www/html/test/MathNetServer/server.js 8888 > /dev/null 2>&1 &", $dummy4);
echo "Ran TEST commands " . $dummy . "\n" . $dummy2 . "\n" . $dummy3 . "\n" . $dummy4;
}
if($user == "mathlive") {
system("cd /var/www/html/live/MathNetClient && /usr/bin/git checkout master && /usr/bin/git fetch && /usr/bin/git reset --hard origin/master", $dummy);
system("cd /var/www/html/live/MathNetServer && /usr/bin/git checkout master && /usr/bin/git fetch && /usr/bin/git reset --hard origin/master", $dummy2);
system("killall node", $dummy3);
system("/usr/bin/node /var/www/html/live/MathNetServer/server.js 8889 > /dev/null 2>&1 &", $dummy4);
echo "Ran LIVE commands " . $dummy . "\n" . $dummy2 . "\n" . $dummy3 . "\n" . $dummy4;
}
break;
default:
header("HTTP/1.0 404 Not Found");
echo "Event:$_SERVER[HTTP_X_GITHUB_EVENT] Payload:\n";
print_r($payload); # For debug only. Can be found in GitHub hook log.
exit;
break;
}