Plugin Directory

Changeset 2577925


Ignore:
Timestamp:
08/04/2021 11:36:19 AM (5 years ago)
Author:
wpsecuredcom
Message:

Adding first version of my plugin

Location:
secured-wp
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • secured-wp/tags/1.4/classes/Controllers/LoginCheck.php

    r2576070 r2577925  
    5555        public static function check( $user, $username, $password ) {
    5656
    57             if ( User::isTwoFaUserExcluded( $username ) ) {
    58                 return $user;
     57            if ( (bool) \WPSEC\Controllers\Modules\LoginAttempts::getGlobalSettingsValue()
     58                &&
     59                (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() ) {
     60                    return $user;
     61            }
     62
     63            if ( (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() || User::isTwoFaUserExcluded( $username ) ) {
     64                if ( (bool) \WPSEC\Controllers\Modules\LoginAttempts::getGlobalSettingsValue() ) {
     65                    return $user;
     66                }
    5967            }
    6068
     
    7583            }
    7684
    77             if ( null === $user || is_wp_error( $user ) ) {
     85            if ( null === $user || \is_wp_error( $user ) ) {
    7886                if ( ! (bool) \WPSEC\Controllers\Modules\LoginAttempts::getGlobalSettingsValue() ) {
    7987                    $userTriedToLogIn = \get_user_by( 'login', $username );
     
    102110            } elseif ( ! \is_wp_error( $user ) ) {
    103111                LoginAttempts::clearLoginAttempts( $user );
    104                 if ( ! (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() && TwoFASettings::isTotpEnabled() ) {
     112                if ( ! (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() && TwoFASettings::isTotpEnabled() && ! User::isTwoFaUserExcluded( $username ) ) {
    105113                    LoginForms::loginTotp( '', $user );
    106114
  • secured-wp/tags/1.4/classes/Controllers/User.php

    r2576070 r2577925  
    280280         *
    281281         * @param mixed $user - @see setUser method of this class.
    282          *
    283          * @return void
    284          */
    285         public static function lockUser( $user = null ): void {
     282         * @param bool  $destroySessions - should we also destroy all the sessions for the user?.
     283         *
     284         * @return void
     285         */
     286        public static function lockUser( $user = null, $destroySessions = false ): void {
    286287            self::setUser( $user );
    287288
     
    292293            );
    293294
    294             $manager = \WP_Session_Tokens::get_instance( self::$user->ID );
    295             $manager->destroy_all();
     295            if ( $destroySessions ) {
     296                $manager = \WP_Session_Tokens::get_instance( self::$user->ID );
     297                $manager->destroy_all();
     298            }
    296299        }
    297300
     
    340343
    341344        /**
     345         * Deletes user meta
     346         *
     347         * @param mixed $user - The user for which the TOTP key must be deleted.
     348         *
     349         * @return void
     350         *
     351         * @since 1.3
     352         */
     353        public static function deleteUserTotp( $user = null ) {
     354            self::deleteMeta( self::$totpKeyMetaKeyName, $user );
     355            self::removeUserTotpEnabledMeta( $user );
     356        }
     357
     358        /**
    342359         * Validates authentication.
    343360         *
     
    387404        public static function enableTotp( $user = null ) {
    388405            self::setMeta( self::$totEnabledKey, true, $user );
     406        }
     407
     408        /**
     409         * Remove the TOTP meta key completely
     410         *
     411         * @param mixed $user - The user for which the meta must be removed.
     412         *
     413         * @return void
     414         *
     415         * @since 1.3
     416         */
     417        public static function removeUserTotpEnabledMeta( $user = null ) {
     418            self::deleteMeta( self::$totEnabledKey, $user );
    389419        }
    390420
     
    593623
    594624            if ( self::isTwoFaUserExcluded( $user ) ) {
    595                 $status['2FAEnabled'] = __( '2FA enabled: NO', 'secured-wp' );
     625                $status['2FAEnabled'] = __( '2FA enabled: EXCLUDED', 'secured-wp' );
    596626            }
    597627
  • secured-wp/tags/1.4/classes/Helpers/NotifyAdmin.php

    r2576070 r2577925  
    3535            $url = WPHelper::getSiteUrl();
    3636
    37             $to = \get_option( 'admin_email' );
     37            $to = \get_bloginfo( 'admin_email' );
    3838
    3939            $subject = \__( 'Maximum number of unsuccessful login attempts reached', 'secured-wp' );
     
    5151            );
    5252
    53             return \wp_mail( $to, $subject, $message );
     53            $headers = [ 'Content-Type: text/html; charset=UTF-8' ];
     54
     55            return \wp_mail( $to, $subject, $message, $headers );
    5456        }
    5557    }
  • secured-wp/tags/1.4/classes/Secured.php

    r2576070 r2577925  
    301301                    AjaxRequests::initAdmin();
    302302
    303                     if ( WPHelper::isMultisite() ) {
    304                         // add_action( 'personal_options_update', [ $this->user_profiles, 'save_user_2fa_options' ] );
    305                     }
     303                    \add_action( 'personal_options_update', [ 'WPSEC\Views\UserProfile', 'regenerateQRCode' ], 10, 1 );
     304                    \add_action( 'edit_user_profile_update', [ 'WPSEC\Views\UserProfile', 'regenerateQRCode' ], 10, 1 );
    306305                }
    307306            }
  • secured-wp/tags/1.4/classes/Views/UserProfile.php

    r2576070 r2577925  
    2828     */
    2929    class UserProfile {
     30
     31        /**
     32         * QR code regeneration nonce prefix
     33         *
     34         * @var string
     35         *
     36         * @since 1.2
     37         */
     38        private static $qrNoncePrefix = '_regenerate-qr-code_';
    3039
    3140        /**
     
    137146                <hr>
    138147                <?php
    139                 if ( User::isCurrentlyLogged() && ! (bool) User::isTwoFaUserExcluded() ) {
     148                if ( \current_user_can( 'edit_user', User::getUser()->ID ) && ! (bool) User::isTwoFaUserExcluded() ) {
    140149                    self::editUserQR();
    141150                }
     
    171180            <div><?php echo \esc_html__( 'Or use the following key, by entering it directly in you preferable authentication application:', 'secured-wp' ); ?></div>
    172181            <div><strong><?php echo \esc_html( $otp->getSecret() ); ?></strong></div>
    173                 <?php
     182            <div class="tablenav">
     183                <div class="alignleft">
     184                <?php
     185                $nonce = \wp_create_nonce( self::$qrNoncePrefix . User::getUser()->ID );
     186
     187                ?>
     188                <input type="hidden" name="qr-nonce" value="<?php echo \esc_attr( $nonce ); ?>" />
     189                <?php
     190
     191                \submit_button(
     192                    __( 'Regenerate QR code', 'secured-wp' ),
     193                    'delete',
     194                    'regenerate-qr-code',
     195                    false
     196                );
     197                ?>
     198                </div>
     199            </div>
     200                <?php
     201            }
     202        }
     203
     204        /**
     205         * Deletes the TOTP code for the user, it will be regenerated next time the user logs / see its profile page
     206         *
     207         * @param int $userId - the user which TOTP must be regenerated.
     208         *
     209         * @return void
     210         *
     211         * @since 1.3
     212         */
     213        public static function regenerateQRCode( $userId ) {
     214            if ( \current_user_can( 'edit_user', $userId ) ) {
     215                if ( isset( $_POST['qr-nonce'] ) &&
     216                    \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['qr-nonce'] ) ), self::$qrNoncePrefix . $userId ) &&
     217                    isset( $_POST['regenerate-qr-code'] ) ) {
     218
     219                        User::deleteUserTotp( $userId );
     220                }
    174221            }
    175222        }
  • secured-wp/tags/1.4/classes/Views/UsersList.php

    r2576070 r2577925  
    364364                if ( self::$changeLockedBulkActionName === $doAction ) {
    365365                    foreach ( $userIds as $userId ) {
    366                         User::lockUser( $userId );
     366                        User::lockUser( $userId, true );
    367367                    }
    368368                }
  • secured-wp/tags/1.4/secured-wp.php

    r2577922 r2577925  
    99 *
    1010 * @link              https://wp-secured.com
    11  * @since             1.0.1
     11 * @since             1.0.0
    1212 * @package           Secured
    1313 *
     
    1616 * Plugin URI:        https://wp-secured.com
    1717 * Description:       Provides Security for WP sites. 2FA, login attempts, hardens WP login process
     18<<<<<<< HEAD
    1819 * Version:           1.4
     20=======
     21 * Version:           1.3
     22>>>>>>> 2f789104d0138048ccdce57a31ec7ac6d526f8ba
    1923 * Author:            wp-secured
    2024 * Author URI:        https://wp-secured.com
  • secured-wp/tags/1.4/uninstall.php

    r2576070 r2577925  
    11<?php
    2 
    32/**
    43 * Plugin WPS secured
  • secured-wp/trunk/classes/Controllers/LoginCheck.php

    r2576070 r2577925  
    5555        public static function check( $user, $username, $password ) {
    5656
    57             if ( User::isTwoFaUserExcluded( $username ) ) {
    58                 return $user;
     57            if ( (bool) \WPSEC\Controllers\Modules\LoginAttempts::getGlobalSettingsValue()
     58                &&
     59                (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() ) {
     60                    return $user;
     61            }
     62
     63            if ( (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() || User::isTwoFaUserExcluded( $username ) ) {
     64                if ( (bool) \WPSEC\Controllers\Modules\LoginAttempts::getGlobalSettingsValue() ) {
     65                    return $user;
     66                }
    5967            }
    6068
     
    7583            }
    7684
    77             if ( null === $user || is_wp_error( $user ) ) {
     85            if ( null === $user || \is_wp_error( $user ) ) {
    7886                if ( ! (bool) \WPSEC\Controllers\Modules\LoginAttempts::getGlobalSettingsValue() ) {
    7987                    $userTriedToLogIn = \get_user_by( 'login', $username );
     
    102110            } elseif ( ! \is_wp_error( $user ) ) {
    103111                LoginAttempts::clearLoginAttempts( $user );
    104                 if ( ! (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() && TwoFASettings::isTotpEnabled() ) {
     112                if ( ! (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() && TwoFASettings::isTotpEnabled() && ! User::isTwoFaUserExcluded( $username ) ) {
    105113                    LoginForms::loginTotp( '', $user );
    106114
  • secured-wp/trunk/classes/Controllers/User.php

    r2576070 r2577925  
    280280         *
    281281         * @param mixed $user - @see setUser method of this class.
    282          *
    283          * @return void
    284          */
    285         public static function lockUser( $user = null ): void {
     282         * @param bool  $destroySessions - should we also destroy all the sessions for the user?.
     283         *
     284         * @return void
     285         */
     286        public static function lockUser( $user = null, $destroySessions = false ): void {
    286287            self::setUser( $user );
    287288
     
    292293            );
    293294
    294             $manager = \WP_Session_Tokens::get_instance( self::$user->ID );
    295             $manager->destroy_all();
     295            if ( $destroySessions ) {
     296                $manager = \WP_Session_Tokens::get_instance( self::$user->ID );
     297                $manager->destroy_all();
     298            }
    296299        }
    297300
     
    340343
    341344        /**
     345         * Deletes user meta
     346         *
     347         * @param mixed $user - The user for which the TOTP key must be deleted.
     348         *
     349         * @return void
     350         *
     351         * @since 1.3
     352         */
     353        public static function deleteUserTotp( $user = null ) {
     354            self::deleteMeta( self::$totpKeyMetaKeyName, $user );
     355            self::removeUserTotpEnabledMeta( $user );
     356        }
     357
     358        /**
    342359         * Validates authentication.
    343360         *
     
    387404        public static function enableTotp( $user = null ) {
    388405            self::setMeta( self::$totEnabledKey, true, $user );
     406        }
     407
     408        /**
     409         * Remove the TOTP meta key completely
     410         *
     411         * @param mixed $user - The user for which the meta must be removed.
     412         *
     413         * @return void
     414         *
     415         * @since 1.3
     416         */
     417        public static function removeUserTotpEnabledMeta( $user = null ) {
     418            self::deleteMeta( self::$totEnabledKey, $user );
    389419        }
    390420
     
    593623
    594624            if ( self::isTwoFaUserExcluded( $user ) ) {
    595                 $status['2FAEnabled'] = __( '2FA enabled: NO', 'secured-wp' );
     625                $status['2FAEnabled'] = __( '2FA enabled: EXCLUDED', 'secured-wp' );
    596626            }
    597627
  • secured-wp/trunk/classes/Helpers/NotifyAdmin.php

    r2576070 r2577925  
    3535            $url = WPHelper::getSiteUrl();
    3636
    37             $to = \get_option( 'admin_email' );
     37            $to = \get_bloginfo( 'admin_email' );
    3838
    3939            $subject = \__( 'Maximum number of unsuccessful login attempts reached', 'secured-wp' );
     
    5151            );
    5252
    53             return \wp_mail( $to, $subject, $message );
     53            $headers = [ 'Content-Type: text/html; charset=UTF-8' ];
     54
     55            return \wp_mail( $to, $subject, $message, $headers );
    5456        }
    5557    }
  • secured-wp/trunk/classes/Secured.php

    r2576070 r2577925  
    301301                    AjaxRequests::initAdmin();
    302302
    303                     if ( WPHelper::isMultisite() ) {
    304                         // add_action( 'personal_options_update', [ $this->user_profiles, 'save_user_2fa_options' ] );
    305                     }
     303                    \add_action( 'personal_options_update', [ 'WPSEC\Views\UserProfile', 'regenerateQRCode' ], 10, 1 );
     304                    \add_action( 'edit_user_profile_update', [ 'WPSEC\Views\UserProfile', 'regenerateQRCode' ], 10, 1 );
    306305                }
    307306            }
  • secured-wp/trunk/classes/Views/UserProfile.php

    r2576070 r2577925  
    2828     */
    2929    class UserProfile {
     30
     31        /**
     32         * QR code regeneration nonce prefix
     33         *
     34         * @var string
     35         *
     36         * @since 1.2
     37         */
     38        private static $qrNoncePrefix = '_regenerate-qr-code_';
    3039
    3140        /**
     
    137146                <hr>
    138147                <?php
    139                 if ( User::isCurrentlyLogged() && ! (bool) User::isTwoFaUserExcluded() ) {
     148                if ( \current_user_can( 'edit_user', User::getUser()->ID ) && ! (bool) User::isTwoFaUserExcluded() ) {
    140149                    self::editUserQR();
    141150                }
     
    171180            <div><?php echo \esc_html__( 'Or use the following key, by entering it directly in you preferable authentication application:', 'secured-wp' ); ?></div>
    172181            <div><strong><?php echo \esc_html( $otp->getSecret() ); ?></strong></div>
    173                 <?php
     182            <div class="tablenav">
     183                <div class="alignleft">
     184                <?php
     185                $nonce = \wp_create_nonce( self::$qrNoncePrefix . User::getUser()->ID );
     186
     187                ?>
     188                <input type="hidden" name="qr-nonce" value="<?php echo \esc_attr( $nonce ); ?>" />
     189                <?php
     190
     191                \submit_button(
     192                    __( 'Regenerate QR code', 'secured-wp' ),
     193                    'delete',
     194                    'regenerate-qr-code',
     195                    false
     196                );
     197                ?>
     198                </div>
     199            </div>
     200                <?php
     201            }
     202        }
     203
     204        /**
     205         * Deletes the TOTP code for the user, it will be regenerated next time the user logs / see its profile page
     206         *
     207         * @param int $userId - the user which TOTP must be regenerated.
     208         *
     209         * @return void
     210         *
     211         * @since 1.3
     212         */
     213        public static function regenerateQRCode( $userId ) {
     214            if ( \current_user_can( 'edit_user', $userId ) ) {
     215                if ( isset( $_POST['qr-nonce'] ) &&
     216                    \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['qr-nonce'] ) ), self::$qrNoncePrefix . $userId ) &&
     217                    isset( $_POST['regenerate-qr-code'] ) ) {
     218
     219                        User::deleteUserTotp( $userId );
     220                }
    174221            }
    175222        }
  • secured-wp/trunk/classes/Views/UsersList.php

    r2576070 r2577925  
    364364                if ( self::$changeLockedBulkActionName === $doAction ) {
    365365                    foreach ( $userIds as $userId ) {
    366                         User::lockUser( $userId );
     366                        User::lockUser( $userId, true );
    367367                    }
    368368                }
  • secured-wp/trunk/secured-wp.php

    r2577922 r2577925  
    99 *
    1010 * @link              https://wp-secured.com
    11  * @since             1.0.1
     11 * @since             1.0.0
    1212 * @package           Secured
    1313 *
     
    1616 * Plugin URI:        https://wp-secured.com
    1717 * Description:       Provides Security for WP sites. 2FA, login attempts, hardens WP login process
     18<<<<<<< HEAD
    1819 * Version:           1.4
     20=======
     21 * Version:           1.3
     22>>>>>>> 2f789104d0138048ccdce57a31ec7ac6d526f8ba
    1923 * Author:            wp-secured
    2024 * Author URI:        https://wp-secured.com
  • secured-wp/trunk/uninstall.php

    r2576070 r2577925  
    11<?php
    2 
    32/**
    43 * Plugin WPS secured
Note: See TracChangeset for help on using the changeset viewer.