=== Blockary - Access Firewall ===
Contributors: migaweb
Tags: firewall, country block, login protection, brute force, security
Requires at least: 6.4
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Blocks visitors by country and blocks malicious login attempts before the page loads.

== Description ==

Blockary blocks visitors by country and stops password guessing on the login page.

The country rule works as a block list or as an allow list. You pick the countries on the settings page. The plugin reads the country from the Cloudflare header or from a local copy of the free "IP to Country Lite" database from DB-IP. Visitors from the whitelist, from private networks, and visitors with a valid login cookie always pass.

The login protection counts failed logins per address and per username. An address that reaches the limit gets a temporary ban. The ban time grows with each ban, and a permanent ban follows after a number of temporary bans. The plugin can also lock a username, show the same error for a wrong username and a wrong password, hide usernames from visitors, and turn off XML-RPC.

The plugin makes its blocking decision as soon as WordPress loads the plugins. Blocked requests do not reach the theme. A log on the settings page shows the blocked requests, the failed logins, and the bans.

= Optional: run the decision before the other plugins =

A small loader file in the folder `wp-content/mu-plugins` moves the decision before WordPress loads the other plugins. Blocked requests then cost less and stay invisible to the other plugins. The plugin does not write that file itself. You download it on the settings page and copy it into the folder by hand, for example with SFTP. The settings page shows the exact path. The loader runs the decision only while the plugin is active. Without the plugin it does nothing. When you delete the plugin, delete the loader file too. When the settings page shows "Outdated" for the loader, download the file again and replace the copy.

= Recovery =

If a rule locks you out, add this line to `wp-config.php`:

`define( 'BLOCKARY_DISABLE', true );`

The plugin then blocks nothing until you remove the line.

== Installation ==

1. Upload the folder `blockary` to `wp-content/plugins`, or install the plugin from Plugins > Add New.
2. Activate the plugin.
3. Open Settings > Blockary.
4. Add your own address to the IP whitelist.
5. Pick the country mode and the countries.
6. If your site runs behind Cloudflare or another proxy, add the proxy to the trusted proxies. Without that entry the plugin sees the proxy address for every visitor.
7. Optional: download the loader file in the section "Early loading" and copy it to the path that the page shows. The firewall then decides before the other plugins load.

== Frequently Asked Questions ==

= Where does the country data come from? =

The plugin reads the country from the Cloudflare header `CF-IPCountry` when the site runs behind Cloudflare. Without Cloudflare the plugin downloads the free "IP to Country Lite" database from DB-IP into `wp-content/uploads/blockary` and refreshes it once a month. See the section "External services".

= Does the plugin send data about my visitors? =

No. The country lookup runs on your server. The plugin sends no visitor data to any service.

= What does the plugin write outside its own folder? =

The plugin writes only the country database into `wp-content/uploads/blockary`. It removes that folder and its settings, bans, and log on uninstall. The optional loader file in `wp-content/mu-plugins` is a file that you copy by hand. The plugin never writes or deletes it.

= I locked myself out. What now? =

Add `define( 'BLOCKARY_DISABLE', true );` to `wp-config.php`. The plugin then blocks nothing. Fix the rule on the settings page and remove the line again.

= Does the plugin work with a caching plugin? =

Yes. The plugin decides as soon as WordPress loads the plugins, or before the other plugins with the optional loader. A page cache that serves files before WordPress starts, for example a web server cache, can serve a cached page to a blocked visitor.

== External services ==

The plugin downloads the country database "IP to Country Lite" from DB-IP when you select the local database as the country source. The download runs once after you select that source and then once a month through WP-Cron. You can also start it on the settings page.

The request goes to `https://download.db-ip.com/free/`. The request carries only the name of the database file for the current month. It carries no data about your site or your visitors. The database is licensed under CC BY 4.0. The settings page shows the attribution link that the license requires.

Terms and privacy policy of DB-IP: https://db-ip.com/about and https://db-ip.com/privacy.php

The plugin sends no other request to an external service.

== Changelog ==

= 1.0.0 =
* First version. Country rule with block list and allow list, login protection with bans, username lock, hidden usernames, XML-RPC switch, and a log.
