-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpush.php
More file actions
30 lines (22 loc) · 883 Bytes
/
push.php
File metadata and controls
30 lines (22 loc) · 883 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
<?php
include_once "config.php";
$headers = getallheaders();
$hubSignature = $headers['X-Hub-Signature'];
list($algo, $hash) = explode('=', $hubSignature, 2);
$payload = $HTTP_RAW_POST_DATA;
$data = json_decode($payload);
$payloadHash = hash_hmac($algo, $payload, $secret);
// record the event anyway
$db->query("INSERT INTO " . $tables['events'] . " (event, payload) VALUES ('" . $headers['X-GitHub-Event'] . "', '" . $db->escape($payload) ."')");
// if it's not sent from github, kill it.
if ($hash !== $payloadHash) {
die('Unauthorized');
}
for($i = 0; $i < count($data->commits); $i++) {
$sha = $data->commits[$i]->id;
$repo = $data->repository->name;
$github_username = $data->sender->login;
$db->query("INSERT INTO " . $tables['pushes'] . " (repository, github_user, commit) VALUES ('" . $repo . "', '" . $github_username . "', '" . $sha ."')");
}
?>
success