• Hey guys,

    Thanks for the amazing plugin! However I have a small problem with it.

    I have a cron script which runs wp-cli to check if there are any updates to plugins and notify me. Because I run it from cli REMOTE_ADDR is not populated, and so the remote_ip is effectively null.

    Can you add a check if the script is run from cli then fail gracefully without throwing fatal errors all over the place.

    https://www.ads-software.com/plugins/wp-cerber/

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author gioni

    (@gioni)

    Hi tjomk!

    Interesting issue! I’ll fix it. I think it would be reasonable to use SERVER_ADDR instead of REMOTE_ADDR.

    Thread Starter tjomk

    (@tjomk)

    Amazing! Thanks Gioni for such a quick reply!

    Ohh, I came across this same. Will write here to keep track of news
    Right now I added the line:
    if (!isset($wp_cerber)) return true;

    Error in my logs:
    Call to a member function getRemoteIp() on a non-object in /var/www/htdocs_newsmine.ru/wp-content/plugins/wp-cerber/wp-cerber.php on line 596

    Is the same issue? Yes, i run from linux cron with:
    define(‘WP_USE_THEMES’, false);
    require_once( dirname( __FILE__ ) . ‘/../wp-load.php’ );

    Plugin Author gioni

    (@gioni)

    Hi guys!

    I added couple of lines and updated files. Reinstall plugin from scratch and let me know how it goes.

    Still same issue. Have compared code to the latest version, so it’s running 2.7.1

    With the plugin disabled, a remote cron.php will execute (with CiviCRM). Enabled, it fails.

    With PHP command line, still getting:
    Fatal error: Call to a member function getRemoteIp() on null in /home/mltawa/public_html/wp-content/plugins/wp-cerber/wp-cerber.php on line 600

    Can a detection be added for PHP via command line?

    Plugin Author gioni

    (@gioni)

    I’ve updated and uploaded new release. Please, reinstall the plugin and let me know how it goes.

    Thanks. Should it be 2.7.2?

    Plugin Author gioni

    (@gioni)

    Do you mean last release with last changes? No, it is still 2.7.1. But files are updated. You need to download fresh release and reinstall the plugin.

    Thread Starter tjomk

    (@tjomk)

    Thanks Gioni for such a quick update but unfortunately it didn’t fix it. Seems like when you use wp-cli it goes through a different path. The error is raised in cerber_access_control() function because $wp_cerber has null value.

    My guess is that wp-cli loads files differently than WordPress itself and so the line where you initialise the class is not executed.

    A dirty fix would be to check if $wp_cerber is null, and if it is just init it.

    Plugin Author gioni

    (@gioni)

    That’s weird.
    Could you provide me with lines from Apache error.log where is error appears?

    Thread Starter tjomk

    (@tjomk)

    It’s not happening in Apache, I’m using wp-cli + cron. The error is triggered in wp-content/plugins/wp-cerber/wp-cerber.php on line 246
    I’ve just placed the following code before it to get rid of the error: if ($wp_cerber == null) $wp_cerber = new WP_Cerber();

    Plugin Author gioni

    (@gioni)

    Sorry, I missed that. Anyway, that is annoying thing. Why that “famous WP-CLI” can’t initialize plugins right way? Lame solution?

    There is another workaround:

    if (defined('WP_CLI')) return;

    Question: Do you see any server activity which is performed via WP-CLI on the Activity tab?

    Thread Starter tjomk

    (@tjomk)

    Nope, zero activity. My wild guess about initialization is that it tries to load as little as possible unlike when a full http request arrives, hence all the issues here. However that’s just a guess.

    I think your suggestion returning early is the best one. Since we don’t really need to check (and can’t protect either when having physical access) when user is running wp-cli, then it’s wise to just exit and give way.

    Plugin Author gioni

    (@gioni)

    Yes, I agree. We should not initialize and run code of the Cerber plugin in case of using WP-CLI environment. I think it’ll be reasonable to add some code to control those situations. I’ll do that soon.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘getRemoteIP function fails when running from cron’ is closed to new replies.