From f272e3074b400e8da674e116414048755adef711 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:06:27 +0300 Subject: [PATCH 01/38] Some adjustments to the WHM module --- src/bb-library/Server/Manager/Whm.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bb-library/Server/Manager/Whm.php b/src/bb-library/Server/Manager/Whm.php index 48c3dc5f3..d3fd55b5a 100644 --- a/src/bb-library/Server/Manager/Whm.php +++ b/src/bb-library/Server/Manager/Whm.php @@ -25,15 +25,15 @@ class Server_Manager_Whm extends Server_Manager } if(empty($this->_config['host'])) { - throw new Server_Exception('Server manager "cPanel WHM" is not configured properly. Hostname is not set'); + throw new Server_Exception('Server manager "WHM" is not configured properly. Hostname is not set'); } if(empty($this->_config['username'])) { - throw new Server_Exception('Server manager "cPanel WHM" is not configured properly. Username is not set'); + throw new Server_Exception('Server manager "WHM" is not configured properly. Username is not set'); } if(empty($this->_config['password']) && empty($this->_config['accesshash'])) { - throw new Server_Exception('Server manager "cPanel WHM" is not configured properly. Authentication is not set'); + throw new Server_Exception('Server manager "WHM" is not configured properly. Authentication is not set'); } if(!empty($this->_config['accesshash'])) { @@ -75,7 +75,7 @@ class Server_Manager_Whm extends Server_Manager public static function getForm() { return array( - 'label' => 'cPanel WHM', + 'label' => 'cPanel (WHM)', ); } @@ -95,7 +95,7 @@ class Server_Manager_Whm extends Server_Manager ); $result = $this->_request($action, $var_hash); if(!isset($result->acct[0])) { - error_log('Could not synchronize account with cPanel server. Account does not exist.'); + error_log('Could not synchronize account with WHM server. Account does not exist.'); return $a; } From 6b07e1b8a023f287752a601fc14792fcdc77fde9 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:10:33 +0300 Subject: [PATCH 02/38] Initial MOFH support --- src/bb-library/Server/Manager/MOFH.php | 186 +++++++++++++++++++++++++ src/bb-library/Server/Manager/Whm.php | 10 +- 2 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 src/bb-library/Server/Manager/MOFH.php diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php new file mode 100644 index 000000000..9a08213ce --- /dev/null +++ b/src/bb-library/Server/Manager/MOFH.php @@ -0,0 +1,186 @@ +MOFHclient = Client::create([ + 'apiUsername' => $this->_config['username'], + 'apiPassword' => $this->_config['password'], + ]); + + if (!extension_loaded('curl')) { + throw new Server_Exception('cURL extension is not enabled'); + } + } + + public static function getForm() + { + return array( + 'label' => 'MyOwnFreeHost', + ); + } + + public function getLoginUrl() + { + if($this->_config['secure']) { + $protocol = 'https'; + } else { + $protocol = 'http'; + } + $host = $this->_config['host']; + return $protocol . '://' . $host; + } + + public function getResellerLoginUrl() + { + return 'https://panel.myownfreehost.net/'; + } + + public function testConnection() + { + $request = $this->MOFHclient->availability([ + 'domain' => 'boxbilling.com', + ]); + + $response = $request->send(); + + if ($response->isSuccessful()) { + return true; + } + + return false; + } + + public function synchronizeAccount(Server_Account $a) + { + $this->getLog()->info('Synchronizing account with server '.$a->getUsername()); + return $a; + } + + public function createAccount(Server_Account $a) { + $p = $a->getPackage(); + + $this->client = $a->getClient(); + + $request = $this->MOFHclient->createAccount([ + 'username' => $a->getId(), + 'password' => $a->getPassword(), + 'domain' => $a->getDomain(), + 'email' => $this->client->getEmail(), + 'plan' => 'boxbilling', + ]); + + $response = $request->send(); + + $this->client = $a->getClient(); + $this->client->setId($a->getUsername()); + $this->client->setUsername($response->getVpUsername()); + + if (!$response->isSuccessful()) { + throw new Server_Exception($response->getMessage()); + } + + return true; + } + + public function suspendAccount(Server_Account $a, $suspend = true) { + + $request = $this->MOFHclient->suspend([ + 'username' => $a->getId(), + 'reason' => $a->getNote(), + 'linked' => false + ]); + + $response = $request->send(); + + if (!$response->isSuccessful()) { + throw new Server_Exception('MOFH error: ' . $response->getMessage()); + } + + return true; + } + + public function unsuspendAccount(Server_Account $a) { + + $request = $this->MOFHclient->unsuspend([ + 'username' => $a->getId() + ]); + + $response = $request->send(); + + if (!$response->isSuccessful()) { + throw new Server_Exception('MOFH error: ' . $response->getMessage()); + } + + return true; + } + + public function cancelAccount(Server_Account $a) + { + throw new Server_Exception("Unfortunately, MyOwnFreeHost API does not support account termination. You may log into your reseller panel, and execute the action there."); + } + + public function changeAccountPackage(Server_Account $a, Server_Package $p) + { + throw new Server_Exception("Unfortunately, MyOwnFreeHost API does not support changing account packages. You may log into your reseller panel, and execute the action there."); + + } + + public function changeAccountPassword(Server_Account $a, $new) { + $request = $this->MOFHclient->password([ + 'username' => $a->getId(), + 'password' => $new, + ]); + + $response = $request->send(); + + if (!$response->isSuccessful()) { + throw new Server_Exception('MOFH error: ' . $response->getMessage()); + } + + return true; + } + + public function changeAccountUsername(Server_Account $a, $new) + { + throw new Server_Exception('Server manager does not support username changes'); + } + + public function changeAccountDomain(Server_Account $a, $new) + { + throw new Server_Exception('Server manager does not support domain changes'); + } + + public function changeAccountIp(Server_Account $a, $new) + { + throw new Server_Exception('Server manager does not support IP changes'); + } + + private function _getResourcePlan(Server_Package $p) + { + + } + + private function _getDnsTemplate(Server_Package $p) + { + throw new Server_Exception('Server manager does not support DNS templates'); + } +} \ No newline at end of file diff --git a/src/bb-library/Server/Manager/Whm.php b/src/bb-library/Server/Manager/Whm.php index d3fd55b5a..48c3dc5f3 100644 --- a/src/bb-library/Server/Manager/Whm.php +++ b/src/bb-library/Server/Manager/Whm.php @@ -25,15 +25,15 @@ class Server_Manager_Whm extends Server_Manager } if(empty($this->_config['host'])) { - throw new Server_Exception('Server manager "WHM" is not configured properly. Hostname is not set'); + throw new Server_Exception('Server manager "cPanel WHM" is not configured properly. Hostname is not set'); } if(empty($this->_config['username'])) { - throw new Server_Exception('Server manager "WHM" is not configured properly. Username is not set'); + throw new Server_Exception('Server manager "cPanel WHM" is not configured properly. Username is not set'); } if(empty($this->_config['password']) && empty($this->_config['accesshash'])) { - throw new Server_Exception('Server manager "WHM" is not configured properly. Authentication is not set'); + throw new Server_Exception('Server manager "cPanel WHM" is not configured properly. Authentication is not set'); } if(!empty($this->_config['accesshash'])) { @@ -75,7 +75,7 @@ class Server_Manager_Whm extends Server_Manager public static function getForm() { return array( - 'label' => 'cPanel (WHM)', + 'label' => 'cPanel WHM', ); } @@ -95,7 +95,7 @@ class Server_Manager_Whm extends Server_Manager ); $result = $this->_request($action, $var_hash); if(!isset($result->acct[0])) { - error_log('Could not synchronize account with WHM server. Account does not exist.'); + error_log('Could not synchronize account with cPanel server. Account does not exist.'); return $a; } From e0ea2d0bf743efda2701eedce11aa9aa9beaccec Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:12:35 +0300 Subject: [PATCH 03/38] Update build.xml --- build.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/build.xml b/build.xml index 03a3bf365..9d7395408 100644 --- a/build.xml +++ b/build.xml @@ -46,6 +46,7 @@ + From 54e3fe45986436e0fc44c5e295a9a13156f582fc Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:14:08 +0300 Subject: [PATCH 04/38] MOFH takes 2 usernames, one to use in API, one for the client area --- src/install/structure.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/src/install/structure.sql b/src/install/structure.sql index 48eed9189..fa6154dfd 100644 --- a/src/install/structure.sql +++ b/src/install/structure.sql @@ -1085,6 +1085,7 @@ CREATE TABLE `service_hosting` ( `tld` varchar(255) DEFAULT NULL, `ip` varchar(45) DEFAULT NULL, `username` varchar(255) DEFAULT NULL, + `panel_username` varchar(255) DEFAULT NULL, `pass` varchar(255) DEFAULT NULL, `reseller` tinyint(1) DEFAULT NULL, `created_at` datetime DEFAULT NULL, From 99340f569a6ced1dc29eed084e5ca3b068b5d12f Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:15:27 +0300 Subject: [PATCH 05/38] this, instead. the main username will be the one being used for the client panel. --- src/install/structure.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install/structure.sql b/src/install/structure.sql index fa6154dfd..715a8a205 100644 --- a/src/install/structure.sql +++ b/src/install/structure.sql @@ -1085,7 +1085,7 @@ CREATE TABLE `service_hosting` ( `tld` varchar(255) DEFAULT NULL, `ip` varchar(45) DEFAULT NULL, `username` varchar(255) DEFAULT NULL, - `panel_username` varchar(255) DEFAULT NULL, + `api_def` varchar(255) DEFAULT NULL, `pass` varchar(255) DEFAULT NULL, `reseller` tinyint(1) DEFAULT NULL, `created_at` datetime DEFAULT NULL, From a96f3d9edbbf9786f0896c9c8f5086d75c4b837b Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:17:00 +0300 Subject: [PATCH 06/38] We changed the database structure, so we need to add these to the updater. --- src/bb-update.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bb-update.php b/src/bb-update.php index 8632057e9..b666cb15f 100644 --- a/src/bb-update.php +++ b/src/bb-update.php @@ -10,6 +10,18 @@ * with this source code in the file LICENSE */ +/** + * The unnamed new release +*/ +class BBPatch_24 extends BBPatchAbstract +{ + public function patch() + { + $q = "ALTER TABLE `service_hosting` ADD `api_def` VARCHAR(255) NULL DEFAULT NULL AFTER `username`;"; + $this->execSql($q); + } +} + class BBPatch_23 extends BBPatchAbstract { public function patch() From 63235b99c117fc8f68abe866e7b983e60962e015 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:18:41 +0300 Subject: [PATCH 07/38] We need to store this somewhere. --- src/bb-library/Server/Account.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bb-library/Server/Account.php b/src/bb-library/Server/Account.php index 24d75487d..421975cbc 100644 --- a/src/bb-library/Server/Account.php +++ b/src/bb-library/Server/Account.php @@ -16,6 +16,7 @@ class Server_Account private $password = NULL; private $domain = NULL; private $ip = NULL; + private $api_def = NULL; /** * @var Server_Package @@ -78,6 +79,17 @@ class Server_Account return $this->ip; } + public function setAPIdef($param) + { + $this->api_def = $param; + return $this; + } + + public function getAPIdef() + { + return $this->api_def; + } + /** * @param Server_Client $param * @return $this From 92ad95cab1d022719308d04ca113fa747b68e4bd Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:20:01 +0300 Subject: [PATCH 08/38] And also, use these --- src/bb-library/Server/Manager/MOFH.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php index 9a08213ce..5d9244f39 100644 --- a/src/bb-library/Server/Manager/MOFH.php +++ b/src/bb-library/Server/Manager/MOFH.php @@ -81,7 +81,7 @@ class Server_Manager_MOFH extends Server_Manager $this->client = $a->getClient(); $request = $this->MOFHclient->createAccount([ - 'username' => $a->getId(), + 'username' => $a->getAPIdef(), 'password' => $a->getPassword(), 'domain' => $a->getDomain(), 'email' => $this->client->getEmail(), @@ -91,7 +91,7 @@ class Server_Manager_MOFH extends Server_Manager $response = $request->send(); $this->client = $a->getClient(); - $this->client->setId($a->getUsername()); + $this->client->setAPIdef($a->getUsername()); $this->client->setUsername($response->getVpUsername()); if (!$response->isSuccessful()) { @@ -104,7 +104,7 @@ class Server_Manager_MOFH extends Server_Manager public function suspendAccount(Server_Account $a, $suspend = true) { $request = $this->MOFHclient->suspend([ - 'username' => $a->getId(), + 'username' => $a->getAPIdef(), 'reason' => $a->getNote(), 'linked' => false ]); @@ -121,7 +121,7 @@ class Server_Manager_MOFH extends Server_Manager public function unsuspendAccount(Server_Account $a) { $request = $this->MOFHclient->unsuspend([ - 'username' => $a->getId() + 'username' => $a->getAPIdef() ]); $response = $request->send(); @@ -146,7 +146,7 @@ class Server_Manager_MOFH extends Server_Manager public function changeAccountPassword(Server_Account $a, $new) { $request = $this->MOFHclient->password([ - 'username' => $a->getId(), + 'username' => $a->getAPIdef(), 'password' => $new, ]); From 027b506a64f34afb1b4d63a2e44f52c4d9bb4e84 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:41:06 +0300 Subject: [PATCH 09/38] no. --- src/bb-library/Server/Account.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/bb-library/Server/Account.php b/src/bb-library/Server/Account.php index 421975cbc..24d75487d 100644 --- a/src/bb-library/Server/Account.php +++ b/src/bb-library/Server/Account.php @@ -16,7 +16,6 @@ class Server_Account private $password = NULL; private $domain = NULL; private $ip = NULL; - private $api_def = NULL; /** * @var Server_Package @@ -79,17 +78,6 @@ class Server_Account return $this->ip; } - public function setAPIdef($param) - { - $this->api_def = $param; - return $this; - } - - public function getAPIdef() - { - return $this->api_def; - } - /** * @param Server_Client $param * @return $this From 7f8c1d68fdd9c4b08973f6f9201b5da1a3d3438a Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:41:45 +0300 Subject: [PATCH 10/38] no. --- src/bb-update.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/bb-update.php b/src/bb-update.php index b666cb15f..8632057e9 100644 --- a/src/bb-update.php +++ b/src/bb-update.php @@ -10,18 +10,6 @@ * with this source code in the file LICENSE */ -/** - * The unnamed new release -*/ -class BBPatch_24 extends BBPatchAbstract -{ - public function patch() - { - $q = "ALTER TABLE `service_hosting` ADD `api_def` VARCHAR(255) NULL DEFAULT NULL AFTER `username`;"; - $this->execSql($q); - } -} - class BBPatch_23 extends BBPatchAbstract { public function patch() From 6ec7e6aca347c67fa5249dcda7b486564f12bc9b Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:42:03 +0300 Subject: [PATCH 11/38] no.. --- src/install/structure.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/src/install/structure.sql b/src/install/structure.sql index 715a8a205..48eed9189 100644 --- a/src/install/structure.sql +++ b/src/install/structure.sql @@ -1085,7 +1085,6 @@ CREATE TABLE `service_hosting` ( `tld` varchar(255) DEFAULT NULL, `ip` varchar(45) DEFAULT NULL, `username` varchar(255) DEFAULT NULL, - `api_def` varchar(255) DEFAULT NULL, `pass` varchar(255) DEFAULT NULL, `reseller` tinyint(1) DEFAULT NULL, `created_at` datetime DEFAULT NULL, From 479e6efe7e86b523c4602f30a43f222325635079 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 17:43:07 +0300 Subject: [PATCH 12/38] Update Account.php --- src/bb-library/Server/Account.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-library/Server/Account.php b/src/bb-library/Server/Account.php index 24d75487d..ee840b808 100644 --- a/src/bb-library/Server/Account.php +++ b/src/bb-library/Server/Account.php @@ -32,7 +32,7 @@ class Server_Account private $ns_2 = NULL; private $ns_3 = NULL; private $ns_4 = NULL; - private $note = 'Client created via BoxBilling'; + private $note = NULL; public function setUsername($param) { From c81556bddefed0ef68885b2064754b86e75e9216 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 19:10:10 +0300 Subject: [PATCH 13/38] Update MOFH.php --- src/bb-library/Server/Manager/MOFH.php | 87 ++++++++++++++++++++------ 1 file changed, 67 insertions(+), 20 deletions(-) diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php index 5d9244f39..06e5ceb89 100644 --- a/src/bb-library/Server/Manager/MOFH.php +++ b/src/bb-library/Server/Manager/MOFH.php @@ -2,23 +2,29 @@ /** * BoxBilling * - * LICENSE + * @copyright BoxBilling, Inc (http://www.boxbilling.com) + * @license Apache-2.0 * - * This source file is subject to the license that is bundled - * with this package in the file LICENSE.txt - * It is also available through the world-wide-web at this URL: - * http://www.boxbilling.com/LICENSE.txt - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@boxbilling.com so we can send you a copy immediately. - * - * @copyright Copyright (c) 2010-2020 BoxBilling (http://www.boxbilling.com) - * @license http://www.boxbilling.com/LICENSE.txt - * @version $Id$ + * 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 */ + use \InfinityFree\MofhClient\Client; class Server_Manager_MOFH extends Server_Manager { + // First, let's start with some information. + // + // MyOwnFreeHost has it's own (and weird) system of storing user identifiers. + // When making API calls, you *must* use the 8-digit username that you've generated and submitted to MOFH while creating the account (a1b2c3d4) + // Then, it generates *another* username, which is basically like "<3 lettered reseller identifier>_" (abc_12345678) + // This makes everything weird, the user logs into the control panel with the abc_12345678 username, but we still need to store the other one somewhere + // While making API calls, the username you submit is not the one which user uses during their sign-in process, it's the one *you* generated in the beginning. + // Hence, you need to store it, or hash the domain as we did. + // + // We used the "domainToID()" function to generate a unique hash for every domain, and we can be sure that it won't change unless the domain was changed + // Changing the domain is not supported by MyOwnFreeHost's API, so the domain probably won't be changed afterwards. + public function init() { $this->MOFHclient = Client::create([ @@ -31,6 +37,29 @@ class Server_Manager_MOFH extends Server_Manager } } + public static function domainToID($domain) + { + // So, here's how this works. + // We first generate a SHA-256 hash with the domain + // And then, strip out the first 8 characters to + // generate a unique ID. + // + // Let's understand it better with an example. + // So, here's the SHA-256 hash of 'boxbilling.com': + // 0d3019bc07e517c2158a2c7eaccdf286fdececa78de7f736f2d1d602522e80c7 + // + // We get the first 8 characters out of that, and it produces: + // 0d3019bc + // + // Since it's a hash, it doesn't matter whether portions are discarded, + // but rather that the same input will produce the same hash. + // + // And the nice part, we don't need to store this in a database. + // As long as it's the same domain, it will always generate the same hash. + + return mb_substr(hash('sha256', $domain), 0, 8); + } + public static function getForm() { return array( @@ -75,42 +104,58 @@ class Server_Manager_MOFH extends Server_Manager return $a; } + /** + * Create an account + * + * We'll use the provided Server_Account object to use the data from the order, + * and call the MyOwnFreeHost API to create an account. + * Then, we'll store the returned vPanel username to our local database. + * + * @param Server_Account $a + */ + public function createAccount(Server_Account $a) { - $p = $a->getPackage(); + // Temporarily suspending the account while it's being set up. + $a->setSuspended(true); $this->client = $a->getClient(); $request = $this->MOFHclient->createAccount([ - 'username' => $a->getAPIdef(), + 'username' => $this->domainToID($a->getDomain()), 'password' => $a->getPassword(), 'domain' => $a->getDomain(), 'email' => $this->client->getEmail(), 'plan' => 'boxbilling', ]); + // Let's send the request, and store the response. $response = $request->send(); - $this->client = $a->getClient(); - $this->client->setAPIdef($a->getUsername()); - $this->client->setUsername($response->getVpUsername()); + // Setting the username to the one that is being used in the client area. + $a->setUsername($response->getVpUsername()); + // If something went wrong, we'll catch the error, and display it. if (!$response->isSuccessful()) { throw new Server_Exception($response->getMessage()); } + // It's all done. We can now unsuspend the account. + $a->setSuspended(false); + return true; } public function suspendAccount(Server_Account $a, $suspend = true) { $request = $this->MOFHclient->suspend([ - 'username' => $a->getAPIdef(), + 'username' => $this->domainToID($a->getDomain()), 'reason' => $a->getNote(), 'linked' => false ]); $response = $request->send(); + // If something went wrong, we'll catch the error, and display it. if (!$response->isSuccessful()) { throw new Server_Exception('MOFH error: ' . $response->getMessage()); } @@ -121,11 +166,13 @@ class Server_Manager_MOFH extends Server_Manager public function unsuspendAccount(Server_Account $a) { $request = $this->MOFHclient->unsuspend([ - 'username' => $a->getAPIdef() + 'username' => $this->domainToID($a->getDomain()) ]); + // Let's send the request, and store the response. $response = $request->send(); + // If something went wrong, we'll catch the error, and display it. if (!$response->isSuccessful()) { throw new Server_Exception('MOFH error: ' . $response->getMessage()); } @@ -146,7 +193,7 @@ class Server_Manager_MOFH extends Server_Manager public function changeAccountPassword(Server_Account $a, $new) { $request = $this->MOFHclient->password([ - 'username' => $a->getAPIdef(), + 'username' => $this->domainToID($a->getDomain()), 'password' => $new, ]); From bcd4937fbdd6d93b293603f4824bde1853c45d47 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 19:20:20 +0300 Subject: [PATCH 14/38] Update MOFH.php --- src/bb-library/Server/Manager/MOFH.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php index 06e5ceb89..dc96d2ece 100644 --- a/src/bb-library/Server/Manager/MOFH.php +++ b/src/bb-library/Server/Manager/MOFH.php @@ -149,7 +149,7 @@ class Server_Manager_MOFH extends Server_Manager $request = $this->MOFHclient->suspend([ 'username' => $this->domainToID($a->getDomain()), - 'reason' => $a->getNote(), + 'reason' => "Triggered by BoxBilling.", 'linked' => false ]); From b3d3c9b5cbd59447dd522fbfd8fa111d135781f8 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 19:59:51 +0300 Subject: [PATCH 15/38] Update MOFH.php --- src/bb-library/Server/Manager/MOFH.php | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php index dc96d2ece..6f48f7f07 100644 --- a/src/bb-library/Server/Manager/MOFH.php +++ b/src/bb-library/Server/Manager/MOFH.php @@ -101,6 +101,32 @@ class Server_Manager_MOFH extends Server_Manager public function synchronizeAccount(Server_Account $a) { $this->getLog()->info('Synchronizing account with server '.$a->getUsername()); + $this->client = $a->getClient(); + + $request = $this->MOFHclient->getDomainUser([ + 'domain' => $a->getDomain(), + ]); + + // Let's send the request, and store the response. + $response = $request->send(); + + if ($response->isFound()) { + + if ($response->getStatus() == "ACTIVE") { + $a->setSuspended(false); + } else if ($response->getStatus() == "SUSPENDED") { + $a->setSuspended(true); + }; + + // Setting the username to the one that is being used in the client area. + $a->username = $response->getUsername(); + } + + // If something went wrong, we'll catch the error, and display it. + if (!$response->isSuccessful()) { + throw new Server_Exception($response->getMessage()); + } + return $a; } @@ -132,7 +158,7 @@ class Server_Manager_MOFH extends Server_Manager $response = $request->send(); // Setting the username to the one that is being used in the client area. - $a->setUsername($response->getVpUsername()); + $a->username = $response->getVpUsername(); // If something went wrong, we'll catch the error, and display it. if (!$response->isSuccessful()) { @@ -142,7 +168,7 @@ class Server_Manager_MOFH extends Server_Manager // It's all done. We can now unsuspend the account. $a->setSuspended(false); - return true; + return $a; } public function suspendAccount(Server_Account $a, $suspend = true) { From 03e2f3bb943ea3877d0b2a5cbe7b5d30b7db8454 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Thu, 26 Nov 2020 20:44:41 +0300 Subject: [PATCH 16/38] Update MOFH.php --- src/bb-library/Server/Manager/MOFH.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php index 6f48f7f07..aa19f7a3f 100644 --- a/src/bb-library/Server/Manager/MOFH.php +++ b/src/bb-library/Server/Manager/MOFH.php @@ -63,7 +63,7 @@ class Server_Manager_MOFH extends Server_Manager public static function getForm() { return array( - 'label' => 'MyOwnFreeHost', + 'label' => 'MyOwnFreeHost', ); } @@ -119,14 +119,14 @@ class Server_Manager_MOFH extends Server_Manager }; // Setting the username to the one that is being used in the client area. - $a->username = $response->getUsername(); + $a->setUsername($response->getUsername()); } // If something went wrong, we'll catch the error, and display it. if (!$response->isSuccessful()) { throw new Server_Exception($response->getMessage()); } - + return $a; } @@ -158,7 +158,7 @@ class Server_Manager_MOFH extends Server_Manager $response = $request->send(); // Setting the username to the one that is being used in the client area. - $a->username = $response->getVpUsername(); + $a->setUsername($response->getVpUsername()); // If something went wrong, we'll catch the error, and display it. if (!$response->isSuccessful()) { From 8a1d8ea1bb0a197a5f212e876d5e637680ea9a41 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Fri, 27 Nov 2020 09:33:57 +0300 Subject: [PATCH 17/38] Update Service.php --- src/bb-modules/Servicehosting/Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-modules/Servicehosting/Service.php b/src/bb-modules/Servicehosting/Service.php index 82f7f7fd2..d06f8cd8c 100644 --- a/src/bb-modules/Servicehosting/Service.php +++ b/src/bb-modules/Servicehosting/Service.php @@ -257,7 +257,7 @@ class Service implements InjectionAwareInterface public function changeAccountUsername(\Model_ClientOrder $order, \Model_ServiceHosting $model, $data) { if(!isset($data['username']) || empty($data['username'])) { - throw new \Box_Exception('Account password is missing or is not valid'); + throw new \Box_Exception('Account username is missing or is not valid'); } $u = strtolower($data['username']); From ae108f1aa1631d508a038d63de7cbdcbe3dab69f Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Fri, 27 Nov 2020 09:36:54 +0300 Subject: [PATCH 18/38] Update MOFH.php --- src/bb-library/Server/Manager/MOFH.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php index aa19f7a3f..9227bfeeb 100644 --- a/src/bb-library/Server/Manager/MOFH.php +++ b/src/bb-library/Server/Manager/MOFH.php @@ -75,7 +75,7 @@ class Server_Manager_MOFH extends Server_Manager $protocol = 'http'; } $host = $this->_config['host']; - return $protocol . '://' . $host; + return $protocol . '://cpanel.' . $host; } public function getResellerLoginUrl() @@ -86,7 +86,7 @@ class Server_Manager_MOFH extends Server_Manager public function testConnection() { $request = $this->MOFHclient->availability([ - 'domain' => 'boxbilling.com', + 'domain' => 'tedmosbyisnotajerk.com', ]); $response = $request->send(); From b48d35736eab02e18318a93bab4d174baa12f53f Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Fri, 27 Nov 2020 09:47:00 +0300 Subject: [PATCH 19/38] Update MOFH.php --- src/bb-library/Server/Manager/MOFH.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php index 9227bfeeb..55ba0655f 100644 --- a/src/bb-library/Server/Manager/MOFH.php +++ b/src/bb-library/Server/Manager/MOFH.php @@ -214,7 +214,6 @@ class Server_Manager_MOFH extends Server_Manager public function changeAccountPackage(Server_Account $a, Server_Package $p) { throw new Server_Exception("Unfortunately, MyOwnFreeHost API does not support changing account packages. You may log into your reseller panel, and execute the action there."); - } public function changeAccountPassword(Server_Account $a, $new) { From 7886d9d8cee0cf3db886fca6ac2a58dfa9d15eb9 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Fri, 27 Nov 2020 09:56:19 +0300 Subject: [PATCH 20/38] Composer update --- src/composer.json | 3 ++- src/composer.lock | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/composer.json b/src/composer.json index 1dfe1db7c..2547f3e9f 100644 --- a/src/composer.json +++ b/src/composer.json @@ -28,7 +28,8 @@ "stripe/stripe-php": "2.1.1", "guzzlehttp/guzzle": "*", "laminas/laminas-httphandlerrunner": "^1.2.0", - "docnet/tfpdf": "^2.2" + "docnet/tfpdf": "^2.2", + "infinityfree/mofh-client": "^0.7.0" }, "suggest": { "ext-gettext": "*" diff --git a/src/composer.lock b/src/composer.lock index 43577929f..fc2a30c27 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": "28b4af5f035ec4db05fb0f54c8d17a8e", + "content-hash": "f628e09f5dff007c1c3b51f040151cbd", "packages": [ { "name": "composer/ca-bundle", @@ -426,6 +426,48 @@ }, "time": "2020-09-30T07:37:11+00:00" }, + { + "name": "infinityfree/mofh-client", + "version": "0.7.0", + "source": { + "type": "git", + "url": "https://github.com/InfinityFreeHosting/mofh-client.git", + "reference": "94a8081dbc1461ad7fa32c8301ae467fbd2c64b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/InfinityFreeHosting/mofh-client/zipball/94a8081dbc1461ad7fa32c8301ae467fbd2c64b3", + "reference": "94a8081dbc1461ad7fa32c8301ae467fbd2c64b3", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "~6.0|~7.0" + }, + "require-dev": { + "fzaninotto/faker": "^1.7", + "mockery/mockery": "^1.3", + "phpunit/phpunit": "^7.0|^8.0|^9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "InfinityFree\\MofhClient\\": "src/", + "InfinityFree\\MofhClient\\Tests\\": "tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Hans Adema", + "email": "hans@infinityfree.net" + } + ], + "description": "A WHM API client for MyOwnFreeHost in PHP", + "time": "2020-09-12T15:50:56+00:00" + }, { "name": "ircmaxell/password-compat", "version": "v1.0.4", @@ -3666,5 +3708,5 @@ "ext-mbstring": "*" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "1.1.0" } From cee352944e4469f2de957d7a82035f51e4ef5302 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Fri, 27 Nov 2020 10:23:34 +0300 Subject: [PATCH 21/38] Update ServiceTest.php --- tests/bb-modules/Servicehosting/ServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bb-modules/Servicehosting/ServiceTest.php b/tests/bb-modules/Servicehosting/ServiceTest.php index 40d262671..3f9f7078a 100644 --- a/tests/bb-modules/Servicehosting/ServiceTest.php +++ b/tests/bb-modules/Servicehosting/ServiceTest.php @@ -562,7 +562,7 @@ class ServiceTest extends \BBTestCase { $data = array(); $this->expectException(\Box_Exception::class); - $this->expectExceptionMessage('Account password is missing or is not valid'); + $this->expectExceptionMessage('Account username is missing or is not valid'); $this->service->changeAccountUsername($orderModel, $model, $data); } From 2834777a5170501e359c222304a8e70667419b44 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Fri, 27 Nov 2020 15:13:00 +0300 Subject: [PATCH 22/38] mkay.. this one *was* a joke :P --- src/bb-library/Server/Manager/MOFH.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-library/Server/Manager/MOFH.php b/src/bb-library/Server/Manager/MOFH.php index 55ba0655f..080b9db93 100644 --- a/src/bb-library/Server/Manager/MOFH.php +++ b/src/bb-library/Server/Manager/MOFH.php @@ -86,7 +86,7 @@ class Server_Manager_MOFH extends Server_Manager public function testConnection() { $request = $this->MOFHclient->availability([ - 'domain' => 'tedmosbyisnotajerk.com', + 'domain' => 'boxbilling.com', ]); $response = $request->send(); From 2919054a7609910c91cd70e3090bfdc7bdafeff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 10:34:28 +0300 Subject: [PATCH 23/38] Removed some leftovers of the licensing module --- tests/bb-modules/System/Api/AdminTest.php | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/tests/bb-modules/System/Api/AdminTest.php b/tests/bb-modules/System/Api/AdminTest.php index 6b94afeb2..4a98f5018 100644 --- a/tests/bb-modules/System/Api/AdminTest.php +++ b/tests/bb-modules/System/Api/AdminTest.php @@ -23,22 +23,6 @@ class AdminTest extends \BBTestCase { $this->assertEquals($di, $getDi); } - public function testlicense_info() - { - $data = array( - - ); - $serviceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock(); - $serviceMock->expects($this->atLeastOnce()) - ->method('getLicenseInfo') - ->will($this->returnValue(array())); - - $this->api->setService($serviceMock); - - $result = $this->api->license_info($data); - $this->assertIsArray($result); - } - public function testparam() { $data = array( @@ -234,4 +218,4 @@ class AdminTest extends \BBTestCase { } - \ No newline at end of file + From b93f0ba115b676b505f800dd4016605342a202d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 10:39:14 +0300 Subject: [PATCH 24/38] Update layout_default.phtml --- src/bb-themes/boxbilling/html/layout_default.phtml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bb-themes/boxbilling/html/layout_default.phtml b/src/bb-themes/boxbilling/html/layout_default.phtml index 97e35334c..9d1a0cbdd 100644 --- a/src/bb-themes/boxbilling/html/layout_default.phtml +++ b/src/bb-themes/boxbilling/html/layout_default.phtml @@ -214,8 +214,6 @@

- {# Removing this link is allowed only for BoxBilling PRO license owners. #} - {#Powered by BoxBilling#} © {{ now|date('Y') }} {{ company.signature }}

@@ -229,4 +227,4 @@ {% include 'partial_pending_messages.phtml' ignore missing %} - \ No newline at end of file + From 179c1e518beac25fd9a29e00624496b1254433bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 10:39:35 +0300 Subject: [PATCH 25/38] Update layout_default.phtml --- src/bb-themes/huraga/html/layout_default.phtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bb-themes/huraga/html/layout_default.phtml b/src/bb-themes/huraga/html/layout_default.phtml index a9762b214..dbf09db4e 100644 --- a/src/bb-themes/huraga/html/layout_default.phtml +++ b/src/bb-themes/huraga/html/layout_default.phtml @@ -247,7 +247,6 @@ {% endif %} - {# Removing this link is allowed only for BoxBilling PRO license owners. #} {% if guest.extension_is_on({"mod":'branding'}) %}
  • {% trans 'Powered by BoxBilling' %} @@ -279,4 +278,4 @@ {% endif %} {% include 'partial_pending_messages.phtml' ignore missing %} - \ No newline at end of file + From 12229e1bedc7af34d95aa831f1a8c18cde8c6fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 10:40:24 +0300 Subject: [PATCH 26/38] Update layout_default.phtml --- src/bb-themes/bootstrap/html/layout_default.phtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bb-themes/bootstrap/html/layout_default.phtml b/src/bb-themes/bootstrap/html/layout_default.phtml index ec37e160f..cbc1f512e 100755 --- a/src/bb-themes/bootstrap/html/layout_default.phtml +++ b/src/bb-themes/bootstrap/html/layout_default.phtml @@ -236,7 +236,6 @@
  • {% endif %} {% endfor %} - {# Removing this link is allowed only for BoxBilling PRO license owners. #} {% if guest.extension_is_on({"mod":'branding'}) or settings.footer_branding_enabled %}
  • {% trans 'Powered by BoxBilling' %}
  • {% endif %} @@ -251,4 +250,4 @@ - \ No newline at end of file + From 3b7f6c4d61cac661fd4e8c98df13130404de30f7 Mon Sep 17 00:00:00 2001 From: bgokcol Date: Sat, 28 Nov 2020 10:59:15 +0300 Subject: [PATCH 27/38] Change TOS text in install page --- src/install/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install/index.php b/src/install/index.php index f18edf11e..8100fd876 100644 --- a/src/install/index.php +++ b/src/install/index.php @@ -185,7 +185,7 @@ final class Box_Installer { $path = BB_PATH_LICENSE; if (!file_exists($path)) { - return 'Please visit http://www.boxbilling.com for licensing information'; + return 'BoxBilling is licensed under the Apache License, Version 2.0.'.PHP_EOL.'Please visit https://github.com/boxbilling/boxbilling/blob/master/LICENSE for full license text.'; } return file_get_contents($path); } From 9dac10c8cc116c3b5c8adf9dc13689780462f477 Mon Sep 17 00:00:00 2001 From: bgokcol Date: Sat, 28 Nov 2020 11:26:02 +0300 Subject: [PATCH 28/38] Automatically delete install folder --- src/install/index.php | 25 ++++++++++++++++++++++++- src/install/install.phtml | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/install/index.php b/src/install/index.php index 8100fd876..5c0e91873 100644 --- a/src/install/index.php +++ b/src/install/index.php @@ -108,11 +108,34 @@ final class Box_Installer $this->makeInstall($this->session); $this->generateEmailTemplates(); session_destroy(); + // Try to remove install folder + function rmAllDir($dir) { + if (is_dir($dir)) { + $contents = scandir($dir); + foreach ($contents as $content) { + if ($content != '.' && $content != '..') { + if (filetype($dir.'/'.$content) == 'dir') { + rmAllDir($dir.'/'.$content); + } + else { + unlink($dir.'/'.$content); + } + } + } + reset($contents); + rmdir($dir); + } + } + try { + rmAllDir('../install'); + } + catch(Exception $e) { + // do nothing + } print 'ok'; } catch (Exception $e) { print $e->getMessage(); } - break; case 'index': diff --git a/src/install/install.phtml b/src/install/install.phtml index 0a63394a7..bf7cde31d 100644 --- a/src/install/install.phtml +++ b/src/install/install.phtml @@ -212,7 +212,7 @@

    Even though BoxBilling was installed successfully, you must take a few more actions.

    Remove installation module

    -

    For security reasons, you have to delete the installer from your web server before getting started.

    +

    Normally install folder should be automatically deleted. But if it's still exists, you have to delete the installer from your web server before getting started.

    {{ install_module_path }}

    Change configuration file permissions

    From f5bf55c1ca3679f9e62836241d57498e9aa229ae Mon Sep 17 00:00:00 2001 From: bgokcol Date: Sat, 28 Nov 2020 12:04:42 +0300 Subject: [PATCH 29/38] Debug tag is deprecated --- src/bb-modules/Example/html_admin/mod_example_index.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bb-modules/Example/html_admin/mod_example_index.phtml b/src/bb-modules/Example/html_admin/mod_example_index.phtml index 66c5b8b58..a84fe8f91 100644 --- a/src/bb-modules/Example/html_admin/mod_example_index.phtml +++ b/src/bb-modules/Example/html_admin/mod_example_index.phtml @@ -54,11 +54,11 @@
    Data from API and passed to template from controller
    -
    {% debug list_from_controller %}
    +
    {{ dump(list_from_controller) }}
    Data from API accessed directly from template file
    {% set list = admin.example_get_something({"microsoft":1}) %} -
    {% debug list %}
    +
    {{ dump(list) }}
    {% endif %} From 62bb39f0034ab8b20b9ecee687995394f8bd7db0 Mon Sep 17 00:00:00 2001 From: bgokcol Date: Sat, 28 Nov 2020 12:06:45 +0300 Subject: [PATCH 30/38] Fix too few arguments error --- src/bb-modules/Example/Controller/Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-modules/Example/Controller/Admin.php b/src/bb-modules/Example/Controller/Admin.php index 076d1adae..0f6a33ac3 100644 --- a/src/bb-modules/Example/Controller/Admin.php +++ b/src/bb-modules/Example/Controller/Admin.php @@ -111,7 +111,7 @@ class Admin implements \Box\InjectionAwareInterface return $app->render('mod_example_index', $params); } - public function get_api(\Box_App $app, $id) + public function get_api(\Box_App $app, $id = null) { // always call this method to validate if admin is logged in $api = $this->di['api_admin']; From 8fce9711985ab8490fd026533752e6e1bc4740a3 Mon Sep 17 00:00:00 2001 From: bgokcol Date: Sat, 28 Nov 2020 17:55:31 +0300 Subject: [PATCH 31/38] Create custom pages plugin --- src/.htaccess | 1 + src/bb-modules/Custompages/Api/Admin.php | 141 ++++++++++++++++++ .../Custompages/Controller/Admin.php | 67 +++++++++ .../Custompages/Controller/Client.php | 64 ++++++++ src/bb-modules/Custompages/Service.php | 90 +++++++++++ .../html_admin/mod_custompages_index.phtml | 106 +++++++++++++ .../html_admin/mod_custompages_page.phtml | 73 +++++++++ .../html_client/mod_custompages_content.phtml | 25 ++++ src/bb-modules/Custompages/manifest.json | 12 ++ 9 files changed, 579 insertions(+) create mode 100644 src/bb-modules/Custompages/Api/Admin.php create mode 100644 src/bb-modules/Custompages/Controller/Admin.php create mode 100644 src/bb-modules/Custompages/Controller/Client.php create mode 100644 src/bb-modules/Custompages/Service.php create mode 100644 src/bb-modules/Custompages/html_admin/mod_custompages_index.phtml create mode 100644 src/bb-modules/Custompages/html_admin/mod_custompages_page.phtml create mode 100644 src/bb-modules/Custompages/html_client/mod_custompages_content.phtml create mode 100644 src/bb-modules/Custompages/manifest.json diff --git a/src/.htaccess b/src/.htaccess index 79070e342..768d7512f 100644 --- a/src/.htaccess +++ b/src/.htaccess @@ -37,6 +37,7 @@ RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] +RewriteRule ^page/(.*)$ index.php?_url=/custompages/$1 RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] diff --git a/src/bb-modules/Custompages/Api/Admin.php b/src/bb-modules/Custompages/Api/Admin.php new file mode 100644 index 000000000..7eeeae19b --- /dev/null +++ b/src/bb-modules/Custompages/Api/Admin.php @@ -0,0 +1,141 @@ +di['array_get']($data, 'search', null); + $pager = $this->getService()->searchPages($search); + + foreach ($pager['list'] as $key => $item) { + $pager['list'][$key] = $item; + } + + return $pager; + } + + /** + * Delete custom page + * + * @param int $id - custom page ID + * + * @return bool + */ + public function delete($data) + { + $required = array( + 'id' => 'Custom Page ID not passed', + ); + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $this->getService()->deletePage($data['id']); + return true; + } + + /** + * Delete custom pages + * + * @param array $ids - custom page IDs + * + * @return bool + */ + public function batch_delete($data) + { + $required = array( + 'ids' => 'Custom Page IDs not passed', + ); + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $this->getService()->deletePage($data['ids']); + return true; + } + + /** + * Create new custom page + * + * @param string $title - custom page title + * @param string $content - custom page content + * + * @optional string $description - custom page meta description + * @optional string $keywords - custom page meta keywords + * + * @return array + */ + public function create($data) + { + $required = array( + 'title' => 'Custom page title not passed', + 'content' => 'Custom page content not passed', + ); + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $title = $data['title']; + + $content = $data['content']; + $description = $this->di['array_get']($data, 'description', NULL); + $keywords = $this->di['array_get']($data, 'keywords', NULL); + + return $this->getService()->createPage($title, $description, $keywords, $content); + } + + /** + * Update custom page + * + * @param string $id - custom page id + * @param string $slug - custom page slug + * @param string $content - custom page content + * + * @optional string $description - custom page meta description + * @optional string $keywords - custom page meta keywords + * + * @return array + */ + public function update($data) + { + $required = array( + 'id' => 'Custom page id not passed', + 'title' => 'Custom page title not passed', + 'slug' => 'Custom page slug not passed', + 'content' => 'Custom page content not passed', + ); + $this->di['validator']->checkRequiredParamsForArray($required, $data); + + $id = $data['id']; + $title = $data['title']; + $content = $data['content']; + $slug = $data['slug']; + $description = $this->di['array_get']($data, 'description', NULL); + $keywords = $this->di['array_get']($data, 'keywords', NULL); + + return $this->getService()->updatePage($id, $title, $description, $keywords, $content, $slug); + } + + /** + * Get custom page by id + * + * @param string $id - custom page id + * + * @return array + */ + public function get_page($data) + { + return $this->getService()->getPage($data['page_id']); + } +} \ No newline at end of file diff --git a/src/bb-modules/Custompages/Controller/Admin.php b/src/bb-modules/Custompages/Controller/Admin.php new file mode 100644 index 000000000..365274ea2 --- /dev/null +++ b/src/bb-modules/Custompages/Controller/Admin.php @@ -0,0 +1,67 @@ +di = $di; + } + + /** + * @return mixed + */ + public function getDi() + { + return $this->di; + } + + public function fetchNavigation() + { + return array( + 'subpages'=> array( + array( + 'location' => 'extensions', + 'label' => 'Custom Pages', + 'index' => 2000, + 'uri' => $this->di['url']->adminLink('custompages'), + 'class' => '', + ), + ), + ); + + } + + public function register(\Box_App &$app) + { + $app->get('/custompages', 'get_index', array(), get_class($this)); + $app->get('/custompages/:id', 'get_page', array('id'=>'[0-9]+'), get_class($this)); + } + + public function get_index(\Box_App $app) + { + $this->di['is_admin_logged']; + return $app->render('mod_custompages_index'); + } + + public function get_page(\Box_App $app, $id) + { + return $app->render('mod_custompages_page', array('page_id' => $id)); + } +} \ No newline at end of file diff --git a/src/bb-modules/Custompages/Controller/Client.php b/src/bb-modules/Custompages/Controller/Client.php new file mode 100644 index 000000000..321a10fed --- /dev/null +++ b/src/bb-modules/Custompages/Controller/Client.php @@ -0,0 +1,64 @@ +di = $di; + } + + /** + * @return mixed + */ + public function getDi() + { + return $this->di; + } + + /** + * Methods maps client areas urls to corresponding methods + * Always use your module prefix to avoid conflicts with other modules + * in future + * + * @param \Box_App $app - returned by reference + */ + public function register(\Box_App &$app) + { + $app->get('/custompages/:slug', 'get_page', array('slug' => '[a-z0-9-]+'), get_class($this)); + } + + public function get_page(\Box_App $app, $slug) + { + $service = new \Box\Mod\Custompages\Service(); + $service->setDi($this->di); + $page = $service->getPage($slug, 'slug'); + if(isset($page['id'])) { + return $app->render('mod_custompages_content', array('page' => $page)); + } + else { + die(header('Location: '.$this->di['url']->get(''))); + } + } +} \ No newline at end of file diff --git a/src/bb-modules/Custompages/Service.php b/src/bb-modules/Custompages/Service.php new file mode 100644 index 000000000..549c4c184 --- /dev/null +++ b/src/bb-modules/Custompages/Service.php @@ -0,0 +1,90 @@ +di = $di; + } + + public function install() + { + $db = $this->di['db']; + $db->exec("CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT,`title` varchar(255) NOT NULL,`description` varchar(555) NOT NULL,`keywords` varchar(555) NOT NULL,`content` text NOT NULL,`slug` varchar(255) NOT NULL,`created_at` timestamp NOT NULL DEFAULT current_timestamp(),PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + return true; + } + + public function searchPages($search = null, $per_page = 100, $page = null) + { + $filter = array(); + $sql = "SELECT * FROM custom_pages WHERE 1"; + if ($search) { + $sql .= " AND title LIKE :q OR content LIKE :q"; + $filter[':q'] = "%$search%"; + } + $sql .= " ORDER BY id DESC"; + return $this->di['pager']->getSimpleResultSet($sql, $filter, $per_page, $page); + } + + public function deletePage($id) { + if(is_array($id)) { + foreach($id as $i => $x) { + $id[$i] = (int)$x; + } + $this->di['pdo']->query('DELETE from custom_pages WHERE id in ('.join(', ', $id).')'); + } + else { + $this->di['pdo']->prepare('DELETE from custom_pages WHERE id = ?')->execute([$id]); + } + } + + public function getPage($id, $type = 'id') { + $q = $this->di['pdo']->prepare('SELECT * from custom_pages WHERE '.$type.' = ?'); + $q->execute([$id]); + return $q->fetch(); + } + + public function createPage($title, $description, $keywords, $content) { + $slug = $this->di['tools']->slug($title); + $i = 0; + $ex = $this->di['pdo']->prepare('SELECT id from custom_pages WHERE slug = ?'); + $ex->execute([$slug]); + $ex = $ex->rowCount(); + while($ex > 0) { + $slug = $this->di['tools']->slug($title).'-'.++$i; + $ex = $this->di['pdo']->prepare('SELECT id from custom_pages WHERE slug = ?'); + $ex->execute([$slug]); + $ex = $ex->rowCount(); + } + $this->di['pdo']->prepare('INSERT into custom_pages (title, description, keywords, content, slug) VALUES (?, ?, ?, ?, ?)')->execute([$title, $description, $keywords, $content, $slug]); + $id = $this->di['pdo']->lastInsertId(); + $this->di['logger']->info('Created new custom page #%s', $id); + return $id; + } + + public function updatePage($id, $title, $description, $keywords, $content, $slug) { + $slug = $this->di['tools']->slug($slug); + $ex = $this->di['pdo']->prepare('SELECT id from custom_pages WHERE slug = ? AND id <> ?'); + $ex->execute([$slug, $id]); + if($ex->rowCount() > 0) { + die(json_encode(['result' => null, 'error' => ['message' => 'You need to set unique slug.', 'code' => 9999]])); + } + $this->di['pdo']->prepare('UPDATE custom_pages SET title = ?, description = ?, keywords = ?, content = ?, slug = ? WHERE id = ?')->execute([$title, $description, $keywords, $content, $slug, $id]); + $this->di['logger']->info('Updated custom page #%s', $id); + return $id; + } +} \ No newline at end of file diff --git a/src/bb-modules/Custompages/html_admin/mod_custompages_index.phtml b/src/bb-modules/Custompages/html_admin/mod_custompages_index.phtml new file mode 100644 index 000000000..acb1dc80e --- /dev/null +++ b/src/bb-modules/Custompages/html_admin/mod_custompages_index.phtml @@ -0,0 +1,106 @@ +{% import "macro_functions.phtml" as mf %} +{% extends "layout_default.phtml" %} +{% set active_menu = 'extensions' %} +{% block meta_title %}{% trans 'Custom Pages' %}{% endblock %} + +{% block content %} +
    + + + +
    + +
    +
    + {{ mf.table_search }} + + + + + + + + + + + + + {% set pages = admin.custompages_get_list({"per_page":30, "page":request.page}|merge(request)) %} + {% for page in pages.list %} + + + + + + + + {% else %} + + + + {% endfor %} + +
    {% trans 'ID' %}{% trans 'Title' %}{% trans 'Slug' %} 
    {{ page.id }}{{ page.title }}{{ page.slug }} + + + +
    {% trans 'The list is empty' %}
    + + {% include "partial_batch_delete.phtml" with {'action' : 'admin/custompages/batch_delete'} %} + {% include "partial_pagination.phtml" with {'list': pages, 'url':'custompages'} %} +
    + +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    + +
    +
    +
    + +
    +
    + +{% endblock %} + +{% block js %} + + + +{% endblock %} + +{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %} \ No newline at end of file diff --git a/src/bb-modules/Custompages/html_admin/mod_custompages_page.phtml b/src/bb-modules/Custompages/html_admin/mod_custompages_page.phtml new file mode 100644 index 000000000..5b9a083cc --- /dev/null +++ b/src/bb-modules/Custompages/html_admin/mod_custompages_page.phtml @@ -0,0 +1,73 @@ +{% extends "layout_default.phtml" %} +{% import "macro_functions.phtml" as mf %} +{% set active_menu = 'extensions' %} +{% block meta_title %} {% trans 'Edit Custom Page' %} {% endblock %} +{% set page = admin.custompages_get_page({page_id}|merge(request)) %} + +{% block breadcrumbs %} + +{% endblock %} + + +{% block content %} +{% if page.id > 0 %} + + +
    + +
    +
    {{ page.title}}
    +
    + +
    + +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    + +
    +
    +
    +{% else %} + +{% endif %} +{% endblock %} + +{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %} \ No newline at end of file diff --git a/src/bb-modules/Custompages/html_client/mod_custompages_content.phtml b/src/bb-modules/Custompages/html_client/mod_custompages_content.phtml new file mode 100644 index 000000000..1d535689f --- /dev/null +++ b/src/bb-modules/Custompages/html_client/mod_custompages_content.phtml @@ -0,0 +1,25 @@ +{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %} + +{% block meta_title %}{{ page.title }}{% endblock %} +{% block meta_description %}{{ page.description }}{% endblock %} +{% block meta_keywords %}{{ page.keywords }}{% endblock %} +{% block breadcrumb %}
  • {% trans 'Example module' %}
  • {% endblock %} +{% block page_header %} + +{% endblock%} +{% block content %} +
    +
    +
    +
    +

    {{ page.title }}

    +
    +
    + {{ page.content | bbmd }} +
    +
    +
    +
    +{% endblock %} \ No newline at end of file diff --git a/src/bb-modules/Custompages/manifest.json b/src/bb-modules/Custompages/manifest.json new file mode 100644 index 000000000..203816704 --- /dev/null +++ b/src/bb-modules/Custompages/manifest.json @@ -0,0 +1,12 @@ +{ + "id": "custompages", + "type": "mod", + "name": "Custom Pages", + "description": "Module allows you to create custom pages.", + "icon_url": "icon.png", + "homepage_url": "https://github.com/boxbilling/", + "author": "BoxBilling", + "author_url": "https://github.com/boxbilling/", + "license": "GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", + "version": "1.0.0" +} \ No newline at end of file From 64555a1cbb9cd5b72d20bd3033e71fe584f01dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 18:04:54 +0300 Subject: [PATCH 32/38] just a little typo :-) --- src/install/install.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install/install.phtml b/src/install/install.phtml index bf7cde31d..576b60fb7 100644 --- a/src/install/install.phtml +++ b/src/install/install.phtml @@ -212,7 +212,7 @@

    Even though BoxBilling was installed successfully, you must take a few more actions.

    Remove installation module

    -

    Normally install folder should be automatically deleted. But if it's still exists, you have to delete the installer from your web server before getting started.

    +

    Normally, install folder should be automatically deleted. But if it still exists, you have to delete the installer from your web server before getting started.

    {{ install_module_path }}

    Change configuration file permissions

    From f417ca21b96e50bd4b86ec54777a966b78fb7e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 18:16:11 +0300 Subject: [PATCH 33/38] As we're creating a new table with the new extension, updater should take care of it --- src/bb-update.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bb-update.php b/src/bb-update.php index 8632057e9..1068da655 100644 --- a/src/bb-update.php +++ b/src/bb-update.php @@ -10,6 +10,18 @@ * with this source code in the file LICENSE */ +/** + * Unnamed new release + */ +class BBPatch_24 extends BBPatchAbstract +{ + public function patch() + { + $q = "CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` varchar(555) NOT NULL, `keywords` varchar(555) NOT NULL, `content` text NOT NULL, `slug` varchar(255) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8"; + $this->execSql($q); + } +} + class BBPatch_23 extends BBPatchAbstract { public function patch() From a8632158f206e0fc6a3c82152626ce0b9d14c77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 18:16:44 +0300 Subject: [PATCH 34/38] Update Service.php --- src/bb-modules/Custompages/Service.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bb-modules/Custompages/Service.php b/src/bb-modules/Custompages/Service.php index 549c4c184..126eb193c 100644 --- a/src/bb-modules/Custompages/Service.php +++ b/src/bb-modules/Custompages/Service.php @@ -24,7 +24,7 @@ class Service public function install() { $db = $this->di['db']; - $db->exec("CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT,`title` varchar(255) NOT NULL,`description` varchar(555) NOT NULL,`keywords` varchar(555) NOT NULL,`content` text NOT NULL,`slug` varchar(255) NOT NULL,`created_at` timestamp NOT NULL DEFAULT current_timestamp(),PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + $db->exec("CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` varchar(555) NOT NULL, `keywords` varchar(555) NOT NULL, `content` text NOT NULL, `slug` varchar(255) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8"); return true; } @@ -87,4 +87,4 @@ class Service $this->di['logger']->info('Updated custom page #%s', $id); return $id; } -} \ No newline at end of file +} From 2a65af971ea6625d3927f2dbca299b1dfe1c9d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 18:19:33 +0300 Subject: [PATCH 35/38] Update bb-update.php --- src/bb-update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-update.php b/src/bb-update.php index 1068da655..5e039b9e1 100644 --- a/src/bb-update.php +++ b/src/bb-update.php @@ -17,7 +17,7 @@ class BBPatch_24 extends BBPatchAbstract { public function patch() { - $q = "CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` varchar(555) NOT NULL, `keywords` varchar(555) NOT NULL, `content` text NOT NULL, `slug` varchar(255) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8"; + $q = "CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` varchar(555) NOT NULL, `keywords` varchar(555) NOT NULL, `content` text NOT NULL, `slug` varchar(255) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8"; $this->execSql($q); } } From a97a52f184b2670468d876003878b31d23b12586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 18:20:18 +0300 Subject: [PATCH 36/38] Update Service.php --- src/bb-modules/Custompages/Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-modules/Custompages/Service.php b/src/bb-modules/Custompages/Service.php index 126eb193c..d7a295e57 100644 --- a/src/bb-modules/Custompages/Service.php +++ b/src/bb-modules/Custompages/Service.php @@ -24,7 +24,7 @@ class Service public function install() { $db = $this->di['db']; - $db->exec("CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` varchar(555) NOT NULL, `keywords` varchar(555) NOT NULL, `content` text NOT NULL, `slug` varchar(255) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8"); + $db->exec("CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` varchar(555) NOT NULL, `keywords` varchar(555) NOT NULL, `content` text NOT NULL, `slug` varchar(255) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8"); return true; } From fa869b7f9f333787c2bdfb24d166045d8405ef03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 28 Nov 2020 18:21:57 +0300 Subject: [PATCH 37/38] no icon supplied, let's use the default one --- src/bb-modules/Custompages/manifest.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bb-modules/Custompages/manifest.json b/src/bb-modules/Custompages/manifest.json index 203816704..558cd9554 100644 --- a/src/bb-modules/Custompages/manifest.json +++ b/src/bb-modules/Custompages/manifest.json @@ -2,11 +2,10 @@ "id": "custompages", "type": "mod", "name": "Custom Pages", - "description": "Module allows you to create custom pages.", - "icon_url": "icon.png", + "description": "This module allows you to create custom pages.", "homepage_url": "https://github.com/boxbilling/", "author": "BoxBilling", "author_url": "https://github.com/boxbilling/", "license": "GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", "version": "1.0.0" -} \ No newline at end of file +} From c9e4ac91d6c64338cd484fd01eb2c561d0e12f43 Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Sat, 28 Nov 2020 18:42:37 +0300 Subject: [PATCH 38/38] Adding the icon --- src/bb-modules/Custompages/icon.png | Bin 0 -> 487 bytes src/bb-modules/Custompages/manifest.json | 1 + 2 files changed, 1 insertion(+) create mode 100644 src/bb-modules/Custompages/icon.png diff --git a/src/bb-modules/Custompages/icon.png b/src/bb-modules/Custompages/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..36da9bfe44e6b392b783015aa8934b42bca02be9 GIT binary patch literal 487 zcmVOO^`x!LGZ3oma zL6T3=z8hy(N1t2}4Ip*9YnezUyoM>8hip?;?73r#s%@DekPx%Ell3w37obKA#`t+2 z4apbqmL=MUkdr(#<2DY_n;?>cEVVK@{ z@y^3lwe8u_RtkgQ3z?}O8fWS*K