1 | <?php |
||||||
2 | |||||||
3 | namespace dokuwiki\plugin\swarmzapierstructwebhook; |
||||||
4 | |||||||
5 | class Webhook |
||||||
6 | { |
||||||
7 | public function run() |
||||||
8 | { |
||||||
9 | global $conf, $INPUT; |
||||||
10 | |||||||
11 | if ($conf['debug']) { |
||||||
12 | dbglog($_SERVER); |
||||||
1 ignored issue
–
show
Bug
introduced
by
![]() |
|||||||
13 | } |
||||||
14 | |||||||
15 | /** @var \helper_plugin_swarmzapierstructwebhook $helper */ |
||||||
16 | $helper = plugin_load('helper', 'swarmzapierstructwebhook'); |
||||||
1 ignored issue
–
show
The function
plugin_load was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
17 | $storedSecret = $helper->getConf('hook secret'); |
||||||
18 | if (!empty($storedSecret)) { |
||||||
19 | $requestSecret = $INPUT->server->str('X_HOOK_SECRET'); |
||||||
20 | if (empty($requestSecret)) { |
||||||
21 | http_status(401, 'Header X_HOOK_SECRET missing!'); |
||||||
1 ignored issue
–
show
The function
http_status was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
22 | return; |
||||||
23 | } |
||||||
24 | |||||||
25 | if ($requestSecret !== $storedSecret) { |
||||||
26 | http_status(403, 'Header X_HOOK_SECRET not identical with configured secret!'); |
||||||
27 | return; |
||||||
28 | } |
||||||
29 | } |
||||||
30 | |||||||
31 | $body = file_get_contents('php://input'); |
||||||
32 | |||||||
33 | $this->handleWebhookPayload($body); |
||||||
34 | |||||||
35 | http_status(202); |
||||||
36 | } |
||||||
37 | |||||||
38 | /** |
||||||
39 | * Stores the webhook's payload to the struct table |
||||||
40 | * |
||||||
41 | * @param string $json the original webhooks payload as json |
||||||
42 | */ |
||||||
43 | protected function handleWebhookPayload($json) { |
||||||
44 | /** @var \helper_plugin_struct $struct */ |
||||||
45 | $struct = plugin_load('helper', 'struct'); |
||||||
1 ignored issue
–
show
The function
plugin_load was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
46 | if (!$struct) { |
||||||
0 ignored issues
–
show
|
|||||||
47 | http_status(422, 'struct plugin not active at this server'); |
||||||
1 ignored issue
–
show
The function
http_status was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
48 | exit(); |
||||||
0 ignored issues
–
show
|
|||||||
49 | } |
||||||
50 | |||||||
51 | /** @var \helper_plugin_swarmzapierstructwebhook $helper */ |
||||||
52 | $helper = plugin_load('helper', 'swarmzapierstructwebhook'); |
||||||
53 | |||||||
54 | $data = json_decode($json, true); |
||||||
55 | $timestamp = $data['createdAt']; |
||||||
56 | $checkinID = $data['id']; |
||||||
57 | $date = date('Y-m-d', $timestamp); // FIXME: use timezone offset? |
||||||
58 | $locationName = $data['venue']['name']; |
||||||
59 | |||||||
60 | $lookupData = [ |
||||||
61 | 'date' => $date, |
||||||
62 | 'time' => date_iso8601($timestamp), |
||||||
1 ignored issue
–
show
The function
date_iso8601 was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
63 | 'checkinid' => $checkinID, |
||||||
64 | 'locname' => $locationName, |
||||||
65 | 'json' => $json, |
||||||
66 | ]; |
||||||
67 | if (!empty($data['shout'])) { |
||||||
68 | $lookupData['shout'] = $data['shout']; |
||||||
69 | } |
||||||
70 | |||||||
71 | try { |
||||||
72 | $helper->deleteCheckinFromLookup($checkinID); |
||||||
73 | $helper->saveDataToLookup($lookupData); |
||||||
74 | } catch (\Exception $e) { |
||||||
75 | $errorMessage = $e->getMessage(); |
||||||
76 | dbglog($errorMessage); |
||||||
1 ignored issue
–
show
The function
dbglog was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
77 | http_status(500, $errorMessage); |
||||||
78 | exit(); |
||||||
0 ignored issues
–
show
|
|||||||
79 | } |
||||||
80 | } |
||||||
81 | } |
||||||
82 |