403)); } global $wpdb; $dwarpal_table_name = $wpdb->prefix . 'dwarpal_logs'; // Handle actions if (isset($_POST['dwarpal_action']) && check_admin_referer('dwarpal_log_action')) { $dwarpal_action = sanitize_text_field(wp_unslash($_POST['dwarpal_action'])); $dwarpal_log_id = isset($_POST['log_id']) ? absint(wp_unslash($_POST['log_id'])) : 0; $dwarpal_ip_address = isset($_POST['ip_address']) ? sanitize_text_field(wp_unslash($_POST['ip_address'])) : ''; switch ($dwarpal_action) { case 'block_ip': if ($dwarpal_ip_address) { $dwarpal_blocked_ips = get_option('dwarpal_blocked_ips', array()); if (!in_array($dwarpal_ip_address, $dwarpal_blocked_ips)) { $dwarpal_blocked_ips[] = $dwarpal_ip_address; update_option('dwarpal_blocked_ips', $dwarpal_blocked_ips); /* translators: %s: IP address */ echo '

' . sprintf(esc_html__('IP %s has been blocked.', 'dwarpal'), esc_html($dwarpal_ip_address)) . '

'; } } break; case 'whitelist_ip': if ($dwarpal_ip_address) { $dwarpal_whitelisted_ips = get_option('dwarpal_whitelisted_ips', array()); if (!in_array($dwarpal_ip_address, $dwarpal_whitelisted_ips)) { $dwarpal_whitelisted_ips[] = $dwarpal_ip_address; update_option('dwarpal_whitelisted_ips', $dwarpal_whitelisted_ips); /* translators: %s: IP address */ echo '

' . sprintf(esc_html__('IP %s has been whitelisted.', 'dwarpal'), esc_html($dwarpal_ip_address)) . '

'; } } break; case 'fix_seo_hack': // Trigger SEO protection fix do_action('dwarpal_fix_seo_hack', $dwarpal_log_id); echo '

' . esc_html__('SEO hack fix initiated.', 'dwarpal') . '

'; break; case 'delete_log': if ($dwarpal_log_id) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom security plugin tables. $wpdb->delete($dwarpal_table_name, array('id' => $dwarpal_log_id), array('%d')); echo '

' . esc_html__('Log entry deleted.', 'dwarpal') . '

'; } break; } } // Handle log deletion if (isset($_POST['dwarpal_delete_logs']) && check_admin_referer('dwarpal_delete_logs')) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Custom security plugin tables. $wpdb->query("TRUNCATE TABLE " . esc_sql($dwarpal_table_name)); echo '

' . esc_html__('Logs deleted.', 'dwarpal') . '

'; } // Pagination $per_page = 50; $dwarpal_current_page = isset($_GET['paged']) ? absint(wp_unslash($_GET['paged'])) : 1; $dwarpal_current_page = max(1, min(10, $dwarpal_current_page)); $dwarpal_offset = ($dwarpal_current_page - 1) * $per_page; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Custom security plugin tables. $dwarpal_total_logs = min(500, Dwarpal_Install::estimated_rows($dwarpal_table_name)); $dwarpal_total_pages = max(1, (int) ceil($dwarpal_total_logs / $per_page)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom security plugin tables. $dwarpal_logs = $wpdb->get_results( $wpdb->prepare( "SELECT id, event_type, ip_address, message, created_at FROM " . esc_sql($dwarpal_table_name) . " ORDER BY id DESC LIMIT %d OFFSET %d", $per_page, $dwarpal_offset ), ARRAY_A ); // Get fix suggestions function dwarpal_get_fix_suggestions($event_type, $message) { $suggestions = array(); switch ($event_type) { case 'seo_hack_attempt': $suggestions[] = __('Enable SEO Protection auto-fix', 'dwarpal'); $suggestions[] = __('Review and revert suspicious content', 'dwarpal'); $suggestions[] = __('Check for compromised user accounts', 'dwarpal'); break; case 'failed_login': case 'brute_force_attempt': $suggestions[] = __('Block the IP address', 'dwarpal'); $suggestions[] = __('Enable two-factor authentication', 'dwarpal'); $suggestions[] = __('Review login security settings', 'dwarpal'); break; case 'firewall_block': $suggestions[] = __('Review firewall rules', 'dwarpal'); $suggestions[] = __('Check if IP should be whitelisted', 'dwarpal'); break; case 'malware_detected': $suggestions[] = __('Run full malware scan', 'dwarpal'); $suggestions[] = __('Quarantine infected files', 'dwarpal'); $suggestions[] = __('Review file integrity', 'dwarpal'); break; } return $suggestions; } $dwarpal_page_title = __('Security Logs', 'dwarpal'); $dwarpal_page_subtitle = __('View and manage firewall blocks, failed logins, SEO hack attempts and other security events.', 'dwarpal'); ?>
80 ? substr($dwarpal_log['message'], 0, 80) . '…' : $dwarpal_log['message']); ?>
1) : ?>
add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => $dwarpal_total_pages, 'current' => $dwarpal_current_page, )); ?>