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.
*