diff --git a/src/bb-library/Box/Tools.php b/src/bb-library/Box/Tools.php index 9d88f0d43..de2dcf34a 100644 --- a/src/bb-library/Box/Tools.php +++ b/src/bb-library/Box/Tools.php @@ -117,29 +117,6 @@ class Box_Tools require_once $file; return new $class(); } - - /** - * Get client IP - * @return string - */ - public function getIpv4() - { - $ip = NULL; - if (isset($_SERVER) ) { - if (isset($_SERVER['REMOTE_ADDR']) ) { - $ip = $_SERVER['REMOTE_ADDR']; - } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { - $ip = $_SERVER['HTTP_CLIENT_IP']; - } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - $iplist = explode(',', $ip); - if(is_array($iplist)) { - $ip = trim(array_pop($iplist)); - } - } - } - return $ip; - } public function checkPerms($path, $perm = '0777') { diff --git a/src/bb-load.php b/src/bb-load.php index 48df4b187..b4f7160cf 100644 --- a/src/bb-load.php +++ b/src/bb-load.php @@ -54,160 +54,170 @@ function handler_exception($e) return false; } - $page = " - - - - - - - - - An error ocurred - - - - - - + if(defined('BB_DEBUG') && BB_DEBUG && file_exists(BB_PATH_VENDOR)) { + /** + * If advanced debugging is enabled, print Whoops instead of our error page. + * flip/whoops documentation: https://github.com/filp/whoops/blob/master/docs/API%20Documentation.md + */ + $whoops = new \Whoops\Run; + $prettyPage = new \Whoops\Handler\PrettyPageHandler; + $prettyPage->setPageTitle("An error ocurred"); + $prettyPage->addDataTable('BoxBilling environment', [ + 'PHP Version' => phpversion(), + 'Error code' => $e->getCode() + ]); + $whoops->pushHandler($prettyPage); + $whoops->allowQuit(false); + $whoops->writeToOutput(false); - - - + code { + font-family: Consolas,'courier new'; + color: crimson; + background-color: #f1f1f1; + padding: 2px; + font-size: 90%; + } + + + + -
-
-
-

Error

"; - $page = str_replace(PHP_EOL, "", $page); - print $page; - if($e->getCode()) { - print sprintf('

Error code: %s

', $e->getCode()); +
+
+
+

Error

"; + + $page = str_replace(PHP_EOL, "", $page); + print $page; + if($e->getCode()) { + print sprintf('

Error code: %s

', $e->getCode()); + } + print sprintf('

%s

', $e->getMessage()); + + print sprintf('

Look for detailed error explanation

', urlencode($e->getMessage())); + print("

Powered by BoxBilling

+ + + "); } - print sprintf('

%s

', $e->getMessage()); - - if(defined('BB_DEBUG') && BB_DEBUG) { - print sprintf('

%s

', 'Set BB_DEBUG to FALSE, to hide the message below'); - print sprintf('

Class: "%s"

', get_class($e)); - print sprintf('

File: "%s"

', $e->getFile()); - print sprintf('

Line: "%s"

', $e->getLine()); - print sprintf('Trace: %s', $e->getTraceAsString()); - } - print sprintf('

Look for detailed error explanation

', urlencode($e->getMessage())); - print("

Powered by BoxBilling

- - - "); } } @@ -215,9 +225,8 @@ set_exception_handler("handler_exception"); set_error_handler('handler_error'); // Check for Composer packages -$vendorPath = BB_PATH_ROOT.'/bb-vendor'; -if(!file_exists($vendorPath)) { - throw new Exception("It seems like Composer packages are missing. You have to run \"composer install\" in order to install them. For detailed instruction, you can see Composer's getting started guide.

If you have downloaded BoxBilling from GitHub releases, this shouldn't happen.", 103); +if(!file_exists(BB_PATH_VENDOR)) { + throw new Exception("It seems like Composer packages are missing. You have to run \"composer install\" in order to install them. For detailed instruction, you can see Composer's getting started guide.

If you have downloaded BoxBilling from GitHub releases, this shouldn't happen.", 110); } // Multisite support. Load new configuration depending on the current hostname diff --git a/src/bb-modules/Branding/manifest.json b/src/bb-modules/Branding/manifest.json index 68caa20f3..69b09a8da 100644 --- a/src/bb-modules/Branding/manifest.json +++ b/src/bb-modules/Branding/manifest.json @@ -1,11 +1,11 @@ { "id": "branding", - "type": "mod", + "type": "mod", "name": "Branding", - "description": "Branding module of BoxBilling. This extension includes the footer reference to BoxBilling's official website.", - "homepage_url": "http://github.com/boxbilling/", + "description": "Show your support by voluntarily displaying references to BoxBilling.", + "homepage_url": "https://boxbilling.org", "author": "BoxBilling", - "author_url": "http://extensions.boxbilling.org/", - "license": "http://www.boxbilling.org/license.txt", - "version": "1.0.0" + "author_url": "https://boxbilling.org", + "license": "https://www.boxbilling.org/license.txt", + "version": "4.22.0" } diff --git a/src/bb-modules/Spamchecker/Service.php b/src/bb-modules/Spamchecker/Service.php index 136ab0776..9f34b4303 100644 --- a/src/bb-modules/Spamchecker/Service.php +++ b/src/bb-modules/Spamchecker/Service.php @@ -95,8 +95,8 @@ class Service implements InjectionAwareInterface if(isset($config['block_ips']) && $config['block_ips'] && isset($config['blocked_ips'])) { $blocked_ips = explode(PHP_EOL, $config['blocked_ips']); $blocked_ips = array_map('trim', $blocked_ips); - if(in_array($di['tools']->getIpv4(), $blocked_ips)) { - throw new \Box_Exception('IP :ip is blocked', array(':ip'=>$di['tools']->getIpv4()), 403); + if(in_array($di['request']->getClientAddress(), $blocked_ips)) { + throw new \Box_Exception('Your IP addresss (:ip) is blocked. Please contact our support to lift your block.', array(':ip'=>$di['request']->getClientAddress()), 403); } } } diff --git a/src/composer.json b/src/composer.json index 3715c8d57..e711e0fbc 100644 --- a/src/composer.json +++ b/src/composer.json @@ -31,7 +31,8 @@ "guzzlehttp/guzzle": "*", "laminas/laminas-httphandlerrunner": "^2.0.1", "docnet/tfpdf": "^2.2", - "nelexa/zip": "^4.0" + "nelexa/zip": "^4.0", + "filp/whoops": "^2.14" }, "suggest": { "ext-gettext": "*" diff --git a/src/composer.lock b/src/composer.lock index 39e63da7b..783446a07 100644 --- a/src/composer.lock +++ b/src/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "eea828e4bbaba5ccb229f3bf5d61af49", + "content-hash": "ed13f26de82447bc7ce2ae3bde213a08", "packages": [ { "name": "composer/ca-bundle", @@ -139,6 +139,77 @@ }, "time": "2019-01-21T10:55:00+00:00" }, + { + "name": "filp/whoops", + "version": "2.14.4", + "source": { + "type": "git", + "url": "https://github.com/filp/whoops.git", + "reference": "f056f1fe935d9ed86e698905a957334029899895" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/filp/whoops/zipball/f056f1fe935d9ed86e698905a957334029899895", + "reference": "f056f1fe935d9ed86e698905a957334029899895", + "shasum": "" + }, + "require": { + "php": "^5.5.9 || ^7.0 || ^8.0", + "psr/log": "^1.0.1 || ^2.0 || ^3.0" + }, + "require-dev": { + "mockery/mockery": "^0.9 || ^1.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.3", + "symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0" + }, + "suggest": { + "symfony/var-dumper": "Pretty print complex values better with var-dumper available", + "whoops/soap": "Formats errors as SOAP responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Whoops\\": "src/Whoops/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Filipe Dobreira", + "homepage": "https://github.com/filp", + "role": "Developer" + } + ], + "description": "php error handling for cool kids", + "homepage": "https://filp.github.io/whoops/", + "keywords": [ + "error", + "exception", + "handling", + "library", + "throwable", + "whoops" + ], + "support": { + "issues": "https://github.com/filp/whoops/issues", + "source": "https://github.com/filp/whoops/tree/2.14.4" + }, + "funding": [ + { + "url": "https://github.com/denis-sokolov", + "type": "github" + } + ], + "time": "2021-10-03T12:00:00+00:00" + }, { "name": "geoip2/geoip2", "version": "v2.11.0", @@ -1280,6 +1351,56 @@ }, "time": "2020-09-17T16:52:43+00:00" }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" + }, { "name": "ralouphie/getallheaders", "version": "3.0.3", diff --git a/tests/bb-modules/Spamchecker/ServiceTest.php b/tests/bb-modules/Spamchecker/ServiceTest.php index 0ac6b802f..b2cb8e10d 100644 --- a/tests/bb-modules/Spamchecker/ServiceTest.php +++ b/tests/bb-modules/Spamchecker/ServiceTest.php @@ -155,9 +155,9 @@ class ServiceTest extends \BBTestCase { ); - $toolsMock = $this->getMockBuilder('\Box_Tools')->getMock(); - $toolsMock->expects($this->atLeastOnce()) - ->method('getIpv4') + $reqMock = $this->getMockBuilder('\Box_Request')->getMock(); + $reqMock->expects($this->atLeastOnce()) + ->method('getClientAddress') ->willReturn($clientIp); $di = new \Box_Di(); @@ -166,7 +166,7 @@ class ServiceTest extends \BBTestCase { return $modConfig; } }); - $di['tools'] = $toolsMock; + $di['request'] = $reqMock; $boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor() ->getMock(); @@ -175,7 +175,7 @@ class ServiceTest extends \BBTestCase { ->willReturn($di); $this->expectException(\Box_Exception::class); - $this->expectExceptionMessage(sprintf("IP %s is blocked", $clientIp), 403); + $this->expectExceptionMessage(sprintf("Your IP addresss (%s) is blocked. Please contact our support to lift your block.", $clientIp), 403); $this->service->isBlockedIp($boxEventMock); } @@ -188,9 +188,9 @@ class ServiceTest extends \BBTestCase { ); - $toolsMock = $this->getMockBuilder('\Box_Tools')->getMock(); - $toolsMock->expects($this->atLeastOnce()) - ->method('getIpv4') + $reqMock = $this->getMockBuilder('\Box_Request')->getMock(); + $reqMock->expects($this->atLeastOnce()) + ->method('getClientAddress') ->willReturn($clientIp); $di = new \Box_Di(); @@ -199,7 +199,7 @@ class ServiceTest extends \BBTestCase { return $modConfig; } }); - $di['tools'] = $toolsMock; + $di['request'] = $reqMock; $boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor() ->getMock();