refactor(admin): consolidate duplicate configuration

Remove duplicate comment, captcha, filing, and website-security configuration paths.

Move front submission verification to the captcha scene matrix and retire obsolete admin routes and components.
This commit is contained in:
2026-08-13 02:26:17 +08:00
parent 0752a2fbf6
commit ab70a5eae9
32 changed files with 86 additions and 912 deletions
-154
View File
@@ -36,27 +36,6 @@ class ExtensionController extends ControllerBase {
'permission_callback' => [$this, 'check_permission'],
]);
// Security settings summary
register_rest_route(self::API_NAMESPACE, '/settings/security', [
'methods' => 'GET',
'callback' => [$this, 'get_security_settings'],
'permission_callback' => [$this, 'check_permission'],
]);
// Security settings — save risk switches
register_rest_route(self::API_NAMESPACE, '/settings/security', [
'methods' => 'POST',
'callback' => [$this, 'save_security_settings'],
'permission_callback' => [$this, 'check_permission'],
]);
// Security audit log
register_rest_route(self::API_NAMESPACE, '/security/audit-log', [
'methods' => 'GET',
'callback' => [$this, 'get_audit_log'],
'permission_callback' => [$this, 'check_permission'],
]);
// IP geo test tool
register_rest_route(self::API_NAMESPACE, '/extensions/ip-test', [
'methods' => 'POST',
@@ -151,139 +130,6 @@ class ExtensionController extends ControllerBase {
]);
}
/**
* GET /settings/security — security settings summary with real service status.
*/
public function get_security_settings(): \WP_REST_Response {
$services = $this->collect_service_statuses();
$settings = \AKSRT\Settings\Settings::get_all();
$email_gate_enabled = true;
if (defined('AKSRT_NO_EMAIL_GATE') && AKSRT_NO_EMAIL_GATE) {
$email_gate_enabled = false;
}
$captcha = function_exists('aksrt_get_captcha_status_summary')
? aksrt_get_captcha_status_summary()
: ['enabled' => false, 'provider' => '', 'configured' => false, 'scenes' => []];
$features = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_cms_features() : [];
$scenes = is_array($captcha['scenes'] ?? null) ? $captcha['scenes'] : [];
$risk_switches = [
'show_unapproved_comments' => !empty($settings['show_unapproved_comments']),
'skip_submit_moderation' => !empty($settings['skip_submit_moderation']),
'guest_comment' => !empty($settings['guest_comment']),
];
return $this->success([
'data' => [
'email_gate_enabled' => $email_gate_enabled,
'captcha' => [
'enabled' => !empty($captcha['enabled']),
'provider' => (string) ($captcha['provider'] ?? ''),
'configured' => !empty($captcha['configured']),
'scenes' => $scenes,
'download_required' => !empty($scenes['download']),
'download_active' => !empty($scenes['download']),
],
'content_audit' => [
'enabled' => !empty($services['audit']['enabled']),
'configured' => !empty($services['audit']['configured']),
],
'ip_geo' => [
'enabled' => !empty($services['ip_geo']['enabled']),
'configured' => !empty($services['ip_geo']['configured']),
],
'risk_switches' => $risk_switches,
'services' => $services,
],
]);
}
/**
* POST /settings/security — save risk switches.
*/
public function save_security_settings(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$risk_switches = $params['risk_switches'] ?? [];
if (!is_array($risk_switches)) {
return $this->error('无效的风险设置数据');
}
$allowed = [
'show_unapproved_comments' => 'bool',
'skip_submit_moderation' => 'bool',
'guest_comment' => 'bool',
];
$sanitized = $this->sanitize_fields($risk_switches, $allowed);
// Merge into main settings
$all = \AKSRT\Settings\Settings::get_all();
foreach ($sanitized as $key => $val) {
$all[$key] = $val;
}
update_option('aksrt_settings', $all);
return $this->success([
'message' => __('风险设置已保存', 'aksrt'),
'data' => $sanitized,
]);
}
/**
* GET /security/audit-log — recent security audit entries.
*/
public function get_audit_log(): \WP_REST_Response {
global $wpdb;
$limit = 20;
$logs = [];
// Recent user registrations
$recent_users = get_users([
'number' => $limit,
'orderby' => 'registered',
'order' => 'DESC',
'fields' => ['ID', 'display_name', 'user_email', 'user_registered'],
]);
foreach ($recent_users as $user) {
$logs[] = [
'id' => 'reg_' . $user->ID,
'action' => '用户注册',
'detail' => sprintf('%s (%s) 完成注册', $user->display_name, $user->user_email),
'time' => $user->user_registered,
'type' => 'auth',
];
}
// Content audit log
$audit_log = get_option('aksrt_content_audit_log', []);
foreach (array_slice(array_reverse($audit_log), 0, 10) as $i => $entry) {
$logs[] = [
'id' => 'audit_' . $i,
'action' => '内容审核',
'detail' => sprintf('%s — %s', $entry['content'] ?? '', ($entry['passed'] ?? false) ? '通过' : '拦截'),
'time' => $entry['time'] ?? '',
'type' => 'audit',
];
}
// Sort by time descending
usort($logs, function ($a, $b) {
return strcmp($b['time'] ?? '', $a['time'] ?? '');
});
return $this->success([
'data' => [
'logs' => array_slice($logs, 0, $limit),
],
]);
}
/**
* POST /extensions/ip-test — test current IP provider with a given IP.
*
+1 -3
View File
@@ -20,14 +20,12 @@ class GlobalSchema {
'version' => '1.0.0',
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'comment', 'title' => '评论功能', 'fields' => [
['key' => 'comment_enabled', 'label' => '开启评论', 'type' => 'switch', 'default' => true],
]],
['key' => 'performance', 'title' => '性能优化', 'fields' => [
['key' => 'lazyload_enabled', 'label' => '图片懒加载', 'type' => 'switch', 'default' => true],
]],
['key' => 'filing', 'title' => '备案信息', 'fields' => [
['key' => 'icp_filing', 'label' => 'ICP 备案号', 'type' => 'input', 'default' => ''],
['key' => 'police_filing', 'label' => '公安备案号', 'type' => 'input', 'default' => ''],
['key' => 'footer_text', 'label' => '页脚附加文字', 'type' => 'input', 'default' => ''],
]],
],
-1
View File
@@ -17,7 +17,6 @@ class SchemaExtensions {
'ip' => SchemaExtensionsIP::build(),
'audit' => SchemaExtensionsAudit::build(),
'push' => SchemaExtensionsPush::build(),
'security' => SchemaExtensionsSecurity::build(),
],
];
}
@@ -1,88 +0,0 @@
<?php
/**
* @package AKSRT
*/
namespace AKSRT\Admin\Schema;
defined('ABSPATH') || exit;
class SchemaExtensionsSecurity {
public static function build(): array {
return [
'key' => 'security',
'title' => '网站安全',
'version' => '1.0.0',
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'basic', 'title' => '基础安全', 'fields' => [
['key' => 'hide_admin_bar', 'label' => '前台关闭顶部 admin_bar', 'type' => 'switch', 'default' => true],
['key' => 'remove_emoji', 'label' => '移除Emoji脚本', 'type' => 'switch', 'default' => true],
['key' => 'remove_open_sans', 'label' => '移除Open Sans字体', 'type' => 'switch', 'default' => true],
['key' => 'disabled_pingback', 'label' => '禁用Pingback', 'type' => 'switch', 'default' => true],
['key' => 'disabled_xmlrpc', 'label' => '禁用XML-RPC', 'type' => 'switch', 'default' => true],
['key' => 'close_attachment_page', 'label' => '关闭附件页面', 'type' => 'switch', 'default' => true],
['key' => 'user_disable_admin', 'label' => '非管理员禁止进入后台', 'type' => 'switch', 'default' => true],
]],
['key' => 'upload', 'title' => '上传设置', 'fields' => [
['key' => 'split_upload_s', 'label' => '分片上传', 'type' => 'switch', 'default' => true],
['key' => 'split_minimum_size', 'label' => '最小分片大小(MB)', 'type' => 'number', 'default' => 20, 'min' => 4, 'max' => 100, 'step' => 2],
['key' => 'newfilename', 'label' => '上传文件自动重命名', 'type' => 'switch', 'default' => false],
['key' => 'newfilename_type', 'label' => '重命名格式', 'type' => 'radio', 'default' => 'time', 'options' => [
['label' => '随机字符串', 'value' => 'random'],
['label' => '时间+原文件名', 'value' => 'time'],
]],
['key' => 'disabled_large_thumbnail', 'label' => '禁用大缩略图', 'type' => 'switch', 'default' => true],
]],
['key' => 'admin', 'title' => '后台设置', 'fields' => [
['key' => 'remove_dashboard_widgets', 'label' => 'WP 后台加速:移除站点健康/活动/禁止浏览器&PHP版本检测', 'type' => 'switch', 'default' => true],
['key' => 'display_wp_update', 'label' => '禁止 WP 检测更新', 'type' => 'switch', 'default' => true],
['key' => 'close_gutenberg', 'label' => '关闭古腾堡编辑器', 'type' => 'switch', 'default' => false, 'help' => '禁用后编辑器增强全部失效'],
['key' => 'disabled_autoembed', 'label' => '禁用自动嵌入', 'type' => 'switch', 'default' => true],
['key' => 'mce_float_toolbar', 'label' => '浮动工具栏', 'type' => 'checkbox', 'default' => ['pc_s', 'm_s'], 'sanitize_type' => 'array', 'options' => [
['label' => 'PC', 'value' => 'pc_s'],
['label' => '移动端', 'value' => 'm_s'],
]],
['key' => 'admin_user_del_fields', 'label' => '关闭后台用户编辑多余选项', 'type' => 'switch', 'default' => true],
['key' => 'admin_frontend_set', 'label' => '前台设置入口', 'type' => 'switch', 'default' => true],
]],
['key' => 'format', 'title' => '格式设置', 'fields' => [
['key' => 'time_ago_s', 'label' => '时间格式', 'type' => 'switch', 'default' => true],
['key' => 'time_format', 'label' => '时间显示格式', 'type' => 'input', 'default' => 'n月j日 H:i'],
['key' => 'remove_more_wp_head', 'label' => '移除WP head多余代码', 'type' => 'switch', 'default' => true],
]],
['key' => 'captcha-note', 'title' => '人机验证', 'fields' => [
['key' => 'captcha_redirect_hint', 'label' => '配置入口', 'type' => 'notice', 'alertType' => 'info', 'alertContent' => '人机验证(腾讯云 / 阿里云 / Cloudflare / 极验)请到「功能&权限 → 人机验证」统一配置;本页不再维护验证码字段。'],
]],
['key' => 'rate-limit', 'title' => '频率限制', 'fields' => [
['key' => 'brush_limit_post_enabled', 'label' => '文章发布限制', 'type' => 'switch', 'default' => false],
['key' => 'brush_limit_post_minutes_10', 'label' => '文章 10 分钟限制', 'type' => 'number', 'default' => 20, 'min' => 1, 'max' => 200],
['key' => 'brush_limit_post_day_1', 'label' => '文章每日限制', 'type' => 'number', 'default' => 50, 'min' => 1, 'max' => 2000],
['key' => 'brush_limit_comment_enabled', 'label' => '评论频率限制', 'type' => 'switch', 'default' => false],
['key' => 'brush_limit_comment_minutes_10', 'label' => '评论 10 分钟限制', 'type' => 'number', 'default' => 20, 'min' => 1, 'max' => 200],
['key' => 'brush_limit_comment_day_1', 'label' => '评论每日限制', 'type' => 'number', 'default' => 100, 'min' => 1, 'max' => 2000],
['key' => 'brush_limit_upload_enabled', 'label' => '上传频率限制', 'type' => 'switch', 'default' => false],
['key' => 'brush_limit_upload_minutes_10', 'label' => '上传 10 分钟限制', 'type' => 'number', 'default' => 50, 'min' => 1, 'max' => 200],
['key' => 'brush_limit_upload_day_1', 'label' => '上传每日限制', 'type' => 'number', 'default' => 200, 'min' => 1, 'max' => 2000],
['key' => 'brush_limit_register_enabled', 'label' => '注册频率限制', 'type' => 'switch', 'default' => false],
['key' => 'brush_limit_register_minutes_10', 'label' => '注册 10 分钟限制', 'type' => 'number', 'default' => 20, 'min' => 1, 'max' => 200],
['key' => 'brush_limit_register_day_1', 'label' => '注册每日限制', 'type' => 'number', 'default' => 100, 'min' => 1, 'max' => 2000],
['key' => 'brush_limit_order_enabled', 'label' => '订单频率限制', 'type' => 'switch', 'default' => false],
['key' => 'brush_limit_order_minutes_10', 'label' => '订单 10 分钟限制', 'type' => 'number', 'default' => 30, 'min' => 1, 'max' => 200],
['key' => 'brush_limit_order_day_1', 'label' => '订单每日限制', 'type' => 'number', 'default' => 100, 'min' => 1, 'max' => 2000],
['key' => 'error_frequency_limit', 'label' => '错误频率限制', 'type' => 'switch', 'default' => true],
]],
['key' => 'content-audit', 'title' => '内容审核', 'fields' => [
['key' => 'audit_comment', 'label' => '审核评论', 'type' => 'switch', 'default' => false],
['key' => 'audit_new_post', 'label' => '审核新文章', 'type' => 'switch', 'default' => false],
['key' => 'audit_upload_img', 'label' => '审核上传图片', 'type' => 'switch', 'default' => false],
['key' => 'audit_user_desc', 'label' => '审核用户简介', 'type' => 'switch', 'default' => false],
['key' => 'audit_msg_private', 'label' => '审核私信', 'type' => 'switch', 'default' => false],
['key' => 'audit_be_like_text', 'label' => '文本允许疑似合规', 'type' => 'switch', 'default' => false],
['key' => 'audit_be_like_img', 'label' => '图片允许疑似合规', 'type' => 'switch', 'default' => false],
]],
],
];
}
}
-2
View File
@@ -452,9 +452,7 @@ class SchemaPageDisplay {
['key' => 'footer_columns', 'label' => '页脚列数', 'type' => 'number', 'default' => 3, 'min' => 1, 'max' => 4],
['key' => 'footer_copyright', 'label' => '显示版权信息', 'type' => 'switch', 'default' => true],
['key' => 'footer_icp', 'label' => '显示ICP备案', 'type' => 'switch', 'default' => true],
['key' => 'icp_number', 'label' => 'ICP备案号', 'type' => 'input', 'default' => '', 'help' => '例如:ICP 备 xxxxxxxx 号'],
['key' => 'footer_police', 'label' => '显示公安备案', 'type' => 'switch', 'default' => true],
['key' => 'police_number', 'label' => '公安备案号', 'type' => 'input', 'default' => '', 'help' => '例如:公网安备 xxxxxx 号'],
]],
['key' => 'color', 'title' => '页脚颜色', 'fields' => [
['key' => 'footer_theme_custom', 'label' => '自定义页脚颜色', 'type' => 'switch', 'default' => false],
+1
View File
@@ -44,6 +44,7 @@ class SchemaPermissions {
['label' => '邮箱验证', 'value' => 'verify_email'],
['label' => '资源下载', 'value' => 'download'],
['label' => '每日签到', 'value' => 'signin'],
['label' => '前台投稿', 'value' => 'front_submit'],
]],
]],
['key' => 'providers', 'title' => '服务商配置', 'fields' => [
-1
View File
@@ -354,7 +354,6 @@ class SchemaPostList {
['key' => 'post_article_cat', 'label' => '允许投稿分类', 'type' => 'taxonomy_select', 'taxonomy' => 'category', 'multiple' => true, 'default' => [], 'help' => '为空则允许全部分类'],
['key' => 'front_submit_guest_enabled', 'label' => '允许免登录投稿', 'type' => 'switch', 'default' => false, 'help' => '开启后访客可投稿;文章归属到下方用户'],
['key' => 'post_article_user', 'label' => '免登录归属用户', 'type' => 'user_select', 'default' => 0, 'help' => '免登录投稿时文章归属的用户,搜索选择'],
['key' => 'front_submit_captcha', 'label' => '提交人机验证', 'type' => 'switch', 'default' => false, 'help' => '提交正式投稿时校验人机验证'],
['key' => 'front_submit_tags', 'label' => '标签输入', 'type' => 'switch', 'default' => true],
['key' => 'post_article_topics_s', 'label' => '专题选择', 'type' => 'switch', 'default' => false, 'help' => '投稿时可选择专题分类'],
['key' => 'post_article_custom_filter_s', 'label' => '高级筛选选择', 'type' => 'switch', 'default' => true, 'help' => '投稿时可选择自定义筛选维度值'],
+10 -21
View File
@@ -306,10 +306,10 @@ class SchemaProvider {
}
}
// Captcha: always surface normalized enabled_scenarios (legacy disabled list inverted).
if ($option_key === 'aksrt_captcha_config' && function_exists('aksrt_get_captcha_config')) {
$normalized = aksrt_get_captcha_config();
foreach (['enabled', 'active_provider', 'enabled_scenarios', 'disabled_scenarios', 'tencent', 'aliyun', 'cloudflare', 'geetest', 'mode'] as $key) {
// Captcha: always surface the normalized positive scene list.
if ($option_key === 'aksrt_captcha_config' && function_exists('aksrt_get_captcha_config')) {
$normalized = aksrt_get_captcha_config();
foreach (['enabled', 'active_provider', 'enabled_scenarios', 'tencent', 'aliyun', 'cloudflare', 'geetest', 'mode'] as $key) {
if (array_key_exists($key, $normalized)) {
$data[$key] = $normalized[$key];
}
@@ -340,23 +340,12 @@ class SchemaProvider {
unset($stored['pay_rebate_withdraw_text_details'], $stored['pay_balance_withdraw_lowest_money']);
}
// Captcha: keep enabled_scenarios / disabled_scenarios mirrors in sync.
if ($option_key === 'aksrt_captcha_config' && function_exists('aksrt_captcha_scenes')) {
$all = array_keys(aksrt_captcha_scenes());
if (array_key_exists('enabled_scenarios', $stored)) {
$enabled = function_exists('aksrt_captcha_sanitize_scene_list')
? aksrt_captcha_sanitize_scene_list($stored['enabled_scenarios'])
: (array) $stored['enabled_scenarios'];
$stored['enabled_scenarios'] = $enabled;
$stored['disabled_scenarios'] = array_values(array_diff($all, $enabled));
} elseif (array_key_exists('disabled_scenarios', $stored)) {
$disabled = function_exists('aksrt_captcha_sanitize_scene_list')
? aksrt_captcha_sanitize_scene_list($stored['disabled_scenarios'])
: (array) $stored['disabled_scenarios'];
$stored['disabled_scenarios'] = $disabled;
$stored['enabled_scenarios'] = array_values(array_diff($all, $disabled));
}
}
// Captcha stores a single positive scene list.
if ($option_key === 'aksrt_captcha_config' && function_exists('aksrt_captcha_scenes')) {
$stored['enabled_scenarios'] = function_exists('aksrt_captcha_sanitize_scene_list')
? aksrt_captcha_sanitize_scene_list($stored['enabled_scenarios'] ?? [])
: (array) ($stored['enabled_scenarios'] ?? []);
}
$updated = update_option($option_key, $stored);
\AKSRT\Settings\Settings::flush_settings_cache();