Files
Testing/tbs/wp-content/plugins/wp-fail2ban/wp-fail2ban-main.php
sean 0e8a8b3028
Some checks failed
deploy-testing / deploy (push) Has been cancelled
Initial testing snapshot
2026-11-17 16:15:01 -05:00

158 lines
4.4 KiB
PHP

<?php
/**
* WP fail2ban main file
*
* @since 4.0.0
* @package wp-fail2ban
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Defaults
*
* @since 4.0.0
*/
define( 'DEFAULT_WP_FAIL2BAN_OPENLOG_OPTIONS', LOG_PID | LOG_NDELAY );
define( 'DEFAULT_WP_FAIL2BAN_AUTH_LOG', LOG_AUTH );
define( 'DEFAULT_WP_FAIL2BAN_COMMENT_LOG', LOG_USER );
define( 'DEFAULT_WP_FAIL2BAN_PINGBACK_LOG', LOG_USER );
define( 'DEFAULT_WP_FAIL2BAN_PASSWORD_REQUEST_LOG', LOG_USER );
define( 'DEFAULT_WP_FAIL2BAN_SPAM_LOG', LOG_USER );
/**
* Allow custom openlog options.
* e.g. you may not want the PID if logging remotely.
*
* @since 3.6.0 Add LOG_NDELAY
* @since 3.5.0
*/
if ( !defined( 'WP_FAIL2BAN_OPENLOG_OPTIONS' ) ) {
define( 'WP_FAIL2BAN_OPENLOG_OPTIONS', DEFAULT_WP_FAIL2BAN_OPENLOG_OPTIONS );
}
/**
* Make sure all custom logs are defined.
* @since 3.5.0
*/
if ( !defined( 'WP_FAIL2BAN_AUTH_LOG' ) ) {
define( 'WP_FAIL2BAN_AUTH_LOG', DEFAULT_WP_FAIL2BAN_AUTH_LOG );
}
if ( !defined( 'WP_FAIL2BAN_COMMENT_LOG' ) ) {
define( 'WP_FAIL2BAN_COMMENT_LOG', DEFAULT_WP_FAIL2BAN_COMMENT_LOG );
}
if ( !defined( 'WP_FAIL2BAN_PINGBACK_LOG' ) ) {
define( 'WP_FAIL2BAN_PINGBACK_LOG', DEFAULT_WP_FAIL2BAN_PINGBACK_LOG );
}
/**
* @since 4.0.0
*/
if ( !defined( 'WP_FAIL2BAN_PASSWORD_REQUEST_LOG' ) ) {
define( 'WP_FAIL2BAN_PASSWORD_REQUEST_LOG', DEFAULT_WP_FAIL2BAN_PASSWORD_REQUEST_LOG );
}
if ( !defined( 'WP_FAIL2BAN_SPAM_LOG' ) ) {
define( 'WP_FAIL2BAN_SPAM_LOG', DEFAULT_WP_FAIL2BAN_SPAM_LOG );
}
if ( is_admin() ) {
require 'admin/summary.php';
} else {
require dirname( __FILE__ ) . '/feature/lib.php';
/**
* @since 3.5.0 Refactored for unit testing
* @since 1.0.0
*
* @param string $user_login
*/
function wp_login( $user_login, $user )
{
openlog();
syslog( LOG_INFO, "Accepted password for {$user_login}" );
// @codeCoverageIgnoreEnd
}
add_action(
'wp_login',
__NAMESPACE__ . '\\wp_login',
10,
2
);
/**
* @since 3.5.0 Refactored for unit testing
* @since 1.0.0
*
* @param string $username
*
* @wp-f2b-hard Authentication attempt for unknown user .*
* @wp-f2b-hard XML-RPC authentication attempt for unknown user .*
* @wp-f2b-soft Authentication failure for .*
* @wp-f2b-soft XML-RPC authentication failure for .*
*/
function wp_login_failed( $username )
{
global $wp_xmlrpc_server ;
$msg = ( $wp_xmlrpc_server ? 'XML-RPC a' : 'A' );
$msg .= ( wp_cache_get( $username, 'userlogins' ) ? "uthentication failure for {$username}" : "uthentication attempt for unknown user {$username}" );
openlog();
syslog( LOG_NOTICE, $msg );
// @codeCoverageIgnoreEnd
}
add_action( 'wp_login_failed', __NAMESPACE__ . '\\wp_login_failed' );
/**
* Comments
*
* @since 4.0.0 Refactored
* @since 3.5.0
*/
if ( defined( 'WP_FAIL2BAN_LOG_COMMENTS' ) && true === WP_FAIL2BAN_LOG_COMMENTS ) {
require_once dirname( __FILE__ ) . '/feature/comments.php';
}
/**
* Password
*
* @since 4.0.0 Refactored
* @since 3.5.0
*/
if ( defined( 'WP_FAIL2BAN_LOG_PASSWORD_REQUEST' ) && true === WP_FAIL2BAN_LOG_PASSWORD_REQUEST ) {
require_once dirname( __FILE__ ) . '/feature/password.php';
}
/**
* Spam
*
* @since 4.0.0 Refactored
* @since 3.5.0
*/
if ( defined( 'WP_FAIL2BAN_LOG_SPAM' ) && true === WP_FAIL2BAN_LOG_SPAM ) {
require_once dirname( __FILE__ ) . '/feature/spam.php';
}
/**
* Users
*
* @since 4.0.0 Refactored
* @since 2.0.0
*/
if ( defined( 'WP_FAIL2BAN_BLOCKED_USERS' ) && '' < WP_FAIL2BAN_BLOCKED_USERS ) {
require_once dirname( __FILE__ ) . '/feature/user.php';
}
/**
* User enumeration
*
* @since 4.0.0 Refactored
* @since 2.1.0
*/
if ( defined( 'WP_FAIL2BAN_BLOCK_USER_ENUMERATION' ) && true === WP_FAIL2BAN_BLOCK_USER_ENUMERATION ) {
require_once dirname( __FILE__ ) . '/feature/user-enum.php';
}
/**
* XML-RPC
*
* @since 4.0.0 Refactored
* @since 3.0.0
*/
if ( defined( 'XMLRPC_REQUEST' ) && true === XMLRPC_REQUEST ) {
require_once dirname( __FILE__ ) . '/feature/xmlrpc.php';
}
}