Merge branch 'master' into maintenance-mode

This commit is contained in:
Yağızhan authored and GitHub committed 2021-10-28 10:48:55 +03:00
commit ea291bb761
7 files changed
+300 -192

No files matched your search

-23
View File
@@ -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')
{
+159 -150
View File
@@ -54,160 +54,170 @@ function handler_exception($e)
return false;
}
$page = "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>An error ocurred</title>
<!-- Google font -->
<link href=\"https://fonts.googleapis.com/css?family=Nunito:400,700\" rel=\"stylesheet\">
<!-- Custom stlylesheet -->
<link type=\"text/css\" rel=\"stylesheet\" href=\"css/style.css\" />
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);
<style>
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
}
#error {
position: relative;
height: 100vh;
}
#error .error {
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.error {
max-width: 560px;
width: 100%;
padding-left: 160px;
line-height: 1.1;
}
.error .error-container {
position: absolute;
left: 0;
top: 0;
display: inline-block;
width: 140px;
height: 140px;
background-image: url('/bb-themes/boxbilling/assets/images/box.png');
background-size: cover;
}
.error .error-container:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
-webkit-transform: scale(2.4);
-ms-transform: scale(2.4);
transform: scale(2.4);
border-radius: 50%;
background-color: #f2f5f8;
z-index: -1;
}
.error h1 {
font-family: 'Nunito', sans-serif;
font-size: 65px;
font-weight: 700;
margin-top: 0px;
margin-bottom: 10px;
color: #151723;
text-transform: uppercase;
}
.error h2 {
font-family: 'Nunito', sans-serif;
font-size: 21px;
font-weight: 400;
margin: 0;
text-transform: uppercase;
color: #151723;
}
.error p {
font-family: 'Nunito', sans-serif;
color: #999fa5;
font-weight: 400;
}
.error a {
font-family: 'Nunito', sans-serif;
display: inline-block;
font-weight: 700;
border-radius: 40px;
text-decoration: none;
color: #388dbc;
}
@media only screen and (max-width: 767px) {
.error .error-container {
width: 110px;
height: 110px;
print($whoops->handleException($e));
} else {
$page = "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>An error ocurred</title>
<!-- Google font -->
<link href=\"https://fonts.googleapis.com/css?family=Nunito:400,700\" rel=\"stylesheet\">
<style>
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
}
#error {
position: relative;
height: 100vh;
}
#error .error {
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.error {
padding-left: 15px;
padding-right: 15px;
padding-top: 110px;
max-width: 560px;
width: 100%;
padding-left: 160px;
line-height: 1.1;
}
.error .error-container {
position: absolute;
left: 0;
top: 0;
display: inline-block;
width: 140px;
height: 140px;
background-image: url('/bb-themes/boxbilling/assets/images/box.png');
background-size: cover;
}
.error .error-container:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
-webkit-transform: scale(2.4);
-ms-transform: scale(2.4);
transform: scale(2.4);
border-radius: 50%;
background-color: #f2f5f8;
z-index: -1;
}
.error h1 {
font-family: 'Nunito', sans-serif;
font-size: 65px;
font-weight: 700;
margin-top: 0px;
margin-bottom: 10px;
color: #151723;
text-transform: uppercase;
}
.error h2 {
font-family: 'Nunito', sans-serif;
font-size: 21px;
font-weight: 400;
margin: 0;
text-transform: uppercase;
color: #151723;
}
.error p {
font-family: 'Nunito', sans-serif;
color: #999fa5;
font-weight: 400;
}
.error a {
font-family: 'Nunito', sans-serif;
display: inline-block;
font-weight: 700;
border-radius: 40px;
text-decoration: none;
color: #388dbc;
}
@media only screen and (max-width: 767px) {
.error .error-container {
width: 110px;
height: 110px;
}
.error {
padding-left: 15px;
padding-right: 15px;
padding-top: 110px;
}
}
}
code {
font-family: Consolas,'courier new';
color: crimson;
background-color: #f1f1f1;
padding: 2px;
font-size: 90%;
}
</style>
</head>
<body>
code {
font-family: Consolas,'courier new';
color: crimson;
background-color: #f1f1f1;
padding: 2px;
font-size: 90%;
}
</style>
</head>
<body>
<div id=\"error\">
<div class=\"error\">
<div class=\"error-container\"></div>
<h1>Error</h1>";
$page = str_replace(PHP_EOL, "", $page);
print $page;
if($e->getCode()) {
print sprintf('<h2>Error code: <em>%s</em></h1>', $e->getCode());
<div id=\"error\">
<div class=\"error\">
<div class=\"error-container\"></div>
<h1>Error</h1>";
$page = str_replace(PHP_EOL, "", $page);
print $page;
if($e->getCode()) {
print sprintf('<h2>Error code: <em>%s</em></h1>', $e->getCode());
}
print sprintf('<p>%s</p>', $e->getMessage());
print sprintf('<center><p><a href="http://docs.boxbilling.com/en/latest/search.html?q=%s&check_keywords=yes&area=default" target="_blank">Look for detailed error explanation</a></p></center>', urlencode($e->getMessage()));
print("<center><hr><p>Powered by <a href=//https://github.com/boxbilling/boxbilling/>BoxBilling</a></p></center>
</body>
</html>");
}
print sprintf('<p>%s</p>', $e->getMessage());
if(defined('BB_DEBUG') && BB_DEBUG) {
print sprintf('<hr><center><small><p><b>%s</b></p></small></center>', 'Set BB_DEBUG to FALSE, to hide the message below');
print sprintf('<p>Class: "%s"</p>', get_class($e));
print sprintf('<p>File: "%s"</p>', $e->getFile());
print sprintf('<p>Line: "%s"</p>', $e->getLine());
print sprintf('Trace: <code>%s</code>', $e->getTraceAsString());
}
print sprintf('<center><p><a href="http://docs.boxbilling.org/en/latest/search.html?q=%s&check_keywords=yes&area=default" target="_blank">Look for detailed error explanation</a></p></center>', urlencode($e->getMessage()));
print("<center><hr><p>Powered by <a href=//https://github.com/boxbilling/boxbilling/>BoxBilling</a></p></center>
</body>
</html>");
}
}
@@ -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 \"<code>composer install</code>\" in order to install them. For detailed instruction, you can see <a href=\"https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies\">Composer's getting started guide</a>.<br /><br />If you have downloaded BoxBilling from <a href=\"https://github.com/boxbilling/boxbilling/releases\">GitHub releases</a>, 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 \"<code>composer install</code>\" in order to install them. For detailed instruction, you can see <a href=\"https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies\">Composer's getting started guide</a>.<br /><br />If you have downloaded BoxBilling from <a href=\"https://github.com/boxbilling/boxbilling/releases\">GitHub releases</a>, this shouldn't happen.", 110);
}
// Multisite support. Load new configuration depending on the current hostname
+6 -6
View File
@@ -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"
}
+2 -2
View File
@@ -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);
}
}
}
+2 -1
View File
@@ -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": "*"
+122 -1
View File
@@ -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",
+9 -9
View File
@@ -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();