Plugin Directory

Changeset 2078871


Ignore:
Timestamp:
05/02/2019 02:52:41 AM (7 years ago)
Author:
gongwan33
Message:

v1.1.0

Location:
geek-mail-blacklist
Files:
36 added
1 deleted
10 edited
6 copied

Legend:

Unmodified
Added
Removed
  • geek-mail-blacklist/tags/1.1.0/backend/actions.php

    r2073886 r2078871  
    66        add_action( 'wp_ajax_gmb_enable', array(get_class(), 'ajaxEnableRule'));
    77        add_action( 'wp_ajax_gmb_del', array(get_class(), 'ajaxDelRule'));
     8        add_action( 'wp_ajax_gmb_get_rules_page', array(get_class(), 'ajaxGetRulePage'));
    89    }
    910
     
    1718        check_ajax_referer( 'gmb_ajax' );
    1819        self::delRule();
     20        wp_die(); // All ajax handlers die when finished
     21    }
     22
     23    public static function ajaxGetRulePage() {
     24        check_ajax_referer( 'gmb_ajax' );
     25        $page = (int) GMBActions::sanitize('num', $_POST['data']);
     26        $res = self::getRules(($page - 1)*GMB_DEFAULT_LIMIT, GMB_DEFAULT_LIMIT);
     27        echo gmb_rules_table($res);
    1928        wp_die(); // All ajax handlers die when finished
    2029    }
     
    6776        $time = current_time('mysql');
    6877        $exp = trim($_POST['gmb-bl-rule']);
    69         $table_name = $wpdb->prefix . GMB_DB_NAME;
     78        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
    7079
    7180        if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) == '/') {
     
    104113    }
    105114
    106     public static function getRules() {
     115    public static function getRules($offset = GMB_DEFAULT_OFFSET, $limit = GMB_DEFAULT_LIMIT) {
    107116        if(!GMB::isUserValid()) {
    108117            return;
     
    111120        global $wpdb;
    112121
    113         $table_name = $wpdb->prefix . GMB_DB_NAME;
    114         $sql = "SELECT * FROM $table_name ORDER BY time DESC";
     122        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
     123        $sql = "SELECT * FROM $table_name ORDER BY time DESC LIMIT $limit OFFSET $offset";
    115124        $res = $wpdb->get_results($sql, ARRAY_A);
     125
     126        return $res;
     127    }
     128
     129    public static function getRuleNum() {
     130        if(!GMB::isUserValid()) {
     131            return;
     132        }
     133
     134        global $wpdb;
     135
     136        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
     137        $sql = "SELECT COUNT(*) FROM $table_name";
     138        $res = $wpdb->get_var($sql);
    116139
    117140        return $res;
     
    154177        }
    155178
    156         $table_name = $wpdb->prefix . GMB_DB_NAME;
     179        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
    157180        $sql = $wpdb->prepare("DELETE FROM $table_name WHERE id=%d", $id);
    158181        $response['sql'] = $sql;
  • geek-mail-blacklist/tags/1.1.0/backend/settings.php

    r2073886 r2078871  
    1111
    1212$gmb_rules = GMBActions::getRules();
     13$gmb_rules_num = GMBActions::getRuleNum();
    1314$GMB_enabled = get_option('gmb-enabled');
    1415
     
    2526}
    2627
    27 $gmb_ajax_nonce = wp_create_nonce('gmb_ajax');
    28 
     28$gmb_monitor_counts = GMBMonitor::getCounts();
     29$gmb_monitor_counts_num = GMBMonitor::getCountsNum();
     30$gmb_monitor_records = GMBMonitor::getRecords();
     31$gmb_monitor_records_num = GMBMonitor::getRecordNum();
    2932?>
    3033<form method="post" class="gmb-add-form">
    3134<div>
    3235    <h3>Emails to Block(Support Regular Expression):</h3>
    33     <label><strong>Instruction</strong>: when adding regular expressions, please wrap it with symbol '/'. For example: /.*@a.com/ means filter all emails with the domain a.com. Any rule without wrapping by '/' will be regarded as a full match rule.</label>
    34     <br/>
    35     <label style="color:red"><strong>Warning</strong>: this blacklist function relys on the default WordPress registration process. So if you are using any customized registration pages, please make sure they follow the WordPress standard registration functions and process.</label>
     36    <h4>Block certain Emails from registration.</h4>
     37    <div class="gmb-instruct">
     38        <strong>Instruction</strong>:
     39        <ul>
     40            <li>when adding regular expressions, please wrap it with symbol '/'. For example: /.*@a.com/ means filter all the Emails with the domain a.com. Any rule without wrapping by '/' will be regarded as a full match rule.</li>
     41        <br/>
     42        <li>This blacklist function relys on the default WordPress registration process. So if you are using any customized registration pages, please make sure they follow the WordPress standard registration functions and process.</li>
     43        </ul>
     44    </div>
    3645</div>
     46<br/>
    3747<div>
    3848    <input type="text" name="gmb-bl-rule" placeholder="One rule at a time" style="width: 500px"/>
     
    5363</div>
    5464
    55 <table class="gmb-rules-tb">
    56 <tr>
    57     <th>Rules</th>
    58     <th>Created Time</th>
    59     <th>By</th>
    60     <th>Action</th>
    61 </tr>
     65<div id="gmb-rules-tb-container">
     66<?php gmb_rules_table($gmb_rules);?>
     67</div>
     68<?php gmb_pagination($gmb_rules_num, 'gmb_get_rules_page', 'gmb-rules-tb-container');?>
    6269
    63 <?php if(!empty($gmb_rules)):?>
    64 <?php foreach($gmb_rules as $rule):?>
    65 <tr>
    66     <td><?php echo esc_html($rule['expression']);?></td>
    67     <td><?php echo esc_html($rule['time']);?></td>
    68     <?php $user = get_user_by('id', $rule['userid']);?>
    69     <td><?php echo esc_html($user->display_name);?></td>
    70     <td><button class="gmb-del-btn" data="<?php echo esc_attr($rule['id']);?>">Delete</button></td>
    71 </tr>
    72 <?php endforeach;?>
    73 <?php endif;?>
    74 </table>
     70<div>
     71<br/>
     72<hr/>
     73<br/>
     74</div>
    7575
    76 <script type="text/javascript">
    77 var delBtns = document.querySelectorAll('.gmb-del-btn');
    78 var enableBtn = document.querySelector('#gmb-enable-btn');
     76<div class="attempts-block">
     77<div>
     78    <h3>Login Attempts</h3>   
     79</div>
    7980
    80 function post(action, data) {
    81     var jsonDat = {
    82         action: action,
    83         data: data,
    84         _ajax_nonce: "<?php echo esc_js($gmb_ajax_nonce);?>",
    85     }
     81<div>
     82    <button id="gmb-del-records-btn" style="font-size:medium;padding:5px;">Clear Records</button>
     83</div>
    8684
    87     jQuery.ajax({
    88         url: ajaxurl,
    89         data: jsonDat,
    90         type: "POST",
    91         dataType: "json",
    92         success: function(res) {
    93             location.href = location.href;
    94         },
    95     });
    96 }
     85<h4>Overall Status</h4>
    9786
    98 if(typeof delBtns != 'undefined' && delBtns.length > 0) {
    99     delBtns.forEach(function(btn, idx) {
    100         btn.addEventListener('click', function(ev) {
    101             if(confirm('Are you sure to delete?')) {
    102                 var ele = ev.target;
    103                 var data = ele.getAttribute('data');
     87<div class="gmb-chart-container">
     88    <canvas id="status-chart"></canvas>
     89</div>
    10490
    105                 post('gmb_del', data);
    106             };
    107         });
    108     });
    109 }
     91<div id="gmb-counts-tb-container">
     92<?php gmb_counts_table($gmb_monitor_counts);?>
     93</div>
     94<?php gmb_pagination($gmb_monitor_counts_num, 'gmb_get_monitor_counts_page', 'gmb-counts-tb-container');?>
    11095
    111 if(typeof enableBtn != 'undefined') {
    112     enableBtn.addEventListener('click', function(ev) {
    113         var ele = ev.target;
    114         var data = ele.getAttribute('data');
     96<h4>Detailed Records</h4>
     97<div id="gmb-records-tb-container">
     98<?php gmb_records_table($gmb_monitor_records);?>
     99</div>
     100<?php gmb_pagination($gmb_monitor_records_num, 'gmb_get_monitor_records_page', 'gmb-records-tb-container');?>
     101</div>
    115102
    116         post("gmb_enable", data);
    117     });
    118 }
    119 </script>
    120103
    121 <style type="text/css">
    122 .gmb-enable-session {
    123     margin: 10px;
    124 }
    125 
    126 .gmb-add-form {
    127     margin: 10px;
    128 }
    129 
    130 .gmb-add-form div{
    131     margin-bottom: 10px;
    132 }
    133 
    134 .gmb-rules-tb {
    135     margin: 10px;
    136     text-align: center;
    137     width: 90%;
    138 }
    139 
    140 .gmb-rules-tb tr:nth-child(1) {
    141     background-color: black;
    142     color: white;
    143 }
    144 
    145 .gmb-rules-tb td, .gmb-rules-tb th {
    146     padding: 5px;
    147 }
    148 
    149 .gmb-rules-tb tr:nth-child(2n) {
    150     background-color: #ccc;
    151 }
    152 </style>
  • geek-mail-blacklist/tags/1.1.0/geek-mail-blacklist.php

    r2073886 r2078871  
    33  Plugin Name: Geek Mail Blacklist
    44  Plugin URI: https://geekblog.mybluemix.net/archives/611
    5   Description: Block users with certain emails from registering
     5  Description: Block users with certain Emails from registration
    66  Author: Wagner
    7   Version: 1.0.0
     7  Version: 1.1.0
    88
    99/*
     
    2626
    2727require_once(dirname(__FILE__).'/variables.php');
     28require_once(GMB_PATH . '/lib/GMU.php');
     29require_once(GMB_PATH . '/backend/table-rule.php');
     30require_once(GMB_PATH . '/backend/table-counts.php');
     31require_once(GMB_PATH . '/backend/table-records.php');
     32require_once(GMB_PATH . '/backend/pagination.php');
     33require_once(GMB_PATH . '/backend/monitor.php');
    2834require_once(GMB_PATH . '/lib/GMB.php');
    29 require_once(GMB_PATH.'/backend/actions.php');
     35require_once(GMB_PATH . '/lib/GMM.php');
     36require_once(GMB_PATH . '/backend/actions.php');
    3037
    3138register_activation_hook( __FILE__, array( 'GMB', 'install' ) );
    3239register_deactivation_hook( __FILE__, array( 'GMB', 'uninstall' ) );
    3340GMB::init();
     41
     42if(!GMB::check_database_exists("gmb_blacklist") || !GMB::check_database_exists("gmb_monitor")) {
     43    //install corrupted
     44    //reinstall
     45    GMB::install();
     46}
     47
     48GMBMonitor::init();
    3449GMBActions::init();
     50GMM::deploy_monitor();
    3551
  • geek-mail-blacklist/tags/1.1.0/lib/GMB.php

    r2073886 r2078871  
    1313    public static function init() {
    1414        add_action('admin_menu', array(get_class(), 'registerAdminPages'));
     15        add_action('admin_enqueue_scripts', array(get_class(), 'enqueueScripts'));
    1516        self::deployBlacklist();
    1617    }
    1718
    18     public static function install() {
     19    public static function enqueueScripts($hook) {
     20        if($hook != 'toplevel_page_gmb_menu') {
     21            return;
     22        }
     23        wp_enqueue_style( 'custom_wp_admin_css_chart', GMB_URL.'/backend/css/chart.min.css' );
     24        wp_enqueue_style( 'custom_wp_admin_css_gmb', GMB_URL.'/backend/css/gmb.css' );
     25        wp_enqueue_script( 'custom_wp_admin_js_chart', GMB_URL.'/backend/js/chart.min.js' );
     26        wp_enqueue_script( 'custom_wp_admin_js_gmb', GMB_URL.'/backend/js/gmb.js', array(), false, true );
     27
     28        $monitor_chart_data = GMBMonitor::getPeriodData();
     29        wp_localize_script( 'custom_wp_admin_js_gmb', 'ajaxobject',
     30            array(
     31                'ajaxurl'   => admin_url( 'admin-ajax.php' ),
     32                'ajaxnonce' => wp_create_nonce( 'gmb_ajax' ),
     33                'monitorchartdata' => $monitor_chart_data,
     34                'today' => current_time('Y-m-d'),
     35            )
     36        );
     37    }
     38
     39    public static function check_database_exists($name) {
    1940        global $wpdb;
    20         $table_name = $wpdb->prefix . GMB_DB_NAME;
     41        $tname = $wpdb->prefix . $name;
     42        $sql = $wpdb->prepare("SELECT COUNT(1) FROM information_schema.tables WHERE table_schema=%s AND table_name=%s", array($wpdb->dbname, $tname));
     43
     44        return (int)$wpdb->get_var($sql);
     45    }
     46
     47    public static function create_database($sql, $tbname) {
     48        global $wpdb;
     49        $table_name = $wpdb->prefix . $tbname;
     50
     51        $sql = "CREATE TABLE $table_name ".$sql." $charset_collate;";
    2152
    2253        $charset_collate = $wpdb->get_charset_collate();
    2354
    24         $sql = "CREATE TABLE $table_name (
     55        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     56        dbDelta( $sql );
     57    }
     58
     59    public static function install() {
     60        $sql = "(
    2561            id mediumint(9) NOT NULL AUTO_INCREMENT,
    2662            time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
     
    2864            userid mediumint(9) NOT NULL,
    2965            PRIMARY KEY  (id)
    30         ) $charset_collate;";
     66        )";
    3167
    32         require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    33         dbDelta( $sql );
     68        self::create_database($sql, GMB_DB_NAME_BLACKLIST);
     69
     70        $sql = "(
     71            id mediumint(9) NOT NULL AUTO_INCREMENT,
     72            time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
     73            email varchar(100) NOT NULL,
     74            username varchar(100) NOT NULL,
     75            userid mediumint(9) NOT NULL DEFAULT -1,
     76            result tinyint(1) NOT NULL DEFAULT 0,
     77            ip varchar(200) NOT NULL DEFAULT '0.0.0.0',
     78            info varchar(200),
     79            PRIMARY KEY  (id),
     80            INDEX (email),
     81            INDEX (username),
     82            INDEX (userid),
     83            INDEX (time),
     84            INDEX (result),
     85            INDEX (ip)
     86        )";
     87
     88        self::create_database($sql, GMB_DB_NAME_LOGIN_MONITOR);
    3489
    3590        $GMB_enabled = get_option('gmb-enabled');
     
    4196    public static function uninstall() {
    4297        global $wpdb;
    43         $table_name = $wpdb->prefix . GMB_DB_NAME;
     98        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
     99        $sql = "DROP TABLE IF EXISTS $table_name";
     100        $wpdb->query( $sql );
     101
     102        $table_name = $wpdb->prefix . GMB_DB_NAME_LOGIN_MONITOR;
    44103        $sql = "DROP TABLE IF EXISTS $table_name";
    45104        $wpdb->query( $sql );
     
    76135        global $wpdb;
    77136
    78         $table_name = $wpdb->prefix . GMB_DB_NAME;
     137        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
    79138        $rules = $wpdb->get_results("SELECT expression FROM $table_name", ARRAY_A);
    80139
     
    83142                $exp = trim($rule['expression']);
    84143
    85                 if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1)) {
     144                if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) == '/') {
    86145                    $match_flag = preg_match($exp, $user_email, $matches);
    87146
  • geek-mail-blacklist/tags/1.1.0/readme.txt

    r2073886 r2078871  
    44Tags: Blacklist, spam, email
    55Requires at least: 3.9
    6 Tested up to: 5.1.0
     6Tested up to: 5.1.1
    77Stable tag: trunk
    88
     
    1414- Support regular expression rules.
    1515- Completely free.
     16- Support tracking and recording login attempts since v1.1.0.
     17- Login attempts chart since v1.1.0.
    1618
    1719== Installation ==
    1820- Download the plugin package.
    19 - Copy it to wp-content/plugins
     21- Copy it to wp-content/plugins.
    2022- Unzip the package.
    21 - Activate it in your WordPress dashboard
     23- Activate it in your WordPress dashboard.
    2224- Configure in 'Geek Mail Blacklist' page.
     25- Attention: deactivating the plugin will clear the blacklist and login attempts this plugin recorded.
    2326
    2427== Screenshots ==
    25 1. Settings page
     281. Settings page 1
     292. Settings page 2
     303. Settings page 3
  • geek-mail-blacklist/tags/1.1.0/variables.php

    r2073886 r2078871  
    44if ( !defined( 'GMB_NAME' ) ) {
    55    define( 'GMB_NAME', 'Geek Mail Blacklist' );
     6}
     7
     8if ( !defined( 'GMB_RECORDS_MAX' ) ) {
     9    define( 'GMB_RECORDS_MAX', 1000000 );
    610}
    711
     
    1822}
    1923
    20 if ( !defined( 'GMB_DB_NAME' ) ) {
    21     define( 'GMB_DB_NAME', 'gmb_blacklist' );
     24if ( !defined( 'GMB_DB_NAME_BLACKLIST' ) ) {
     25    define( 'GMB_DB_NAME_BLACKLIST', 'gmb_blacklist' );
     26}
     27
     28if ( !defined( 'GMB_DB_NAME_LOGIN_MONITOR' ) ) {
     29    define( 'GMB_DB_NAME_LOGIN_MONITOR', 'gmb_monitor' );
    2230}
    2331
     
    2937    define( 'GMB_URL', plugins_url( '', __FILE__ ) );
    3038}
     39
     40if(!defined('GMB_DEFAULT_OFFSET')) {
     41    define('GMB_DEFAULT_OFFSET', 0);
     42}
     43
     44if(!defined('GMB_DEFAULT_LIMIT')) {
     45    define('GMB_DEFAULT_LIMIT', 15);
     46}
     47
    3148?>
  • geek-mail-blacklist/trunk/backend/actions.php

    r2073886 r2078871  
    66        add_action( 'wp_ajax_gmb_enable', array(get_class(), 'ajaxEnableRule'));
    77        add_action( 'wp_ajax_gmb_del', array(get_class(), 'ajaxDelRule'));
     8        add_action( 'wp_ajax_gmb_get_rules_page', array(get_class(), 'ajaxGetRulePage'));
    89    }
    910
     
    1718        check_ajax_referer( 'gmb_ajax' );
    1819        self::delRule();
     20        wp_die(); // All ajax handlers die when finished
     21    }
     22
     23    public static function ajaxGetRulePage() {
     24        check_ajax_referer( 'gmb_ajax' );
     25        $page = (int) GMBActions::sanitize('num', $_POST['data']);
     26        $res = self::getRules(($page - 1)*GMB_DEFAULT_LIMIT, GMB_DEFAULT_LIMIT);
     27        echo gmb_rules_table($res);
    1928        wp_die(); // All ajax handlers die when finished
    2029    }
     
    6776        $time = current_time('mysql');
    6877        $exp = trim($_POST['gmb-bl-rule']);
    69         $table_name = $wpdb->prefix . GMB_DB_NAME;
     78        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
    7079
    7180        if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) == '/') {
     
    104113    }
    105114
    106     public static function getRules() {
     115    public static function getRules($offset = GMB_DEFAULT_OFFSET, $limit = GMB_DEFAULT_LIMIT) {
    107116        if(!GMB::isUserValid()) {
    108117            return;
     
    111120        global $wpdb;
    112121
    113         $table_name = $wpdb->prefix . GMB_DB_NAME;
    114         $sql = "SELECT * FROM $table_name ORDER BY time DESC";
     122        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
     123        $sql = "SELECT * FROM $table_name ORDER BY time DESC LIMIT $limit OFFSET $offset";
    115124        $res = $wpdb->get_results($sql, ARRAY_A);
     125
     126        return $res;
     127    }
     128
     129    public static function getRuleNum() {
     130        if(!GMB::isUserValid()) {
     131            return;
     132        }
     133
     134        global $wpdb;
     135
     136        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
     137        $sql = "SELECT COUNT(*) FROM $table_name";
     138        $res = $wpdb->get_var($sql);
    116139
    117140        return $res;
     
    154177        }
    155178
    156         $table_name = $wpdb->prefix . GMB_DB_NAME;
     179        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
    157180        $sql = $wpdb->prepare("DELETE FROM $table_name WHERE id=%d", $id);
    158181        $response['sql'] = $sql;
  • geek-mail-blacklist/trunk/backend/settings.php

    r2073886 r2078871  
    1111
    1212$gmb_rules = GMBActions::getRules();
     13$gmb_rules_num = GMBActions::getRuleNum();
    1314$GMB_enabled = get_option('gmb-enabled');
    1415
     
    2526}
    2627
    27 $gmb_ajax_nonce = wp_create_nonce('gmb_ajax');
    28 
     28$gmb_monitor_counts = GMBMonitor::getCounts();
     29$gmb_monitor_counts_num = GMBMonitor::getCountsNum();
     30$gmb_monitor_records = GMBMonitor::getRecords();
     31$gmb_monitor_records_num = GMBMonitor::getRecordNum();
    2932?>
    3033<form method="post" class="gmb-add-form">
    3134<div>
    3235    <h3>Emails to Block(Support Regular Expression):</h3>
    33     <label><strong>Instruction</strong>: when adding regular expressions, please wrap it with symbol '/'. For example: /.*@a.com/ means filter all emails with the domain a.com. Any rule without wrapping by '/' will be regarded as a full match rule.</label>
    34     <br/>
    35     <label style="color:red"><strong>Warning</strong>: this blacklist function relys on the default WordPress registration process. So if you are using any customized registration pages, please make sure they follow the WordPress standard registration functions and process.</label>
     36    <h4>Block certain Emails from registration.</h4>
     37    <div class="gmb-instruct">
     38        <strong>Instruction</strong>:
     39        <ul>
     40            <li>when adding regular expressions, please wrap it with symbol '/'. For example: /.*@a.com/ means filter all the Emails with the domain a.com. Any rule without wrapping by '/' will be regarded as a full match rule.</li>
     41        <br/>
     42        <li>This blacklist function relys on the default WordPress registration process. So if you are using any customized registration pages, please make sure they follow the WordPress standard registration functions and process.</li>
     43        </ul>
     44    </div>
    3645</div>
     46<br/>
    3747<div>
    3848    <input type="text" name="gmb-bl-rule" placeholder="One rule at a time" style="width: 500px"/>
     
    5363</div>
    5464
    55 <table class="gmb-rules-tb">
    56 <tr>
    57     <th>Rules</th>
    58     <th>Created Time</th>
    59     <th>By</th>
    60     <th>Action</th>
    61 </tr>
     65<div id="gmb-rules-tb-container">
     66<?php gmb_rules_table($gmb_rules);?>
     67</div>
     68<?php gmb_pagination($gmb_rules_num, 'gmb_get_rules_page', 'gmb-rules-tb-container');?>
    6269
    63 <?php if(!empty($gmb_rules)):?>
    64 <?php foreach($gmb_rules as $rule):?>
    65 <tr>
    66     <td><?php echo esc_html($rule['expression']);?></td>
    67     <td><?php echo esc_html($rule['time']);?></td>
    68     <?php $user = get_user_by('id', $rule['userid']);?>
    69     <td><?php echo esc_html($user->display_name);?></td>
    70     <td><button class="gmb-del-btn" data="<?php echo esc_attr($rule['id']);?>">Delete</button></td>
    71 </tr>
    72 <?php endforeach;?>
    73 <?php endif;?>
    74 </table>
     70<div>
     71<br/>
     72<hr/>
     73<br/>
     74</div>
    7575
    76 <script type="text/javascript">
    77 var delBtns = document.querySelectorAll('.gmb-del-btn');
    78 var enableBtn = document.querySelector('#gmb-enable-btn');
     76<div class="attempts-block">
     77<div>
     78    <h3>Login Attempts</h3>   
     79</div>
    7980
    80 function post(action, data) {
    81     var jsonDat = {
    82         action: action,
    83         data: data,
    84         _ajax_nonce: "<?php echo esc_js($gmb_ajax_nonce);?>",
    85     }
     81<div>
     82    <button id="gmb-del-records-btn" style="font-size:medium;padding:5px;">Clear Records</button>
     83</div>
    8684
    87     jQuery.ajax({
    88         url: ajaxurl,
    89         data: jsonDat,
    90         type: "POST",
    91         dataType: "json",
    92         success: function(res) {
    93             location.href = location.href;
    94         },
    95     });
    96 }
     85<h4>Overall Status</h4>
    9786
    98 if(typeof delBtns != 'undefined' && delBtns.length > 0) {
    99     delBtns.forEach(function(btn, idx) {
    100         btn.addEventListener('click', function(ev) {
    101             if(confirm('Are you sure to delete?')) {
    102                 var ele = ev.target;
    103                 var data = ele.getAttribute('data');
     87<div class="gmb-chart-container">
     88    <canvas id="status-chart"></canvas>
     89</div>
    10490
    105                 post('gmb_del', data);
    106             };
    107         });
    108     });
    109 }
     91<div id="gmb-counts-tb-container">
     92<?php gmb_counts_table($gmb_monitor_counts);?>
     93</div>
     94<?php gmb_pagination($gmb_monitor_counts_num, 'gmb_get_monitor_counts_page', 'gmb-counts-tb-container');?>
    11095
    111 if(typeof enableBtn != 'undefined') {
    112     enableBtn.addEventListener('click', function(ev) {
    113         var ele = ev.target;
    114         var data = ele.getAttribute('data');
     96<h4>Detailed Records</h4>
     97<div id="gmb-records-tb-container">
     98<?php gmb_records_table($gmb_monitor_records);?>
     99</div>
     100<?php gmb_pagination($gmb_monitor_records_num, 'gmb_get_monitor_records_page', 'gmb-records-tb-container');?>
     101</div>
    115102
    116         post("gmb_enable", data);
    117     });
    118 }
    119 </script>
    120103
    121 <style type="text/css">
    122 .gmb-enable-session {
    123     margin: 10px;
    124 }
    125 
    126 .gmb-add-form {
    127     margin: 10px;
    128 }
    129 
    130 .gmb-add-form div{
    131     margin-bottom: 10px;
    132 }
    133 
    134 .gmb-rules-tb {
    135     margin: 10px;
    136     text-align: center;
    137     width: 90%;
    138 }
    139 
    140 .gmb-rules-tb tr:nth-child(1) {
    141     background-color: black;
    142     color: white;
    143 }
    144 
    145 .gmb-rules-tb td, .gmb-rules-tb th {
    146     padding: 5px;
    147 }
    148 
    149 .gmb-rules-tb tr:nth-child(2n) {
    150     background-color: #ccc;
    151 }
    152 </style>
  • geek-mail-blacklist/trunk/geek-mail-blacklist.php

    r2073886 r2078871  
    33  Plugin Name: Geek Mail Blacklist
    44  Plugin URI: https://geekblog.mybluemix.net/archives/611
    5   Description: Block users with certain emails from registering
     5  Description: Block users with certain Emails from registration
    66  Author: Wagner
    7   Version: 1.0.0
     7  Version: 1.1.0
    88
    99/*
     
    2626
    2727require_once(dirname(__FILE__).'/variables.php');
     28require_once(GMB_PATH . '/lib/GMU.php');
     29require_once(GMB_PATH . '/backend/table-rule.php');
     30require_once(GMB_PATH . '/backend/table-counts.php');
     31require_once(GMB_PATH . '/backend/table-records.php');
     32require_once(GMB_PATH . '/backend/pagination.php');
     33require_once(GMB_PATH . '/backend/monitor.php');
    2834require_once(GMB_PATH . '/lib/GMB.php');
    29 require_once(GMB_PATH.'/backend/actions.php');
     35require_once(GMB_PATH . '/lib/GMM.php');
     36require_once(GMB_PATH . '/backend/actions.php');
    3037
    3138register_activation_hook( __FILE__, array( 'GMB', 'install' ) );
    3239register_deactivation_hook( __FILE__, array( 'GMB', 'uninstall' ) );
    3340GMB::init();
     41
     42if(!GMB::check_database_exists("gmb_blacklist") || !GMB::check_database_exists("gmb_monitor")) {
     43    //install corrupted
     44    //reinstall
     45    GMB::install();
     46}
     47
     48GMBMonitor::init();
    3449GMBActions::init();
     50GMM::deploy_monitor();
    3551
  • geek-mail-blacklist/trunk/lib/GMB.php

    r2073886 r2078871  
    1313    public static function init() {
    1414        add_action('admin_menu', array(get_class(), 'registerAdminPages'));
     15        add_action('admin_enqueue_scripts', array(get_class(), 'enqueueScripts'));
    1516        self::deployBlacklist();
    1617    }
    1718
    18     public static function install() {
     19    public static function enqueueScripts($hook) {
     20        if($hook != 'toplevel_page_gmb_menu') {
     21            return;
     22        }
     23        wp_enqueue_style( 'custom_wp_admin_css_chart', GMB_URL.'/backend/css/chart.min.css' );
     24        wp_enqueue_style( 'custom_wp_admin_css_gmb', GMB_URL.'/backend/css/gmb.css' );
     25        wp_enqueue_script( 'custom_wp_admin_js_chart', GMB_URL.'/backend/js/chart.min.js' );
     26        wp_enqueue_script( 'custom_wp_admin_js_gmb', GMB_URL.'/backend/js/gmb.js', array(), false, true );
     27
     28        $monitor_chart_data = GMBMonitor::getPeriodData();
     29        wp_localize_script( 'custom_wp_admin_js_gmb', 'ajaxobject',
     30            array(
     31                'ajaxurl'   => admin_url( 'admin-ajax.php' ),
     32                'ajaxnonce' => wp_create_nonce( 'gmb_ajax' ),
     33                'monitorchartdata' => $monitor_chart_data,
     34                'today' => current_time('Y-m-d'),
     35            )
     36        );
     37    }
     38
     39    public static function check_database_exists($name) {
    1940        global $wpdb;
    20         $table_name = $wpdb->prefix . GMB_DB_NAME;
     41        $tname = $wpdb->prefix . $name;
     42        $sql = $wpdb->prepare("SELECT COUNT(1) FROM information_schema.tables WHERE table_schema=%s AND table_name=%s", array($wpdb->dbname, $tname));
     43
     44        return (int)$wpdb->get_var($sql);
     45    }
     46
     47    public static function create_database($sql, $tbname) {
     48        global $wpdb;
     49        $table_name = $wpdb->prefix . $tbname;
     50
     51        $sql = "CREATE TABLE $table_name ".$sql." $charset_collate;";
    2152
    2253        $charset_collate = $wpdb->get_charset_collate();
    2354
    24         $sql = "CREATE TABLE $table_name (
     55        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     56        dbDelta( $sql );
     57    }
     58
     59    public static function install() {
     60        $sql = "(
    2561            id mediumint(9) NOT NULL AUTO_INCREMENT,
    2662            time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
     
    2864            userid mediumint(9) NOT NULL,
    2965            PRIMARY KEY  (id)
    30         ) $charset_collate;";
     66        )";
    3167
    32         require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    33         dbDelta( $sql );
     68        self::create_database($sql, GMB_DB_NAME_BLACKLIST);
     69
     70        $sql = "(
     71            id mediumint(9) NOT NULL AUTO_INCREMENT,
     72            time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
     73            email varchar(100) NOT NULL,
     74            username varchar(100) NOT NULL,
     75            userid mediumint(9) NOT NULL DEFAULT -1,
     76            result tinyint(1) NOT NULL DEFAULT 0,
     77            ip varchar(200) NOT NULL DEFAULT '0.0.0.0',
     78            info varchar(200),
     79            PRIMARY KEY  (id),
     80            INDEX (email),
     81            INDEX (username),
     82            INDEX (userid),
     83            INDEX (time),
     84            INDEX (result),
     85            INDEX (ip)
     86        )";
     87
     88        self::create_database($sql, GMB_DB_NAME_LOGIN_MONITOR);
    3489
    3590        $GMB_enabled = get_option('gmb-enabled');
     
    4196    public static function uninstall() {
    4297        global $wpdb;
    43         $table_name = $wpdb->prefix . GMB_DB_NAME;
     98        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
     99        $sql = "DROP TABLE IF EXISTS $table_name";
     100        $wpdb->query( $sql );
     101
     102        $table_name = $wpdb->prefix . GMB_DB_NAME_LOGIN_MONITOR;
    44103        $sql = "DROP TABLE IF EXISTS $table_name";
    45104        $wpdb->query( $sql );
     
    76135        global $wpdb;
    77136
    78         $table_name = $wpdb->prefix . GMB_DB_NAME;
     137        $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST;
    79138        $rules = $wpdb->get_results("SELECT expression FROM $table_name", ARRAY_A);
    80139
     
    83142                $exp = trim($rule['expression']);
    84143
    85                 if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1)) {
     144                if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) == '/') {
    86145                    $match_flag = preg_match($exp, $user_email, $matches);
    87146
  • geek-mail-blacklist/trunk/readme.txt

    r2073886 r2078871  
    44Tags: Blacklist, spam, email
    55Requires at least: 3.9
    6 Tested up to: 5.1.0
     6Tested up to: 5.1.1
    77Stable tag: trunk
    88
     
    1414- Support regular expression rules.
    1515- Completely free.
     16- Support tracking and recording login attempts since v1.1.0.
     17- Login attempts chart since v1.1.0.
    1618
    1719== Installation ==
    1820- Download the plugin package.
    19 - Copy it to wp-content/plugins
     21- Copy it to wp-content/plugins.
    2022- Unzip the package.
    21 - Activate it in your WordPress dashboard
     23- Activate it in your WordPress dashboard.
    2224- Configure in 'Geek Mail Blacklist' page.
     25- Attention: deactivating the plugin will clear the blacklist and login attempts this plugin recorded.
    2326
    2427== Screenshots ==
    25 1. Settings page
     281. Settings page 1
     292. Settings page 2
     303. Settings page 3
  • geek-mail-blacklist/trunk/variables.php

    r2073886 r2078871  
    44if ( !defined( 'GMB_NAME' ) ) {
    55    define( 'GMB_NAME', 'Geek Mail Blacklist' );
     6}
     7
     8if ( !defined( 'GMB_RECORDS_MAX' ) ) {
     9    define( 'GMB_RECORDS_MAX', 1000000 );
    610}
    711
     
    1822}
    1923
    20 if ( !defined( 'GMB_DB_NAME' ) ) {
    21     define( 'GMB_DB_NAME', 'gmb_blacklist' );
     24if ( !defined( 'GMB_DB_NAME_BLACKLIST' ) ) {
     25    define( 'GMB_DB_NAME_BLACKLIST', 'gmb_blacklist' );
     26}
     27
     28if ( !defined( 'GMB_DB_NAME_LOGIN_MONITOR' ) ) {
     29    define( 'GMB_DB_NAME_LOGIN_MONITOR', 'gmb_monitor' );
    2230}
    2331
     
    2937    define( 'GMB_URL', plugins_url( '', __FILE__ ) );
    3038}
     39
     40if(!defined('GMB_DEFAULT_OFFSET')) {
     41    define('GMB_DEFAULT_OFFSET', 0);
     42}
     43
     44if(!defined('GMB_DEFAULT_LIMIT')) {
     45    define('GMB_DEFAULT_LIMIT', 15);
     46}
     47
    3148?>
Note: See TracChangeset for help on using the changeset viewer.