|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace dokuwiki\plugin\swarmzapierstructwebhook; |
|
4
|
|
|
|
|
5
|
|
|
use dokuwiki\plugin\struct\meta\Schema; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class Webhook |
|
8
|
|
|
{ |
|
9
|
|
|
public function run() |
|
10
|
|
|
{ |
|
11
|
|
|
global $conf, $INPUT; |
|
12
|
|
|
|
|
13
|
|
|
if ($conf['debug']) { |
|
14
|
|
|
dbglog($_SERVER); |
|
|
|
|
|
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** @var \helper_plugin_swarmzapierstructwebhook $helper */ |
|
18
|
|
|
$helper = plugin_load('helper', 'swarmzapierstructwebhook'); |
|
|
|
|
|
|
19
|
|
|
$storedSecret = $helper->getConf('hook secret'); |
|
20
|
|
|
if (!empty($storedSecret)) { |
|
21
|
|
|
$requestSecret = $INPUT->server->str('X_HOOK_SECRET'); |
|
22
|
|
|
if (empty($requestSecret)) { |
|
23
|
|
|
http_status(401, 'Header X_HOOK_SECRET missing!'); |
|
|
|
|
|
|
24
|
|
|
return; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
if ($requestSecret !== $storedSecret) { |
|
28
|
|
|
http_status(403, 'Header X_HOOK_SECRET not identical with configured secret!'); |
|
29
|
|
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$body = file_get_contents('php://input'); |
|
34
|
|
|
|
|
35
|
|
|
$ok = $this->handleWebhookPayload($body); |
|
36
|
|
|
|
|
37
|
|
|
if ($ok) { |
|
38
|
|
|
http_status(202); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Stores the webhook's payload to the struct table |
|
44
|
|
|
* |
|
45
|
|
|
* FIXME: don't set http status here |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $json the original webhooks payload as json |
|
48
|
|
|
* |
|
49
|
|
|
* @return bool false if there was an error, http status has already been set, true if everything was ok |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function handleWebhookPayload($json) |
|
52
|
|
|
{ |
|
53
|
|
|
/** @var \helper_plugin_struct $struct */ |
|
54
|
|
|
$struct = plugin_load('helper', 'struct'); |
|
|
|
|
|
|
55
|
|
|
if (!$struct) { |
|
|
|
|
|
|
56
|
|
|
http_status(422, 'struct plugin not active at this server'); |
|
|
|
|
|
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** @var \helper_plugin_swarmzapierstructwebhook $helper */ |
|
61
|
|
|
$helper = plugin_load('helper', 'swarmzapierstructwebhook'); |
|
62
|
|
|
|
|
63
|
|
|
$lookupData = $helper->extractDataFromPayload(json_decode($json, true)); |
|
64
|
|
|
$lookupData['json'] = $json; |
|
65
|
|
|
|
|
66
|
|
|
try { |
|
67
|
|
|
$schemas = Schema::getAll('lookup'); |
|
68
|
|
|
if (!in_array('swarm', $schemas)) { |
|
69
|
|
|
$helper->createNewSwarmSchema(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$helper->deleteCheckinFromLookup($lookupData['checkinid']); |
|
73
|
|
|
$helper->saveDataToLookup($lookupData); |
|
74
|
|
|
} catch (\Exception $e) { // FIXME: catch more specific exceptions! |
|
75
|
|
|
$errorMessage = $e->getMessage(); |
|
76
|
|
|
dbglog($errorMessage); |
|
|
|
|
|
|
77
|
|
|
http_status(500, $errorMessage); |
|
78
|
|
|
return false; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return true; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths