Changeset 2078871
- Timestamp:
- 05/02/2019 02:52:41 AM (7 years ago)
- Location:
- geek-mail-blacklist
- Files:
-
- 36 added
- 1 deleted
- 10 edited
- 6 copied
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-2.png (added)
-
assets/screenshot-3.png (added)
-
tags/1.1.0 (copied) (copied from geek-mail-blacklist/trunk)
-
tags/1.1.0/backend (copied) (copied from geek-mail-blacklist/trunk/backend)
-
tags/1.1.0/backend/actions.php (modified) (6 diffs)
-
tags/1.1.0/backend/css (added)
-
tags/1.1.0/backend/css/chart.min.css (added)
-
tags/1.1.0/backend/css/gmb.css (added)
-
tags/1.1.0/backend/js (added)
-
tags/1.1.0/backend/js/chart.min.js (added)
-
tags/1.1.0/backend/js/gmb.js (added)
-
tags/1.1.0/backend/monitor.php (added)
-
tags/1.1.0/backend/pagination.php (added)
-
tags/1.1.0/backend/settings.php (modified) (3 diffs)
-
tags/1.1.0/backend/table-counts.php (added)
-
tags/1.1.0/backend/table-records.php (added)
-
tags/1.1.0/backend/table-rule.php (added)
-
tags/1.1.0/geek-mail-blacklist.php (copied) (copied from geek-mail-blacklist/trunk/geek-mail-blacklist.php) (2 diffs)
-
tags/1.1.0/icon.svg (added)
-
tags/1.1.0/lib (copied) (copied from geek-mail-blacklist/trunk/lib)
-
tags/1.1.0/lib/GMB.php (modified) (5 diffs)
-
tags/1.1.0/lib/GMM.php (added)
-
tags/1.1.0/lib/GMU.php (added)
-
tags/1.1.0/readme.txt (copied) (copied from geek-mail-blacklist/trunk/readme.txt) (2 diffs)
-
tags/1.1.0/screenshot-1.png (added)
-
tags/1.1.0/screenshot-2.png (added)
-
tags/1.1.0/screenshot-3.png (added)
-
tags/1.1.0/variables.php (copied) (copied from geek-mail-blacklist/trunk/variables.php) (3 diffs)
-
trunk/backend/actions.php (modified) (6 diffs)
-
trunk/backend/css (added)
-
trunk/backend/css/chart.min.css (added)
-
trunk/backend/css/gmb.css (added)
-
trunk/backend/js (added)
-
trunk/backend/js/chart.min.js (added)
-
trunk/backend/js/gmb.js (added)
-
trunk/backend/monitor.php (added)
-
trunk/backend/pagination.php (added)
-
trunk/backend/settings.php (modified) (3 diffs)
-
trunk/backend/table-counts.php (added)
-
trunk/backend/table-records.php (added)
-
trunk/backend/table-rule.php (added)
-
trunk/geek-mail-blacklist.php (modified) (2 diffs)
-
trunk/icon.svg (added)
-
trunk/lib/GMB.php (modified) (5 diffs)
-
trunk/lib/GMM.php (added)
-
trunk/lib/GMU.php (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/screenshot-1.png (added)
-
trunk/screenshot-2.png (added)
-
trunk/screenshot-3.png (added)
-
trunk/snapshot1.png (deleted)
-
trunk/variables.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
geek-mail-blacklist/tags/1.1.0/backend/actions.php
r2073886 r2078871 6 6 add_action( 'wp_ajax_gmb_enable', array(get_class(), 'ajaxEnableRule')); 7 7 add_action( 'wp_ajax_gmb_del', array(get_class(), 'ajaxDelRule')); 8 add_action( 'wp_ajax_gmb_get_rules_page', array(get_class(), 'ajaxGetRulePage')); 8 9 } 9 10 … … 17 18 check_ajax_referer( 'gmb_ajax' ); 18 19 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); 19 28 wp_die(); // All ajax handlers die when finished 20 29 } … … 67 76 $time = current_time('mysql'); 68 77 $exp = trim($_POST['gmb-bl-rule']); 69 $table_name = $wpdb->prefix . GMB_DB_NAME ;78 $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST; 70 79 71 80 if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) == '/') { … … 104 113 } 105 114 106 public static function getRules( ) {115 public static function getRules($offset = GMB_DEFAULT_OFFSET, $limit = GMB_DEFAULT_LIMIT) { 107 116 if(!GMB::isUserValid()) { 108 117 return; … … 111 120 global $wpdb; 112 121 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"; 115 124 $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); 116 139 117 140 return $res; … … 154 177 } 155 178 156 $table_name = $wpdb->prefix . GMB_DB_NAME ;179 $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST; 157 180 $sql = $wpdb->prepare("DELETE FROM $table_name WHERE id=%d", $id); 158 181 $response['sql'] = $sql; -
geek-mail-blacklist/tags/1.1.0/backend/settings.php
r2073886 r2078871 11 11 12 12 $gmb_rules = GMBActions::getRules(); 13 $gmb_rules_num = GMBActions::getRuleNum(); 13 14 $GMB_enabled = get_option('gmb-enabled'); 14 15 … … 25 26 } 26 27 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(); 29 32 ?> 30 33 <form method="post" class="gmb-add-form"> 31 34 <div> 32 35 <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> 36 45 </div> 46 <br/> 37 47 <div> 38 48 <input type="text" name="gmb-bl-rule" placeholder="One rule at a time" style="width: 500px"/> … … 53 63 </div> 54 64 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');?> 62 69 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> 75 75 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> 79 80 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> 86 84 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> 97 86 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> 104 90 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');?> 110 95 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> 115 102 116 post("gmb_enable", data);117 });118 }119 </script>120 103 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 3 3 Plugin Name: Geek Mail Blacklist 4 4 Plugin URI: https://geekblog.mybluemix.net/archives/611 5 Description: Block users with certain emails from registering5 Description: Block users with certain Emails from registration 6 6 Author: Wagner 7 Version: 1. 0.07 Version: 1.1.0 8 8 9 9 /* … … 26 26 27 27 require_once(dirname(__FILE__).'/variables.php'); 28 require_once(GMB_PATH . '/lib/GMU.php'); 29 require_once(GMB_PATH . '/backend/table-rule.php'); 30 require_once(GMB_PATH . '/backend/table-counts.php'); 31 require_once(GMB_PATH . '/backend/table-records.php'); 32 require_once(GMB_PATH . '/backend/pagination.php'); 33 require_once(GMB_PATH . '/backend/monitor.php'); 28 34 require_once(GMB_PATH . '/lib/GMB.php'); 29 require_once(GMB_PATH.'/backend/actions.php'); 35 require_once(GMB_PATH . '/lib/GMM.php'); 36 require_once(GMB_PATH . '/backend/actions.php'); 30 37 31 38 register_activation_hook( __FILE__, array( 'GMB', 'install' ) ); 32 39 register_deactivation_hook( __FILE__, array( 'GMB', 'uninstall' ) ); 33 40 GMB::init(); 41 42 if(!GMB::check_database_exists("gmb_blacklist") || !GMB::check_database_exists("gmb_monitor")) { 43 //install corrupted 44 //reinstall 45 GMB::install(); 46 } 47 48 GMBMonitor::init(); 34 49 GMBActions::init(); 50 GMM::deploy_monitor(); 35 51 -
geek-mail-blacklist/tags/1.1.0/lib/GMB.php
r2073886 r2078871 13 13 public static function init() { 14 14 add_action('admin_menu', array(get_class(), 'registerAdminPages')); 15 add_action('admin_enqueue_scripts', array(get_class(), 'enqueueScripts')); 15 16 self::deployBlacklist(); 16 17 } 17 18 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) { 19 40 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;"; 21 52 22 53 $charset_collate = $wpdb->get_charset_collate(); 23 54 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 = "( 25 61 id mediumint(9) NOT NULL AUTO_INCREMENT, 26 62 time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, … … 28 64 userid mediumint(9) NOT NULL, 29 65 PRIMARY KEY (id) 30 ) $charset_collate;";66 )"; 31 67 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); 34 89 35 90 $GMB_enabled = get_option('gmb-enabled'); … … 41 96 public static function uninstall() { 42 97 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; 44 103 $sql = "DROP TABLE IF EXISTS $table_name"; 45 104 $wpdb->query( $sql ); … … 76 135 global $wpdb; 77 136 78 $table_name = $wpdb->prefix . GMB_DB_NAME ;137 $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST; 79 138 $rules = $wpdb->get_results("SELECT expression FROM $table_name", ARRAY_A); 80 139 … … 83 142 $exp = trim($rule['expression']); 84 143 85 if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) ) {144 if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) == '/') { 86 145 $match_flag = preg_match($exp, $user_email, $matches); 87 146 -
geek-mail-blacklist/tags/1.1.0/readme.txt
r2073886 r2078871 4 4 Tags: Blacklist, spam, email 5 5 Requires at least: 3.9 6 Tested up to: 5.1. 06 Tested up to: 5.1.1 7 7 Stable tag: trunk 8 8 … … 14 14 - Support regular expression rules. 15 15 - Completely free. 16 - Support tracking and recording login attempts since v1.1.0. 17 - Login attempts chart since v1.1.0. 16 18 17 19 == Installation == 18 20 - Download the plugin package. 19 - Copy it to wp-content/plugins 21 - Copy it to wp-content/plugins. 20 22 - Unzip the package. 21 - Activate it in your WordPress dashboard 23 - Activate it in your WordPress dashboard. 22 24 - Configure in 'Geek Mail Blacklist' page. 25 - Attention: deactivating the plugin will clear the blacklist and login attempts this plugin recorded. 23 26 24 27 == Screenshots == 25 1. Settings page 28 1. Settings page 1 29 2. Settings page 2 30 3. Settings page 3 -
geek-mail-blacklist/tags/1.1.0/variables.php
r2073886 r2078871 4 4 if ( !defined( 'GMB_NAME' ) ) { 5 5 define( 'GMB_NAME', 'Geek Mail Blacklist' ); 6 } 7 8 if ( !defined( 'GMB_RECORDS_MAX' ) ) { 9 define( 'GMB_RECORDS_MAX', 1000000 ); 6 10 } 7 11 … … 18 22 } 19 23 20 if ( !defined( 'GMB_DB_NAME' ) ) { 21 define( 'GMB_DB_NAME', 'gmb_blacklist' ); 24 if ( !defined( 'GMB_DB_NAME_BLACKLIST' ) ) { 25 define( 'GMB_DB_NAME_BLACKLIST', 'gmb_blacklist' ); 26 } 27 28 if ( !defined( 'GMB_DB_NAME_LOGIN_MONITOR' ) ) { 29 define( 'GMB_DB_NAME_LOGIN_MONITOR', 'gmb_monitor' ); 22 30 } 23 31 … … 29 37 define( 'GMB_URL', plugins_url( '', __FILE__ ) ); 30 38 } 39 40 if(!defined('GMB_DEFAULT_OFFSET')) { 41 define('GMB_DEFAULT_OFFSET', 0); 42 } 43 44 if(!defined('GMB_DEFAULT_LIMIT')) { 45 define('GMB_DEFAULT_LIMIT', 15); 46 } 47 31 48 ?> -
geek-mail-blacklist/trunk/backend/actions.php
r2073886 r2078871 6 6 add_action( 'wp_ajax_gmb_enable', array(get_class(), 'ajaxEnableRule')); 7 7 add_action( 'wp_ajax_gmb_del', array(get_class(), 'ajaxDelRule')); 8 add_action( 'wp_ajax_gmb_get_rules_page', array(get_class(), 'ajaxGetRulePage')); 8 9 } 9 10 … … 17 18 check_ajax_referer( 'gmb_ajax' ); 18 19 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); 19 28 wp_die(); // All ajax handlers die when finished 20 29 } … … 67 76 $time = current_time('mysql'); 68 77 $exp = trim($_POST['gmb-bl-rule']); 69 $table_name = $wpdb->prefix . GMB_DB_NAME ;78 $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST; 70 79 71 80 if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) == '/') { … … 104 113 } 105 114 106 public static function getRules( ) {115 public static function getRules($offset = GMB_DEFAULT_OFFSET, $limit = GMB_DEFAULT_LIMIT) { 107 116 if(!GMB::isUserValid()) { 108 117 return; … … 111 120 global $wpdb; 112 121 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"; 115 124 $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); 116 139 117 140 return $res; … … 154 177 } 155 178 156 $table_name = $wpdb->prefix . GMB_DB_NAME ;179 $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST; 157 180 $sql = $wpdb->prepare("DELETE FROM $table_name WHERE id=%d", $id); 158 181 $response['sql'] = $sql; -
geek-mail-blacklist/trunk/backend/settings.php
r2073886 r2078871 11 11 12 12 $gmb_rules = GMBActions::getRules(); 13 $gmb_rules_num = GMBActions::getRuleNum(); 13 14 $GMB_enabled = get_option('gmb-enabled'); 14 15 … … 25 26 } 26 27 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(); 29 32 ?> 30 33 <form method="post" class="gmb-add-form"> 31 34 <div> 32 35 <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> 36 45 </div> 46 <br/> 37 47 <div> 38 48 <input type="text" name="gmb-bl-rule" placeholder="One rule at a time" style="width: 500px"/> … … 53 63 </div> 54 64 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');?> 62 69 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> 75 75 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> 79 80 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> 86 84 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> 97 86 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> 104 90 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');?> 110 95 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> 115 102 116 post("gmb_enable", data);117 });118 }119 </script>120 103 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 3 3 Plugin Name: Geek Mail Blacklist 4 4 Plugin URI: https://geekblog.mybluemix.net/archives/611 5 Description: Block users with certain emails from registering5 Description: Block users with certain Emails from registration 6 6 Author: Wagner 7 Version: 1. 0.07 Version: 1.1.0 8 8 9 9 /* … … 26 26 27 27 require_once(dirname(__FILE__).'/variables.php'); 28 require_once(GMB_PATH . '/lib/GMU.php'); 29 require_once(GMB_PATH . '/backend/table-rule.php'); 30 require_once(GMB_PATH . '/backend/table-counts.php'); 31 require_once(GMB_PATH . '/backend/table-records.php'); 32 require_once(GMB_PATH . '/backend/pagination.php'); 33 require_once(GMB_PATH . '/backend/monitor.php'); 28 34 require_once(GMB_PATH . '/lib/GMB.php'); 29 require_once(GMB_PATH.'/backend/actions.php'); 35 require_once(GMB_PATH . '/lib/GMM.php'); 36 require_once(GMB_PATH . '/backend/actions.php'); 30 37 31 38 register_activation_hook( __FILE__, array( 'GMB', 'install' ) ); 32 39 register_deactivation_hook( __FILE__, array( 'GMB', 'uninstall' ) ); 33 40 GMB::init(); 41 42 if(!GMB::check_database_exists("gmb_blacklist") || !GMB::check_database_exists("gmb_monitor")) { 43 //install corrupted 44 //reinstall 45 GMB::install(); 46 } 47 48 GMBMonitor::init(); 34 49 GMBActions::init(); 50 GMM::deploy_monitor(); 35 51 -
geek-mail-blacklist/trunk/lib/GMB.php
r2073886 r2078871 13 13 public static function init() { 14 14 add_action('admin_menu', array(get_class(), 'registerAdminPages')); 15 add_action('admin_enqueue_scripts', array(get_class(), 'enqueueScripts')); 15 16 self::deployBlacklist(); 16 17 } 17 18 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) { 19 40 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;"; 21 52 22 53 $charset_collate = $wpdb->get_charset_collate(); 23 54 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 = "( 25 61 id mediumint(9) NOT NULL AUTO_INCREMENT, 26 62 time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, … … 28 64 userid mediumint(9) NOT NULL, 29 65 PRIMARY KEY (id) 30 ) $charset_collate;";66 )"; 31 67 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); 34 89 35 90 $GMB_enabled = get_option('gmb-enabled'); … … 41 96 public static function uninstall() { 42 97 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; 44 103 $sql = "DROP TABLE IF EXISTS $table_name"; 45 104 $wpdb->query( $sql ); … … 76 135 global $wpdb; 77 136 78 $table_name = $wpdb->prefix . GMB_DB_NAME ;137 $table_name = $wpdb->prefix . GMB_DB_NAME_BLACKLIST; 79 138 $rules = $wpdb->get_results("SELECT expression FROM $table_name", ARRAY_A); 80 139 … … 83 142 $exp = trim($rule['expression']); 84 143 85 if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) ) {144 if(substr($exp, 0, 1) == '/' && substr($exp, -1, 1) == '/') { 86 145 $match_flag = preg_match($exp, $user_email, $matches); 87 146 -
geek-mail-blacklist/trunk/readme.txt
r2073886 r2078871 4 4 Tags: Blacklist, spam, email 5 5 Requires at least: 3.9 6 Tested up to: 5.1. 06 Tested up to: 5.1.1 7 7 Stable tag: trunk 8 8 … … 14 14 - Support regular expression rules. 15 15 - Completely free. 16 - Support tracking and recording login attempts since v1.1.0. 17 - Login attempts chart since v1.1.0. 16 18 17 19 == Installation == 18 20 - Download the plugin package. 19 - Copy it to wp-content/plugins 21 - Copy it to wp-content/plugins. 20 22 - Unzip the package. 21 - Activate it in your WordPress dashboard 23 - Activate it in your WordPress dashboard. 22 24 - Configure in 'Geek Mail Blacklist' page. 25 - Attention: deactivating the plugin will clear the blacklist and login attempts this plugin recorded. 23 26 24 27 == Screenshots == 25 1. Settings page 28 1. Settings page 1 29 2. Settings page 2 30 3. Settings page 3 -
geek-mail-blacklist/trunk/variables.php
r2073886 r2078871 4 4 if ( !defined( 'GMB_NAME' ) ) { 5 5 define( 'GMB_NAME', 'Geek Mail Blacklist' ); 6 } 7 8 if ( !defined( 'GMB_RECORDS_MAX' ) ) { 9 define( 'GMB_RECORDS_MAX', 1000000 ); 6 10 } 7 11 … … 18 22 } 19 23 20 if ( !defined( 'GMB_DB_NAME' ) ) { 21 define( 'GMB_DB_NAME', 'gmb_blacklist' ); 24 if ( !defined( 'GMB_DB_NAME_BLACKLIST' ) ) { 25 define( 'GMB_DB_NAME_BLACKLIST', 'gmb_blacklist' ); 26 } 27 28 if ( !defined( 'GMB_DB_NAME_LOGIN_MONITOR' ) ) { 29 define( 'GMB_DB_NAME_LOGIN_MONITOR', 'gmb_monitor' ); 22 30 } 23 31 … … 29 37 define( 'GMB_URL', plugins_url( '', __FILE__ ) ); 30 38 } 39 40 if(!defined('GMB_DEFAULT_OFFSET')) { 41 define('GMB_DEFAULT_OFFSET', 0); 42 } 43 44 if(!defined('GMB_DEFAULT_LIMIT')) { 45 define('GMB_DEFAULT_LIMIT', 15); 46 } 47 31 48 ?>
Note: See TracChangeset
for help on using the changeset viewer.