-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
web-hook.php
79 lines (49 loc) · 2.57 KB
/
web-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
<?php
/*
* Copyright 2014-2024 GPLv3, Open Crypto Tracker by Mike Kilday: [email protected] (leave this copyright / attribution intact in ALL forks / copies!)
*/
// Runtime mode
$runtime_mode = 'webhook';
// Load app config / etc
require("app-lib/php/init.php");
header('Content-type: text/html; charset=' . $ct['dev']['charset_default']);
header('Access-Control-Allow-Headers: *'); // Allow ALL headers
// Allow access from ANY SERVER (AS THIS IS A WEBHOOK ACCESS POINT)
header('Access-Control-Allow-Origin: *');
// Seems useful for javascript-based API connects:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
header('Access-Control-Allow-Credentials: true');
// Webhook security check (hash must match our concatenated [service name + webhook key]'s hash, or we abort runtime)
// Using the hash of the concatenated [service name + webhook key] keeps our webhook key a secret, that only we know (for security)!
$webhook_key = preg_replace("/\/(.*)/", '', $_GET['webhook_params']); // Remove any (forwardslash-seperated) data after the webhook hash
if ( !isset($plug['activated']['webhook']) ) {
$result = array('error' => "No service match for webhook: " . $webhook_key);
echo json_encode($result, JSON_PRETTY_PRINT);
}
foreach ( $plug['activated']['webhook'] as $plugin_key => $plugin_init ) {
$this_plug = $plugin_key;
if ( file_exists($plugin_init) && isset($ct['int_webhooks'][$this_plug]) && trim($ct['int_webhooks'][$this_plug]) != '' && $webhook_key == $ct['gen']->nonce_digest($this_plug, $ct['int_webhooks'][$this_plug] . $webhook_master_key) ) {
$webhook_exists = true; // Flag webhook service as found
$webhook_params = explode("/", $_GET['webhook_params']);
unset($webhook_params[0]); // Remove webhook key
$webhook_params = array_values($webhook_params); // 'reindex' array
// This plugin's plug-init.php file (runs the plugin)
include($plugin_init);
}
// Reset $this_plug at end of loop
unset($this_plug);
}
// If no plugin webhook service was found
if ( !$webhook_exists ) {
$result = array('error' => "No service match for webhook: " . $webhook_key);
echo json_encode($result, JSON_PRETTY_PRINT);
}
// Access stats logging
$ct['cache']->log_access_stats();
// Log errors / debugging, send notifications
$ct['cache']->app_log();
$ct['cache']->send_notifications();
flush(); // Clean memory output buffer for echo
gc_collect_cycles(); // Clean memory cache
// DON'T LEAVE ANY WHITESPACE AFTER THE CLOSING PHP TAG!
?>