This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
hook.php
80 lines (59 loc) · 1.48 KB
/
hook.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
$dir = dirname(__FILE__);
include("$dir/lib/init.php");
#
# build request object
#
$headers = array();
foreach ($_SERVER as $k => $v){
if (substr($k, 0, 5) == 'HTTP_'){
$k = substr($k, 5);
$k = StrToLower($k);
$k = preg_replace_callback('!(^|_)([a-z])!', 'local_replace_header', $k);
$k = str_replace('_', '-', $k);
$headers[$k] = $v;
}
}
function local_replace_header($m){
return $m[1].StrToUpper($m[2]);
}
$req = array(
'headers' => $headers,
'get' => $_GET,
'post' => $_POST,
);
#
# if the body has been posted as something other than 'application/x-www-form-urlencoded'
# or 'multipart/form-data', capture the entire post body as a string
#
if (!count($_POST)){
$body = file_get_contents("php://input");
if (strlen($body)) $req['post_body'] = $body;
}
#
# log to a file (this is temporary)
#
$log = HAMMOCK_ROOT.'/data/hook_'.uniqid().'.log';
$fh = fopen($log, 'w');
fwrite($fh, '<'.'? $req = '.var_export($req, true).';');
fclose($fh);
#
# see if we can find a plugin to handle it
#
load_plugins();
$instance = getPluginInstance($_GET['id']);
if (is_object($instance)){
$ret = $instance->onLiveHook($req);
$out = $instance->getLog();
$uid = uniqid('', true);
$data->set('hooks', $uid, array(
'ts' => time(),
'req' => $req,
'ret' => $ret,
'out' => $out,
));
$list = $data->get('hook_lists', $instance->iid);
$list[] = $uid;
$data->set('hook_lists', $instance->iid, $list);
}
echo "ok\n";