-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathcommit.php
More file actions
60 lines (46 loc) · 1.31 KB
/
commit.php
File metadata and controls
60 lines (46 loc) · 1.31 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
<?php
error_reporting(E_ALL);
// $emailaddress = 'androidhub@intel.com';
$emailaddress = 'androidhub@intel.com';
define("DEBUG_MODE", FALSE);
if (!$_SERVER || $_SERVER['REQUEST_METHOD'] != "POST") {
die ("go away\n\n");
}
$json = stream_get_contents(detectRequestBody());
$body = formatData(json_decode($json));
$headers =
'From: ' . $emailaddress . "\r\n" .
'Reply-To: ' . $emailaddress . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$args = '-f' . $emailaddress;
if (!email($emailaddress, "Someone wants to commit to the Android Hub!", $body, $headers, $args)) {
header('HTTP/1.1 400 Internal Server Error');
echo json_encode(array(
'success' => false
));
} else {
header('HTTP/1.1 200 OK');
echo json_encode(array(
'success' => true
));
}
function formatData($data) {
$emailBody = array();;
foreach ($data as $key => $value) {
$emailBody[] = $key . ': ' . $value;
}
return implode("\r\n", $emailBody);
}
function email($to, $subject, $body, $headers, $args) {
if (DEBUG_MODE) {
return TRUE;
}
return mail($to, $subject, $body, $headers, $args);
}
function detectRequestBody() {
$rawInput = fopen('php://input', 'r');
$tempStream = fopen('php://temp', 'r+');
stream_copy_to_stream($rawInput, $tempStream);
rewind($tempStream);
return $tempStream;
}