Whitelist Programmatically

I have WP Cerber on Wordpress and use WP Engine to host. I’d like to add a few CIDR Ranges to my site and remove them daily at specific times. This is for a migration feature and we just want the IPs whitelisted for a brief period of time and there’s too many to have this be a manual process. Is there a way programmatically to achieve this through scripting?

To whitelist an IP address, range, or network, use the cerber_acl_add function as shown below.

cerber_acl_add( $ip, 'W', $comment );

/**
 * Parameters:
 * - $ip (required): The IP address, range, or network you want to whitelist. Allowed formats are listed on the "Access List" page.
 * - $comment (optional): A text note visible to the website administrator.
 */

Example Usage:

cerber_acl_add( '192.168.1.1', 'W', 'My home IP' );
cerber_acl_add( '192.168.0.0/16', 'W', 'Office network' );

I was just testing this out through wp-cli. I ssh into the site and went to the root directory and executed wp eval “cerber_acl_add(‘ip’,‘W’,'Comment)” I ended up getting a " Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website." the plugin is confirmed activated. Any reason for this error to occur? Also is there a cerber_acl_remove or delete function too?

When using wp-cli you need to execute cerber_load_admin_code() before:

cerber_load_admin_code();
cerber_acl_add( '192.168.1.1', 'W', 'My home IP' );

To remove IP address, use cerber_acl_remove( $ip );

I ran the cerber_load_admin_code(); successfully but still get the critical error on this site message when running cerber_acl_add or cerber_acl_remove

To identify the root cause, the best approach is to check the server error log. This will provide actionable information and minimize unnecessary guesswork.

got it I’ve managed to get that working fine thanks for the help, is there any way to add/remove a bulk of IPs without looping through them and repeatedly calling this command?

There’s no programmatic way to remove IPs from the access lists in bulk. However, if you’re comfortable working with your database directly and familiar with SQL, you can run a query to delete entries from the cerber_acl table. To remove all whitelisted entries run this query:

DELETE FROM cerber_acl WHERE tag = "W"