Merge pull request #699 from boxbilling/fix/remove-license-check

Remove license check
This commit is contained in:
Andrius Putna authored and GitHub committed 2020-11-01 03:30:04 +02:00
commit 5c5bd4e3f0
16 files changed
+15 -546

No files matched your search

+8 -6
View File
@@ -19,15 +19,17 @@ $user = $config['db']['user'];
$password = $config['db']['password'];
echo sprintf("Connecting to database %s@%s/%s", $user, $host, $dbname) . PHP_EOL;
$dbh = new PDO($type . ':host=' . $host, $user, $password, array(
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
));
$iter = 5;
$iter = 30;
$connected = false;
while ($connected == false && $iter > 0) {
$dbh = new PDO($type . ':host=' . $host, $user, $password, array(
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
));
try {
$dbh->query('select 1;');
$connected = true;
-5
View File
@@ -247,11 +247,6 @@ $di['api_guest'] = function() use ($di) { return $di['api']('guest'); };
$di['api_client'] = function() use ($di) { return $di['api']('client');};
$di['api_admin'] = function() use ($di) { return $di['api']('admin'); };
$di['api_system'] = function() use ($di) { return $di['api']('system'); };
$di['license'] = function () use ($di) {
$service = new Box_License();
$service->setDi($di);
return $service;
};
$di['tools'] = function () use ($di){
$service = new Box_Tools();
-205
View File
@@ -1,205 +0,0 @@
<?php
/**
* BoxBilling
*
* @copyright BoxBilling, Inc (http://www.boxbilling.com)
* @license Apache-2.0
*
* Copyright BoxBilling, Inc
* This source file is subject to the Apache-2.0 License that is bundled
* with this source code in the file LICENSE
*/
class Box_License implements \Box\InjectionAwareInterface
{
protected $di;
public function setDi($di)
{
$this->di = $di;
}
public function getDi()
{
return $this->di;
}
/**
* @return string
*/
public function getKey()
{
$license = $this->di['config']['license'];
if(!$license || $license == '') {
throw new \Box_Exception('BoxBilling license key must be defined in bb-config.php file.', null, 315);
}
return $license;
}
public function check()
{
if(!$this->isValid()) {
throw new \Box_Exception('License is not valid');
}
}
public function isValid()
{
return true;
try {
$this->getDetails();
return true;
} catch(\Exception $e) {
return false;
}
}
public function isPro()
{
return ($this->getBBType() == \Box_Version::TYPE_PRO);
}
private function getBBType()
{
$prefixes = array(
'PRO-',
'HOSTING24-',
);
$bb_license = $this->getKey();
foreach($prefixes as $prefix){
if(substr($bb_license, 0, strlen($prefix)) == $prefix) {
return \Box_Version::TYPE_PRO;
}
}
return \Box_Version::TYPE_FREE;
}
public function getDetails($from_server = false)
{
$license = $this->getKey();
$systemService = $this->di['mod_service']('system');
$salt = 'IJ2bspsxk1U1INr';
$key = md5('_lc_'.$license);
$cache = $systemService->getParamValue($key);
//set when last time was license checked
$check_key = md5('_last_check_'.$license);
$v = $systemService->getParamValue($check_key);
$last_check = time();
if(!$v) {
$from_server = true;
} else {
$checkd = $this->di['crypt']->decrypt($v, $salt);
if(is_numeric($checkd)) {
$last_check = $checkd;
}
}
if((time() - $last_check) > 60 * 60 * 1) {
$from_server = true;
}
if($cache && !$from_server) {
$data = @unserialize($this->di['crypt']->decrypt($cache, $salt));
if ($data === false) {
$from_server = true;
}
}
if(!$cache || $from_server) {
try {
$servers = array(
'http://www.boxbilling.com/api/guest/servicelicense/check',
);
$l = $this->_getLicenseDetailsFromServer($servers);
} catch(\LogicException $e) {
error_log($e->getMessage());
return array();
}
$data = $l;
$systemService->setParamValue($key, $this->di['crypt']->encrypt(serialize($l), $salt), true);
$systemService->setParamValue($check_key, $this->di['crypt']->encrypt(time(), $salt), true);
} else {
$data = @unserialize($this->di['crypt']->decrypt($cache, $salt));
if (!is_array($data)) {
error_log('Invalid response from licensing server. 9115');
$systemService->setParamValue($key, $this->di['crypt']->encrypt(serialize(false), $salt), true);
}
}
return $data;
}
public function _getLicenseDetailsFromServer(array $servers)
{
$params = array();
$params['license'] = $this->di['config']['license'];
$params['host'] = BB_URL;
$params['path'] = BB_PATH_ROOT;
$params['version'] = \Box_Version::VERSION;
$params['os'] = PHP_OS;
$params['format'] = 2;
foreach($servers as $server) {
$response = $this->_tryLicensingServer($server, $params);
// check empty response
if(!$response) {
error_log($response);
continue;
}
// check invalid json
$r = json_decode($response, 1);
if(!is_array($r) || !isset($r['result'])) {
error_log('Invalid json result '. $response);
continue;
}
// check server error
if(isset($r['error']) && is_array($r['error'])) {
error_log(print_r($r['error'], 1));
continue;
}
if(!is_array($r['result']) || !isset($r['result']['valid'])) {
error_log('Strange response from licensing server');
continue;
}
if(!$r['result']['valid']) {
$code = $r['result']['error_code'] ? (int)$r['result']['error_code'] : 9019;
$msg = (string)$r['result']['error'];
throw new \Exception($msg, $code);
}
return $r['result'];
}
return array();
}
private function _tryLicensingServer($url, $params)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
-1
View File
@@ -148,7 +148,6 @@ class Client implements InjectionAwareInterface
{
$this->_loadConfig();
$this->checkAllowedIps();
$this->di['license']->check();
$service = $this->di['mod_service']('api');
$service->logRequest();
-3
View File
@@ -35,9 +35,6 @@ class Service implements \Box\InjectionAwareInterface
public function uninstall()
{
if(!$this->di['license']->isPro()) {
throw new \Exception('Branding module can only be disabled for PRO license owners', 509);
}
return true;
}
+4 -6
View File
@@ -539,12 +539,10 @@ class Service implements \Box\InjectionAwareInterface
{
$queue->status = 'sending';
$this->di['db']->store($queue);
//@demoVersionLimit
if (!$this->di['license']->isPro()) {
$queue->content .= PHP_EOL;
$queue->content .= 'Powered by BoxBilling. Client management, invoicing and support software. http://www.boxbilling.com/';
$queue->content .= PHP_EOL;
}
$queue->content .= PHP_EOL;
$queue->content .= 'Powered by BoxBilling. Client management, invoicing and support software. https://www.boxbilling.com/';
$queue->content .= PHP_EOL;
$mod = $this->di['mod']('email');
$settings = $mod->getConfig();
-4
View File
@@ -487,10 +487,6 @@ class Service implements InjectionAwareInterface
public function createOrder(\Model_Client $client, \Model_Product $product, array $data)
{
if (!$this->di['license']->isPro()) {
throw new \Box_Exception('This feature is available in BoxBilling PRO version.', null, 876);
}
$currencyService = $this->di['mod_service']('currency');
if (isset($data['currency']) && !empty($data['currency'])) {
$currency = $currencyService->getByCode($data['currency']);
@@ -30,10 +30,6 @@ class Service implements \Box\InjectionAwareInterface
public function install()
{
if(!$this->di['license']->isPro()) {
throw new \Exception('This extension can only be enabled by PRO license owners', 509);
}
$sql="
CREATE TABLE IF NOT EXISTS `service_centovacast` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
+2 -25
View File
@@ -185,25 +185,9 @@ class Service
public function getLicenseInfo($data)
{
$details = $this->di['license']->getDetails();
$owner = null;
$expires_at = null;
if(isset($details['expires_at']) && $details['expires_at']) {
if(is_numeric($details['expires_at'])) {
$expires_at = date('Y-m-d H:i:s', $details['expires_at']);
} else {
$expires_at = $details['expires_at'];
}
}
if(isset($details['licensed_to']) && $details['licensed_to']) {
$owner = $details['licensed_to'];
}
$result = array(
'licensed_to' => $owner,
'key' => $this->di['config']['license'],
'expires_at' => $expires_at,
'licensed_to' => 'BoxBilling CE',
'key' => 'BoxBilling CE',
);
return $result;
}
@@ -1539,14 +1523,7 @@ class Service
*/
public function checkLimits($model, $limit = 2)
{
if (!$this->di['license']->isPro()) {
$model = str_replace('Model_', '', $model);
$count = count($this->di['db']->find($model));
if ($count >= $limit) {
throw new \Box_Exception('You have reached free version limit. Upgrade to PRO version of BoxBilling if you want this limit removed.', null, 875);
}
}
}
public function getNameservers()
@@ -54,7 +54,7 @@
{% if license.expires_at %}
<tr>
<td>{% trans 'Expires at' %}</td>
<td align="right">{{ license.expires_at|date('Y-m-d') }}</td>
<td align="right">{{ license.expires_at }}</td>
</tr>
{% endif %}
-20
View File
@@ -1,20 +0,0 @@
<?php
/**
* @group Core
*/
class Box_LicenseTest extends PHPUnit\Framework\TestCase
{
protected function setup() : void
{
global $di;
$this->di = $di;
}
public function testLicense()
{
self::expectNotToPerformAssertions();
$license = $this->di['license'];
$license->getDetails();
$license->getDetails(true);
}
}
-37
View File
@@ -20,42 +20,5 @@ class ServiceTest extends \BBTestCase
$this->assertEquals($di, $result);
}
public function testuninstallException()
{
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->will($this->returnValue(false));
$di = new \Box_Di();
$di['license'] = $licenseMock;
$brandingService = new \Box\Mod\Branding\Service();
$brandingService->setDi($di);
$this->expectException(\Exception::class);
$this->expectExceptionCode(509);
$this->expectExceptionMessage('Branding module can only be disabled for PRO license owners');
$brandingService->uninstall();
}
public function testuninstal()
{
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->will($this->returnValue(true));
$di = new \Box_Di();
$di['license'] = $licenseMock;
$brandingService = new \Box\Mod\Branding\Service();
$brandingService->setDi($di);
$result = $brandingService->uninstall();
$this->assertTrue($result);
}
}
-12
View File
@@ -1001,11 +1001,6 @@ class ServiceTest extends \BBTestCase
->method('logEmail')
->will($this->returnValue(true));
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->will($this->returnValue(false));
$modMock = $this->getMockBuilder('\Box_Mod')->disableOriginalConstructor()->getMock();
$modMock->expects($this->atLeastOnce())
->method('getConfig')
@@ -1030,7 +1025,6 @@ class ServiceTest extends \BBTestCase
$di['mod'] = $di->protect(function () use ($modMock) {
return $modMock;
});
$di['license'] = $licenseMock;
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use ($di) {
return isset ($array[$key]) ? $array[$key] : $default;
});
@@ -1120,11 +1114,6 @@ class ServiceTest extends \BBTestCase
$dbMock->expects($this->atLeastOnce())
->method('store');
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->will($this->returnValue(false));
$modMock = $this->getMockBuilder('\Box_Mod')->disableOriginalConstructor()->getMock();
$modMock->expects($this->atLeastOnce())
->method('getConfig')
@@ -1143,7 +1132,6 @@ class ServiceTest extends \BBTestCase
$di['mod'] = $di->protect(function () use ($modMock) {
return $modMock;
});
$di['license'] = $licenseMock;
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use ($di) {
return isset ($array[$key]) ? $array[$key] : $default;
});
-53
View File
@@ -1288,29 +1288,6 @@ class ServiceTest extends \BBTestCase
$this->assertTrue(array_diff_key($result[1], $expectedParams) == array());
}
public function testcreateOrder_FeatureAvailableToPro()
{
$modelClient = new \Model_Client();
$modelClient->loadBean(new \RedBeanPHP\OODBBean());
$modelProduct = new \Model_Product();
$modelProduct->loadBean(new \RedBeanPHP\OODBBean());
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(false);
$di = new \Box_Di();
$di['license'] = $licenseMock;
$this->service->setDi($di);
$this->expectException(\Box_Exception::class);
$this->expectExceptionCode(876);
$this->expectExceptionMessage('This feature is available in BoxBilling PRO version.');
$this->service->createOrder($modelClient, $modelProduct, array());
}
public function testcreateOrder_MissingOrderCurrency()
{
$modelClient = new \Model_Client();
@@ -1319,18 +1296,12 @@ class ServiceTest extends \BBTestCase
$modelProduct = new \Model_Product();
$modelProduct->loadBean(new \RedBeanPHP\OODBBean());
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(true);
$currencyServiceMock = $this->getMockBuilder('\Box\Mod\Currency\Service')->getMock();
$currencyServiceMock->expects($this->atLeastOnce())
->method('getDefault')
->willReturn(null);
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['mod_service'] = $di->protect(function ($serviceName) use ($currencyServiceMock) {
if ($serviceName == 'currency') {
return $currencyServiceMock;
@@ -1353,11 +1324,6 @@ class ServiceTest extends \BBTestCase
$modelProduct->loadBean(new \RedBeanPHP\OODBBean());
$modelProduct->id = 1;
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(true);
$currencyModel = new \Model_Currency();
$currencyModel->loadBean(new \RedBeanPHP\OODBBean());
@@ -1377,7 +1343,6 @@ class ServiceTest extends \BBTestCase
->method('fire');
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['mod_service'] = $di->protect(function ($serviceName) use ($currencyServiceMock, $cartServiceMock) {
if ($serviceName == 'currency') {
return $currencyServiceMock;
@@ -1409,11 +1374,6 @@ class ServiceTest extends \BBTestCase
$modelProduct->id = 1;
$modelProduct->is_addon = 1;
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(true);
$currencyModel = new \Model_Currency();
$currencyModel->loadBean(new \RedBeanPHP\OODBBean());
@@ -1433,7 +1393,6 @@ class ServiceTest extends \BBTestCase
->method('fire');
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['mod_service'] = $di->protect(function ($serviceName) use ($currencyServiceMock, $cartServiceMock) {
if ($serviceName == 'currency') {
return $currencyServiceMock;
@@ -1464,11 +1423,6 @@ class ServiceTest extends \BBTestCase
$modelProduct->loadBean(new \RedBeanPHP\OODBBean());
$modelProduct->id = 1;
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(true);
$currencyModel = new \Model_Currency();
$currencyModel->loadBean(new \RedBeanPHP\OODBBean());
@@ -1488,7 +1442,6 @@ class ServiceTest extends \BBTestCase
->method('fire');
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['mod_service'] = $di->protect(function ($serviceName) use ($currencyServiceMock, $cartServiceMock) {
if ($serviceName == 'currency') {
return $currencyServiceMock;
@@ -1526,11 +1479,6 @@ class ServiceTest extends \BBTestCase
$modelProduct->id = 1;
$modelProduct->type = 'custom';
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(true);
$currencyModel = new \Model_Currency();
$currencyModel->loadBean(new \RedBeanPHP\OODBBean());
$currencyServiceMock = $this->getMockBuilder('\Box\Mod\Currency\Service')->getMock();
@@ -1569,7 +1517,6 @@ class ServiceTest extends \BBTestCase
->willReturn('1Y');
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['mod_service'] = $di->protect(function ($serviceName) use ($currencyServiceMock, $cartServiceMock, $productServiceMock) {
if ($serviceName == 'currency') {
return $currencyServiceMock;
-163
View File
@@ -85,38 +85,6 @@ class ServiceTest extends \BBTestCase {
$this->assertEquals($expected, $result);
}
public function testgetLicenseInfo()
{
$expires_at = '2012-09-01 00:00';
$licensed_to = 'testing Inc.';
$config['license'] = 'HOSTING24-e8eqa9a8yqetu9ytynam';
$expected = array(
'licensed_to' => $licensed_to,
'key' => $config['license'],
'expires_at' => $expires_at,
);
$licenseDetails = array(
'expires_at' => $expires_at,
'licensed_to' => $licensed_to,
);
$licenseMock = $this->getMockBuilder('\Box_License')->setMethods(array('getDetails'))->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('getDetails')
->will($this->returnValue($licenseDetails));
$di = new \Box_Di();
$di['config'] = $config;
$di['license'] = $licenseMock;
$this->service->setDi($di);
$result = $this->service->getLicenseInfo(array());
$this->assertIsArray($result);
$this->assertEquals($expected, $result);
}
public function testgetParams()
{
$expected = array(
@@ -434,137 +402,6 @@ class ServiceTest extends \BBTestCase {
$this->assertEquals(\Box_Version::VERSION, $result);
}
public function testcheckLimits_UserIsPro()
{
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(true);
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->never())
->method('find');
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['db'] = $dbMock;
$this->service->setDi($di);
$result = $this->service->checkLimits('Model_Product');
}
public function testcheckLimits_LimitIsNotReached()
{
$modelName = 'Model_Product';
$model = new \Model_Product();
$model->loadBean(new \RedBeanPHP\OODBBean());
$findResult = array(
array($model),
array($model),
);
$limit = 5;
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(false);
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->once())
->method('find')
->willReturn($findResult);
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['db'] = $dbMock;
$this->service->setDi($di);
$result = $this->service->checkLimits($modelName, $limit);
}
public function testcheckLimits_OverTheLimit()
{
$modelName = 'Model_Product';
$model = new \Model_Product();
$model->loadBean(new \RedBeanPHP\OODBBean());
$findResult = array(
array($model),
array($model),
array($model),
array($model),
array($model),
array($model),
);
$limit = 5;
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(false);
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->once())
->method('find')
->willReturn($findResult);
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['db'] = $dbMock;
$this->service->setDi($di);
$this->expectException(\Box_Exception::class);
$this->expectExceptionCode(875);
$this->expectExceptionMessage('You have reached free version limit. Upgrade to PRO version of BoxBilling if you want this limit removed.');
$this->service->checkLimits($modelName, $limit);
}
public function testcheckLimits_LimitAndResultRowsEqual()
{
$modelName = 'Model_Product';
$model = new \Model_Product();
$model->loadBean(new \RedBeanPHP\OODBBean());
$findResult = array(
array($model),
array($model),
array($model),
array($model),
array($model),
array($model),
);
$limit = count($findResult);
$licenseMock = $this->getMockBuilder('\Box_License')->getMock();
$licenseMock->expects($this->atLeastOnce())
->method('isPro')
->willReturn(false);
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->once())
->method('find')
->willReturn($findResult);
$di = new \Box_Di();
$di['license'] = $licenseMock;
$di['db'] = $dbMock;
$this->service->setDi($di);
$this->expectException(\Box_Exception::class);
$this->expectExceptionCode(875);
$this->expectExceptionMessage('You have reached free version limit. Upgrade to PRO version of BoxBilling if you want this limit removed.');
$this->service->checkLimits($modelName, $limit);
}
public function testgetPendingMessages()
{
$di = new \Box_Di();
@@ -28,7 +28,6 @@ class DiTest extends PHPUnit\Framework\TestCase
$this->assertInstanceOf('FileCache', $di['cache']);
$this->assertInstanceOf('Box_Authorization', $di['auth']);
$this->assertInstanceOf('Twig\Environment', $di['twig']);
$this->assertInstanceOf('Box_License', $di['license']);
$this->assertInstanceOf('Box_Tools', $di['tools']);
$this->assertInstanceOf('Box_Validate', $di['validator']);