Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] WP-CLI integration #117

Open
michacassola opened this issue Nov 24, 2022 · 5 comments
Open

[Feature Request] WP-CLI integration #117

michacassola opened this issue Nov 24, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@michacassola
Copy link

michacassola commented Nov 24, 2022

Hi, I'd like to script the installation of the crowdsec plugin. I know of a workaround that could possibly work, but native integration to hand the API key and host details to the plugin and change the settings would be nice!

https://discord.com/channels/921520481163673640/1042925611427057786

@LtSich
Copy link

LtSich commented Nov 24, 2022

I don't use it, as I block request on the network level, but being able to manage plugins through wp-cli is a must have for a good plugin :)

@julienloizelet
Copy link
Collaborator

Hi @michacassola,
Thanks for your message.

Adding some wp-cli commands seems indeed a great idea.

But I guess I need more details on the type of command you want available.

Considering the API Key, this is already possible to set it in setting (if you know the API Key):

wp option set crowdsec_api_key ${BOUNCER_KEY}

But if you want a command to create the key itself, I think this won't be possible to have something that will work in all possible cases.

The bouncer key cannot be created with a pure PHP script, as we have to use the CrowdSec CLI cscli tool.
For example, the bouncer key can be retrieved as the result of the :

cscli bouncers add $BOUNCER_NAME -o raw

And, as the cscli command is only available on the server with the installed CrowdSec agent, it won't be possible to create it if the agent is not on the same server as the WordPress. There could also be some permission issues between the cscli user and the wp user.

For now, I guess the easiest way to script the installation of the CrowdSec plugin is to retrieve a bouncer key with the cscli command and pass it as a parameter of the wp option set command.

In my opinion, modifying the settings is already possible with the wp option set command, but we could add some command to manage the cache (clear, refresh, ...)

Please let me know if you were thinking about other wp-cli integration.

@julienloizelet julienloizelet added the enhancement New feature or request label Nov 25, 2022
@michacassola
Copy link
Author

Yeah, you are right, if all the options can be passed like that it is sufficient.
Then I would like to request documentation on how to set and change all the options of the plugin that way. :)
Thanks!

@julienloizelet
Copy link
Collaborator

Then I would like to request documentation on how to set and change all the options of the plugin that way. :)

I add this to my TODO list :) . I think I will provide a wp-cli example for each item in this documentation part: https://github.com/crowdsecurity/cs-wordpress-bouncer/blob/main/docs/USER_GUIDE.md#configurations

If you can't wait, you could start by looking in the wp_options table and search all items with option_name beginning by crowdsec.

Thanks

@julienloizelet
Copy link
Collaborator

Hi @michacassola,

as a first step in the integration work of WP-CLI, I added a paragraph about How to update settings with WP-CLI.

Next step would be to add some real WP-CLI command to act on the bouncer (clearing, refreshing cache for example).

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants