开发版本

This commit is contained in:
文派备案 2025-05-26 02:01:06 +08:00
parent c42c0919c4
commit 1c46a29e0d
9 changed files with 5872 additions and 0 deletions

2553
admin/class-wpicp-admin.php Normal file

File diff suppressed because it is too large Load diff

537
assets/admin.css Normal file
View file

@ -0,0 +1,537 @@
/* WPBan Pro Admin Styles - WordPress Native Experience */
.wpban-wrap {
margin-top: 20px;
max-width: 1400px;
}
/* Dashboard Grid */
.wpban-dashboard {
margin-top: 20px;
}
.wpban-stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.wpban-stat-card {
background: #fff;
border: 1px solid #c3c4c7;
padding: 20px;
text-align: center;
box-shadow: 0 1px 1px rgba(0,0,0,0.04);
position: relative;
transition: all 0.3s ease;
}
.wpban-stat-card:hover {
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
transform: translateY(-2px);
}
.wpban-stat-card h3 {
margin: 0 0 10px 0;
font-size: 14px;
font-weight: 600;
color: #1d2327;
}
.wpban-stat-number {
font-size: 36px;
font-weight: 300;
color: #2271b1;
line-height: 1;
}
.wpban-stat-trend {
margin-top: 10px;
font-size: 12px;
}
.wpban-stat-trend .up {
color: #d63638;
}
.wpban-stat-trend .down {
color: #00a32a;
}
/* Grid Layout */
.wpban-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 20px;
}
@media (max-width: 1200px) {
.wpban-grid {
grid-template-columns: 1fr;
}
}
/* Cards */
.wpban-card {
background: #fff;
border: 1px solid #c3c4c7;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.wpban-card h2 {
margin: 0 0 15px 0;
font-size: 1.3em;
font-weight: 600;
color: #1d2327;
}
.wpban-card h3 {
margin: 20px 0 10px 0;
font-size: 1.1em;
font-weight: 600;
}
/* Actions */
.wpban-actions {
display: flex;
gap: 10px;
margin: 20px 0;
flex-wrap: wrap;
}
/* Bypass URL */
.wpban-bypass-url {
margin: 20px 0;
}
.wpban-bypass-url label {
display: block;
margin-bottom: 10px;
font-weight: 600;
}
.wpban-input-group {
display: flex;
gap: 10px;
margin-bottom: 10px;
}
.wpban-input-group input {
flex: 1;
}
/* Templates Grid */
.wpban-templates-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
}
.wpban-template-card {
background: #f6f7f7;
border: 1px solid #dcdcde;
padding: 20px;
border-radius: 4px;
transition: all 0.2s;
}
.wpban-template-card:hover {
background: #fff;
border-color: #2271b1;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.wpban-template-card h3 {
margin: 0 0 10px 0;
font-size: 16px;
font-weight: 600;
}
.wpban-template-card p {
margin: 0 0 15px 0;
color: #50575e;
font-size: 13px;
line-height: 1.5;
}
/* Tabs */
.wpban-tabs {
margin-top: 20px;
}
.tab-content {
display: none;
background: #fff;
border: 1px solid #c3c4c7;
border-top: none;
padding: 20px;
}
.tab-content.active {
display: block;
}
.tab-content h2 {
margin-top: 0;
}
/* Crawler Controls */
.wpban-crawler-controls {
margin-bottom: 20px;
display: flex;
gap: 10px;
flex-wrap: wrap;
}
/* Crawler Grid */
.wpban-crawler-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
gap: 10px;
margin-bottom: 30px;
}
.wpban-crawler-item {
display: block;
padding: 12px;
background: #f6f7f7;
border: 1px solid #dcdcde;
cursor: pointer;
transition: all 0.2s;
}
.wpban-crawler-item:hover {
background: #fff;
border-color: #2271b1;
}
.wpban-crawler-item input[type="checkbox"] {
margin-right: 8px;
}
.wpban-crawler-name {
font-weight: 600;
display: inline-block;
margin-right: 8px;
font-family: Consolas, Monaco, monospace;
font-size: 13px;
}
.wpban-crawler-desc {
font-size: 12px;
color: #50575e;
display: inline;
}
/* Notices */
.wpban-notice {
padding: 12px;
margin: 15px 0;
border-left: 4px solid;
background: #fff;
}
.wpban-notice-warning {
border-left-color: #f0b849;
background-color: #fef8ee;
}
.wpban-notice-warning p {
margin: 0;
}
/* Logs */
.wpban-logs-filters {
background: #fff;
border: 1px solid #c3c4c7;
padding: 15px;
margin-bottom: 20px;
}
.wpban-logs-filters form {
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap;
}
.wpban-logs-filters input[type="date"],
.wpban-logs-filters input[type="text"],
.wpban-logs-filters select {
height: 30px;
line-height: 28px;
}
/* Badges */
.wpban-badge {
display: inline-block;
padding: 3px 8px;
border-radius: 3px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
}
.wpban-badge-banned {
background: #d63638;
color: #fff;
}
.wpban-badge-blocked {
background: #f0b849;
color: #000;
}
.wpban-badge-failed_login {
background: #dba617;
color: #fff;
}
.wpban-badge-bypass {
background: #00a32a;
color: #fff;
}
/* Truncate */
.wpban-truncate {
display: inline-block;
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
vertical-align: middle;
}
/* Country Selector */
.wpban-country-selector select {
font-family: Consolas, Monaco, monospace;
font-size: 13px;
}
/* Rate Limit Settings */
.form-table input[type="number"] {
width: 80px;
}
/* Tools Grid */
.wpban-tools-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
gap: 20px;
}
/* Chart Container */
#wpban-country-chart {
max-height: 300px;
}
/* Activity List */
.wpban-activity-list {
margin: 0;
padding: 0;
list-style: none;
}
.wpban-activity-list li {
padding: 8px 0;
border-bottom: 1px solid #f0f0f1;
}
.wpban-activity-list li:last-child {
border-bottom: none;
}
/* Form Elements */
.form-table textarea.code {
font-family: Consolas, Monaco, monospace;
font-size: 13px;
line-height: 1.5;
}
/* Pagination */
.tablenav-pages {
margin: 20px 0;
text-align: right;
}
.tablenav-pages .pagination-links {
display: inline-block;
}
.tablenav-pages a,
.tablenav-pages span {
display: inline-block;
padding: 3px 8px;
margin: 0 2px;
background: #f6f7f7;
border: 1px solid #dcdcde;
text-decoration: none;
}
.tablenav-pages .current {
background: #2271b1;
color: #fff;
border-color: #2271b1;
}
/* Responsive Tables */
@media (max-width: 782px) {
.wp-list-table {
display: block;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
.wpban-stats-grid {
grid-template-columns: 1fr;
}
.wpban-templates-grid {
grid-template-columns: 1fr;
}
.wpban-crawler-grid {
grid-template-columns: 1fr;
}
.wpban-tools-grid {
grid-template-columns: 1fr;
}
.wpban-logs-filters form {
flex-direction: column;
align-items: stretch;
}
.wpban-logs-filters input,
.wpban-logs-filters select,
.wpban-logs-filters button {
width: 100%;
margin-bottom: 10px;
}
}
/* Loading States */
.wpban-loading {
opacity: 0.6;
pointer-events: none;
position: relative;
}
.wpban-loading::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
margin: -10px 0 0 -10px;
border: 2px solid #f3f3f3;
border-top: 2px solid #2271b1;
border-radius: 50%;
animation: wpban-spin 1s linear infinite;
}
@keyframes wpban-spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Buttons */
.button.button-small {
padding: 0 8px;
line-height: 26px;
height: 28px;
font-size: 12px;
}
/* WP Editor in Settings */
.tab-content .wp-editor-wrap {
margin-top: 10px;
}
/* Empty States */
.wpban-empty-state {
text-align: center;
padding: 40px;
color: #646970;
}
.wpban-empty-state p {
font-size: 16px;
margin: 0;
}
/* Success/Error Messages */
.wpban-message {
padding: 12px;
margin: 15px 0;
border-left: 4px solid;
background: #fff;
animation: wpban-fade-in 0.3s ease;
}
.wpban-message.success {
border-left-color: #00a32a;
background-color: #f0f8f0;
}
.wpban-message.error {
border-left-color: #d63638;
background-color: #fef1f1;
}
@keyframes wpban-fade-in {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Row Actions */
.row-actions {
font-size: 12px;
padding-top: 4px;
}
.row-actions a {
text-decoration: none;
}
/* Status Indicators */
.wpban-status {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
margin-right: 5px;
}
.wpban-status.active {
background: #00a32a;
}
.wpban-status.inactive {
background: #787c82;
}
/* Code Preview */
.wpban-code-preview {
background: #f6f7f7;
border: 1px solid #dcdcde;
padding: 15px;
font-family: Consolas, Monaco, monospace;
font-size: 13px;
overflow-x: auto;
white-space: pre;
max-height: 300px;
overflow-y: auto;
}

335
assets/admin.js Normal file
View file

@ -0,0 +1,335 @@
/**
* WPBan Pro Admin JavaScript
*/
(function($) {
'use strict';
// Tab Navigation
$(document).on('click', '.nav-tab', function(e) {
e.preventDefault();
const target = $(this).attr('href');
$('.nav-tab').removeClass('nav-tab-active');
$(this).addClass('nav-tab-active');
$('.tab-content').removeClass('active');
$(target).addClass('active');
// Save active tab to localStorage
localStorage.setItem('wpban_active_tab', target);
});
// Restore active tab
$(document).ready(function() {
const activeTab = localStorage.getItem('wpban_active_tab');
if (activeTab && $(activeTab).length) {
$('.nav-tab[href="' + activeTab + '"]').trigger('click');
}
});
// Settings Form Handler
$('#wpban-settings-form').on('submit', function(e) {
e.preventDefault();
const $form = $(this);
const $button = $('#wpban-save-settings');
const $spinner = $button.next('.spinner');
$button.prop('disabled', true);
$spinner.addClass('is-active');
$.ajax({
url: wpban.ajax_url,
type: 'POST',
data: {
action: 'wpban_save_settings',
settings: $form.serialize(),
_ajax_nonce: $('#wpban_nonce').val()
},
success: function(response) {
if (response.success) {
showMessage('success', response.data.message);
} else {
showMessage('error', response.data || wpban.i18n.error);
}
},
error: function() {
showMessage('error', wpban.i18n.error);
},
complete: function() {
$button.prop('disabled', false);
$spinner.removeClass('is-active');
}
});
});
// Apply Template
window.wpbanApplyTemplate = function(templateId) {
if (!confirm(wpban.i18n.confirm_template)) {
return;
}
$.post(wpban.ajax_url, {
action: 'wpban_apply_template',
template: templateId,
_ajax_nonce: wpban.nonce
}, function(response) {
if (response.success) {
showMessage('success', response.data.message);
setTimeout(() => location.reload(), 1500);
} else {
showMessage('error', response.data || wpban.i18n.error);
}
});
};
// Copy Text to Clipboard
window.wpbanCopyText = function(text) {
navigator.clipboard.writeText(text).then(() => {
showMessage('success', 'Copied to clipboard!');
}).catch(() => {
// Fallback for older browsers
const $temp = $('<input>');
$('body').append($temp);
$temp.val(text).select();
document.execCommand('copy');
$temp.remove();
showMessage('success', 'Copied to clipboard!');
});
};
// Crawler Selection
window.wpbanSelectCrawlers = function(type, select) {
if (type === 'all') {
$('.wpban-crawler-item input').prop('checked', select);
} else {
$(`.wpban-crawler-item[data-type="${type}"] input`).prop('checked', select);
}
};
// Export Logs
window.wpbanExportLogs = function() {
window.location.href = wpban.ajax_url + '?action=wpban_export_logs&_ajax_nonce=' + wpban.nonce;
};
// Clear Logs
window.wpbanClearLogs = function() {
if (!confirm(wpban.i18n.confirm_clear)) {
return;
}
$.post(wpban.ajax_url, {
action: 'wpban_clear_logs',
_ajax_nonce: wpban.nonce
}, function(response) {
if (response.success) {
showMessage('success', response.data.message);
setTimeout(() => location.reload(), 1500);
}
});
};
// Test Email
window.wpbanTestEmail = function() {
const $button = event.target;
$button.disabled = true;
$.post(wpban.ajax_url, {
action: 'wpban_test_email',
_ajax_nonce: wpban.nonce
}, function(response) {
if (response.success) {
showMessage('success', response.data.message);
} else {
showMessage('error', response.data || wpban.i18n.error);
}
}).always(function() {
$button.disabled = false;
});
};
// Export Settings
window.wpbanExportSettings = function() {
$.get(wpban.ajax_url, {
action: 'wpban_export_settings',
_ajax_nonce: wpban.nonce
}, function(response) {
if (response.success) {
const blob = new Blob([response.data], {type: 'application/json'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'wpban-settings-' + new Date().toISOString().split('T')[0] + '.json';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
});
};
// Optimize Database
window.wpbanOptimizeDatabase = function() {
const $button = event.target;
$button.disabled = true;
$.post(wpban.ajax_url, {
action: 'wpban_optimize_database',
_ajax_nonce: wpban.nonce
}, function(response) {
if (response.success) {
showMessage('success', 'Database optimized successfully!');
}
}).always(function() {
$button.disabled = false;
});
};
// Clear Old Logs
window.wpbanClearOldLogs = function() {
if (!confirm('This will permanently delete all logs older than 30 days. Continue?')) {
return;
}
$.post(wpban.ajax_url, {
action: 'wpban_clear_old_logs',
_ajax_nonce: wpban.nonce
}, function(response) {
if (response.success) {
showMessage('success', response.data.message);
setTimeout(() => location.reload(), 1500);
}
});
};
// Live Search for Crawlers
let searchTimeout;
$(document).on('input', '#wpban-crawler-search', function() {
const query = $(this).val().toLowerCase();
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => {
$('.wpban-crawler-item').each(function() {
const $item = $(this);
const text = $item.text().toLowerCase();
$item.toggle(text.indexOf(query) > -1);
});
}, 300);
});
// Real-time Log Updates (optional)
if ($('#wpban-logs-container').length) {
// Auto-refresh logs every 30 seconds
setInterval(function() {
if (document.visibilityState === 'visible') {
refreshLogs();
}
}, 30000);
}
function refreshLogs() {
const params = new URLSearchParams(window.location.search);
$.get(wpban.ajax_url, {
action: 'wpban_get_logs',
page: params.get('paged') || 1,
date_from: params.get('date_from'),
date_to: params.get('date_to'),
action_filter: params.get('action_filter'),
ip_filter: params.get('ip_filter'),
_ajax_nonce: wpban.nonce
}, function(response) {
if (response.success) {
$('#wpban-logs-container tbody').html(response.data.html);
}
});
}
// Show Message
function showMessage(type, message) {
const $message = $('<div>')
.addClass('wpban-message ' + type)
.text(message)
.prependTo('.wpban-wrap')
.hide()
.fadeIn();
setTimeout(() => {
$message.fadeOut(() => $message.remove());
}, 5000);
}
// Geo Blocking Mode Toggle
$('input[name="settings[geo_blocking][mode]"]').on('change', function() {
const mode = $(this).val();
const $label = $('.wpban-country-selector').prev('th').find('label');
if (mode === 'whitelist') {
$label.text('Allowed Countries');
} else {
$label.text('Blocked Countries');
}
});
// Initialize Select2 for country selector (if available)
if ($.fn.select2) {
$('.wpban-country-selector select').select2({
placeholder: 'Select countries...',
width: '100%'
});
}
// Handle browser restrictions toggle
$('input[name="settings[browser_restrictions][wechat_qq][enabled]"]').on('change', function() {
const $fields = $(this).closest('table').find('tr').not(':first');
$fields.toggle($(this).is(':checked'));
}).trigger('change');
// Email notifications toggle
$('input[name="settings[email_notifications][enabled]"]').on('change', function() {
const $fields = $(this).closest('table').find('tr').not(':first');
$fields.toggle($(this).is(':checked'));
}).trigger('change');
// Geo blocking toggle
$('input[name="settings[geo_blocking][enabled]"]').on('change', function() {
const $fields = $(this).closest('table').find('tr').not(':first');
$fields.toggle($(this).is(':checked'));
}).trigger('change');
// Keyboard shortcuts
$(document).on('keydown', function(e) {
// Ctrl/Cmd + S to save
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
e.preventDefault();
$('#wpban-save-settings').trigger('click');
}
});
// Tooltip initialization
$('.wpban-tooltip').tooltip({
position: {
my: 'center bottom-10',
at: 'center top'
}
});
// Confirm before leaving with unsaved changes
let formChanged = false;
$('#wpban-settings-form').on('change', 'input, select, textarea', function() {
formChanged = true;
});
window.addEventListener('beforeunload', function(e) {
if (formChanged) {
e.preventDefault();
e.returnValue = 'You have unsaved changes. Are you sure you want to leave?';
}
});
$('#wpban-save-settings').on('click', function() {
formChanged = false;
});
})(jQuery);

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,311 @@
<?php
/**
* 插件的前端功能
*
* @package WPICP
* @subpackage WPICP/public
*/
// 如果直接访问此文件,则退出
if (!defined('WPINC')) {
die;
}
/**
* ICP信息小工具类
*/
class WPICP_Widget extends WP_Widget {
/**
* 初始化小工具
*/
public function __construct() {
parent::__construct(
'wpicp_widget',
__('ICP备案信息', 'wpicp'),
array('description' => __('显示ICP备案信息', 'wpicp'))
);
}
/**
* 前端显示小工具
*/
public function widget($args, $instance) {
$options = get_option('wpicp_options');
if(empty($options['icp_number'])) {
return;
}
$title = !empty($instance['title']) ? apply_filters('widget_title', $instance['title']) : __('ICP备案信息', 'wpicp');
$icp_number = esc_html($options['icp_number']);
$custom_link = !empty($options['custom_link']) ? esc_url($options['custom_link']) : 'https://beian.miit.gov.cn/';
$style_class = !empty($options['display_style']) ? 'wpicp-style-' . esc_attr($options['display_style']) : 'wpicp-style-default';
// 显示公安备案信息
$police_number = isset($options['police_number']) ? esc_html($options['police_number']) : '';
$police_link = isset($options['police_link']) ? esc_url($options['police_link']) : 'http://www.beian.gov.cn/';
echo $args['before_widget'];
if(!empty($title)) {
echo $args['before_title'] . $title . $args['after_title'];
}
echo '<div class="wpicp-widget ' . $style_class . '">';
echo '<a href="' . $custom_link . '" target="_blank" rel="nofollow noopener">' . $icp_number . '</a>';
// 如果有公安备案号,也显示
if(!empty($police_number)) {
echo '<br>';
echo '<a href="' . $police_link . '" target="_blank" rel="nofollow noopener">' . $police_number . '</a>';
}
echo '</div>';
echo $args['after_widget'];
}
/**
* 后台显示表单
*/
public function form($instance) {
$title = !empty($instance['title']) ? $instance['title'] : __('ICP备案信息', 'wpicp');
?>
<p>
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('标题:', 'wpicp'); ?></label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
</p>
<p><?php _e('ICP备案信息将从插件设置中获取。', 'wpicp'); ?></p>
<?php
}
/**
* 保存小工具选项
*/
public function update($new_instance, $old_instance) {
$instance = array();
$instance['title'] = (!empty($new_instance['title'])) ? sanitize_text_field($new_instance['title']) : '';
return $instance;
}
}
/**
* 前端类 - 注意修改类名为WPICP_Public以匹配主文件中的引用
*/
class WPICP_Public {
/**
* 初始化类并设置属性
*/
public function __construct() {
// 根据设置决定在何处显示ICP信息
$options = get_option('wpicp_options');
$display_location = isset($options['display_location']) ? $options['display_location'] : 'footer';
if($display_location == 'footer') {
add_action('wp_footer', array($this, 'display_icp_info_footer'), 20);
} elseif($display_location == 'sidebar') {
add_action('widgets_init', array($this, 'register_icp_widget'));
}
// 注册短代码
add_shortcode('wpicp_info', array($this, 'icp_info_shortcode'));
// 添加备案状态检查
add_action('wp_head', array($this, 'check_icp_status'));
}
/**
* 在页脚显示ICP信息
*/
public function display_icp_info_footer() {
$options = get_option('wpicp_options');
if(empty($options['icp_number'])) {
return;
}
$icp_number = esc_html($options['icp_number']);
$custom_link = !empty($options['custom_link']) ? esc_url($options['custom_link']) : 'https://beian.miit.gov.cn/';
$style_class = !empty($options['display_style']) ? 'wpicp-style-' . esc_attr($options['display_style']) : 'wpicp-style-default';
// 显示公安备案信息
$police_number = isset($options['police_number']) ? esc_html($options['police_number']) : '';
$police_link = isset($options['police_link']) ? esc_url($options['police_link']) : 'http://www.beian.gov.cn/';
echo '<div class="wpicp-footer ' . $style_class . '">';
echo '<a href="' . $custom_link . '" target="_blank" rel="nofollow noopener">' . $icp_number . '</a>';
// 如果有公安备案号,也显示
if(!empty($police_number)) {
echo ' | <a href="' . $police_link . '" target="_blank" rel="nofollow noopener">' . $police_number . '</a>';
}
echo '</div>';
}
/**
* 注册ICP信息小工具
*/
public function register_icp_widget() {
register_widget('WPICP_Widget');
}
/**
* ICP信息短代码
*/
public function icp_info_shortcode($atts) {
$options = get_option('wpicp_options');
if(empty($options['icp_number'])) {
return '';
}
$atts = shortcode_atts(
array(
'style' => isset($options['display_style']) ? $options['display_style'] : 'default',
),
$atts,
'wpicp_info'
);
$icp_number = esc_html($options['icp_number']);
$custom_link = !empty($options['custom_link']) ? esc_url($options['custom_link']) : 'https://beian.miit.gov.cn/';
$style_class = 'wpicp-style-' . esc_attr($atts['style']);
// 显示公安备案信息
$police_number = isset($options['police_number']) ? esc_html($options['police_number']) : '';
$police_link = isset($options['police_link']) ? esc_url($options['police_link']) : 'http://www.beian.gov.cn/';
$output = '<div class="wpicp-shortcode ' . $style_class . '">';
$output .= '<a href="' . $custom_link . '" target="_blank" rel="nofollow noopener">' . $icp_number . '</a>';
// 如果有公安备案号,也显示
if(!empty($police_number)) {
$output .= ' | <a href="' . $police_link . '" target="_blank" rel="nofollow noopener">' . $police_number . '</a>';
}
$output .= '</div>';
return $output;
}
/**
* 检查ICP备案状态
*/
public function check_icp_status() {
$options = get_option('wpicp_options');
// 如果已启用状态通知
if(isset($options['status_notification']) && $options['status_notification'] == 'yes') {
$domain = parse_url(get_site_url(), PHP_URL_HOST);
require_once WPICP_PLUGIN_DIR . 'includes/class-wpicp-core.php';
$core = new WPICP_Core();
$status_message = $core->get_status_message($domain);
// 如果未备案并且是管理员,显示前台提醒
if(current_user_can('manage_options') &&
($status_message['icp_status'] == 'not_registered' || $status_message['icp_status'] == 'unknown')) {
if(!isset($_COOKIE['wpicp_notice_dismissed'])) {
?>
<div class="wpicp-admin-notice wpicp-status-notice">
<p><?php echo esc_html($status_message['message']); ?> <a href="<?php echo admin_url('admin.php?page=wpicp-guide'); ?>"><?php _e('查看备案指南', 'wpicp'); ?></a></p>
<button class="wpicp-notice-dismiss"><?php _e('忽略', 'wpicp'); ?></button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var dismissButton = document.querySelector('.wpicp-notice-dismiss');
if(dismissButton) {
dismissButton.addEventListener('click', function() {
var notice = this.parentNode;
notice.style.display = 'none';
document.cookie = 'wpicp_notice_dismissed=1; path=/; max-age=86400';
});
}
});
</script>
<style>
.wpicp-status-notice {
background-color: #f8d7da;
color: #721c24;
padding: 10px 15px;
border-left: 4px solid #f5c6cb;
margin: 10px 0;
position: fixed;
bottom: 20px;
right: 20px;
z-index: 9999;
max-width: 300px;
}
.wpicp-notice-dismiss {
background: none;
border: none;
color: #721c24;
cursor: pointer;
float: right;
font-size: 16px;
}
</style>
<?php
}
}
}
// 如果没有设置ICP备案号显示提醒
if(empty($options['icp_number']) && current_user_can('manage_options') && !is_admin()) {
echo '<!-- WPICP提醒尚未设置ICP备案号请在管理后台设置 -->';
if(!isset($_COOKIE['wpicp_notice_dismissed'])) {
?>
<div class="wpicp-admin-notice">
<p><?php _e('提醒您尚未设置ICP备案号。根据中国法律网站需要进行ICP备案。', 'wpicp'); ?> <a href="<?php echo admin_url('admin.php?page=wpicp'); ?>"><?php _e('立即设置', 'wpicp'); ?></a></p>
<button class="wpicp-notice-dismiss"><?php _e('忽略', 'wpicp'); ?></button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var dismissButton = document.querySelector('.wpicp-notice-dismiss');
if(dismissButton) {
dismissButton.addEventListener('click', function() {
var notice = this.parentNode;
notice.style.display = 'none';
document.cookie = 'wpicp_notice_dismissed=1; path=/; max-age=86400';
});
}
});
</script>
<style>
.wpicp-admin-notice {
background-color: #f8d7da;
color: #721c24;
padding: 10px 15px;
border-left: 4px solid #f5c6cb;
margin: 10px 0;
position: fixed;
bottom: 20px;
right: 20px;
z-index: 9999;
max-width: 300px;
}
.wpicp-notice-dismiss {
background: none;
border: none;
color: #721c24;
cursor: pointer;
float: right;
font-size: 16px;
}
</style>
<?php
}
}
// 验证方式是API调用验证
if(isset($options['verification_method']) && $options['verification_method'] == 'api' && !empty($options['icp_number']) && !empty($options['api_key'])) {
require_once WPICP_PLUGIN_DIR . 'includes/class-wpicp-core.php';
$core = new WPICP_Core();
$core->verify_icp_status();
}
}
}

236
readme.txt Normal file
View file

@ -0,0 +1,236 @@
=== wpban Pro ===
Contributors: wpban
Tags: security, firewall, ban, geo-blocking, rate-limiting, crawler-blocking, brute-force, ip-blocking
Requires at least: 6.7.2
Tested up to: 6.7.2
Stable tag: 5.0
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Advanced WordPress security plugin with geo-blocking, rate limiting, AI crawler blocking, and intelligent threat detection.
== Description ==
wpban Pro is a comprehensive security solution for WordPress that protects your site from various threats including malicious bots, brute force attacks, content scrapers, and unauthorized access attempts.
= Key Features =
**🛡️ IP Management**
* Ban IPs with wildcard support (e.g., 192.168.*.*)
* IP range blocking (CIDR and range notation)
* Whitelist trusted IPs
* Automatic reverse proxy detection
**🌍 Geographic Blocking**
* Block or allow specific countries
* Real-time IP geolocation
* Cached country lookups for performance
* Whitelist/blacklist modes
**⚡ Rate Limiting**
* Protect against DDoS and flood attacks
* Separate limits for general requests, login attempts, and API calls
* Automatic temporary bans for violators
* Customizable thresholds
**🤖 Crawler Control**
* Block 40+ AI crawlers (GPTBot, ClaudeBot, etc.)
* Control SEO crawler access
* Protect content from AI training datasets
* robots.txt integration
**📊 Advanced Logging**
* Detailed security event logs
* Filter by date, action, IP, or country
* Export logs to CSV
* Automatic log rotation
**📧 Email Notifications**
* Real-time security alerts
* Customizable alert thresholds
* Multiple event types
* Test email functionality
**🚪 Login Protection**
* Restrict wp-login.php access by IP
* Brute force detection
* Failed login tracking
* Emergency bypass URL
**🎯 Security Templates**
* Quick setup with pre-configured templates
* Basic, Strict, Content Protection, and Performance modes
* One-click application
* Customizable settings
**🔧 Additional Features**
* Browser restrictions (block WeChat/QQ)
* User agent filtering
* Referer blocking
* Host-based banning
* Import/export settings
* Database optimization tools
= Performance Optimized =
* Smart caching system
* Optimized database queries with indexes
* Minimal performance impact
* Lazy loading of features
= Emergency Access =
Never get locked out! WPBan provides an emergency bypass URL that allows you to access your site even if your IP gets banned accidentally.
== Installation ==
1. Upload the `wpban` folder to `/wp-content/plugins/`
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Go to 'WPBan Security' in your admin menu
4. Choose a security template or configure settings manually
5. Save your emergency bypass URL in a safe place
= Minimum Requirements =
* WordPress 6.7.2 or higher
* PHP 7.4 or higher
* MySQL 5.7 or higher
== Frequently Asked Questions ==
= Will this plugin slow down my website? =
No. WPBan is designed with performance in mind. It uses intelligent caching, optimized database queries, and only loads features when needed.
= What happens if I accidentally ban myself? =
Use the emergency bypass URL provided in the dashboard. This special URL allows you to access your site and disable the ban. Always save this URL in a secure location.
= Can I block entire countries? =
Yes! WPBan includes geographic blocking that allows you to block or exclusively allow specific countries. The plugin uses free IP geolocation services for this feature.
= Will blocking SEO crawlers hurt my rankings? =
Yes, blocking major search engine crawlers (Googlebot, Bingbot) will negatively impact your SEO. The plugin shows warnings for these critical crawlers. Only block SEO crawlers if you have a specific reason.
= How do I protect against AI content scraping? =
Use the "Content Protection" template which blocks major AI crawlers, or manually select AI crawlers to block in the Crawlers settings. The plugin blocks access and adds robots.txt rules.
= Can I import/export settings? =
Yes! Go to Tools > Import/Export to backup your settings or migrate them to another site.
= How long are logs kept? =
Logs are automatically cleaned after 30 days to prevent database bloat. You can export logs before they're deleted or manually clear them at any time.
= Does it work with Cloudflare? =
Yes! Enable the "Reverse Proxy" option in General settings to properly detect visitor IPs when using Cloudflare or other proxy services.
== Screenshots ==
1. Dashboard - Overview of security statistics and quick actions
2. Security Templates - One-click security configurations
3. IP Rules - Manage banned IPs, ranges, and whitelists
4. Rate Limiting - Configure request limits
5. Geographic Blocking - Block or allow countries
6. Crawler Management - Control bot access
7. Security Logs - Detailed event tracking
8. Email Notifications - Real-time alerts
== Changelog ==
= 5.0 =
* Added geographic blocking with real-time IP geolocation
* Implemented advanced rate limiting system
* Added email notifications for security events
* Improved logging with country tracking and pagination
* Added import/export functionality
* Optimized database performance with indexes
* Added emergency bypass URL feature
* Improved UI with WordPress native design
* Added security templates for quick setup
* Fixed array structure issue in templates
= 4.0 =
* Complete rewrite with improved architecture
* Added caching system
* Enhanced performance
* Better code organization
= 3.3 =
* Initial public release
* Basic IP blocking functionality
* Crawler blocking
* Simple logging
== Upgrade Notice ==
= 5.0 =
Major update with geographic blocking, rate limiting, and email notifications. Backup your settings before upgrading.
== Advanced Usage ==
= Custom Templates =
You can create custom security templates by hooking into the `wpban_templates` filter:
`
add_filter('wpban_templates', function($templates) {
$templates['custom'] = [
'name' => 'My Custom Template',
'description' => 'Custom security configuration',
'settings' => [
'banned_ips' => ['1.2.3.4'],
'rate_limits' => [
'requests_per_minute' => 45
]
]
];
return $templates;
});
`
= Custom Country Detection =
Integrate with premium GeoIP services:
`
add_filter('wpban_ip_country', function($country, $ip) {
// Your custom country detection logic
return $detected_country;
}, 10, 2);
`
= Whitelist Specific Pages =
Exclude certain pages from security checks:
`
add_filter('wpban_skip_checks', function($skip) {
if (is_page('special-page')) {
return true;
}
return $skip;
});
`
== Support ==
For support, feature requests, or bug reports, please visit our [support forum](https://wordpress.org/support/plugin/wpban/) or [GitHub repository](https://github.com/wpban/wpban).
== Privacy Policy ==
This plugin stores:
* Security logs containing IP addresses, user agents, and geographic data
* Your security configuration settings
This plugin may connect to external services:
* IP geolocation APIs (ip-api.com, ipinfo.io) for country detection
* These services only receive IP addresses for lookup
All data is stored locally in your WordPress database and is not shared with third parties.

341
style.css Normal file
View file

@ -0,0 +1,341 @@
/**
* WPICP - WordPress ICP备案插件样式
*/
/* 通用样式 */
.wpicp-footer,
.wpicp-widget,
.wpicp-shortcode {
font-size: 12px;
line-height: 1.5;
margin: 10px 0;
text-align: center;
padding: 5px;
}
.wpicp-footer a,
.wpicp-widget a,
.wpicp-shortcode a {
text-decoration: none;
color: #666;
}
/* 默认样式 */
.wpicp-style-default {
font-family: Arial, sans-serif;
}
.wpicp-style-default .wpicp-icp a {
position: relative;
display: inline-block;
padding-left: 20px;
}
.wpicp-style-default .wpicp-icp a:before {
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 16px;
height: 16px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23666"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1h-6v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>');
background-size: contain;
background-repeat: no-repeat;
}
.wpicp-style-default .wpicp-police a {
position: relative;
display: inline-block;
padding-left: 20px;
}
.wpicp-style-default .wpicp-police a:before {
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 16px;
height: 16px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23666"><path d="M12 1L3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4zm0 10.99h7c-.53 4.12-3.28 7.79-7 8.94V12H5V6.3l7-3.11v8.8z"/></svg>');
background-size: contain;
background-repeat: no-repeat;
}
/* 简洁样式 */
.wpicp-style-simple {
border-top: 1px solid #eee;
padding-top: 10px;
color: #999;
}
.wpicp-style-simple a {
color: #999;
}
/* 深色样式 */
.wpicp-style-dark {
background-color: #333;
color: #fff;
padding: 10px;
}
.wpicp-style-dark a {
color: #fff;
}
/* 管理页面样式 */
.wpicp-admin-info {
background-color: #f9f9f9;
border-left: 4px solid #0073aa;
box-shadow: 0 1px 1px rgba(0,0,0,.04);
margin: 20px 0;
padding: 15px;
}
.wpicp-admin-info h2 {
margin-top: 0;
}
.wpicp-admin-form,
.wpicp-admin-records,
.wpicp-export-tools,
.wpicp-admin-tools,
.wpicp-check-results,
.wpicp-admin-history,
.wpicp-tool-box,
.wpicp-province-selection,
.wpicp-province-guide,
.wpicp-general-guide,
.wpicp-faq-list {
margin: 20px 0;
padding: 15px;
background-color: #fff;
border: 1px solid #ccd0d4;
box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.wpicp-tool-box {
display: inline-block;
vertical-align: top;
margin-right: 20px;
min-width: 250px;
}
.wpicp-export-tools {
margin-top: 20px;
}
.wpicp-check-results {
margin-top: 20px;
}
.wpicp-check-summary {
background-color: #f9f9f9;
padding: 15px;
margin-top: 20px;
border: 1px solid #ccd0d4;
}
/* 新增 - 状态摘要样式 */
.wpicp-status-summary {
padding: 15px;
border-radius: 3px;
margin: 20px 0;
}
.wpicp-status-summary-success {
background-color: #d4edda;
border: 1px solid #c3e6cb;
color: #155724;
}
.wpicp-status-summary-warning {
background-color: #fff3cd;
border: 1px solid #ffeeba;
color: #856404;
}
.wpicp-status-summary-error {
background-color: #f8d7da;
border: 1px solid #f5c6cb;
color: #721c24;
}
.wpicp-status-message {
font-size: 16px;
font-weight: 500;
margin-bottom: 15px;
}
.wpicp-status-details {
width: 100%;
border-collapse: collapse;
margin-bottom: 15px;
}
.wpicp-status-details th,
.wpicp-status-details td {
padding: 8px;
text-align: left;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
.wpicp-status-details th {
width: 30%;
}
.wpicp-status-actions {
margin-top: 15px;
}
/* 新增 - 状态指示器样式 */
.wpicp-status {
display: inline-block;
padding: 3px 8px;
border-radius: 3px;
font-size: 12px;
font-weight: 600;
}
.wpicp-status-success {
background-color: #d4edda;
color: #155724;
}
.wpicp-status-error {
background-color: #f8d7da;
color: #721c24;
}
.wpicp-status-warning {
background-color: #fff3cd;
color: #856404;
}
.wpicp-status-pending {
background-color: #d1ecf1;
color: #0c5460;
}
/* 新增 - 敏感词级别指示器 */
.wpicp-level {
display: inline-block;
padding: 2px 6px;
border-radius: 3px;
font-size: 12px;
font-weight: 600;
}
.wpicp-level-low {
background-color: #d4edda;
color: #155724;
}
.wpicp-level-medium {
background-color: #fff3cd;
color: #856404;
}
.wpicp-level-high {
background-color: #f8d7da;
color: #721c24;
}
/* 新增 - 省份列表 */
.wpicp-province-list {
display: flex;
flex-wrap: wrap;
list-style: none;
padding: 0;
margin: 0;
}
.wpicp-province-list li {
margin: 5px;
}
/* 新增 - 备案指南步骤 */
.wpicp-guide-step {
margin-bottom: 20px;
padding: 15px;
background-color: #f9f9f9;
border-left: 4px solid #0073aa;
}
.wpicp-guide-step h3 {
margin-top: 0;
color: #0073aa;
}
.wpicp-guide-notes {
margin-top: 20px;
padding: 15px;
background-color: #fff3cd;
border-left: 4px solid #ffeeba;
}
.wpicp-useful-links {
margin-top: 20px;
}
/* 新增 - FAQ样式 */
.wpicp-faq-item {
margin-bottom: 20px;
border-bottom: 1px solid #eee;
padding-bottom: 15px;
}
.wpicp-faq-question {
background-color: #f9f9f9;
padding: 10px 15px;
cursor: pointer;
margin: 0;
}
.wpicp-faq-question:before {
content: "Q: ";
font-weight: bold;
color: #0073aa;
}
.wpicp-faq-answer {
padding: 15px;
background-color: #fff;
}
.wpicp-faq-answer:before {
content: "A: ";
font-weight: bold;
color: #28a745;
}
.wpicp-more-help {
margin-top: 30px;
padding: 15px;
background-color: #f9f9f9;
}
/* 响应式样式 */
@media screen and (max-width: 782px) {
.wpicp-admin-form,
.wpicp-admin-records,
.wpicp-export-tools,
.wpicp-admin-tools,
.wpicp-check-results,
.wpicp-tool-box {
padding: 10px;
}
.wpicp-tool-box {
display: block;
width: 100%;
margin-right: 0;
margin-bottom: 15px;
}
.wpicp-status-details th {
width: 40%;
}
}

65
uninstall.php Normal file
View file

@ -0,0 +1,65 @@
<?php
/**
* 在插件卸载时执行的操作
*
* @package WPICP
*/
// 如果未通过WordPress调用卸载则退出
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
// 删除插件选项
delete_option('wpicp_options');
delete_option('wpicp_last_scheduled_check');
delete_option('wpicp_last_check_results');
// 删除所有临时选项
delete_transient('wpicp_sensitive_words');
delete_transient('wpicp_verification_result');
delete_transient('wpicp_admin_notice_dismissed');
// 删除任何以wpicp_开头的选项
global $wpdb;
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'wpicp_%'");
// 删除插件创建的表
$tables = array(
'wpicp_records',
'wpicp_sensitive_words',
'wpicp_real_name_info',
'wpicp_record_history',
'wpicp_status'
);
foreach($tables as $table) {
$wpdb->query("DROP TABLE IF EXISTS " . $wpdb->prefix . $table);
}
// 清除用户元数据
$wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'wpicp_%'");
// 清除评论元数据
$wpdb->query("DELETE FROM $wpdb->commentmeta WHERE meta_key LIKE 'wpicp_%'");
// 清除已计划的事件
wp_clear_scheduled_hook('wpicp_daily_verification');
wp_clear_scheduled_hook('wpicp_daily_status_check');
// 删除上传的文件
$upload_dir = wp_upload_dir();
$verification_dir = $upload_dir['basedir'] . '/wpicp-verification/';
if(file_exists($verification_dir)) {
// 删除目录中的所有文件
$files = glob($verification_dir . '*');
foreach($files as $file) {
if(is_file($file)) {
unlink($file);
}
}
// 删除目录
rmdir($verification_dir);
}

106
wpicp.php Normal file
View file

@ -0,0 +1,106 @@
<?php
/**
* Plugin Name: WPICP - WordPress ICP备案插件
* Plugin URI: https://example.com/wpicp
* Description: 帮助中国WordPress站点进行ICP备案管理和显示的插件
* Version: 1.0.0
* Author: WordPress开发者
* Author URI: https://example.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wpicp
* Domain Path: /languages
*/
// 如果直接访问此文件,则退出
if (!defined('WPINC')) {
die;
}
// 定义插件版本
define('WPICP_VERSION', '1.0.0');
// 定义插件目录
define('WPICP_PLUGIN_DIR', plugin_dir_path(__FILE__));
// 定义插件URL
define('WPICP_PLUGIN_URL', plugin_dir_url(__FILE__));
/**
* 插件激活函数
*/
function activate_wpicp() {
require_once WPICP_PLUGIN_DIR . 'includes/class-wpicp-core.php';
$core = new WPICP_Core();
$core->create_database_tables();
// 添加默认选项
$default_options = array(
'icp_number' => '',
'display_location' => 'footer',
'display_style' => 'default',
'verification_method' => 'manual',
'api_key' => '',
'custom_link' => 'https://beian.miit.gov.cn/',
'enable_sensitive_check' => 'no',
// 新增选项
'police_number' => '',
'police_link' => 'http://www.beian.gov.cn/',
'status_notification' => 'yes',
'verification_api_provider' => 'none',
'verification_api_key' => '',
'beian_query_method' => 'manual',
'beian_query_api_key' => '',
'check_on_publish' => 'no',
'scheduled_check' => 'no'
);
add_option('wpicp_options', $default_options);
}
register_activation_hook(__FILE__, 'activate_wpicp');
/**
* 插件停用函数
*/
function deactivate_wpicp() {
// 停用时的操作
flush_rewrite_rules();
// 清除计划任务
wp_clear_scheduled_hook('wpicp_daily_status_check');
wp_clear_scheduled_hook('wpicp_weekly_compliance_check');
}
register_deactivation_hook(__FILE__, 'deactivate_wpicp');
/**
* 加载插件文本域
*/
function wpicp_load_textdomain() {
load_plugin_textdomain('wpicp', false, dirname(plugin_basename(__FILE__)) . '/languages/');
}
add_action('plugins_loaded', 'wpicp_load_textdomain');
/**
* 加载插件组件
*/
require_once WPICP_PLUGIN_DIR . 'includes/class-wpicp-core.php';
require_once WPICP_PLUGIN_DIR . 'admin/class-wpicp-admin.php';
require_once WPICP_PLUGIN_DIR . 'public/class-wpicp-public.php';
/**
* 加载样式
*/
function wpicp_enqueue_styles() {
wp_enqueue_style('wpicp-style', WPICP_PLUGIN_URL . 'style.css', array(), WPICP_VERSION);
}
add_action('wp_enqueue_scripts', 'wpicp_enqueue_styles');
add_action('admin_enqueue_scripts', 'wpicp_enqueue_styles');
/**
* 初始化插件组件
*/
function run_wpicp() {
new WPICP_Admin();
new WPICP_Public(); // 这里使用WPICP_Public类名
}
add_action('plugins_loaded', 'run_wpicp');