Plugin Directory


Ignore:
Timestamp:
08/20/2022 04:27:16 PM (3 years ago)
Author:
Gioni
Message:

A new 9.1 version of WP Cerber Security

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-cerber/trunk/cerber-load.php

    r2721561 r2772930  
    818818    cerber_upgrade_all();
    819819
    820     $use_eng = false;
    821     if ( is_admin() && crb_get_settings( 'admin_lang' ) ) {
    822         $use_eng = true;
    823         add_filter( 'override_load_textdomain', function ( $val, $domain, $mofile ) {
    824             if ( $domain == 'wp-cerber' ) {
    825                 $val = true;
    826             }
    827 
    828             return $val;
    829         }, 100, 3 );
    830     }
    831 
    832     if ( ! $use_eng ) {
    833         load_plugin_textdomain( 'wp-cerber', false, 'wp-cerber/languages' );
    834     }
    835 
    836820    get_wp_cerber();
    837821
     
    11321116    if ( ! ( $user instanceof WP_User ) || ! $user->ID ) {
    11331117
    1134         if ( is_wp_error( $user ) ) {
     1118        if ( crb_is_wp_error( $user ) ) {
    11351119
    11361120            $err_code = $user->get_error_code();
     
    11971181        }
    11981182        else {
    1199             cerber_log( 5, $username, $user->ID );
     1183            cerber_log( CRB_EV_LIN, $username, $user->ID );
    12001184        }
    12011185    }
     
    13371321    $fa = CRB_2FA::enforce( $user_login, $user );
    13381322
    1339     if ( is_wp_error( $fa ) ) {
     1323    if ( crb_is_wp_error( $fa ) ) {
    13401324        cerber_error_log( $fa->get_error_message() . ' | RID: ' . get_wp_cerber()->getRequestID(), '2FA' );
    13411325    }
     
    13431327    cerber_login_history( $user->ID );
    13441328
    1345     cerber_log( 5, $user_login, $user->ID );
     1329    cerber_log( CRB_EV_LIN, $user_login, $user->ID );
    13461330
    13471331}
     
    18681852
    18691853    if ( $user
    1870          && ! is_wp_error( $user )
     1854         && ! crb_is_wp_error( $user )
    18711855         && ( $to = cerber_get_user_policy( $policy, $user ) ) ) {
    18721856
     
    24162400
    24172401    cerber_post_control();
     2402
     2403    // Load translations
     2404
     2405    $use_eng = false;
     2406
     2407    if ( is_admin() && crb_get_settings( 'admin_lang' ) ) {
     2408
     2409        $use_eng = true;
     2410
     2411        add_filter( 'override_load_textdomain', function ( $val, $domain, $mofile ) {
     2412            if ( $domain == 'wp-cerber' ) {
     2413                $val = true;
     2414            }
     2415
     2416            return $val;
     2417        }, 100, 3 );
     2418    }
     2419
     2420    if ( ! $use_eng ) {
     2421        load_plugin_textdomain( 'wp-cerber', false, 'wp-cerber/languages' );
     2422    }
    24182423
    24192424    if ( ( ! defined( 'CERBER_OLD_LP' ) || ! CERBER_OLD_LP )
     
    28262831        }
    28272832
    2828         if ( is_numeric( trim( $a ) ) && ! is_admin() ) {
     2833        if ( preg_match( '/\d/', $a ) && ! is_admin() ) {
    28292834            cerber_404_page();
    28302835        }
     
    28502855        return $provider;
    28512856    }, PHP_INT_MAX, 2 );
     2857}
     2858
     2859if ( crb_get_settings( 'nouserpages_bylogin' ) ) {
     2860    add_action( 'template_redirect', function () {
     2861
     2862        if ( ( cerber_get_get( 'author_name' )
     2863               || cerber_get_post( 'author_name' ) )
     2864             && ! is_admin() ) {
     2865            cerber_404_page();
     2866        }
     2867
     2868    }, 0 );
    28522869}
    28532870
     
    34433460
    34443461    // Do not log 'clear_auth_cookie' event (logout/login sequence) that occurs after password reset
    3445     CRB_Globals::$do_not_log[5] = true;
     3462    CRB_Globals::$do_not_log[ CRB_EV_LIN ] = true;
    34463463    CRB_Globals::$do_not_log[6] = true;
    34473464}
     
    38873904    if ( $tag = cerber_acl_check( $ip ) ) {
    38883905        if ( $tag == 'W' ) {
    3889             if ( in_array( $activity, array( 1, 2, 5, 20, CRB_EV_PRS ) ) ) {
     3906            if ( in_array( $activity, array( 1, 2, CRB_EV_LIN, 20, CRB_EV_PRS ) ) ) {
    38903907                return 500;
    38913908            }
     
    49494966    }
    49504967
    4951     $footer .= "\n\n\n" . __( 'This message was sent by', 'wp-cerber' ) . ' WP Cerber Security ' . ( lab_lab() ? 'PRO ' : '' ) . CERBER_VER . "\n";
     4968    $footer .= "\n\n\n" . __( 'This message created by', 'wp-cerber' ) . ' WP Cerber Security ' . ( lab_lab() ? 'PRO ' : '' ) . CERBER_VER . "\n";
     4969    $footer .= __( 'Date:', 'wp-cerber' ) . ' ' . cerber_date( time(), false );
    49524970    $footer .= 'https://wpcerber.com';
    49534971
     
    49624980        $body_go = ( $type == 'send_alert' && crb_get_settings( 'pb_mask' ) ) ? $body_masked : $body;
    49634981        $res = cerber_pb_send( $subj, $body_go, $more, $footer );
    4964         if ( $res && ! is_wp_error( $res ) ) {
     4982        if ( $res && ! crb_is_wp_error( $res ) ) {
    49654983            $results[ $go ] = true;
    49664984            $recipients[ $go ] = cerber_pb_get_active();
     
    55605578                if ( $d < ( time() - DAY_IN_SECONDS * crb_get_settings( 'scan_qcleanup' ) ) ) {
    55615579                    $fs = cerber_init_wp_filesystem();
    5562                     if ( ! is_wp_error( $fs ) ) {
     5580                    if ( ! crb_is_wp_error( $fs ) ) {
    55635581                        $fs->delete( $dir, true );
    55645582                        $sync = true;
     
    60506068 * @param string $limit
    60516069 *
    6052  * @return array|null
     6070 * @return object[]|null
    60536071 */
    60546072function cerber_get_log( $activity = array(), $user = array(), $order = array(), $limit = '' ) {
     
    61026120 * @param $user_email string
    61036121 *
    6104  * @return array|null|object|string
     6122 * @return false|object
    61056123 */
    61066124function cerber_get_last_login( $user_id, $user_email = '' ) {
     
    61116129        $u = array( 'email' => $user_email );
    61126130    }
    6113 
    6114     if ( ! $u ) {
    6115         return false;
    6116     }
    6117 
    6118     if ( $recs = cerber_get_log( array( 5 ), $u, array( 'DESC' => 'stamp' ), 1 ) ) {
     6131    else {
     6132        return false;
     6133    }
     6134
     6135    if ( $recs = cerber_get_log( array( CRB_EV_LIN ), $u, array( 'DESC' => 'stamp' ), 1 ) ) {
    61196136        return $recs[0];
    61206137    }
    61216138
    61226139    return false;
     6140}
     6141
     6142/**
     6143 * Finds the last failed/denied attempt to log in. Uses user login and email.
     6144 * Returns an activity log entry.
     6145 *
     6146 * @param string $login
     6147 * @param string $email
     6148 * @param bool $denied
     6149 *
     6150 * @return false|object
     6151 *
     6152 * @since 9.0.2
     6153 */
     6154function crb_get_last_failed( $login, $email, $denied = false ) {
     6155    $act = ( $denied ) ? 53 : CRB_EV_LFL;
     6156
     6157    return cerber_db_get_row( 'SELECT * FROM ' . CERBER_LOG_TABLE . ' WHERE ( user_login = "' . $login . '" OR user_login = "' . $email . '" ) AND activity = ' . $act . ' ORDER BY stamp DESC LIMIT 1', MYSQL_FETCH_OBJECT );
    61236158}
    61246159
     
    62346269
    62356270        if ( ! crb_get_settings( 'no_white_my_ip' ) ) {
    6236             cerber_add_white( $ip, 'My IP address' ); // Protection for non-experienced users
     6271            cerber_add_white( $ip, 'My IP address (' . cerber_date( time(), false ) . ')' ); // Protection for non-experienced users
    62376272            $whited = ' <p>' . sprintf( __( 'Your IP address %s has been added to the White IP Access List', 'wp-cerber' ), cerber_get_remote_ip() );
    62386273        }
     
    63006335    if ( $dir && file_exists( $dir ) ) {
    63016336        $fs = cerber_init_wp_filesystem();
    6302         if ( ! is_wp_error( $fs ) ) {
     6337        if ( ! crb_is_wp_error( $fs ) ) {
    63036338            $fs->rmdir( $dir, true );
    63046339        }
     
    68896924} );
    68906925
    6891 /*
    6892     Fix an issue with the empty user_id field in the comments table.
    6893 */
     6926/**
     6927 * Fixing an issue with the empty user_id field in the WordPress comments table.
     6928 * We use it to count comments for the Users page.
     6929 *
     6930 */
    68946931add_filter( 'preprocess_comment', 'cerber_add_uid' );
    68956932function cerber_add_uid( $commentdata ) {
Note: See TracChangeset for help on using the changeset viewer.