plugin_name = $plugin_name; $this->version = $version; } /** * The sections of the plugin: the top bar and the sidebar show the same list, * and a section with tabs shows them as a second row in the top bar. * 'server' tabs are separate requests (?tab=), 'client' tabs switch in the page (#tab). * * @since 1.2.0 * @return array */ public static function sections() { $s = array( 'dashboard' => array( 'slug' => self::DASHBOARD, 'top' => true, 'side' => true, 'label' => __( 'Dashboard', 'ai-guardwall' ), 'title' => __( 'Security dashboard', 'ai-guardwall' ), 'icon' => 'dashicons-dashboard', ), 'database' => array( 'slug' => self::DATABASE, 'top' => false, 'side' => true, 'label' => __( 'Database', 'ai-guardwall' ), 'title' => __( 'Database', 'ai-guardwall' ), 'icon' => 'dashicons-database', 'mode' => 'server', 'tabs' => array( 'optimize' => array( __( 'Optimizations', 'ai-guardwall' ), 'dashicons-performance', __( 'Clean revisions, spam, transients and orphaned data', 'ai-guardwall' ) ), 'tables' => array( __( 'Tables', 'ai-guardwall' ), 'dashicons-editor-table', __( 'Optimize tables and remove unused ones', 'ai-guardwall' ) ), 'settings' => array( __( 'Schedule & backups', 'ai-guardwall' ), 'dashicons-backup', __( 'Automatic cleaning and the backups taken first', 'ai-guardwall' ) ), ), ), 'cleanup' => array( 'slug' => self::CLEANUP, 'top' => true, 'side' => false, 'label' => __( 'Malware Cleanup', 'ai-guardwall' ), 'title' => __( 'Malware Cleanup', 'ai-guardwall' ), 'icon' => 'dashicons-search', 'mode' => 'server', // In the order a cleanup is done: connect the AI, check its instructions, scan, read the findings. 'tabs' => array( 'model' => array( __( 'AI model', 'ai-guardwall' ), 'dashicons-admin-site-alt3', __( 'Step 1: the AI that explains each finding', 'ai-guardwall' ) ), 'knowledge' => array( __( 'Knowledge', 'ai-guardwall' ), 'dashicons-welcome-learn-more', __( 'Step 2: the .md instructions it follows', 'ai-guardwall' ) ), 'scan' => array( __( 'Scan', 'ai-guardwall' ), 'dashicons-search', __( 'Step 3: scan the whole site', 'ai-guardwall' ) ), 'findings' => array( __( 'Findings', 'ai-guardwall' ), 'dashicons-warning', __( 'Step 4: what was found and how to fix it', 'ai-guardwall' ) ), 'scans' => array( __( 'Scan settings', 'ai-guardwall' ), 'dashicons-admin-generic', __( 'Schedule, scope and extra checks', 'ai-guardwall' ) ), ), // Numbered in the top bar, with a tick once done. 'steps' => array( 'model', 'knowledge', 'scan', 'findings' ), // The tabs that are settings forms (the others are pages of their own). 'forms' => array( 'model', 'knowledge', 'scans' ), ), 'security' => array( 'slug' => self::SECURITY, 'top' => true, 'side' => false, 'label' => __( 'Security Wall', 'ai-guardwall' ), 'title' => __( 'Security Wall', 'ai-guardwall' ), 'icon' => 'dashicons-shield-alt', 'mode' => 'client', // Grouped like All-In-One Security: dashboard, users, database, files, firewall, brute force, spam, then live traffic and tools. 'tabs' => array( 'hardening' => array( __( 'Dashboard', 'ai-guardwall' ), 'dashicons-dashboard', __( 'Security score, presets, every rule, locked IPs', 'ai-guardwall' ) ), 'usersec' => array( __( 'User security', 'ai-guardwall' ), 'dashicons-admin-users', __( 'Accounts, lockouts, sessions, 2FA, passkeys', 'ai-guardwall' ) ), 'dbsec' => array( __( 'Database security', 'ai-guardwall' ), 'dashicons-database', __( 'Table prefix and backups', 'ai-guardwall' ) ), 'filesec' => array( __( 'File security', 'ai-guardwall' ), 'dashicons-media-default', __( 'Permissions, file protection, logs, headers', 'ai-guardwall' ) ), 'firewall' => array( __( 'Firewall', 'ai-guardwall' ), 'dashicons-superhero-alt', __( 'Rules, bots, lists, countries, rate limits', 'ai-guardwall' ) ), 'bruteforce' => array( __( 'Brute force', 'ai-guardwall' ), 'dashicons-lock', __( 'Login page, CAPTCHA, whitelist, 404s, honeypot', 'ai-guardwall' ) ), 'spam' => array( __( 'Spam prevention', 'ai-guardwall' ), 'dashicons-feedback', __( 'Comment spam and registrations', 'ai-guardwall' ) ), 'traffic' => array( __( 'Live traffic', 'ai-guardwall' ), 'dashicons-chart-line', __( 'Visits, logins and attacks as they happen', 'ai-guardwall' ) ), 'tools' => array( __( 'Tools', 'ai-guardwall' ), 'dashicons-admin-tools', __( 'Password tool, WHOIS, .htaccess, emergency', 'ai-guardwall' ) ), ), ), 'tools' => array( 'slug' => self::TOOLS, 'top' => false, 'side' => true, 'label' => __( 'Tools', 'ai-guardwall' ), 'title' => __( 'Tools', 'ai-guardwall' ), 'icon' => 'dashicons-admin-tools', 'mode' => 'client', 'tabs' => self::tools_tabs(), 'form' => false, ), 'alerts' => array( 'slug' => self::ALERTS, 'top' => false, 'side' => true, 'label' => __( 'Alerts', 'ai-guardwall' ), 'title' => __( 'Alerts', 'ai-guardwall' ), 'icon' => 'dashicons-bell', 'mode' => 'client', 'tabs' => array( 'alerts' => array( __( 'Alerts', 'ai-guardwall' ), 'dashicons-bell', '' ) ), ), 'activity' => array( 'slug' => self::ACTIVITY, 'top' => false, 'side' => true, 'label' => __( 'Activity', 'ai-guardwall' ), 'title' => __( 'Activity log', 'ai-guardwall' ), 'icon' => 'dashicons-list-view', ), 'settings' => array( 'slug' => self::PAGE, 'top' => true, 'side' => true, 'label' => __( 'Settings', 'ai-guardwall' ), 'title' => __( 'AI GuardWall settings', 'ai-guardwall' ), 'icon' => 'dashicons-admin-generic', 'mode' => 'client', 'tabs' => array( 'advanced' => array( __( 'General', 'ai-guardwall' ), 'dashicons-admin-generic', __( 'Activity log, managers, data', 'ai-guardwall' ) ), 'backup' => array( __( 'Import / export', 'ai-guardwall' ), 'dashicons-migrate', __( 'Copy the settings to another site, or reset them', 'ai-guardwall' ) ), ), ), ); $s['pro'] = array( 'slug' => self::PRO, 'top' => true, 'side' => true, 'label' => __( 'Pro', 'ai-guardwall' ), 'title' => __( 'AI GuardWall Pro', 'ai-guardwall' ), 'icon' => 'dashicons-star-filled', ); /** * The sections of the AI GuardWall screens. * * @since 1.2.0 * @param array $s Sections keyed by id. */ return (array) apply_filters( 'svabg_admin_sections', $s ); } /** * Tools: the site features, the admin tools, and a tab for each feature that * has one and is on (the security tools live in Security Wall › Tools). */ private static function tools_tabs() { $tabs = array( 'features' => array( __( 'Site features', 'ai-guardwall' ), 'dashicons-forms', __( 'Switch the extra tools on or off', 'ai-guardwall' ) ), 'admin' => array( __( 'Admin tools', 'ai-guardwall' ), 'dashicons-admin-users', __( 'Roles, switch user, scheduled tasks, email', 'ai-guardwall' ) ), ); if ( Softvolt_Ai_Bodyguard_Modules::enabled( 'redirects' ) ) { $tabs['redirects'] = array( __( 'Redirects', 'ai-guardwall' ), 'dashicons-randomize', __( 'Old addresses and the 404 log', 'ai-guardwall' ) ); } if ( Softvolt_Ai_Bodyguard_Modules::enabled( 'links' ) ) { $tabs['links'] = array( __( 'Broken links', 'ai-guardwall' ), 'dashicons-editor-unlink', __( 'Links in your content that do not work', 'ai-guardwall' ) ); } $more = array( 'maintenance' => array( __( 'Maintenance', 'ai-guardwall' ), 'dashicons-hammer', __( 'Maintenance or coming-soon page', 'ai-guardwall' ) ), 'posttypes' => array( __( 'Post types', 'ai-guardwall' ), 'dashicons-layout', __( 'Custom post types and taxonomies', 'ai-guardwall' ) ), ); foreach ( $more as $id => $tab ) { if ( Softvolt_Ai_Bodyguard_Modules::enabled( $id ) ) { $tabs[ $id ] = $tab; } } return $tabs; } /** * The address of a section, optionally one of its tabs. * * @since 1.2.0 * @param string $section Section id (or a tab id of any section). * @param string $tab Tab id. * @param array $args Extra query arguments. * @return string */ public static function url( $section, $tab = '', $args = array() ) { $sections = self::sections(); if ( ! isset( $sections[ $section ] ) ) { foreach ( $sections as $id => $info ) { if ( ! empty( $info['tabs'] ) && isset( $info['tabs'][ $section ] ) ) { $tab = $section; $section = $id; break; } } } if ( ! isset( $sections[ $section ] ) ) { $section = 'dashboard'; } $info = $sections[ $section ]; $mode = isset( $info['mode'] ) ? $info['mode'] : ''; $q = array( 'page' => $info['slug'] ); if ( 'server' === $mode && '' !== $tab ) { $q['tab'] = $tab; } $url = add_query_arg( array_merge( $q, (array) $args ), admin_url( 'admin.php' ) ); if ( 'client' === $mode && '' !== $tab && count( $info['tabs'] ) > 1 ) { $url .= '#' . $tab; } return $url; } /** * Where a settings tab lives: Security Wall, Malware Cleanup, Tools, Alerts or Settings. * * @since 1.1.0 * @param string $tab Tab id. * @return string */ public static function tab_url( $tab ) { // A tab wins over a section of the same name ("tools" is the Security tools tab). foreach ( self::sections() as $id => $info ) { if ( 'database' !== $id && ! empty( $info['tabs'] ) && isset( $info['tabs'][ $tab ] ) ) { return self::url( $id, $tab ); } } return self::url( $tab ); } /** * The open tab of a 'server' section (Malware Cleanup). * * @since 1.2.0 * @param string $section Section. * @return string */ public static function current_tab( $section = 'cleanup' ) { $sections = self::sections(); if ( empty( $sections[ $section ]['tabs'] ) ) { return ''; } $tabs = $sections[ $section ]['tabs']; $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $tabs[ $tab ] ) ) { return $tab; } // Malware Cleanup opens on step 1 until an AI model is connected, then on the scan. if ( 'cleanup' === $section && isset( $tabs['scan'] ) && self::setup_state()['model'] ) { return 'scan'; } return (string) key( $tabs ); } /** * Where the owner is in the cleanup steps: AI model connected, instruction * files active, a scan finished. * * @since 1.4.0 * @return array model (bool), model_label, knowledge (int active files), scanned (bool) */ public static function setup_state() { static $state = null; if ( null !== $state ) { return $state; } $model = Softvolt_Ai_Bodyguard_Settings::is_configured(); $label = ''; if ( $model ) { $provider = (string) Softvolt_Ai_Bodyguard_Settings::get( 'provider' ); $info = 'custom' === $provider ? null : Softvolt_Ai_Bodyguard_Catalog::provider( $provider ); $label = Softvolt_Ai_Bodyguard_Claude::PROVIDER === $provider ? __( 'Claude Desktop (MCP)', 'ai-guardwall' ) : ( $info ? $info['name'] : __( 'Custom service', 'ai-guardwall' ) ) . ' · ' . Softvolt_Ai_Bodyguard_Settings::model(); } $files = 0; foreach ( Softvolt_Ai_Bodyguard_Knowledge::all() as $file ) { if ( ! empty( $file['active'] ) && in_array( $file['purpose'], array( 'malware', 'general' ), true ) ) { $files++; } } $state = array( 'model' => $model, 'model_label' => $label, 'knowledge' => $files, 'scanned' => (bool) Softvolt_Ai_Bodyguard_Scanner::last_scan(), ); return $state; } public function current_page( $hook_suffix = null ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( null === $hook_suffix ) { $hook_suffix = $screen ? $screen->id : ''; } $page = array_search( $hook_suffix, $this->hooks, true ); if ( false !== $page ) { return $page; } return (string) apply_filters( 'svabg_admin_page', '', (string) $hook_suffix ); } public function enqueue_styles( $hook_suffix ) { if ( '' === $this->current_page( $hook_suffix ) ) { return; } wp_enqueue_style( $this->plugin_name . '-admin', plugin_dir_url( __FILE__ ) . 'css/softvolt-ai-bodyguard-admin.css', array(), $this->version, 'all' ); } public function enqueue_scripts( $hook_suffix ) { $page = $this->current_page( $hook_suffix ); if ( '' === $page ) { return; } $deps = array( 'jquery', 'wp-api-fetch', 'wp-i18n' ); if ( 'tools' === $page && Softvolt_Ai_Bodyguard_Modules::enabled( 'maintenance' ) ) { wp_enqueue_media(); } wp_enqueue_script( $this->plugin_name . '-admin', plugin_dir_url( __FILE__ ) . 'js/softvolt-ai-bodyguard-admin.js', $deps, $this->version, array( 'in_footer' => true ) ); wp_set_script_translations( $this->plugin_name . '-admin', 'ai-guardwall', plugin_dir_path( SOFTVOLT_AI_BODYGUARD_FILE ) . 'languages' ); $data = $this->script_data(); wp_add_inline_script( $this->plugin_name . '-admin', 'window.svabgAdmin = ' . wp_json_encode( $data ) . ';', 'before' ); Softvolt_Ai_Bodyguard_Claude::enqueue( $this->plugin_name . '-admin' ); } private function script_data() { $providers = array(); foreach ( Softvolt_Ai_Bodyguard_Catalog::providers() as $id => $provider ) { $providers[ $id ] = array( 'name' => $provider['name'], 'group' => $provider['group'], 'defaultModel' => $provider['default_model'], 'models' => $provider['models'], 'live' => ! empty( $provider['live_models'] ), 'keyHint' => Softvolt_Ai_Bodyguard_Settings::secret_hint( 'key_' . $id ), 'pro' => false, ); } $providers['custom'] = array( 'name' => __( 'Other (OpenAI-compatible)', 'ai-guardwall' ), 'group' => 'custom', 'defaultModel' => '', 'models' => array(), 'live' => false, 'keyHint' => Softvolt_Ai_Bodyguard_Settings::secret_hint( 'key_custom' ), 'pro' => false, ); $presets = array(); foreach ( Softvolt_Ai_Bodyguard_Hardening::presets() as $key => $preset ) { $presets[ $key ] = $preset[2]; } return array( 'providers' => $providers, 'presets' => $presets, 'pro' => Softvolt_Ai_Bodyguard_Pro::is_active(), 'restPath' => '/' . Softvolt_Ai_Bodyguard_Rest::NS, 'page' => $this->current_page(), 'tab' => in_array( $this->current_page(), array( 'cleanup', 'database' ), true ) ? self::current_tab( $this->current_page() ) : '', 'edition' => Softvolt_Ai_Bodyguard_Pro::edition(), 'scanBudget' => (int) Softvolt_Ai_Bodyguard_Settings::get( 'scan_time_budget', 12 ), 'findingsUrl' => self::url( 'cleanup', 'findings' ), 'securityUrl' => self::url( 'security' ), // Settings tabs of 1.3 that moved to Malware Cleanup: old #links are sent on. 'movedTabs' => 'settings' === $this->current_page() ? array( 'model' => self::url( 'cleanup', 'model' ), 'knowledge' => self::url( 'cleanup', 'knowledge' ), 'scans' => self::url( 'cleanup', 'scans' ), ) : new stdClass(), 'maxUpload' => wp_max_upload_size(), 'updatesUrl' => admin_url( 'update-core.php' ), 'severities' => array( 'critical' => __( 'Critical', 'ai-guardwall' ), 'high' => __( 'High', 'ai-guardwall' ), 'medium' => __( 'Medium', 'ai-guardwall' ), 'low' => __( 'Low', 'ai-guardwall' ), 'info' => __( 'Info', 'ai-guardwall' ), ), 'verdicts' => array( 'confirmed' => __( 'Confirmed malware', 'ai-guardwall' ), 'suspicious' => __( 'Suspicious', 'ai-guardwall' ), 'confirmed_malware' => __( 'AI: confirmed malware', 'ai-guardwall' ), 'likely_legitimate' => __( 'AI: likely legitimate', 'ai-guardwall' ), 'needs_manual_review' => __( 'AI: needs manual review', 'ai-guardwall' ), ), 'i18n' => array( 'testing' => __( 'Testing…', 'ai-guardwall' ), 'working' => __( 'Working…', 'ai-guardwall' ), 'failed' => __( 'Something went wrong. Save your settings and try again.', 'ai-guardwall' ), 'keySaved' => /* translators: %s: value */ __( 'A key is saved (ending in %s). Paste a new one only to replace it.', 'ai-guardwall' ), 'noKey' => __( 'No key saved for this provider yet.', 'ai-guardwall' ), 'defaultModel' => __( '(recommended)', 'ai-guardwall' ), 'modelsLoaded' => /* translators: %d: number */ __( '%d free models listed (largest context first).', 'ai-guardwall' ), 'unsaved' => __( 'You have unsaved changes.', 'ai-guardwall' ), 'saveFirst' => __( 'You have unsaved changes. Save them first.', 'ai-guardwall' ), 'scanning' => __( 'Scanning…', 'ai-guardwall' ), 'scanDone' => __( 'Scan finished.', 'ai-guardwall' ), 'scanCancel' => __( 'Cancel this scan?', 'ai-guardwall' ), 'filesOf' => /* translators: 1: value, 2: value */ __( '%1$s of %2$s files', 'ai-guardwall' ), 'findingsSoFar' => /* translators: %d: number */ __( '%d findings so far', 'ai-guardwall' ), 'noFindings' => __( 'Nothing matches these filters.', 'ai-guardwall' ), 'stepEmpty' => __( 'Nothing to do in this step. Pick the next step on the left.', 'ai-guardwall' ), 'closedEmpty' => __( 'Nothing was fixed or ignored yet.', 'ai-guardwall' ), 'confirmAction' => __( 'Are you sure? This changes your site. A backup copy is kept where possible.', 'ai-guardwall' ), 'confirmDelete' => __( 'Delete this user? Their content is reassigned to you. This cannot be undone.', 'ai-guardwall' ), 'analysing' => /* translators: 1: number, 2: number */ __( 'AI is analysing %1$d of %2$d…', 'ai-guardwall' ), 'analysed' => /* translators: 1: number, 2: number */ __( 'AI analysis finished: %1$d analysed, %2$d failed.', 'ai-guardwall' ), 'selectSome' => __( 'Select at least one finding first.', 'ai-guardwall' ), 'line' => /* translators: %d: number */ __( 'line %d', 'ai-guardwall' ), 'confidence' => /* translators: %d: number */ __( '%d%% confidence', 'ai-guardwall' ), 'analyze' => __( 'AI analyse', 'ai-guardwall' ), 'details' => __( 'Details', 'ai-guardwall' ), 'hide' => __( 'Hide', 'ai-guardwall' ), 'whyTitle' => __( 'Why it is suspicious', 'ai-guardwall' ), 'aiTitle' => __( 'AI analyst', 'ai-guardwall' ), 'aiWhy' => __( 'Why', 'ai-guardwall' ), 'aiAffected' => __( 'What could be affected', 'ai-guardwall' ), 'aiRemediation' => __( 'Recommended remediation', 'ai-guardwall' ), 'aiOfficial' => __( 'Replacing from the official source is safer than editing', 'ai-guardwall' ), 'aiNotSafer' => __( 'Editing/removing by hand is fine here', 'ai-guardwall' ), 'aiIndicators' => __( 'Indicators', 'ai-guardwall' ), 'notAnalysed' => __( 'Not analysed by AI yet.', 'ai-guardwall' ), 'snippet' => __( 'Code', 'ai-guardwall' ), 'indicators' => __( 'Matched indicators', 'ai-guardwall' ), 'recommended' => __( 'Scanner recommendation', 'ai-guardwall' ), 'actions' => __( 'Actions', 'ai-guardwall' ), 'relogin' => __( 'You will now be logged out. Log in again to continue.', 'ai-guardwall' ), 'confirmSalts' => __( 'Rotate the security keys? Every user (including you) is logged out.', 'ai-guardwall' ), 'confirmRename' => __( 'Rename this user? Use the new name to log in from now on.', 'ai-guardwall' ), 'confirmEmail' => __( 'Change the admin email without a confirmation mail?', 'ai-guardwall' ), 'confirmUnblock'=> __( 'Unblock this IP?', 'ai-guardwall' ), 'presetApplied' => __( 'Preset ticked. Review the list, then press Save changes.', 'ai-guardwall' ), 'copied' => __( 'Copied', 'ai-guardwall' ), 'page' => /* translators: 1: number, 2: number */ __( 'Page %1$d of %2$d', 'ai-guardwall' ), 'reportDone' => __( 'Report written. Scroll down to read it.', 'ai-guardwall' ), 'howToFix' => __( 'How to fix it', 'ai-guardwall' ), 'afterCleanup' => __( 'After the cleanup', 'ai-guardwall' ), 'goTo' => __( 'Go to', 'ai-guardwall' ), 'recommendedBtn' => __( 'Recommended', 'ai-guardwall' ), 'planEmpty' => __( 'Nothing to do in this step.', 'ai-guardwall' ), 'planItems' => /* translators: %d: number */ __( '%d findings', 'ai-guardwall' ), 'planUpdates' => /* translators: %d: number */ __( '%d updates waiting on Dashboard › Updates', 'ai-guardwall' ), 'planShow' => __( 'Show these findings', 'ai-guardwall' ), 'planConfirm' => __( 'Run this step on every listed finding? Files go to quarantine and database values are backed up first.', 'ai-guardwall' ), 'open' => __( 'Open', 'ai-guardwall' ), 'save' => __( 'Save', 'ai-guardwall' ), 'saved' => __( 'Saved.', 'ai-guardwall' ), 'unsavedFile' => __( 'This file has unsaved changes. Discard them?', 'ai-guardwall' ), 'confirmFileDelete' => /* translators: %s: value */ __( 'Delete "%s"? A copy is kept in quarantine for 30 days.', 'ai-guardwall' ), 'confirmFolderDelete' => /* translators: %s: value */ __( 'Delete the folder "%s" and everything in it? It is archived into quarantine first.', 'ai-guardwall' ), 'confirmRestore' => __( 'Replace the current file with this backup?', 'ai-guardwall' ), 'promptName' => __( 'Name:', 'ai-guardwall' ), 'promptRename' => /* translators: %s: value */ __( 'New name for "%s":', 'ai-guardwall' ), 'promptMode' => __( 'Permissions (octal, for example 644 or 755):', 'ai-guardwall' ), 'promptTable' => __( 'New table name:', 'ai-guardwall' ), 'folder' => __( 'Folder', 'ai-guardwall' ), 'file' => __( 'File', 'ai-guardwall' ), 'size' => __( 'Size', 'ai-guardwall' ), 'modified' => __( 'Modified', 'ai-guardwall' ), 'perms' => __( 'Perms', 'ai-guardwall' ), 'edit' => __( 'Edit', 'ai-guardwall' ), 'view' => __( 'View', 'ai-guardwall' ), 'download' => __( 'Download', 'ai-guardwall' ), 'rename' => __( 'Rename', 'ai-guardwall' ), 'copy' => __( 'Copy', 'ai-guardwall' ), 'delete' => __( 'Delete', 'ai-guardwall' ), 'zip' => __( 'Zip', 'ai-guardwall' ), 'unzip' => __( 'Unzip', 'ai-guardwall' ), 'chmod' => __( 'Permissions', 'ai-guardwall' ), 'protected' => __( 'WordPress needs this; it cannot be deleted or renamed here.', 'ai-guardwall' ), 'recent' => __( 'changed in the last 3 days', 'ai-guardwall' ), 'emptyFolder' => __( 'This folder is empty.', 'ai-guardwall' ), 'readOnly' => __( 'read-only', 'ai-guardwall' ), 'binary' => __( 'This is a binary file; it can be downloaded but not edited here.', 'ai-guardwall' ), 'verified' => __( 'Identical to the official WordPress.org copy.', 'ai-guardwall' ), 'notVerified' => __( 'Differs from the official WordPress.org copy.', 'ai-guardwall' ), 'backups' => __( 'Backups of this file', 'ai-guardwall' ), 'restore' => __( 'Restore', 'ai-guardwall' ), 'searchResults' => /* translators: 1: number, 2: number, 3: value */ __( '%1$d matches in %2$d files (%3$s s)', 'ai-guardwall' ), 'searchPartial' => __( 'Stopped early: narrow the search or start in a deeper folder.', 'ai-guardwall' ), 'uploading' => __( 'Uploading…', 'ai-guardwall' ), ), ); } public function add_menu() { $this->hooks['dashboard'] = add_menu_page( __( 'AI GuardWall', 'ai-guardwall' ), __( 'AI GuardWall', 'ai-guardwall' ), Softvolt_Ai_Bodyguard::cap(), self::DASHBOARD, array( $this, 'render_dashboard' ), 'dashicons-shield', 59 ); if ( $this->hooks['dashboard'] ) { add_action( 'load-' . $this->hooks['dashboard'], array( 'Softvolt_Ai_Bodyguard_Dashboard', 'load' ) ); } // Every section is a page of the AI GuardWall menu (so WordPress keeps the menu open on it); the ones // that live only in the top bar are taken out of the sidebar list by hide_menu_items(), without CSS. $position = 0; foreach ( self::sections() as $id => $info ) { $callback = array( $this, 'dashboard' === $id ? 'render_dashboard' : 'render_' . $id ); $hook = add_submenu_page( self::DASHBOARD, $info['title'], $info['label'], Softvolt_Ai_Bodyguard::cap(), $info['slug'], is_callable( $callback ) ? $callback : array( $this, 'render_section' ), $position++ ); if ( 'dashboard' !== $id && $hook ) { $this->hooks[ $id ] = $hook; } } // Old page addresses (bookmarks, alert emails) go to their new home. $legacy = array( self::SCAN => self::url( 'cleanup', 'scan' ), self::FINDINGS => self::url( 'cleanup', 'findings' ), ); foreach ( $legacy as $slug => $target ) { $hook = add_submenu_page( 'options.php', '', '', Softvolt_Ai_Bodyguard::cap(), $slug, '__return_null' ); if ( $hook ) { add_action( 'load-' . $hook, function () use ( $target ) { $keep = array(); foreach ( array( 'severity', 'status', 'finding', 'plan', 'scan_id', 'autostart', 'path', 'open', 'line', 'search', 'table', 'pk', 'id', 'column' ) as $arg ) { if ( isset( $_GET[ $arg ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $keep[ $arg ] = sanitize_text_field( wp_unslash( $_GET[ $arg ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } } wp_safe_redirect( add_query_arg( $keep, $target ) ); exit; } ); } } } public function menu_badge() { global $menu; if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) || empty( $menu ) ) { return; } $counts = Softvolt_Ai_Bodyguard_Findings::counts( 0 ); $count = (int) $counts['critical'] + (int) $counts['high']; if ( ! $count ) { return; } // On the "AI GuardWall" menu itself: Malware Cleanup is not in the sidebar. foreach ( $menu as &$item ) { if ( isset( $item[2] ) && self::DASHBOARD === $item[2] ) { $item[0] .= sprintf( ' %2$s', $count, esc_html( number_format_i18n( $count ) ) ); } } unset( $item ); } /** * Take the top-bar-only sections out of the sidebar list just before WordPress prints the menu. They stay * registered pages (WordPress has already checked access and found the open menu), so no CSS is needed. * * @since 1.5.1 */ public function hide_menu_items() { global $submenu; if ( empty( $submenu[ self::DASHBOARD ] ) ) { return; } $hidden = array(); foreach ( self::sections() as $info ) { if ( isset( $info['side'] ) && ! $info['side'] ) { $hidden[] = $info['slug']; } } foreach ( $submenu[ self::DASHBOARD ] as $i => $item ) { if ( isset( $item[2] ) && in_array( $item[2], $hidden, true ) ) { unset( $submenu[ self::DASHBOARD ][ $i ] ); } } } public function render_app_header() { $svabg_page = $this->current_page(); $svabg_sections = self::sections(); $svabg_tab = isset( $svabg_sections[ $svabg_page ]['mode'] ) && 'server' === $svabg_sections[ $svabg_page ]['mode'] ? self::current_tab( $svabg_page ) : ''; if ( '' === $svabg_page || ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { return; } require plugin_dir_path( __FILE__ ) . 'partials/app-header.php'; } /** * Mark the AI GuardWall screens with the edition, so the Pro edition can hide the "Pro" badges. * * @param string $classes Body classes. * @return string */ public function body_class( $classes ) { if ( '' !== $this->current_page() ) { $classes .= ' svabg-screen svabg-edition-' . Softvolt_Ai_Bodyguard_Pro::edition() . ( Softvolt_Ai_Bodyguard_Pro::is_active() ? ' svabg-pro-on' : '' ); } return $classes; } public function register_settings() { register_setting( 'svabg_settings_group', Softvolt_Ai_Bodyguard_Settings::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( 'Softvolt_Ai_Bodyguard_Settings', 'sanitize' ), 'show_in_rest' => false, 'default' => array(), ) ); } public function maybe_redirect_after_activation() { if ( get_transient( 'svabg_activated' ) && current_user_can( Softvolt_Ai_Bodyguard::cap() ) && ! wp_doing_ajax() && ! ( isset( $_GET['activate-multi'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended delete_transient( 'svabg_activated' ); wp_safe_redirect( admin_url( 'admin.php?page=' . self::DASHBOARD . '&welcome=1' ) ); exit; } } public function render_dashboard() { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { return; } require plugin_dir_path( __FILE__ ) . 'partials/page-dashboard.php'; } /** * Malware Cleanup: Scan and Findings, and the scanner's settings (AI model, knowledge, scan settings). */ public function render_cleanup() { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { return; } $files = array( 'scan' => 'page-scan.php', 'findings' => 'page-findings.php', ); $tab = self::current_tab( 'cleanup' ); $sections = self::sections(); if ( in_array( $tab, (array) $sections['cleanup']['forms'], true ) ) { $svabg_section = 'cleanup'; $svabg_only_tabs = array( $tab ); require plugin_dir_path( __FILE__ ) . 'partials/softvolt-ai-bodyguard-admin-display.php'; return; } require plugin_dir_path( __FILE__ ) . 'partials/' . ( isset( $files[ $tab ] ) ? $files[ $tab ] : 'page-scan.php' ); } /** * Database: optimizations, tables and schedule (WP-Optimize style); the full manager opens in its own tab. */ public function render_database() { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { return; } $svabg_db_tab = self::current_tab( 'database' ); require plugin_dir_path( __FILE__ ) . 'partials/page-database.php'; } public function render_activity() { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { return; } require plugin_dir_path( __FILE__ ) . 'partials/page-activity.php'; } public function render_pro() { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { return; } require plugin_dir_path( __FILE__ ) . 'partials/page-pro.php'; } public function render_page() { $this->render_settings_section( 'settings' ); } public function render_settings() { $this->render_page(); } public function render_security() { $this->render_settings_section( 'security' ); } public function render_tools() { $this->render_settings_section( 'tools' ); } public function render_alerts() { $this->render_settings_section( 'alerts' ); } /** * Fallback for a section added through the svabg_admin_sections filter. */ public function render_section() { do_action( 'svabg_render_section', $this->current_page() ); } /** * A section made of settings tabs (one form, saved through options.php). * * @param string $section Section id. */ private function render_settings_section( $section ) { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { return; } $svabg_section = $section; require plugin_dir_path( __FILE__ ) . 'partials/softvolt-ai-bodyguard-admin-display.php'; } public function action_links( $links ) { array_unshift( $links, sprintf( '%2$s', esc_url( admin_url( 'admin.php?page=' . self::DASHBOARD ) ), esc_html__( 'Dashboard', 'ai-guardwall' ) ), sprintf( '%2$s', esc_url( self::url( 'settings' ) ), esc_html__( 'Settings', 'ai-guardwall' ) ), sprintf( '%2$s', esc_url( self::url( 'pro' ) ), esc_html__( 'Go Pro', 'ai-guardwall' ) ) ); return $links; } public function notices() { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { return; } $page = $this->current_page(); $db_error = Softvolt_Ai_Bodyguard_Db::error(); if ( $db_error && ( '' !== $page || ( isset( $GLOBALS['pagenow'] ) && 'plugins.php' === $GLOBALS['pagenow'] ) ) ) { printf( '

%1$s %2$s

', esc_html__( 'AI GuardWall could not create its database tables:', 'ai-guardwall' ), esc_html( sprintf( /* translators: 1: table names, 2: the database error */ __( '%1$s. The database answered: %2$s. It tries again by itself every ten minutes; if this stays, ask your host whether the database user may create tables.', 'ai-guardwall' ), implode( ', ', (array) $db_error['tables'] ), '' !== (string) $db_error['error'] ? (string) $db_error['error'] : __( 'no error message', 'ai-guardwall' ) ) ) ); } if ( '' !== $page ) { Softvolt_Ai_Bodyguard_Settings::secret( 'key_' . Softvolt_Ai_Bodyguard_Settings::get( 'provider' ) ); if ( Softvolt_Ai_Bodyguard_Settings::secrets_unreadable() ) { printf( '

%s

', esc_html__( 'Your saved API key can no longer be read, usually because the security keys in wp-config.php changed. Please paste the key again.', 'ai-guardwall' ) ); } $ht = get_transient( 'svabg_htaccess_error' ); if ( is_array( $ht ) && $ht ) { printf( '

%s %s

', esc_html__( 'Server rules:', 'ai-guardwall' ), esc_html( implode( ' ', $ht ) ) ); } } // Critical findings: on the Dashboard, the Plugins screen and this plugin's screens only. global $pagenow; $where = '' !== $page || in_array( (string) $pagenow, array( 'index.php', 'plugins.php' ), true ); $counts = $where ? Softvolt_Ai_Bodyguard_Findings::counts( 0 ) : array( 'critical' => 0 ); if ( $counts['critical'] > 0 && ! ( 'cleanup' === $page && 'findings' === self::current_tab( 'cleanup' ) ) && ! get_user_meta( get_current_user_id(), 'svabg_dismiss_' . gmdate( 'Ymd' ), true ) ) { printf( '

%1$s %2$s %4$s

', esc_html__( 'AI GuardWall:', 'ai-guardwall' ), esc_html( sprintf( /* translators: %d: critical */ _n( '%d critical finding needs your attention.', '%d critical findings need your attention.', $counts['critical'], 'ai-guardwall' ), $counts['critical'] ) ), esc_url( self::url( 'cleanup', 'findings', array( 'severity' => 'critical' ) ) ), esc_html__( 'Review', 'ai-guardwall' ) ); } // 2FA grace-period reminder. if ( Softvolt_Ai_Bodyguard_Settings::hardening_enabled( 'two_factor' ) && ! Softvolt_Ai_Bodyguard_Two_Factor::enabled_for_user( get_current_user_id() ) ) { $user = wp_get_current_user(); if ( array_intersect( (array) Softvolt_Ai_Bodyguard_Settings::get( 'twofa_roles', array() ), (array) $user->roles ) ) { printf( '

%1$s %3$s

', esc_html__( 'Two-factor authentication is required for your role. Set it up now, before the grace period ends.', 'ai-guardwall' ), esc_url( admin_url( 'profile.php#svabg-2fa' ) ), esc_html__( 'Set up 2FA on your profile', 'ai-guardwall' ) ); } } } public function admin_bar( $bar ) { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) || ! is_admin_bar_showing() ) { return; } $counts = Softvolt_Ai_Bodyguard_Findings::counts( 0 ); $alert = (int) $counts['critical'] + (int) $counts['high']; $bar->add_node( array( 'id' => 'svabg', 'title' => '' . esc_html__( 'AI GuardWall', 'ai-guardwall' ) . ( $alert ? ' ' . (int) $alert . '' : '' ) . '', 'href' => admin_url( 'admin.php?page=' . self::DASHBOARD ), ) ); $bar->add_node( array( 'parent' => 'svabg', 'id' => 'svabg-scan', 'title' => __( 'Run a scan', 'ai-guardwall' ), 'href' => self::url( 'cleanup', 'scan', array( 'autostart' => wp_create_nonce( 'svabg_autostart' ) ) ) ) ); $bar->add_node( array( 'parent' => 'svabg', 'id' => 'svabg-findings', 'title' => __( 'Findings', 'ai-guardwall' ), 'href' => self::url( 'cleanup', 'findings' ) ) ); $bar->add_node( array( 'parent' => 'svabg', 'id' => 'svabg-security', 'title' => __( 'Security Wall', 'ai-guardwall' ), 'href' => self::url( 'security' ) ) ); $bar->add_node( array( 'parent' => 'svabg', 'id' => 'svabg-settings', 'title' => __( 'Settings', 'ai-guardwall' ), 'href' => self::url( 'settings' ) ) ); } public function add_privacy_policy_content() { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } $chosen = (string) Softvolt_Ai_Bodyguard_Settings::get( 'provider' ); $provider = Softvolt_Ai_Bodyguard_Catalog::provider( $chosen ); $name = Softvolt_Ai_Bodyguard_Claude::PROVIDER === $chosen ? __( 'Anthropic, through the Claude Desktop app of the site owner', 'ai-guardwall' ) : ( $provider ? $provider['name'] : __( 'our AI provider', 'ai-guardwall' ) ); $content = '

' . esc_html__( 'This site uses AI GuardWall to protect itself. It records the IP address, browser identifier and requested address of visits that look like attacks, and of login attempts, in a security log kept for a limited time. Addresses that attack the site may be blocked.', 'ai-guardwall' ) . '

'; $content .= '

' . sprintf( /* translators: %s: name */ esc_html__( 'When the site owner asks for an AI analysis of a suspicious file, the relevant code excerpt is sent to %s. Visitor data is not included in those excerpts.', 'ai-guardwall' ), esc_html( $name ) ) . '

'; wp_add_privacy_policy_content( __( 'AI GuardWall – AI-Powered Digital Security Guardian', 'ai-guardwall' ), wp_kses_post( $content ) ); } /** * Download the malware report as Markdown. */ public function export_report() { if ( ! current_user_can( Softvolt_Ai_Bodyguard::cap() ) ) { wp_die( esc_html__( 'You are not allowed to export reports.', 'ai-guardwall' ) ); } check_admin_referer( 'svabg_export_report' ); $scan_id = isset( $_GET['scan_id'] ) ? (int) $_GET['scan_id'] : 0; $status = isset( $_GET['status'] ) ? sanitize_key( wp_unslash( $_GET['status'] ) ) : 'open'; $rows = Softvolt_Ai_Bodyguard_Findings::export_rows( $scan_id, $status ); nocache_headers(); $name = 'ai-guardwall-report-' . gmdate( 'Y-m-d' ); header( 'Content-Type: text/markdown; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="' . $name . '.md"' ); $scan = $scan_id ? Softvolt_Ai_Bodyguard_Scanner::get_scan( $scan_id ) : Softvolt_Ai_Bodyguard_Scanner::last_scan(); echo '# AI GuardWall malware report' . "\n\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo '- Site: ' . esc_url( home_url() ) . "\n- Generated: " . gmdate( 'Y-m-d H:i' ) . " UTC\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( $scan ) { $s = $scan['stats_arr']; echo '- Scan #' . (int) $scan['id'] . ': ' . (int) ( isset( $s['files_scanned'] ) ? $s['files_scanned'] : 0 ) . ' files, ' . (int) ( isset( $s['findings'] ) ? $s['findings'] : 0 ) . " findings\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } echo "\n| # | File / table | Line | Severity | Confidence | Verdict | Why it is suspicious | Recommendation | How to fix | AI verdict |\n|---|---|---|---|---|---|---|---|---|---|\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $i = 0; foreach ( $rows as $row ) { $cell = function ( $v ) { return str_replace( array( '|', "\n", "\r" ), array( '\|', ' ', '' ), (string) $v ); }; echo '| ' . ( ++$i ) . ' | ' . $cell( $row['file_or_table'] ) . ' | ' . $cell( $row['line'] ) . ' | ' . $cell( $row['severity'] ) . ' | ' . (int) $row['confidence'] . '% | ' . $cell( $row['verdict'] ) . ' | ' . $cell( $row['title'] . ' — ' . $row['why_suspicious'] ) . ' | ' . $cell( $row['recommendation'] ) . ' | ' . $cell( isset( $row['how_to_fix'] ) ? $row['how_to_fix'] : '' ) . ' | ' . $cell( '' !== $row['ai_verdict'] ? $row['ai_verdict'] . ' (' . (int) $row['ai_confidence'] . '%): ' . $row['ai_reason'] : '' ) . " |\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $plan = Softvolt_Ai_Bodyguard_Fixes::plan( $scan_id ); echo "\n## Cleanup plan\n\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $n = 0; foreach ( $plan['phases'] as $phase ) { if ( ! $phase['count'] && empty( $phase['updates'] ) ) { continue; } echo ( ++$n ) . '. **' . wp_strip_all_tags( $phase['title'] ) . '** (' . (int) $phase['count'] . ( ! empty( $phase['updates'] ) ? ' + ' . (int) $phase['updates'] . ' updates' : '' ) . '): ' . wp_strip_all_tags( $phase['text'] ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } echo "\n## After the cleanup\n\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped foreach ( $plan['after'] as $k => $step ) { echo ( $k + 1 ) . '. ' . wp_strip_all_tags( $step ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ( $scan && ! empty( $scan['summary'] ) ) { echo "\n## AI summary\n\n" . wp_strip_all_tags( $scan['summary'] ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } exit; } }