diff --git a/app/Base.php b/app/Base.php index 20feac36e..90f262701 100644 --- a/app/Base.php +++ b/app/Base.php @@ -7,7 +7,7 @@ abstract class Base { protected static DB\Mysql $db; protected static Cache $cache; - protected static BaseRequestContext $requestContext; + protected static RequestContext $requestContext; protected static \Twig\Environment $twig; public static function initialize(Cache $cache, DB\Mysql $db, \Twig\Environment $twig): void { @@ -16,15 +16,15 @@ abstract class Base { static::$twig = $twig; } - public static function setRequestContext(BaseRequestContext $c): void { + public static function setRequestContext(RequestContext $c): void { static::$requestContext = $c; } - public static function staticRequestContext(): BaseRequestContext { + public static function staticRequestContext(): RequestContext { return static::$requestContext; } - public function requestContext(): BaseRequestContext { + public function requestContext(): RequestContext { return static::$requestContext; } diff --git a/app/BaseRequestContext.php b/app/RequestContext.php similarity index 98% rename from app/BaseRequestContext.php rename to app/RequestContext.php index 9d1714c6f..db133728f 100644 --- a/app/BaseRequestContext.php +++ b/app/RequestContext.php @@ -2,7 +2,7 @@ namespace Gazelle; -class BaseRequestContext { +class RequestContext { protected string $module; // previously known as global $Document protected bool $isValid; protected array $ua; diff --git a/bin/boris b/bin/boris index 32eff62a7..d907574f9 100755 --- a/bin/boris +++ b/bin/boris @@ -27,7 +27,7 @@ if ($remove) { define('BORIS', 1); $_SERVER['HTTP_USER_AGENT'] = 'boris'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; -Base::setRequestContext(new BaseRequestContext( +Base::setRequestContext(new RequestContext( 'boris', $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'] )); diff --git a/bin/scheduler b/bin/scheduler index 1debc2f06..b671f06da 100755 --- a/bin/scheduler +++ b/bin/scheduler @@ -4,6 +4,6 @@ require_once(__DIR__ . '/../lib/bootstrap.php'); Gazelle\Base::setRequestContext( - new Gazelle\BaseRequestContext('cli', '127.0.0.1', 'scheduler') + new Gazelle\RequestContext('cli', '127.0.0.1', 'scheduler') ); (new Gazelle\TaskScheduler)->run(); diff --git a/gazelle.php b/gazelle.php index 9fc1b23a6..1c8252d8f 100644 --- a/gazelle.php +++ b/gazelle.php @@ -20,7 +20,7 @@ if ( $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; } -$context = new BaseRequestContext( +$context = new RequestContext( $_SERVER['SCRIPT_NAME'], $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'] ?? '[no-useragent]', @@ -130,7 +130,7 @@ if ($Viewer) { } if ($Viewer->ipaddr() != $context->remoteAddr() && !$Viewer->permitted('site_disable_ip_history')) { if ($ipv4Man->isBanned($context->remoteAddr())) { - error('Your IP address has been banned.'); + Error403::error('Your IP address has been banned.'); } $ipv4Man->register($Viewer, $context->remoteAddr()); } diff --git a/lib/bootstrap.php b/lib/bootstrap.php index 8123c935c..f3a104a99 100644 --- a/lib/bootstrap.php +++ b/lib/bootstrap.php @@ -28,7 +28,7 @@ $Twig = Gazelle\Util\Twig::factory(new Gazelle\Manager\User()); Gazelle\Base::initialize($Cache, Gazelle\DB::DB(), $Twig); -Gazelle\Base::setRequestContext(new Gazelle\BaseRequestContext( +Gazelle\Base::setRequestContext(new Gazelle\RequestContext( scriptName: 'none', remoteAddr: '127.0.0.1', useragent: 'none', diff --git a/public/feeds.php b/public/feeds.php index d72ec9a0b..141e7e9f1 100644 --- a/public/feeds.php +++ b/public/feeds.php @@ -29,7 +29,7 @@ if ( ) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; } -$context = new Gazelle\BaseRequestContext( +$context = new Gazelle\RequestContext( $_SERVER['SCRIPT_NAME'], $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'] ?? '[no-useragent]', diff --git a/sections/login/login.php b/sections/login/login.php index fc9448b6c..be83fc26f 100644 --- a/sections/login/login.php +++ b/sections/login/login.php @@ -46,7 +46,7 @@ if (!empty($_POST['username']) && !empty($_POST['password'])) { exit; } $useragent = $_SERVER['HTTP_USER_AGENT'] ?? '[no-useragent]'; - $context = new BaseRequestContext( + $context = new RequestContext( $_SERVER['SCRIPT_NAME'], $_SERVER['REMOTE_ADDR'], $useragent, diff --git a/tests/phpunit/ForumTest.php b/tests/phpunit/ForumTest.php index 822842ff3..30f77ba38 100644 --- a/tests/phpunit/ForumTest.php +++ b/tests/phpunit/ForumTest.php @@ -547,7 +547,7 @@ class ForumTest extends TestCase { description: 'This is where it renders', ); $paginator = (new Util\Paginator(TOPICS_PER_PAGE, 1))->setTotal(1); - Base::setRequestContext(new BaseRequestContext('/forum.php', '127.0.0.1', '')); + Base::setRequestContext(new RequestContext('/forum.php', '127.0.0.1', '')); global $SessionID; // to render header() $SessionID = 'phpunit'; Util\Twig::setViewer($admin); diff --git a/tests/phpunit/FriendTest.php b/tests/phpunit/FriendTest.php index 0c5d5b7b8..e3bebae3c 100644 --- a/tests/phpunit/FriendTest.php +++ b/tests/phpunit/FriendTest.php @@ -59,7 +59,7 @@ class FriendTest extends TestCase { 'ipaddr' => '127.0.0.1', 'useragent' => 'phpunit-browser', ]); - Base::setRequestContext(new BaseRequestContext('/friends.php', '127.0.0.1', '')); + Base::setRequestContext(new RequestContext('/friends.php', '127.0.0.1', '')); global $SessionID; $SessionID = $current['SessionID']; diff --git a/tests/phpunit/LogTest.php b/tests/phpunit/LogTest.php index 20cb4e89f..ed21d71de 100644 --- a/tests/phpunit/LogTest.php +++ b/tests/phpunit/LogTest.php @@ -138,7 +138,7 @@ class LogTest extends TestCase { $page = $siteLog->page($paginator->page(), $paginator->offset(), ''); $paginator->setTotal($siteLog->total('')); - Base::setRequestContext(new BaseRequestContext('/index.php', '127.0.0.1', '')); + Base::setRequestContext(new RequestContext('/index.php', '127.0.0.1', '')); global $SessionID; $SessionID = 'phpunit'; Util\Twig::setViewer($this->user); diff --git a/tests/phpunit/BaseRequestContextTest.php b/tests/phpunit/RequestContextTest.php similarity index 92% rename from tests/phpunit/BaseRequestContextTest.php rename to tests/phpunit/RequestContextTest.php index feae60818..b6d00905d 100644 --- a/tests/phpunit/BaseRequestContextTest.php +++ b/tests/phpunit/RequestContextTest.php @@ -4,7 +4,7 @@ namespace Gazelle; use PHPUnit\Framework\TestCase; -class BaseRequestContextTest extends TestCase { +class RequestContextTest extends TestCase { protected User $user; public function tearDown(): void { @@ -13,8 +13,8 @@ class BaseRequestContextTest extends TestCase { } } - public function testBaseRequestContext(): void { - $context = new BaseRequestContext( + public function testRequestContext(): void { + $context = new RequestContext( '/phpunit.php', '224.0.0.1', 'Lidarr/3.5.8 (windows 98)', @@ -38,7 +38,7 @@ class BaseRequestContextTest extends TestCase { } public function testBadRequest(): void { - $context = new BaseRequestContext('', '', ''); + $context = new RequestContext('', '', ''); $this->assertFalse($context->isValid(), 'context-not-valid'); $this->assertEquals('', $context->browser(), 'context-invalid-browser'); } @@ -46,7 +46,7 @@ class BaseRequestContextTest extends TestCase { // Any object that derives from Base has access to the request context public function testObject(): void { Base::setRequestContext( - new BaseRequestContext( + new RequestContext( '/phpunit.php', '225.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.3', diff --git a/tests/phpunit/UploadTest.php b/tests/phpunit/UploadTest.php index b4bf6bc94..060daed3d 100644 --- a/tests/phpunit/UploadTest.php +++ b/tests/phpunit/UploadTest.php @@ -20,7 +20,7 @@ class UploadTest extends TestCase { $this->assertStringContainsString($this->user->auth(), $upload->head(0), 'upload-head'); - Base::setRequestContext(new BaseRequestContext('/upload.php', '127.0.0.1', '')); + Base::setRequestContext(new RequestContext('/upload.php', '127.0.0.1', '')); global $SessionID; $SessionID = ''; Util\Twig::setViewer($this->user); diff --git a/tests/phpunit/UserTest.php b/tests/phpunit/UserTest.php index 5a965850c..ba30d67d3 100644 --- a/tests/phpunit/UserTest.php +++ b/tests/phpunit/UserTest.php @@ -380,7 +380,7 @@ class UserTest extends TestCase { public function testLogin(): void { $_SERVER['REMOTE_ADDR'] = '127.0.0.255'; - Base::setRequestContext(new BaseRequestContext( + Base::setRequestContext(new RequestContext( 'phpunit', $_SERVER['REMOTE_ADDR'], 'whatever' )); $login = new Login(); diff --git a/tests/phpunit/Util/TwigTest.php b/tests/phpunit/Util/TwigTest.php index d9f1f026e..7e84ec239 100644 --- a/tests/phpunit/Util/TwigTest.php +++ b/tests/phpunit/Util/TwigTest.php @@ -227,7 +227,7 @@ END; } public function testFunction(): void { - Base::setRequestContext(new BaseRequestContext('/index.php', '127.0.0.1', '')); + Base::setRequestContext(new RequestContext('/index.php', '127.0.0.1', '')); Util\Twig::setViewer($this->user); $this->assertStringStartsWith('', self::twig('{{ header("page") }}')->render(), 'twig-function-header');