Skip to content

Commit

Permalink
feat(*): Use namespace to avoid class confilcts with other third part…
Browse files Browse the repository at this point in the history
…y code (#149)
  • Loading branch information
julienloizelet authored Mar 29, 2024
1 parent 5d11f87 commit 2685fa5
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions inc/Bouncer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

declare(strict_types=1);

namespace CrowdSecWordPressBouncer;

use CrowdSec\RemediationEngine\CacheStorage\CacheStorageException;
use CrowdSec\RemediationEngine\LapiRemediation;
use CrowdSec\Common\Logger\FileLog;
Expand Down
2 changes: 2 additions & 0 deletions inc/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

namespace CrowdSecWordPressBouncer;

use CrowdSecBouncer\Constants as LibConstants;

/**
Expand Down
4 changes: 4 additions & 0 deletions inc/admin/advanced-settings.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

use CrowdSecWordPressBouncer\AdminNotice;
use CrowdSecWordPressBouncer\Constants;
use CrowdSecWordPressBouncer\Bouncer;
use CrowdSecBouncer\BouncerException;
use CrowdSec\RemediationEngine\Constants as RemConstants;
use IPLib\Factory;

require_once __DIR__ . '/../Constants.php';
require_once __DIR__ . '/../options-config.php';
require_once __DIR__ . '/notice.php';
Expand Down
7 changes: 5 additions & 2 deletions inc/admin/init.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

use CrowdSecWordPressBouncer\Constants;
use CrowdSecBouncer\BouncerException;
use CrowdSec\RemediationEngine\Geolocation;
use CrowdSecWordPressBouncer\AdminNotice;
use CrowdSecWordPressBouncer\Bouncer;

require_once __DIR__ . '/notice.php';
require_once __DIR__ . '/../Constants.php';
Expand Down Expand Up @@ -222,7 +225,7 @@ function testGeolocationInAdminPage($ip)
!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'crowdsec_test_connection')) {
die('This link expired.');
}
$ip = isset($_POST['crowdsec_test_connection_ip']) ? $_POST['crowdsec_test_connection_ip'] : $_SERVER['REMOTE_ADDR'];
$ip = $_POST['crowdsec_test_connection_ip'] ?? $_SERVER['REMOTE_ADDR'];
testBouncerConnexionInAdminPage($ip);
header("Location: {$_SERVER['HTTP_REFERER']}");
exit(0);
Expand All @@ -233,7 +236,7 @@ function testGeolocationInAdminPage($ip)
!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'crowdsec_test_geolocation')) {
die('This link expired.');
}
$ip = isset($_POST['crowdsec_test_geolocation_ip']) ? $_POST['crowdsec_test_geolocation_ip'] : $_SERVER['REMOTE_ADDR'];
$ip = $_POST['crowdsec_test_geolocation_ip'] ?? $_SERVER['REMOTE_ADDR'];
testGeolocationInAdminPage($ip);
header("Location: {$_SERVER['HTTP_REFERER']}");
exit(0);
Expand Down
4 changes: 3 additions & 1 deletion inc/admin/notice.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

namespace CrowdSecWordPressBouncer;

class AdminNotice
{
const NOTICE_FIELD = 'crowdsec_admin_notice_message';

public function displayAdminNotice()
{
$option = is_multisite() ? get_site_option(self::NOTICE_FIELD) : get_option(self::NOTICE_FIELD);
$message = isset($option['message']) ? $option['message'] : false;
$message = $option['message'] ?? false;
$noticeLevel = !empty($option['notice-level']) ? $option['notice-level'] : 'notice-error';

if ($message) {
Expand Down
2 changes: 2 additions & 0 deletions inc/admin/settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
require_once __DIR__ . '/../Constants.php';
use CrowdSecWordPressBouncer\Constants;


function adminSettings()
{
Expand Down
2 changes: 2 additions & 0 deletions inc/bounce-current-ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
require_once __DIR__ . '/Constants.php';
require_once __DIR__ . '/options-config.php';

use CrowdSecWordPressBouncer\Constants;
use CrowdSecWordPressBouncer\Bouncer;
use CrowdSecBouncer\BouncerException;
use Psr\Cache\CacheException;

Expand Down
2 changes: 2 additions & 0 deletions inc/options-config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
require_once __DIR__ . '/Constants.php';
use CrowdSecWordPressBouncer\Constants;


function getCrowdSecOptionsConfig(): array
{
Expand Down
2 changes: 2 additions & 0 deletions inc/plugin-setup.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CrowdSecWordPressBouncer\Constants;

require_once __DIR__.'/options-config.php';
require_once __DIR__ . '/Constants.php';

Expand Down
3 changes: 3 additions & 0 deletions inc/scheduling.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use CrowdSecWordPressBouncer\Bouncer;

require_once __DIR__ . '/options-config.php';
require_once __DIR__ . '/Bouncer.php';

Expand Down
5 changes: 2 additions & 3 deletions inc/standalone-bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
define('CROWDSEC_STANDALONE_RUNNING_CONTEXT', true);

require_once __DIR__.'/../vendor/autoload.php';

require_once __DIR__.'/Bouncer.php';
require_once __DIR__.'/Constants.php';


use CrowdSecBouncer\BouncerException;

use CrowdSecWordPressBouncer\Constants;
use CrowdSecWordPressBouncer\Bouncer;

// If there is any technical problem while bouncing, don't block the user.
try {
Expand Down

0 comments on commit 2685fa5

Please sign in to comment.