chesio / bc-security

Helps keeping WordPress websites secure.
The Unlicense
14 stars 3 forks source link

Webhooks? #118

Closed michelep closed 2 years ago

michelep commented 2 years ago

Could be great to have webhooks on events (like bans...) to be able to use also external tools.

chesio commented 2 years ago

Hi @michelep,

thank you for your suggestion and sorry for a late reply.

I would like to avoid adding such functionality directly, I don't want to dictate any specific format of webhook URLs. Moreover, webhooks can be quite easily implemented using action hooks. An example for lockout event:

add_action(\BlueChip\Security\Modules\Login\Hooks::LOCKOUT_EVENT, function (string $remote_address, string $username, int $duration, int $reason) {

    $url = \add_query_arg([
            'ip-address' => $remote_address,
            'duration' => $duration,
            ...,
        ],
        'https://www.example.com/url-of-the-webhook/'
    );

    // We are not interested in response from the server, so make a non-blocking request.
    \wp_remote_get($url, ['blocking' => false]);

}, 10, 4);

Would something like this work for you? If there is no action triggered for an event you would like to be notified about, I can add it.

michelep commented 2 years ago

Thanks chesio for you prompt reply! It's exacly what i'm looking for, because i want to implement a Telegram notification system for blocked IPs and so on... maybe, just in case, did you plain to work for integration with crowdsec?

chesio commented 2 years ago

maybe, just in case, did you plain to work for integration with crowdsec?

No, I have to admit I haven't heard about this project until now. I'll check it out, it might be a good addition to the plugin.

I'm closing this issue, but if you have any further questions or requests, feel free to reopen it.