-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
62 lines (52 loc) · 1.48 KB
/
index.php
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
<?php
// As we can't return any content to Xero, this PHP script outputs the request to a text file this helps us debug any issues
// Based on the script found here:
// https://gist.github.com/magnetikonline/650e30e485c0f91f2f40
//everything we want to see gets written to $data
//headers
$data = sprintf(
"%s %s %s\n\nHTTP headers:\n",
$_SERVER['REQUEST_METHOD'],
$_SERVER['REQUEST_URI'],
$_SERVER['SERVER_PROTOCOL']
);
foreach (getHeaderList() as $name => $value) {
$data .= $name . ': ' . $value . "\n";
}
//get the payload
$payload = file_get_contents('php://input');
$data .= "\nRequest body:\n";
$data .= $payload . "\n";
//calculate our signature
$hookkey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //INSERT WEBHOOK KEY HERE
$data .= "\nOur Signature:\n";
$calculatedhash = base64_encode(hash_hmac('sha256',$payload,$hookkey,true));
$data .= $calculatedhash;
//display what Xero has sent
$data .= "\nXero Sig:\n";
$xerohash = $_SERVER['HTTP_X_XERO_SIGNATURE'];
$data .= $xerohash;
//see if they match
$data .= "\nMatch?:\n";
if (hash_equals($calculatedhash,$xerohash)) {
$data .= "Yes";
http_response_code(200);
} else {
$data .= "No";
http_response_code(401);
}
//format filename
$fn = microtime();
$fn = substr($fn,11) . substr($fn,2,8);
//output to file
file_put_contents('./'.$fn.'.txt',$data);
function getHeaderList() {
$headerList = [];
foreach ($_SERVER as $name => $value) {
if (preg_match('/^HTTP_/',$name)) {
$headerList[$name] = $value;
}
}
return $headerList;
}
?>