=== FrankWall – Perimeter Defense & UEBA Security ===
Contributors: poyait26
Tags: security, firewall, 2fa, totp, login protection
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 1.0.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Perimeter defense, TOTP two-factor authentication, decoy traps, core integrity monitor, and per-user behavioral UEBA perceptron for WordPress.

== Description ==

FrankWall is a lightweight, self-contained security and behavioral analytics suite engineered by **POYA.IT** (*better place for your data* — [https://www.poya.it](https://www.poya.it)) for WordPress administrators who want deterministic perimeter protection without external cloud subscriptions.

Key features:

* **Per-User Behavioral Perceptron (UEBA):** Evaluates 15 behavioral and contextual signals (impossible travel speed, Haversine distance, ASN/ISP changes, browser/OS shifts, screen resolution, timezone mismatches, login form timing, non-linear multi-signal device shifts, and mid-session hijacking detection) with L2-regularized SGD feedback training and TOTP step-up authentication.
* **Two-Factor Authentication (TOTP RFC 6238):** Built-in Google Authenticator compatible 2FA with iOS/Android-ready QR code, dashboard onboarding widget, Sudo Mode step-up, and mobile deep-link (`otpauth://`) support.
* **Perimeter Shield & Active Decoys:** HTTP method filtering, scanner User-Agent blocking, query-string SQLi/traversal shield, XML-RPC suppression, canary honey-paths, `robots.txt` spider trap, and optional stack/path camouflage.
* **Rate Limiting, Login Slug & CIDR Whitelist:** Brute-force lockout by IP and username, custom login URL slug, idle session timeout, unauthenticated admin escalation guard, and permanent IPv4/IPv6 CIDR safelist.
* **Core & Content File Integrity Monitor (FIM):** Compares `wp-admin`, `wp-includes`, and root core files against official WordPress.org MD5 checksums, tracks local `wp-content` baseline snapshots, and scans uploads/modified files for heuristic web shell signatures.
* **Interactive WGS84 Radar & Telemetry:** Optional opt-in WGS84 Leaflet threat map with cross-filtering drill-down, 14-day Plotly.js attack timeline with live auto-refresh, searchable engagement logs, Threat & Countermeasure Matrix, CSV export, and executive email digests with circular peak-hour and top-URI analytics.

== Architecture & File Structure ==

FrankWall is built following a modular, single-responsibility architecture with zero external CDN dependencies:

    frankwall/
    ├── frankwall.php                       # Plugin bootstrap, autoloader, lifecycle hooks, and module orchestrator
    ├── uninstall.php                       # Clean removal of plugin options, user meta, transients, cron hooks, and .htaccess markers
    ├── readme.txt                          # WordPress.org documentation, external services disclosure, and licensing
    ├── assets/
    │   ├── css/                            # Admin stylesheets
    │   ├── js/                             # Admin, authentication, and login telemetry scripts
    │   └── vendor/                         # Self-hosted open-source libraries (Leaflet, Plotly.js, qrcode-generator)
    ├── languages/                          # Gettext translation template (.pot) for the 'frankwall' text domain
    ├── templates/                          # Executive HTML email alert & digest templates
    └── includes/
        ├── class-frankwall-config.php      # Tab-aware settings management, threat registry, storage schema, CIDR safelist, and JSON backup
        ├── class-frankwall-geo.php         # Client IP extraction, opt-in WGS84/ASN/ISP/timezone lookup (24h cache), and Haversine math
        ├── class-frankwall-telemetry.php   # Aggregated counters, 30-day daily series, WGS84/URI event log, GD charts, and WP-Cron digest
        ├── class-frankwall-perimeter.php   # Early perimeter checks: HTTP methods, scanner User-Agents, query shield, XML-RPC, decoys, GeoIP
        ├── class-frankwall-camouflage.php  # Optional path cloaking via wp_final_output_buffer, DOM/HTTP footprint removal, and decoy headers
        ├── class-frankwall-hardening.php   # Comment suppression, user enumeration blocks, double-extension filter, privilege guard, headers
        ├── class-frankwall-auth.php        # Custom login slug, honeypot, rate limiting, RFC 6238 TOTP 2FA, dashboard widget, Sudo Mode
        ├── class-frankwall-ueba.php        # Per-user 15-feature adaptive perceptron, decayed EMA baseline, session binding, and SGD training
        ├── class-frankwall-fim.php         # Core checksum verification, wp-content baseline snapshots, and heuristic web shell scanner
        ├── class-frankwall-table.php       # Native WP_List_Table implementation for searchable/filterable engagement logs and bulk bans
        └── class-frankwall-admin.php       # Admin interface, tabbed Rules of Engagement, Threat Matrix, Help & Consulting guide, AJAX handlers

== External services ==

By default, FrankWall performs **zero external network calls** during normal operation. External services are used only when explicitly opted-in by an administrator or when manually running an integrity scan:

1. **ipwho.is (`https://ipwho.is/`) — Disabled by default (Explicit Opt-In Required)**
   * **Purpose:** When explicitly enabled by the site administrator, resolves public IP addresses into country codes, ASN/ISP identifiers, timezones, and approximate WGS84 coordinates for the GeoIP login filter, threat map, and UEBA behavioral checks.
   * **Data sent:** The visitor or administrator public IP address, cached locally for 24 hours to minimize requests. Nothing is sent while opt-in is disabled.
   * **Provider policies:** [Terms & Privacy](https://ipwhois.io/privacy)

2. **OpenStreetMap Tile Servers (`https://tile.openstreetmap.org/`) — Disabled by default (Explicit Opt-In Required)**
   * **Purpose:** When the external GeoIP & Map Tiles opt-in is enabled by the administrator, loads map tiles inside the admin dashboard widget and Telemetry WGS84 radar.
   * **Data sent:** Standard HTTP tile requests from the administrator's browser (IP address and User-Agent). Nothing is loaded while opt-in is disabled.
   * **Provider policies:** [OpenStreetMap Privacy Policy](https://osmfoundation.org/wiki/Privacy_Policy)

3. **WordPress.org Checksums API (`https://api.wordpress.org/core/checksums/1.0/`)**
   * **Purpose:** Retrieves official MD5 file checksums for the installed WordPress version and locale when an administrator runs the Core File Integrity Monitor scan.
   * **Data sent:** Installed WordPress version string and site locale.
   * **Provider policies:** [WordPress.org Privacy Policy](https://wordpress.org/about/privacy/)

== Third-Party Libraries ==

This plugin bundles the following open-source libraries locally in `assets/vendor/`:

* **Leaflet 1.9.4** (`leaflet.js`, `leaflet.css`) — BSD-2-Clause License. Source: https://github.com/Leaflet/Leaflet
* **Plotly.js 2.35.2** (`plotly.min.js`) — MIT License. Unminified source: https://github.com/plotly/plotly.js
* **qrcode-generator 1.4.4** (`qrcode.js`) — MIT License. Source: https://github.com/kazuhikoarase/qrcode-generator

== Installation ==

1. Upload the `frankwall` folder to the `/wp-content/plugins/` directory.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. Navigate to **FrankWall → Rules of Engagement** to configure your security rules.
4. Enable Two-Factor Authentication in **Users → Profile**.

== Frequently Asked Questions ==

= Does FrankWall send any data to external clouds without my knowledge? =
No. All behavioral models (UEBA), TOTP secrets, logs, and `wp-content` baselines are stored exclusively in your local WordPress database. External GeoIP lookups (`ipwho.is`) and OpenStreetMap map tiles are **disabled by default** and require explicit administrator opt-in. The only other external request is the official `api.wordpress.org` checksum endpoint when an administrator triggers a Core FIM scan.

= What happens if I forget my custom login URL slug or get locked out? =
You can add your static IP or CIDR subnet to the Safelist, or temporarily rename the `frankwall` folder via FTP/SSH to restore the default `/wp-login.php` access.

= Is FrankWall compatible with Nginx and Apache? =
Yes. Core perimeter rules, UEBA, TOTP 2FA, and FIM work on both Nginx and Apache. Optional `.htaccess` rules (for `/uploads/` PHP blocking and path camouflage) are written cleanly inside `# BEGIN FrankWall` / `# END FrankWall` markers only when enabled.

== Changelog ==

= 1.0.3 =
* Replaced legacy `ob_start()` output buffering in `FrankWall_Camouflage` exclusively with WordPress 6.9+ native `wp_final_output_buffer`.
* Hardened `FrankWall_Perimeter::unlock_key()` with `sanitize_key()` and strict `frankwall_lock_` prefix validation before deleting transients.
* Added dedicated nonce verification (`frankwall_login_sensors_nonce`) on client-side login telemetry fields and deferred UEBA behavioral baseline updates to `wp_login` after both password and TOTP verification succeed.
* Improved TOTP `otpauth://` issuer sanitization and QR quiet-zone rendering for iOS Google Authenticator compatibility, and added a mandatory 2FA onboarding dashboard widget for administrators.
* Added `uninstall.php`, unified threat category registry in `FrankWall_Config`, and circular peak-hour + Top 5 targeted URI analytics in executive weekly digests.

= 1.0.2 =
* Made external GeoIP lookups (`ipwho.is`) and OpenStreetMap tile loading strictly opt-in (disabled by default) in compliance with WordPress.org privacy guidelines.
* Enqueued all admin, authentication, and login telemetry scripts/styles via native WordPress APIs (`wp_enqueue_script`, `wp_enqueue_style`, `wp_add_inline_script`).
* Improved path resolution to support custom `WP_CONTENT_DIR`, `WP_PLUGIN_DIR`, theme root, and uploads directories outside `ABSPATH`.
* Hardened CIDR prefix validation on settings save and JSON import, enforced active IP lockouts at the early perimeter stage, and aligned output buffering with WordPress native standards.

= 1.0.1 =
* Added boardroom-ready HTML email digest & alert templates in `templates/` (with `wp-content/uploads/frankwall-templates/` override support) and local PHP GD embedded PNG charts (`CID`).
* Added cryptographic `SameSite=Strict` session canary cookie (`__Host-frankwall_bind`), Client Hints verification, REST/AJAX session binding, optional subnet lock, and TOTP Sudo Mode.
* Added universal query-string (`?slug`) routing support for custom login URLs across Nginx and Apache.
* Refined File Integrity Monitor (FIM) to ignore harmless `index.php` directory stubs in `/uploads/` and normalize CRLF/localized core text files.
* Added "Protected by FrankWall" shield badge to the login form.

= 1.0.0 =
* Initial release for the WordPress.org Plugin Directory by POYA.IT – better place for your data.