Skip to content

Commit

Permalink
Merge branch 'hotfix-0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
chesio committed Aug 1, 2017
2 parents 0a6c280 + 604bb2a commit f63043e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bc-security.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: BC Security
* Plugin URI: https://github.com/chesio/bc-security
* Description: Helps keeping WordPress websites secure. Plugin requires PHP 5.6 or newer to run.
* Version: 0.4.0
* Version: 0.4.1
* Author: Česlav Przywara <[email protected]>
* Author URI: https://www.chesio.com
* Requires at least: 4.7
Expand Down
11 changes: 9 additions & 2 deletions classes/BlueChip/Security/Modules/Events/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ class Monitor implements \BlueChip\Security\Modules\Initializable
*/
private $remote_address;

/**
* @var string Server IP address
*/
private $server_address;


/**
* @param string $remote_address Remote IP address.
* @param string $server_address Server IP address.
*/
public function __construct($remote_address)
public function __construct($remote_address, $server_address)
{
$this->remote_address = $remote_address;
$this->server_address = $server_address;
}


Expand All @@ -36,7 +43,7 @@ public function init()
// - successful login
add_action('wp_login', [$this, 'logSuccessfulLogin'], 5, 1);
// - 404 query (only if request did not originate from the webserver itself)
if ($this->remote_address !== $_SERVER['SERVER_ADDR']) {
if ($this->remote_address !== $this->server_address) {
add_action('wp', [$this, 'log404Queries'], 20, 1);
}

Expand Down
10 changes: 6 additions & 4 deletions classes/BlueChip/Security/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ public function __construct($wpdb)
// Get setup info.
$setup = new Setup\Core($this->settings['setup']);

// IP address is at core interest within this plugin :)
// IP addresses are at core interest within this plugin :)
$remote_address = $setup->getRemoteAddress();
$server_address = $setup->getServerAddress();

// Init admin, if necessary.
$this->admin = is_admin() ? new Admin() : null;

// Construct modules.
$this->modules = $this->constructModules($wpdb, $remote_address, $this->settings);
$this->modules = $this->constructModules($wpdb, $remote_address, $server_address, $this->settings);

// Construct cron jobs.
$this->cron_jobs = $this->constructCronJobs($this->settings, $this->modules);
Expand All @@ -85,13 +86,14 @@ private function constructSettings()
* Construct plugin modules.
* @param \wpdb $wpdb
* @param string $remote_address
* @param string $server_address
* @param array $settings
* @return array
*/
private function constructModules($wpdb, $remote_address, $settings)
private function constructModules($wpdb, $remote_address, $server_address, $settings)
{
$logger = new Modules\Log\Logger($wpdb, $remote_address);
$monitor = new Modules\Events\Monitor($remote_address);
$monitor = new Modules\Events\Monitor($remote_address, $server_address);
$notifier = new Modules\Notifications\Watchman($settings['notifications'], $remote_address, $logger);
$hardening = new Modules\Hardening\Core($settings['hardening']);
$bl_manager = new Modules\IpBlacklist\Manager($wpdb);
Expand Down
11 changes: 11 additions & 0 deletions classes/BlueChip/Security/Setup/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ public function getRemoteAddress()
{
return IpAddress::get($this->connection_type);
}


/**
* Get server IP address. In the moment, there is no way to "configure" it.
*
* @return string
*/
public function getServerAddress()
{
return IpAddress::getServer();
}
}
13 changes: 12 additions & 1 deletion classes/BlueChip/Security/Setup/IpAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace BlueChip\Security\Setup;

/**
* Remote IP address retrieval
* IP address retrieval (both remote and server)
*/
abstract class IpAddress
{
Expand Down Expand Up @@ -85,6 +85,17 @@ public static function getRaw($type)
}


/**
* Get IP address of webserver.
*
* @return string IP address of webserver or empty string if none provided (typically when running via PHP-CLI).
*/
public static function getServer()
{
return isset($_SERVER['SERVER_ADDR']) ? self::getFirst($_SERVER['SERVER_ADDR']) : '';
}


/**
* Get the first from possibly multiple $ip_addresses.
* @param string $ip_addresses
Expand Down

0 comments on commit f63043e

Please sign in to comment.