Plugin Directory

Changeset 2938444


Ignore:
Timestamp:
07/13/2023 06:40:56 PM (3 years ago)
Author:
senpaisoftware
Message:

New version 2.0.0

Location:
senpai-software-2fa
Files:
20 added
4 edited

Legend:

Unmodified
Added
Removed
  • senpai-software-2fa/trunk/admin/senpai-software-2fa-admin.php

    r2895877 r2938444  
    110110add_action('personal_options_update', 'senpai_software_2fa_profile_fields_save');
    111111add_action('edit_user_profile_update', 'senpai_software_2fa_profile_fields_save');
     112
     113/**
     114 * Add plugin page
     115 */
     116function senpai_software_2fa_menu() {
     117
     118    add_options_page(
     119        esc_html(__( '2FA Settings','senpai-software-2fa' )),
     120        esc_html(__( '2FA Settings','senpai-software-2fa' )),
     121        'manage_options',
     122        'snp_2fa',
     123        'senpai_software_2fa_set',
     124        99
     125    );
     126}
     127
     128add_action('admin_menu', 'senpai_software_2fa_menu');
     129
     130function senpai_software_2fa_set() {
     131
     132    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     133
     134        $xmlrpc = sanitize_text_field( $_POST['snp_2fa_xmlrpc'] );
     135        $hints = sanitize_text_field( $_POST['snp_2fa_hint'] );
     136        $attempts = sanitize_text_field( $_POST['snp_2fa_attempts'] );
     137        $block_period = sanitize_text_field( $_POST['snp_2fa_block_period'] );
     138
     139        update_option( 'snp_2fa_xmlrpc', $xmlrpc );
     140        update_option( 'snp_2fa_hint', $hints );
     141        update_option( 'snp_2fa_attempts', $attempts );
     142        update_option( 'snp_2fa_block_period', $block_period );
     143
     144        if ( get_option( 'snp_2fa_attempts' ) !== null ) {
     145
     146            global $wpdb;
     147            $table_name = $wpdb->prefix . 'snp_2fa_ip';
     148
     149            if ( $wpdb->get_var("show tables like '".$table_name."'") != $table_name ) {
     150
     151                $charset_collate = $wpdb->get_charset_collate();
     152
     153                $sql = "CREATE TABLE $table_name (
     154                  id int(10) NOT NULL AUTO_INCREMENT,
     155                  ip varchar(40) NOT NULL,
     156                  counter int(10) NOT NULL,
     157                  blockdate varchar(30) NOT NULL,
     158                  PRIMARY KEY  (id)
     159                ) $charset_collate;";
     160
     161                require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     162                dbDelta( $sql );
     163
     164            }
     165        }
     166
     167        add_settings_error(
     168            'snp-2fa-settings',
     169            'settings-saved',
     170            __('Settings saved.', 'default'),
     171            'updated'
     172        );
     173        settings_errors('snp-2fa-settings');
     174
     175    }
     176
     177    $xmlrpc_disable=null;
     178    $xmlrpc_enable=null;
     179
     180    $xmlrpc=get_option( 'snp_2fa_xmlrpc' );
     181
     182    if($xmlrpc==1){
     183        $xmlrpc_disable="checked";
     184    } else {
     185        $xmlrpc_enable="checked";
     186    }
     187
     188    $hint=null;
     189    $hint=get_option( 'snp_2fa_hint' );
     190
     191    $attempts=null;
     192    $attempts=get_option( 'snp_2fa_attempts' );
     193
     194    $block_period=null;
     195    $block_period=get_option( 'snp_2fa_block_period' );
     196    ?>
     197
     198    <div class="wrap">
     199        <h1><?php echo esc_html(__( '2FA Settings','senpai-software-2fa' )); ?></h1>
     200        <form method="post">
     201            <table class="form-table">
     202                <tbody>
     203                <tr>
     204                    <th>XML-RPC</th>
     205                    <td>
     206                        <input type="radio" <?php echo esc_html($xmlrpc_disable); ?> id="snp_2fa_xmlrpc_disable" name="snp_2fa_xmlrpc" value="1">
     207                        <label for="snp_2fa_xmlrpc_disable"><?php echo esc_html(__( 'Disable','senpai-software-2fa' )); ?></label>
     208
     209                        <input type="radio" <?php echo esc_html($xmlrpc_enable); ?> id="snp_2fa_xmlrpc_enable" name="snp_2fa_xmlrpc" value="0">
     210                        <label for="snp_2fa_xmlrpc_enable"><?php echo esc_html(__( 'Enable','senpai-software-2fa' )); ?></label>
     211                        <p class="description">
     212                            <?php echo esc_html(__( 'XML-RPC creates serious vulnerabilities for the site. For full protection, it must be disabled.','senpai-software-2fa' )); ?>
     213                        </p>
     214                    </td>
     215                </tr>
     216                <tr>
     217                    <th><?php echo esc_html(__( 'Login hints','senpai-software-2fa' )); ?></th>
     218                    <td><textarea class="regular-text" name="snp_2fa_hint"><?php echo sanitize_text_field($hint); ?></textarea>
     219                        <p class="description">
     220                            <?php echo esc_html(__( ' Default hints help hackers crack your credentials. Replace hints with neutral text, such as "Invalid data".','senpai-software-2fa' )); ?>
     221                        </p>
     222                    </td>
     223                </tr>
     224                <tr>
     225                    <th><?php echo esc_html(__( 'Limiting login attempts','senpai-software-2fa' )); ?></th>
     226                    <td>
     227                        <input type="number" min="1" placeholder="For example: 3" name="snp_2fa_attempts" value="<?php echo sanitize_text_field($attempts); ?>">
     228                        <p class="description">
     229                            <?php echo esc_html(__( 'The number of failed login attempts after which the IP will be blocked. To remove restrictions, leave the field blank.','senpai-software-2fa' )); ?>
     230                        </p>
     231                        <br/>
     232                        <input type="number" min="1" placeholder="For example: 15" name="snp_2fa_block_period" value="<?php echo sanitize_text_field($block_period); ?>">
     233                        <p class="description">
     234                            <?php echo esc_html(__( 'The period for which the IP will be blocked (in minutes).','senpai-software-2fa' )); ?>
     235                        </p>
     236                    </td>
     237                </tr>
     238                </tbody>
     239            </table>
     240            <p><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php echo __('Save', 'default'); ?>"></p>
     241        </form>
     242    </div>
     243
     244    <?php
     245}
  • senpai-software-2fa/trunk/readme.txt

    r2911947 r2938444  
    22Contributors: senpaisoftware
    33Donate link: https://senpai.software/donate
    4 Tags: 2FA, two factor authentication, brute force, key file, security, senpai software
     4Tags: 2FA, two factor authentication, limit login attempts, disable XML-RPC, brute force, key file, security, senpai software
    55Requires at least: 5.0
    66Requires PHP: 5.6
    77Tested up to: 6.2
    8 Stable tag: 1.0.2
     8Stable tag: 2.0.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2828* Any file can be used as a key, for example: photo, video, text document, song, operating system system file, whatever...
    2929* File size up to 1 GB.
     30* Limit Login Attempts.
     31* Disable XML-RPC.
    3032
    3133Keep in mind that if you change the contents of the file selected as a key, you will not be able to access the admin area.
     
    55571. This is what the login page will look like
    56582. This is how the section in the profile settings will look like
     593. 2FA Settings page
    5760
    5861== Changelog ==
     62
     63= 2.0.0 =
     64* Added ability to disable XML-RPC.
     65* Added ability to set restrictions for login attempts.
    5966
    6067= 1.0.2 =
  • senpai-software-2fa/trunk/senpai-software-2fa-core.php

    r2895877 r2938444  
    6363}
    6464add_action( 'wp_authenticate_user', 'senpai_software_2fa_validation', 10, 3 );
     65
     66/**
     67 * Check xmlrpc settings
     68 */
     69if(get_option( 'snp_2fa_xmlrpc' )==1){
     70    add_filter('xmlrpc_enabled', '__return_false');
     71}
     72
     73/**
     74 * Check hints settings
     75 */
     76if(!empty(get_option( 'snp_2fa_hint' ))) {
     77
     78    function senpai_software_2fa_hints(){
     79        return __( sanitize_text_field(get_option( 'snp_2fa_hint' )),'default' );
     80    }
     81    add_filter( 'login_errors', 'senpai_software_2fa_hints' );
     82}
     83
     84/**
     85 * Check IP
     86 */
     87if ( $GLOBALS['pagenow'] === 'wp-login.php' ) {
     88
     89    function senpai_software_2fa_check() {
     90
     91        $attempts=get_option('snp_2fa_attempts');
     92        $ip=sanitize_text_field($_SERVER['REMOTE_ADDR']);
     93
     94        global $wpdb;
     95        $table = $wpdb->prefix . 'snp_2fa_ip';
     96
     97        $results = $wpdb->get_results( "SELECT `counter`,`blockdate` FROM `{$table}` WHERE `ip`='{$ip}' LIMIT 1" );
     98
     99        if($results && (!empty($attempts))) {
     100
     101            $counter    = $results[0]->counter;
     102            $block_time = $results[0]->blockdate;
     103
     104            if ( $counter >= $attempts ) {
     105
     106                $duration=sanitize_text_field(get_option('snp_2fa_block_period'));
     107                if(empty($duration)){ $duration=15; }
     108                $duration='PT'.$duration.'M';
     109
     110                $currentDateTime   = new DateTime();
     111                $specifiedDateTime = new DateTime( $block_time );
     112                $specifiedDateTime->add( new DateInterval( $duration ) );
     113
     114                if ( $currentDateTime > $specifiedDateTime ) {
     115                    $wpdb->get_results( "DELETE FROM `{$table}` WHERE `ip`='{$ip}' LIMIT 1" );
     116                } else {
     117                    wp_die( 'Access temporarily restricted', 'Blocked', array( 'response' => 403 ) );
     118                }
     119            }
     120        }
     121    }
     122    add_filter( 'init', 'senpai_software_2fa_check' );
     123}
     124
     125function senpai_software_2fa_login_failed(){
     126
     127    $attempts=get_option('snp_2fa_attempts');
     128    $ip=sanitize_text_field($_SERVER['REMOTE_ADDR']);
     129
     130    global $wpdb;
     131    $table = $wpdb->prefix . 'snp_2fa_ip';
     132
     133    $results = $wpdb->get_results( "SELECT `counter`,`blockdate` FROM `{$table}` WHERE `ip`='{$ip}' LIMIT 1" );
     134
     135    $currentDateTime = new DateTime();
     136    $date=$currentDateTime->format('Y-m-d H:i:s');
     137
     138    if(!empty($attempts)) {
     139
     140        if ( $results ) {
     141
     142            $counter = $results[0]->counter;
     143            $counter ++;
     144
     145            $block_date = new DateTime( $results[0]->blockdate );
     146            $block_date->add( new DateInterval( 'PT5M' ) );
     147
     148            if ( $currentDateTime > $block_date ) {
     149                $counter = 1;
     150            }
     151
     152            $data  = array(
     153                'counter'   => $counter,
     154                'blockdate' => $date
     155            );
     156            $where = array(
     157                'ip' => $ip
     158            );
     159            $wpdb->update( $table, $data, $where );
     160
     161        } else {
     162            $data = array(
     163                'ip'        => $ip,
     164                'counter'   => 1,
     165                'blockdate' => $date
     166            );
     167            $wpdb->insert( $table, $data );
     168        }
     169    }
     170}
     171add_action('wp_login_failed', 'senpai_software_2fa_login_failed');
  • senpai-software-2fa/trunk/senpai-software-2fa.php

    r2895905 r2938444  
    33 * Plugin Name:       Senpai Software - Two-factor authentication (2FA) with a key file
    44 * Plugin URI:        https://senpai.software/wp-plugins/2fa/
    5  * Description:       You can select any file on your computer and use it as a secret key to log into the admin area. This way you will get maximum protection against brute force attacks.
    6  * Version:           1.0.2
     5 * Description:       Unique method two-factor auth (2FA). Limit Login Attempts. Disable XML-RPC. Protection against brute force attacks.
     6 * Version:           2.0.0
    77 * Author:            Senpai Software
    88 * Author URI:        https://senpai.software
     
    6969        delete_user_meta($user->ID, 'senpai_software_2fa_status');
    7070    }
     71
     72    delete_option( 'snp_2fa_xmlrpc');
     73    delete_option( 'snp_2fa_hint');
     74    delete_option( 'snp_2fa_attempts');
     75    delete_option( 'snp_2fa_block_period');
     76
     77    $table_name = $wpdb->prefix . 'snp_2fa_ip';
     78    $query = "DROP TABLE IF EXISTS $table_name";
     79    $wpdb->query($query);
    7180}
    7281
Note: See TracChangeset for help on using the changeset viewer.