This commit is contained in:
Mauro Torrez
2019-09-17 18:28:38 -03:00
commit 3a8e77323e
30 changed files with 3648 additions and 0 deletions

66
admin/admin.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
/**
* Admin
*
* @package wp-fail2ban
* @since 4.0.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
require __DIR__ . '/config.php';
require __DIR__ . '/lib/about.php';
/**
* Register admin menus
*
* @since 4.0.0
*/
function admin_menu()
{
global $submenu ;
add_menu_page(
'WP fail2ban',
'WP fail2ban',
'manage_options',
'wp-fail2ban',
__NAMESPACE__ . '\\about',
'dashicons-analytics'
);
add_submenu_page(
'wp-fail2ban',
'Settings',
'Settings',
'manage_options',
'wp-fail2ban-settings',
__NAMESPACE__ . '\\settings'
);
$submenu['wp-fail2ban'][0][0] = __( 'Welcome' );
}
add_action( 'admin_menu', __NAMESPACE__ . '\\admin_menu' );
/**
* Add Settings link on Plugins page
*
* @since 4.2.0
*
* @param array $links
* @param string $file
*/
function plugin_action_links( $links, $file )
{
if ( preg_match( "|{$file}\$|", WP_FAIL2BAN_FILE ) ) {
// Add Settings at the start
array_unshift( $links, '<a href="' . admin_url( 'admin.php' ) . '?page=wp-fail2ban-settings&tab=about">Settings</a>' );
}
return $links;
}
add_filter(
'plugin_action_links',
__NAMESPACE__ . '\\plugin_action_links',
10,
2
);

69
admin/config.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
/**
* Config
*
* @package wp-fail2ban
* @since 4.0.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
require_once 'lib/tab.php';
foreach ( glob( __DIR__ . '/config/*.php' ) as $filename ) {
require_once $filename;
}
/**
* Render Settings
*
* @since 4.0.0
*/
function settings()
{
$tabs = [
'logging',
'syslog',
'block',
'remote-ips',
'plugins'
];
$title = 'WP fail2ban';
?>
<div class="wrap">
<h1><?php
echo $title ;
?></h1>
<hr class="wp-header-end">
<h2 class="nav-tab-wrapper wp-clearfix">
<?php
$active_tab = Tab::getActiveTab( 'logging' );
foreach ( $tabs as $slug ) {
$class = 'nav-tab';
if ( $active_tab->getSlug() == $slug ) {
$class .= ' nav-tab-active';
}
printf(
'<a class="%s" href="?page=wp-fail2ban-settings&tab=%s">%s</a>',
$class,
$slug,
Tab::getTabName( $slug )
);
}
?>
</h2>
<form action="options.php?tab=<?php
echo $active_tab->getSlug() ;
?>" method="post">
<?php
settings_fields( 'wp-fail2ban' );
$active_tab->render();
echo '<hr><p>' . __( '<strong>Note:</strong> The Free version of <em>WP fail2ban</em> is configured by defining constants in <tt>wp-config.php</tt>; these tabs display those values.<br>Upgrade to the Premium version to enable this interface.' ) . '</p>' ;
?>
</form>
</div>
<?php
}

120
admin/config/block.php Normal file
View File

@@ -0,0 +1,120 @@
<?php
/**
* Settings - Block
*
* @package wp-fail2ban
* @since 4.0.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Tab: Block
*
* @since 4.0.0
*/
class TabBlock extends Tab
{
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function __construct()
{
add_action( 'admin_init', [ $this, 'admin_init' ] );
parent::__construct( 'block', 'Users' );
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function admin_init()
{
// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing
add_settings_section(
'wp-fail2ban-block',
__( 'Block' ),
[ $this, 'section' ],
'wp-fail2ban-block'
);
add_settings_field(
'block-user-enumeration',
parent::doc_link( 'WP_FAIL2BAN_BLOCK_USER_ENUMERATION', __( 'User Enumeration' ) ),
[ $this, 'userEnumeration' ],
'wp-fail2ban-block',
'wp-fail2ban-block'
);
add_settings_field(
'block-users',
parent::doc_link( 'WP_FAIL2BAN_BLOCKED_USERS', __( 'Usernames' ) ),
[ $this, 'usernames' ],
'wp-fail2ban-block',
'wp-fail2ban-block'
);
// phpcs:enable
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*
* @param array $settings
* @param array $input
*/
public function sanitize( array $settings, array $input = null )
{
return $settings;
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function section()
{
echo '' ;
}
/**
* User Enumeration
*
* @since 4.0.0
*/
public function userEnumeration()
{
printf( '<input type="checkbox" disabled="disabled" %s>', checked( WP_FAIL2BAN_BLOCK_USER_ENUMERATION, true, false ) );
}
/**
* Blocked usernames
*
* @since 4.0.0
*/
public function usernames()
{
if ( defined( 'WP_FAIL2BAN_BLOCKED_USERS' ) ) {
if ( is_array( WP_FAIL2BAN_BLOCKED_USERS ) ) {
$value = join( ', ', WP_FAIL2BAN_BLOCKED_USERS );
} else {
$value = WP_FAIL2BAN_BLOCKED_USERS;
}
} else {
$value = '';
}
printf( '<input class="regular-text" type="text" disabled="disabled" value="%s">', esc_attr( $value ) );
}
}
new TabBlock();

255
admin/config/logging.php Normal file
View File

@@ -0,0 +1,255 @@
<?php
/**
* Settings - Logging
*
* @package wp-fail2ban
* @since 4.0.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Tab: Logging
*
* @since 4.0.0
*/
class TabLogging extends Tab
{
/**
* {@inheritDoc}
*/
public function __construct()
{
add_action( 'admin_init', [ $this, 'admin_init' ], 100 );
parent::__construct( 'logging', 'Logging' );
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function admin_init()
{
// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing
add_settings_section(
'wp-fail2ban-logging',
__( 'What & Where' ),
[ $this, 'sectionWhatWhere' ],
'wp-fail2ban-logging'
);
add_settings_field(
'logging-log-authentication',
parent::doc_link( 'WP_FAIL2BAN_AUTH_LOG', __( 'Authentication' ) ),
[ $this, 'authentication' ],
'wp-fail2ban-logging',
'wp-fail2ban-logging'
);
add_settings_field(
'logging-log-comments',
parent::doc_link( 'WP_FAIL2BAN_LOG_COMMENTS', __( 'Comments' ) ),
[ $this, 'comments' ],
'wp-fail2ban-logging',
'wp-fail2ban-logging'
);
add_settings_field(
'logging-log-spam',
parent::doc_link( 'WP_FAIL2BAN_LOG_SPAM', __( 'Spam' ) ),
[ $this, 'spam' ],
'wp-fail2ban-logging',
'wp-fail2ban-logging'
);
add_settings_field(
'logging-log-password-request',
parent::doc_link( 'WP_FAIL2BAN_LOG_PASSWORD_REQUEST', __( 'Password Requests' ) ),
[ $this, 'passwordRequest' ],
'wp-fail2ban-logging',
'wp-fail2ban-logging'
);
add_settings_field(
'logging-log-pingbacks',
parent::doc_link( 'WP_FAIL2BAN_LOG_PINGBACKS', __( 'Pingbacks' ) ),
[ $this, 'pingbacks' ],
'wp-fail2ban-logging',
'wp-fail2ban-logging'
);
// phpcs:enable
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function render()
{
parent::render();
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*
* @param array $settings {@inheritDoc}
* @param array $input {@inheritDoc}
*
* @return array {@inheritDoc}
*/
public function sanitize( array $settings, array $input = null )
{
return $settings;
}
/**
* Section summary.
*
* @since 4.0.0
*/
public function sectionWhatWhere()
{
echo '' ;
}
/**
* Authentication.
*
* @since 4.0.0
*/
public function authentication()
{
printf( '<label>%s: %s</label>', __( 'Use facility' ), $this->getLogFacilities( 'WP_FAIL2BAN_AUTH_LOG', true ) );
}
/**
* Comments.
*
* @since 4.0.0
*/
public function comments()
{
add_filter(
'wp_fail2ban_log_WP_FAIL2BAN_LOG_COMMENTS',
[ $this, 'commentsExtra' ],
10,
3
);
$this->log(
'WP_FAIL2BAN_LOG_COMMENTS',
'WP_FAIL2BAN_COMMENT_LOG',
'',
[ 'comments-extra', 'logging-comments-extra-facility' ]
);
}
/**
* Comments extra helper - checked.
*
* @since 4.0.0
*
* @param int $value Value to check
*/
protected function commentExtraChecked( $value )
{
if ( !defined( 'WP_FAIL2BAN_LOG_COMMENTS_EXTRA' ) ) {
return '';
}
return checked( $value & WP_FAIL2BAN_LOG_COMMENTS_EXTRA, $value, false );
}
/**
* Comments extra helper - disabled.
*
* @since 4.0.0
*/
protected function commentExtraDisabled()
{
return 'disabled="disabled';
}
/**
* Comments extra.
*
* @since 4.0.0
*
* @param string $html HTML prefixed to output
* @param string $define_name Not used
* @param string $define_log Not used
*
* @return string
*/
public function commentsExtra( $html, $define_name, $define_log )
{
$fmt = <<<___HTML___
<table>
<tr>
<th>%s</th>
<td>
<fieldset id="comments-extra" disabled="disabled">
<label><input type="checkbox" %s> %s</label><br>
<label><input type="checkbox" %s> %s</label><br>
<label><input type="checkbox" %s> %s</label><br>
<label><input type="checkbox" %s> %s</label><br>
<label><input type="checkbox" %s> %s</label>
</fieldset>
</td>
</tr>
<tr>
<th>%s</th>
<td>%s</td>
</tr>
</table>
___HTML___;
return $html . sprintf(
$fmt,
parent::doc_link( 'WP_FAIL2BAN_LOG_COMMENTS_EXTRA', __( 'Also log:' ) ),
$this->commentExtraChecked( WPF2B_EVENT_COMMENT_NOT_FOUND ),
__( 'Post not found' ),
$this->commentExtraChecked( WPF2B_EVENT_COMMENT_CLOSED ),
__( 'Comments closed' ),
$this->commentExtraChecked( WPF2B_EVENT_COMMENT_TRASH ),
__( 'Trash post' ),
$this->commentExtraChecked( WPF2B_EVENT_COMMENT_DRAFT ),
__( 'Draft post' ),
$this->commentExtraChecked( WPF2B_EVENT_COMMENT_PASSWORD ),
__( 'Password-protected post' ),
parent::doc_link( 'WP_FAIL2BAN_COMMENT_EXTRA_LOG', __( 'Use facility:' ) ),
$this->getLogFacilities( 'WP_FAIL2BAN_COMMENT_EXTRA_LOG', false )
);
}
/**
* Password request
*
* @since 4.0.0
*/
public function passwordRequest()
{
$this->log( 'WP_FAIL2BAN_LOG_PASSWORD_REQUEST', 'WP_FAIL2BAN_PASSWORD_REQUEST_LOG' );
}
/**
* Pingbacks
*
* @since 4.0.0
*/
public function pingbacks()
{
$this->log( 'WP_FAIL2BAN_LOG_PINGBACKS', 'WP_FAIL2BAN_PINGBACK_LOG' );
}
/**
* Spam
*
* @since 4.0.0
*/
public function spam()
{
$this->log( 'WP_FAIL2BAN_LOG_SPAM', 'WP_FAIL2BAN_SPAM_LOG' );
}
}
new TabLogging();

185
admin/config/plugins.php Normal file
View File

@@ -0,0 +1,185 @@
<?php
/**
* Settings - Plugins
*
* @package wp-fail2ban
* @since 4.2.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Tab: Plugins
*
* @since 4.2.0
*/
class TabPlugins extends Tab
{
/**
* {@inheritDoc}
*/
public function __construct()
{
add_action( 'admin_init', [ $this, 'admin_init' ], 100 );
parent::__construct( 'plugins', 'Plugins' );
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function admin_init()
{
// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing
add_settings_section(
'wp-fail2ban-plugins',
__( 'Event Class Facilities' ),
[ $this, 'sectionLoggingEventClasses' ],
'wp-fail2ban-plugins'
);
add_settings_field(
'plugins-log-auth',
parent::doc_link( 'WP_FAIL2BAN_PLUGIN_LOG_AUTH', __( 'Authentication' ) ),
[ $this, 'auth' ],
'wp-fail2ban-plugins',
'wp-fail2ban-plugins'
);
add_settings_field(
'plugins-log-comment',
parent::doc_link( 'WP_FAIL2BAN_PLUGIN_LOG_COMMENT', __( 'Comment' ) ),
[ $this, 'comment' ],
'wp-fail2ban-plugins',
'wp-fail2ban-plugins'
);
add_settings_field(
'plugins-log-password',
parent::doc_link( 'WP_FAIL2BAN_PLUGIN_LOG_PASSWORD', __( 'Password' ) ),
[ $this, 'password' ],
'wp-fail2ban-plugins',
'wp-fail2ban-plugins'
);
add_settings_field(
'plugins-log-rest',
parent::doc_link( 'WP_FAIL2BAN_PLUGIN_LOG_REST', __( 'REST' ) ),
[ $this, 'rest' ],
'wp-fail2ban-plugins',
'wp-fail2ban-plugins'
);
add_settings_field(
'plugins-log-spam',
parent::doc_link( 'WP_FAIL2BAN_PLUGIN_LOG_SPAM', __( 'Spam' ) ),
[ $this, 'spam' ],
'wp-fail2ban-plugins',
'wp-fail2ban-plugins'
);
add_settings_field(
'plugins-log-xmlrpc',
parent::doc_link( 'WP_FAIL2BAN_PLUGIN_LOG_XMLRPC', __( 'XML-RPC' ) ),
[ $this, 'xmlrpc' ],
'wp-fail2ban-plugins',
'wp-fail2ban-plugins'
);
// phpcs:enable
}
/**
* {@inheritDoc}
*
* @since 4.2.0
*/
public function render()
{
parent::render();
}
/**
* {@inheritDoc}
*
* @since 4.2.0
*
* @param array $settings {@inheritDoc}
* @param array $input {@inheritDoc}
*
* @return array {@inheritDoc}
*/
public function sanitize( array $settings, array $input = null )
{
return $settings;
}
/**
* Section summary.
*
* @since 4.2.0
*/
public function sectionLoggingEventClasses()
{
echo __( 'Facilities to use for plugin-generated messages. The defaults follow the Core defaults.' ) ;
}
/**
* Auth
*
* @since 4.2.0
*/
public function auth()
{
$this->log( 'WP_FAIL2BAN_PLUGIN_LOG_AUTH', 'WP_FAIL2BAN_PLUGIN_AUTH_LOG' );
}
/**
* Comment
*
* @since 4.2.0
*/
public function comment()
{
$this->log( 'WP_FAIL2BAN_PLUGIN_LOG_COMMENT', 'WP_FAIL2BAN_PLUGIN_COMMENT_LOG' );
}
/**
* Password
*
* @since 4.2.0
*/
public function password()
{
$this->log( 'WP_FAIL2BAN_PLUGIN_LOG_PASSWORD', 'WP_FAIL2BAN_PLUGIN_PASSWORD_LOG' );
}
/**
* REST
*
* @since 4.2.0
*/
public function rest()
{
$this->log( 'WP_FAIL2BAN_PLUGIN_LOG_REST', 'WP_FAIL2BAN_PLUGIN_REST_LOG' );
}
/**
* Spam
*
* @since 4.2.0
*/
public function spam()
{
$this->log( 'WP_FAIL2BAN_PLUGIN_LOG_SPAM', 'WP_FAIL2BAN_PLUGIN_SPAM_LOG' );
}
/**
* XML-RPC
*
* @since 4.2.0
*/
public function xmlrpc()
{
$this->log( 'WP_FAIL2BAN_PLUGIN_LOG_XMLRPC', 'WP_FAIL2BAN_PLUGIN_XMLRPC_LOG' );
}
}
new TabPlugins();

100
admin/config/remote-ips.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
/**
* Settings - Remote IPs
*
* @package wp-fail2ban
* @since 4.0.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Tab: Remote IPs
*
* @since 4.0.0
*/
class TabRemoteIPs extends Tab
{
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function __construct()
{
add_action( 'admin_init', [ $this, 'admin_init' ] );
parent::__construct( 'remote-ips', 'Remote IPs' );
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function admin_init()
{
// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing
add_settings_section(
'wp-fail2ban-proxies',
__( 'Proxies' ),
[ $this, 'section' ],
'wp-fail2ban-remote-ips'
);
add_settings_field(
'remote-ips-proxies',
parent::doc_link( 'WP_FAIL2BAN_PROXIES', __( 'IP list' ) ),
[ $this, 'proxies' ],
'wp-fail2ban-remote-ips',
'wp-fail2ban-proxies'
);
// phpcs:enable
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*
* @param array $settings
* @param array $input
*/
public function sanitize( array $settings, array $input = null )
{
return $settings;
}
/**
* Section blurb.
*
* @since 4.0.0
*/
public function section()
{
echo '' ;
}
/**
* Proxies.
*
* @since 4.0.0
*/
public function proxies()
{
$value = '';
if ( defined( 'WP_FAIL2BAN_PROXIES' ) ) {
if ( is_array( WP_FAIL2BAN_PROXIES ) ) {
$value = join( "\n", WP_FAIL2BAN_PROXIES );
} else {
$value = join( "\n", array_map( 'trim', explode( ',', WP_FAIL2BAN_PROXIES ) ) );
}
}
printf( '<fieldset><textarea class="code" cols="20" rows="10" disabled="disabled">%s</textarea></fieldset>', esc_html( $value ) );
}
}
new TabRemoteIPs();

159
admin/config/syslog.php Normal file
View File

@@ -0,0 +1,159 @@
<?php
/**
* Settings - syslog
*
* @package wp-fail2ban
* @since 4.0.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Tab: Syslog
*
* @since 4.0.0
*/
class TabSyslog extends Tab
{
/**
* {@inheritDoc}
*/
public function __construct()
{
add_action( 'admin_init', [ $this, 'admin_init' ], 100 );
parent::__construct( 'syslog', '<tt>syslog</tt>' );
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*/
public function admin_init()
{
// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing
add_settings_section(
'wp-fail2ban-connection',
__( 'Connection' ),
[ $this, 'sectionConnection' ],
'wp-fail2ban-syslog'
);
add_settings_field(
'logging-connection',
parent::doc_link( 'WP_FAIL2BAN_OPENLOG_OPTIONS', __( 'Options' ) ),
[ $this, 'connection' ],
'wp-fail2ban-syslog',
'wp-fail2ban-connection'
);
add_settings_section(
'wp-fail2ban-workarounds',
__( 'Workarounds' ),
[ $this, 'sectionWorkarounds' ],
'wp-fail2ban-syslog'
);
add_settings_field(
'logging-workarounds',
parent::doc_link( '../syslog', __( 'Options' ) ),
[ $this, 'workarounds' ],
'wp-fail2ban-syslog',
'wp-fail2ban-workarounds'
);
// phpcs:enable
}
/**
* {@inheritDoc}
*
* @since 4.0.0
*
* @param array $settings {@inheritDoc}
* @param array $input {@inheritDoc}
*
* @return array {@inheritDoc}
*/
public function sanitize( array $settings, array $input = null )
{
return $settings;
}
/**
* Connection section blurb.
*
* @since 4.0.0
*/
public function sectionConnection()
{
echo '' ;
}
/**
* Connection.
*
* @since 4.0.0
*/
public function connection()
{
$class = '';
$fmt = <<<___STR___
<fieldset>
<label><input type="checkbox" disabled="disabled" %s> <code>LOG_CONS</code></label><br>
<label><input type="checkbox" disabled="disabled" %s> <code>LOG_PERROR</code></label><br>
<label><input type="checkbox" disabled="disabled" %s> <code>LOG_PID</code> <em>(%s)</em></label><br>
<label><input type="radio" disabled="disabled" %s> <code>LOG_NDELAY</code> <em>(%s)</em></label><br>
<label><input type="radio" disabled="disabled" %s> <code>LOG_ODELAY</code></label>
</fieldset>
___STR___;
printf(
$fmt,
checked( WP_FAIL2BAN_OPENLOG_OPTIONS & LOG_CONS, LOG_CONS, false ),
checked( WP_FAIL2BAN_OPENLOG_OPTIONS & LOG_PERROR, LOG_PERROR, false ),
checked( WP_FAIL2BAN_OPENLOG_OPTIONS & LOG_PID, LOG_PID, false ),
__( 'default' ),
checked( WP_FAIL2BAN_OPENLOG_OPTIONS & LOG_NDELAY, LOG_NDELAY, false ),
__( 'default' ),
checked( WP_FAIL2BAN_OPENLOG_OPTIONS & LOG_ODELAY, LOG_ODELAY, false )
);
}
/**
* Workarounds section blurb.
*
* @since 4.0.0
*/
public function sectionWorkarounds()
{
echo '' ;
}
/**
* Workarounds.
*
* @since 4.0.0
*/
public function workarounds()
{
$fmt = <<<___STR___
<fieldset>
<label><input type="checkbox" disabled="disabled" %s> %s</label>
<br>
<label><input type="checkbox" disabled="disabled" %s> %s</label>
<br>
<label><input type="checkbox" disabled="disabled" %s> %s</label>
</fieldset>
___STR___;
printf(
$fmt,
checked( @WP_FAIL2BAN_SYSLOG_SHORT_TAG, true, false ),
__( 'Short Tag' ),
checked( @WP_FAIL2BAN_HTTP_HOST, true, false ),
__( 'Specify Host' ),
checked( @WP_FAIL2BAN_TRUNCATE_HOST, true, false ),
__( 'Truncate Host' )
);
}
}
new TabSyslog();

6
admin/img/docs.svg Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 26 26" version="1.1" width="16px" height="16px">
<g id="surface1">
<path style=" " d="M 7 0 C 4.796875 0 3 1.796875 3 4 L 3 22 C 3 24.203125 4.796875 26 7 26 L 19 26 C 21.203125 26 23 24.203125 23 22 L 23 8 C 23 6.9375 22.027344 5.929688 20.28125 4.21875 C 20.039063 3.980469 19.777344 3.714844 19.53125 3.46875 C 19.285156 3.222656 19.019531 2.992188 18.78125 2.75 C 17.070313 1.003906 16.0625 0 15 0 Z M 7 2 L 14.28125 2 C 15.003906 2.183594 15 3.050781 15 3.9375 L 15 7 C 15 7.550781 15.449219 8 16 8 L 19 8 C 19.996094 8 21 8.003906 21 9 L 21 22 C 21 23.105469 20.105469 24 19 24 L 7 24 C 5.894531 24 5 23.105469 5 22 L 5 4 C 5 2.894531 5.894531 2 7 2 Z M 7.8125 10 C 7.261719 10.050781 6.855469 10.542969 6.90625 11.09375 C 6.957031 11.644531 7.449219 12.050781 8 12 L 18 12 C 18.359375 12.003906 18.695313 11.816406 18.878906 11.503906 C 19.058594 11.191406 19.058594 10.808594 18.878906 10.496094 C 18.695313 10.183594 18.359375 9.996094 18 10 L 8 10 C 7.96875 10 7.9375 10 7.90625 10 C 7.875 10 7.84375 10 7.8125 10 Z M 7.8125 14 C 7.261719 14.050781 6.855469 14.542969 6.90625 15.09375 C 6.957031 15.644531 7.449219 16.050781 8 16 L 16 16 C 16.359375 16.003906 16.695313 15.816406 16.878906 15.503906 C 17.058594 15.191406 17.058594 14.808594 16.878906 14.496094 C 16.695313 14.183594 16.359375 13.996094 16 14 L 8 14 C 7.96875 14 7.9375 14 7.90625 14 C 7.875 14 7.84375 14 7.8125 14 Z M 7.8125 18 C 7.261719 18.050781 6.855469 18.542969 6.90625 19.09375 C 6.957031 19.644531 7.449219 20.050781 8 20 L 18 20 C 18.359375 20.003906 18.695313 19.816406 18.878906 19.503906 C 19.058594 19.191406 19.058594 18.808594 18.878906 18.496094 C 18.695313 18.183594 18.359375 17.996094 18 18 L 8 18 C 7.96875 18 7.9375 18 7.90625 18 C 7.875 18 7.84375 18 7.8125 18 Z "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

143
admin/lib/about.php Normal file
View File

@@ -0,0 +1,143 @@
<?php
/**
* About
*
* @package wp-fail2ban
* @since 4.2.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* About content
*
* @since 4.2.0
*
* @param bool $hide_title
*/
function about( $hide_title = false )
{
$wp_f2b_ver = substr( WP_FAIL2BAN_VER, 0, strrpos( WP_FAIL2BAN_VER, '.' ) );
?>
<div class="wrap">
<style>
div.inside ul {
list-style: disc;
padding-left: 2em;
}
</style>
<?php
if ( !$hide_title ) {
?>
<h1>WP fail2ban</h1>
<?php
}
?>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<h2>Version 4.2.5</h2>
<div class="inside">
<ul>
<li>Properly fix PHP 5.3 support; tested on CentOS 6. Does not support any UI or Premium features.</li>
<li>Fix potential issue with <tt>WP_FAIL2BAN_BLOCK_USER_ENUMERATION</tt> if calling REST API or XMLRPC from admin area.</li>
</ul>
</div>
</div>
</div>
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<h2>Version 4.2.4</h2>
<div class="inside">
<ul>
<li>Add filter for login failed message.</li>
<li>Fix logging spam comments from admin area.</li>
<li>Fix Settings link from Plugins page.</li>
<li>Update Freemius library.</li>
</ul>
</div>
</div>
</div>
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<h2>Version 4.2.3</h2>
<div class="inside">
<ul>
<li>Workaround for some versions of PHP 7.x that would cause <tt>define()</tt>s to be ignored.</li>
<li>Add config note to settings tabs.</li>
<li>Fix documentation links.</li>
</ul>
</div>
</div>
</div>
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<h2>Version 4.2.2</h2>
<div class="inside">
<ul>
<li>Fix 5.3 compatibility.</li>
</ul>
</div>
</div>
</div>
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<h2>Version 4.2.1</h2>
<div class="inside">
<ul>
<li>Completed support for <tt><a href="https://docs.wp-fail2ban.com/en/4.2/defines/WP_FAIL2BAN_COMMENT_EXTRA_LOG.html" target="docs.wp-fail2ban.com">WP_FAIL2BAN_COMMENT_EXTRA_LOG</a></tt>.</li>
<li>Add support for 3rd-party plugins; see <a href="https://docs.wp-fail2ban.com/en/4.2/developers.html" target="docs.wp-fail2ban.com">Developers</a>.<br>
<p><ul>
<li>Add-on for <a href="https://wordpress.org/plugins/wp-fail2ban-addon-contact-form-7/">Contact Form 7</a> (experimental).</li>
<li>Add-on for <a href="https://wordpress.org/plugins/wp-fail2ban-addon-gravity-forms/">Gravity Forms</a> (experimental).</li>
</ul></p>
</li>
<li>Change logging for known-user with incorrect password; previously logged as unknown user and matched by <tt>hard</tt> filters (due to limitations in older versions of WordPress), now logged as known user and matched by <tt>soft</tt>.</li>
<li>Bugfix for email-as-username - now logged correctly and matched by <tt>soft</tt>, not <tt>hard</tt>, filters.</li>
<li>Bugfix for regression in code to prevent Free/Premium conflict.</li>
</ul>
</div>
</div>
</div>
</div>
<div id="postbox-container-1" class="postbox-container">
<div class="meta-box-sortables">
<div class="postbox">
<h2>Getting Started</h2>
<div class="inside">
<ol>
<li><a href="https://docs.wp-fail2ban.com/en/<?php
echo $wp_f2b_ver ;
?>/introduction.html" target="docs.wp-fail2ban.com">Introduction</a></li>
<li><a href="https://docs.wp-fail2ban.com/en/<?php
echo $wp_f2b_ver ;
?>/configuration.html" target="docs.wp-fail2ban.com">Configuration</a></li>
</ol>
</div>
</div>
<div class="postbox">
<h2>Getting Help</h2>
<div class="inside">
<ul>
<?php
if ( wf_fs()->is_free_plan() ) {
?>
<li><a href="https://wordpress.org/support/plugin/wp-fail2ban/" target="_blank">WordPress.org Forum</a></li>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
&nbsp;
</div>
</div>
<?php
}

260
admin/lib/tab.php Normal file
View File

@@ -0,0 +1,260 @@
<?php
/**
* Tab base class
*
* @package wp-fail2ban-premium
* @since 4.0.0
*/
namespace org\lecklider\charles\wordpress\wp_fail2ban;
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Base Tab class
*
* @since 4.0.0
*/
abstract class Tab
{
/**
* @var array Array of Tab objects
*/
protected static $tabs = array() ;
/**
* @var string Active tab slug
*/
protected static $active_tab ;
/**
* @var string Tab slug
*/
protected $tab_slug ;
/**
* @var string Tab name
*/
protected $tab_name ;
/**
* Hook: admin_init
*
* @since 4.0.0
*/
public abstract function admin_init();
/**
* Sanitize and store form fields
*
* @since 4.0.0
*
* @param array $settings Settings to update
* @param array $input Form fields
*
* @return array $settings
*/
public abstract function sanitize( array $settings, array $input = null );
/**
* Contruct.
*
* @since 4.0.0
*
* @param string $slug Tab slug
* @param string $name Tab name
*/
public function __construct( $slug, $name )
{
$this->tab_slug = $slug;
$this->tab_name = $name;
self::$tabs[$slug] = $this;
}
/**
* Getter - slug
*
* @since 4.0.0
*
* @return string Tab slug
*/
public function getSlug()
{
return $this->tab_slug;
}
/**
* Getter - name
*
* @since 4.0.0
*
* @return string Tab name
*/
public function getName()
{
return $this->tab_name;
}
/**
* Render settings section
*
* @since 4.0.0
*/
public function render()
{
do_settings_sections( 'wp-fail2ban-' . $this->tab_slug );
}
/**
* Helper - tab
*
* @since 4.0.0
*
* @param string $slug Tab slug
*
* @return Tab Tab
*/
public static function getTab( $slug )
{
return self::$tabs[$slug];
}
/**
* Helper - current tab
*
* @since 4.0.0
*
* @param string $default Default slug
*
* @return Tab Tab
*/
public static function getActiveTab( $default = null )
{
if ( !empty(self::$active_tab) ) {
return self::$active_tab;
}
return self::$active_tab = ( array_key_exists( @$_GET['tab'], self::$tabs ) ? self::$tabs[$_GET['tab']] : self::$tabs[$default] );
}
/**
* Helper - tab name
*
* @since 4.0.0
*
* @param string $slug Tab slug
*
* @return string Tab name
*/
public static function getTabName( $slug )
{
return self::getTab( $slug )->getName();
}
/**
* Link to documentation
*
* @since 4.2.0
*
* @param string $define
* @param string $name
*
* @return string
*/
public static function doc_link( $define, $name )
{
static $wp_f2b_ver ;
if ( empty($wp_f2b_ver) ) {
$wp_f2b_ver = substr( WP_FAIL2BAN_VER, 0, strrpos( WP_FAIL2BAN_VER, '.' ) );
}
return sprintf(
'<a href="https://docs.wp-fail2ban.com/en/%s/defines/constants/%s.html" style="text-decoration: none;" target="_blank" title="Documentation"><span class="dashicons dashicons-external" style="vertical-align: text-bottom"></span></a> %s',
$wp_f2b_ver,
$define,
$name
);
}
/**
* Helper - drop-down list of facilities
*
* @since 4.0.0
*
* @param string $def Name of define for selected value
* @param bool $_enabled Enabled?
*/
protected function getLogFacilities( $def, $_enabled = false )
{
$enabled = false;
$facilities = [
LOG_AUTH => 'LOG_AUTH',
LOG_AUTHPRIV => 'LOG_AUTHPRIV',
LOG_CRON => 'LOG_CRON',
LOG_DAEMON => 'LOG_DAEMON',
LOG_KERN => 'LOG_KERN',
LOG_LOCAL0 => 'LOG_LOCAL0',
LOG_LOCAL1 => 'LOG_LOCAL1',
LOG_LOCAL2 => 'LOG_LOCAL2',
LOG_LOCAL3 => 'LOG_LOCAL3',
LOG_LOCAL4 => 'LOG_LOCAL4',
LOG_LOCAL5 => 'LOG_LOCAL5',
LOG_LOCAL6 => 'LOG_LOCAL6',
LOG_LOCAL7 => 'LOG_LOCAL7',
LOG_LPR => 'LOG_LPR',
LOG_MAIL => 'LOG_MAIL',
LOG_NEWS => 'LOG_NEWS',
LOG_SYSLOG => 'LOG_SYSLOG',
LOG_USER => 'LOG_USER',
LOG_UUCP => 'LOG_UUCP',
];
$default = constant( "DEFAULT_{$def}" );
$value = ( defined( $def ) ? constant( $def ) : $default );
$str = '<select disabled="disabled">';
foreach ( $facilities as $facility => $name ) {
$str .= sprintf(
'<option value="%s" %s>%s%s</option>',
$facility,
selected( $value, $facility, false ),
$name,
( $facility == $default ? __( ' (default)' ) : '' )
);
}
$str .= '</select>';
return $str;
}
/**
* Log helper - enable/disable+facility
*
* @since 4.2.0 Moved to Tab
* @since 4.0.0
*
* @param string $define_name Name of define to enable logging
* @param string $define_log Name of define for log facility
* @param string $description Description
* @param array $toggle Array of IDs to sync toggle state
*/
protected function log(
$define_name,
$define_log,
$description = '',
array $toggle = array()
)
{
$enabled = defined( $define_name ) && true === constant( $define_name );
$fmt = <<<___FMT___
<label><input type="checkbox" disabled="disabled" %s> Enable logging</label>,
<label>use facility: %s</label>
<p class="description">%s</p>
___FMT___;
$html = sprintf(
$fmt,
checked( $enabled, true, false ),
$this->getLogFacilities( $define_log ),
$description
);
echo apply_filters(
"wp_fail2ban_log_{$define_name}",
$html,
$define_name,
$define_log
) ;
}
}