forked from tinyspeck/hammock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.php
68 lines (51 loc) · 1.2 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
<?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,
);
#
# 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";