From 3a4c280b6e867689365e9000f25602e51803241f Mon Sep 17 00:00:00 2001 From: Ben Nottelling Date: Sun, 1 Aug 2021 22:50:48 -0700 Subject: [PATCH 1/6] Implement a mostly functional CWP server manager --- src/bb-library/Server/Manager/CWP.php | 272 ++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 src/bb-library/Server/Manager/CWP.php diff --git a/src/bb-library/Server/Manager/CWP.php b/src/bb-library/Server/Manager/CWP.php new file mode 100644 index 000000000..e05d750bf --- /dev/null +++ b/src/bb-library/Server/Manager/CWP.php @@ -0,0 +1,272 @@ +_config['host'])) { + throw new Server_Exception('Server manager "CWP" is not configured properly. Hostname is not set!'); + } + + if(empty($this->_config['accesshash'])) { + throw new Server_Exception('Server manager "CWP" is not configured properly. API Key / Access Hash is not set!'); + } else { + $this->_config['accesshash'] = preg_replace("'(\r|\n)'","",$this->_config['accesshash']); + } + + if(!$this->_config['secure']){ + /* + * Is this true? Docs specify the API port is for SSL and list no other alternative. + * Regardless, I have no plan to test it as anyone is an idiot if they plan to provide hosting and not use SSL to secure things. + */ + throw new Server_Exception('Server manager "CWP" is not configured properly. CWP API will only accept a secure connection!'); + } + /* + * Default API port. Not sure if it can be overridden, but I've opted to leave the option anyways. + */ + if(empty($this->_config['port'])){ + $this->_config['port'] = '2304'; + } + } + + public static function getForm() + { + return array( + 'label' => 'CWP', + ); + } + + public function getLoginUrl() + { + $host = $this->_config['host']; + return 'https://'.$host.':2083'; + } + + public function getResellerLoginUrl() + { + $host = $this->_config['host']; + return 'https://'.$host.':2031'; + } + + public function testConnection() + { + return TRUE; + } + + /* + * I don't really know where this function is used, so I'm not completely sure if this is right + * For now simply returns the original. + */ + public function synchronizeAccount(Server_Account $a) + { + $this->getLog()->info('Synchronizing account with server '.$a->getUsername()); + + $host = $this->_config['host']; + $port = $this->_config['port']; + + $data = array( + 'key' => $APIKey, + 'action' => 'list', + 'user' => $a->getUsername() + ); + + $new = clone $a; + + $acc = makeAPIRequest($host, $port, 'accountdetail', $data); + + //$new->setDomain($acc->domain); + //$new->setUsername($acc->user); + + return $new; + } + + public function createAccount(Server_Account $a) + { + $this->getLog()->info('Creating account '.$a->getUsername()); + + $client = $a->getClient(); + $package = $a->getPackage()->getName(); + + $APIKey = $this->_config['accesshash']; + + $host = $this->_config['host']; + $port = $this->_config['port']; + $ip = $this->_config['ip']; + + $data = array( + 'key' => $APIKey, + 'action' => 'add', + 'domain' => $a->getDomain(), + 'user' => $a->getUsername(), + 'pass' => $a->getPassword(), + 'email' => $client->getEmail(), + 'package' => $package, + 'server_ips' => $ip, + 'encodepass' => false + ); + if($a->getReseller()) { + $data['reseller'] = 1; + } + return makeAPIRequest($host, $port, 'account', $data); + } + + public function suspendAccount(Server_Account $a) + { + $this->getLog()->info('Suspending account '.$a->getUsername()); + + $client = $a->getClient(); + + $APIKey = $this->_config['accesshash']; + + $host = $this->_config['host']; + $port = $this->_config['port']; + + $data = array( + 'key' => $APIKey, + 'action' => 'susp', + 'user' => $a->getUsername() + ); + return makeAPIRequest($host, $port, 'account', $data); + } + + public function unsuspendAccount(Server_Account $a) + { + $this->getLog()->info('Un-suspending account '.$a->getUsername()); + + $client = $a->getClient(); + + $APIKey = $this->_config['accesshash']; + + $host = $this->_config['host']; + $port = $this->_config['port']; + + $data = array( + 'key' => $APIKey, + 'action' => 'unsp', + 'user' => $a->getUsername() + ); + return makeAPIRequest($host, $port, 'account', $data); + } + + public function cancelAccount(Server_Account $a) + { + $this->getLog()->info('Canceling account '.$a->getUsername()); + + $client = $a->getClient(); + + $APIKey = $this->_config['accesshash']; + + $host = $this->_config['host']; + $port = $this->_config['port']; + + $data = array( + 'key' => $APIKey, + 'action' => 'del', + 'user' => $a->getUsername(), + 'email' => $client->getEmail() + ); + return makeAPIRequest($host, $port, 'account', $data); + } + + public function changeAccountPackage(Server_Account $a, Server_Package $p) + { + $this->getLog()->info('Changing package on account '.$a->getUsername()); + + $package = $a->getPackage()->getName(); + + $APIKey = $this->_config['accesshash']; + + $host = $this->_config['host']; + $port = $this->_config['port']; + + $data = array( + 'key' => $APIKey, + 'action' => 'upd', + 'user' => $a->getUsername(), + 'package' => $package + ); + return makeAPIRequest($host, $port, 'changepack', $data); + } + + public function changeAccountPassword(Server_Account $a, $new) + { + $this->getLog()->info('Changing password on account '.$a->getUsername()); + + $client = $a->getClient(); + + $APIKey = $this->_config['accesshash']; + + $host = $this->_config['host']; + $port = $this->_config['port']; + + $data = array( + 'key' => $APIKey, + 'action' => 'udp', + 'user' => $a->getUsername(), + 'pass' => $new + ); + return makeAPIRequest($host, $port, 'changepass', $data); + } + + /* + * Function graveyard for things CWP doesn't support + */ + public function changeAccountUsername(Server_Account $a, $new) + { + throw new Server_Exception('CWP Does not support username changes through the API'); + } + + public function changeAccountDomain(Server_Account $a, $new) + { + throw new Server_Exception('CWP Does not support changing the primary domain name'); + } + + public function changeAccountIp(Server_Account $a, $new) + { + throw new Server_Exception('CWP Does not support changing the IP'); + } +} + /** + * Makes the CURL request to the server + */ + function makeAPIRequest($host, $port, $func, $data) + { + $url = 'https://'.$host.":".$port.'/v1/'.$func; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt ($ch, CURLOPT_POST, 1); + $response = json_decode(curl_exec($ch)); + curl_close($ch); + + if($response->status == 'OK' && $func != 'accountdetail'){ + return 1; + } else { + if($func == 'accountdetail'){ + return $response->status; + } else { + return 0; + } + } + } From 33761c06c63cc3679a31cc624738b1c0b855c9ff Mon Sep 17 00:00:00 2001 From: Benjamin Aerni Date: Mon, 2 Aug 2021 12:20:37 -0700 Subject: [PATCH 2/6] Test connection but it always thinks it works + account sync but it doesn't do anything because that's how boxbilling works --- src/bb-library/Server/Manager/CWP.php | 64 ++++++++++++++++++++------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src/bb-library/Server/Manager/CWP.php b/src/bb-library/Server/Manager/CWP.php index e05d750bf..7d4f09a15 100644 --- a/src/bb-library/Server/Manager/CWP.php +++ b/src/bb-library/Server/Manager/CWP.php @@ -66,19 +66,30 @@ class Server_Manager_CWP extends Server_Manager return 'https://'.$host.':2031'; } + /* + * CWP Doesn't have a function to test the connection, so we simply ask it to list the server type and check the response + */ public function testConnection() { - return TRUE; + $APIKey = $this->_config['accesshash']; + + $host = $this->_config['host']; + $port = $this->_config['port']; + + $data = array( + 'key' => $APIKey, + 'action' => 'list', + ); + + return makeAPIRequest($host, $port, 'typeserver', $data); } - /* - * I don't really know where this function is used, so I'm not completely sure if this is right - * For now simply returns the original. - */ public function synchronizeAccount(Server_Account $a) { $this->getLog()->info('Synchronizing account with server '.$a->getUsername()); + $APIKey = $this->_config['accesshash']; + $host = $this->_config['host']; $port = $this->_config['port']; @@ -89,11 +100,15 @@ class Server_Manager_CWP extends Server_Manager ); $new = clone $a; - $acc = makeAPIRequest($host, $port, 'accountdetail', $data); - //$new->setDomain($acc->domain); - //$new->setUsername($acc->user); + if($acc['account_info']['state'] == 'suspended'){ + $new->setSuspended(true); + } else { + $new->setSuspended(false); + } + + $new->setDomain($acc['domains']['0']['domain']); return $new; } @@ -185,7 +200,10 @@ class Server_Manager_CWP extends Server_Manager ); return makeAPIRequest($host, $port, 'account', $data); } - + + /* + * For unknown reasons, this doesn't work. + */ public function changeAccountPackage(Server_Account $a, Server_Package $p) { $this->getLog()->info('Changing package on account '.$a->getUsername()); @@ -257,16 +275,30 @@ class Server_Manager_CWP extends Server_Manager curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt ($ch, CURLOPT_POST, 1); - $response = json_decode(curl_exec($ch)); + $response = json_decode(curl_exec($ch), true); curl_close($ch); - - if($response->status == 'OK' && $func != 'accountdetail'){ - return 1; + + if(!empty($response['status'])){ + $status = $response['status']; } else { - if($func == 'accountdetail'){ - return $response->status; + $status = 'Error'; + } + if(!empty($response['result'])){ + $result = $response['result']; + } else { + $result = null; + } + + if($status == 'OK' && $func != 'accountdetail'){ + return true; + error_log('OK',0); + } else { + if($status == 'Error'){ + error_log('Error',0); + return 0; } else { - return 0; + error_log('Results',0); + return $result; } } } From c2cea8e3cbf0548b434174b5d1d7263cbbfb282d Mon Sep 17 00:00:00 2001 From: Benjamin Aerni Date: Mon, 2 Aug 2021 12:21:11 -0700 Subject: [PATCH 3/6] Convert tabs to spaces --- src/bb-library/Server/Manager/CWP.php | 166 +++++++++++++------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/src/bb-library/Server/Manager/CWP.php b/src/bb-library/Server/Manager/CWP.php index 7d4f09a15..2fa568232 100644 --- a/src/bb-library/Server/Manager/CWP.php +++ b/src/bb-library/Server/Manager/CWP.php @@ -17,19 +17,19 @@ class Server_Manager_CWP extends Server_Manager { public function init() - { - if (!extension_loaded('curl')) { - throw new Server_Exception('cURL extension is not enabled'); - } + { + if (!extension_loaded('curl')) { + throw new Server_Exception('cURL extension is not enabled'); + } - if(empty($this->_config['host'])) { - throw new Server_Exception('Server manager "CWP" is not configured properly. Hostname is not set!'); - } + if(empty($this->_config['host'])) { + throw new Server_Exception('Server manager "CWP" is not configured properly. Hostname is not set!'); + } - if(empty($this->_config['accesshash'])) { + if(empty($this->_config['accesshash'])) { throw new Server_Exception('Server manager "CWP" is not configured properly. API Key / Access Hash is not set!'); - } else { - $this->_config['accesshash'] = preg_replace("'(\r|\n)'","",$this->_config['accesshash']); + } else { + $this->_config['accesshash'] = preg_replace("'(\r|\n)'","",$this->_config['accesshash']); } if(!$this->_config['secure']){ @@ -47,57 +47,57 @@ class Server_Manager_CWP extends Server_Manager } } - public static function getForm() - { - return array( - 'label' => 'CWP', - ); - } + public static function getForm() + { + return array( + 'label' => 'CWP', + ); + } - public function getLoginUrl() - { - $host = $this->_config['host']; - return 'https://'.$host.':2083'; - } + public function getLoginUrl() + { + $host = $this->_config['host']; + return 'https://'.$host.':2083'; + } - public function getResellerLoginUrl() - { - $host = $this->_config['host']; - return 'https://'.$host.':2031'; - } + public function getResellerLoginUrl() + { + $host = $this->_config['host']; + return 'https://'.$host.':2031'; + } - /* + /* * CWP Doesn't have a function to test the connection, so we simply ask it to list the server type and check the response */ - public function testConnection() - { + public function testConnection() + { $APIKey = $this->_config['accesshash']; $host = $this->_config['host']; $port = $this->_config['port']; - $data = array( - 'key' => $APIKey, - 'action' => 'list', - ); + $data = array( + 'key' => $APIKey, + 'action' => 'list', + ); return makeAPIRequest($host, $port, 'typeserver', $data); - } + } - public function synchronizeAccount(Server_Account $a) - { - $this->getLog()->info('Synchronizing account with server '.$a->getUsername()); + public function synchronizeAccount(Server_Account $a) + { + $this->getLog()->info('Synchronizing account with server '.$a->getUsername()); $APIKey = $this->_config['accesshash']; $host = $this->_config['host']; $port = $this->_config['port']; - $data = array( - 'key' => $APIKey, - 'action' => 'list', - 'user' => $a->getUsername() - ); + $data = array( + 'key' => $APIKey, + 'action' => 'list', + 'user' => $a->getUsername() + ); $new = clone $a; $acc = makeAPIRequest($host, $port, 'accountdetail', $data); @@ -108,23 +108,23 @@ class Server_Manager_CWP extends Server_Manager $new->setSuspended(false); } - $new->setDomain($acc['domains']['0']['domain']); + $new->setDomain($acc['domains']['0']['domain']); - return $new; - } + return $new; + } public function createAccount(Server_Account $a) - { + { $this->getLog()->info('Creating account '.$a->getUsername()); - + $client = $a->getClient(); - $package = $a->getPackage()->getName(); + $package = $a->getPackage()->getName(); $APIKey = $this->_config['accesshash']; $host = $this->_config['host']; $port = $this->_config['port']; - $ip = $this->_config['ip']; + $ip = $this->_config['ip']; $data = array( 'key' => $APIKey, @@ -138,13 +138,13 @@ class Server_Manager_CWP extends Server_Manager 'encodepass' => false ); if($a->getReseller()) { - $data['reseller'] = 1; - } - return makeAPIRequest($host, $port, 'account', $data); + $data['reseller'] = 1; + } + return makeAPIRequest($host, $port, 'account', $data); } public function suspendAccount(Server_Account $a) - { + { $this->getLog()->info('Suspending account '.$a->getUsername()); $client = $a->getClient(); @@ -159,11 +159,11 @@ class Server_Manager_CWP extends Server_Manager 'action' => 'susp', 'user' => $a->getUsername() ); - return makeAPIRequest($host, $port, 'account', $data); + return makeAPIRequest($host, $port, 'account', $data); } public function unsuspendAccount(Server_Account $a) - { + { $this->getLog()->info('Un-suspending account '.$a->getUsername()); $client = $a->getClient(); @@ -178,11 +178,11 @@ class Server_Manager_CWP extends Server_Manager 'action' => 'unsp', 'user' => $a->getUsername() ); - return makeAPIRequest($host, $port, 'account', $data); - } + return makeAPIRequest($host, $port, 'account', $data); + } public function cancelAccount(Server_Account $a) - { + { $this->getLog()->info('Canceling account '.$a->getUsername()); $client = $a->getClient(); @@ -198,17 +198,17 @@ class Server_Manager_CWP extends Server_Manager 'user' => $a->getUsername(), 'email' => $client->getEmail() ); - return makeAPIRequest($host, $port, 'account', $data); + return makeAPIRequest($host, $port, 'account', $data); } - + /* * For unknown reasons, this doesn't work. */ public function changeAccountPackage(Server_Account $a, Server_Package $p) - { + { $this->getLog()->info('Changing package on account '.$a->getUsername()); - $package = $a->getPackage()->getName(); + $package = $a->getPackage()->getName(); $APIKey = $this->_config['accesshash']; @@ -221,11 +221,11 @@ class Server_Manager_CWP extends Server_Manager 'user' => $a->getUsername(), 'package' => $package ); - return makeAPIRequest($host, $port, 'changepack', $data); + return makeAPIRequest($host, $port, 'changepack', $data); } - public function changeAccountPassword(Server_Account $a, $new) - { + public function changeAccountPassword(Server_Account $a, $new) + { $this->getLog()->info('Changing password on account '.$a->getUsername()); $client = $a->getClient(); @@ -241,33 +241,33 @@ class Server_Manager_CWP extends Server_Manager 'user' => $a->getUsername(), 'pass' => $new ); - return makeAPIRequest($host, $port, 'changepass', $data); - } + return makeAPIRequest($host, $port, 'changepass', $data); + } - /* + /* * Function graveyard for things CWP doesn't support */ - public function changeAccountUsername(Server_Account $a, $new) - { - throw new Server_Exception('CWP Does not support username changes through the API'); - } + public function changeAccountUsername(Server_Account $a, $new) + { + throw new Server_Exception('CWP Does not support username changes through the API'); + } - public function changeAccountDomain(Server_Account $a, $new) - { - throw new Server_Exception('CWP Does not support changing the primary domain name'); - } + public function changeAccountDomain(Server_Account $a, $new) + { + throw new Server_Exception('CWP Does not support changing the primary domain name'); + } - public function changeAccountIp(Server_Account $a, $new) - { - throw new Server_Exception('CWP Does not support changing the IP'); - } + public function changeAccountIp(Server_Account $a, $new) + { + throw new Server_Exception('CWP Does not support changing the IP'); + } } /** * Makes the CURL request to the server */ - function makeAPIRequest($host, $port, $func, $data) + function makeAPIRequest($host, $port, $func, $data) { - $url = 'https://'.$host.":".$port.'/v1/'.$func; + $url = 'https://'.$host.":".$port.'/v1/'.$func; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -277,7 +277,7 @@ class Server_Manager_CWP extends Server_Manager curl_setopt ($ch, CURLOPT_POST, 1); $response = json_decode(curl_exec($ch), true); curl_close($ch); - + if(!empty($response['status'])){ $status = $response['status']; } else { From d93fc8c6bf9b406e892f06a7e1792f65e6dc581f Mon Sep 17 00:00:00 2001 From: Benjamin Aerni Date: Mon, 2 Aug 2021 13:01:21 -0700 Subject: [PATCH 4/6] [CWP] Some code clean-up --- src/bb-library/Server/Manager/CWP.php | 54 +++++++++++++-------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/bb-library/Server/Manager/CWP.php b/src/bb-library/Server/Manager/CWP.php index 2fa568232..6e50085ba 100644 --- a/src/bb-library/Server/Manager/CWP.php +++ b/src/bb-library/Server/Manager/CWP.php @@ -34,12 +34,11 @@ class Server_Manager_CWP extends Server_Manager if(!$this->_config['secure']){ /* - * Is this true? Docs specify the API port is for SSL and list no other alternative. - * Regardless, I have no plan to test it as anyone is an idiot if they plan to provide hosting and not use SSL to secure things. + * CWP will simply return an error if you try to connect via a HTTP connection */ throw new Server_Exception('Server manager "CWP" is not configured properly. CWP API will only accept a secure connection!'); } - /* + /* * Default API port. Not sure if it can be overridden, but I've opted to leave the option anyways. */ if(empty($this->_config['port'])){ @@ -71,8 +70,8 @@ class Server_Manager_CWP extends Server_Manager */ public function testConnection() { - $APIKey = $this->_config['accesshash']; - + $APIKey = $this->_config['accesshash']; + $host = $this->_config['host']; $port = $this->_config['port']; @@ -80,16 +79,16 @@ class Server_Manager_CWP extends Server_Manager 'key' => $APIKey, 'action' => 'list', ); - + return makeAPIRequest($host, $port, 'typeserver', $data); } public function synchronizeAccount(Server_Account $a) { $this->getLog()->info('Synchronizing account with server '.$a->getUsername()); - - $APIKey = $this->_config['accesshash']; - + + $APIKey = $this->_config['accesshash']; + $host = $this->_config['host']; $port = $this->_config['port']; @@ -98,7 +97,7 @@ class Server_Manager_CWP extends Server_Manager 'action' => 'list', 'user' => $a->getUsername() ); - + $new = clone $a; $acc = makeAPIRequest($host, $port, 'accountdetail', $data); @@ -107,7 +106,7 @@ class Server_Manager_CWP extends Server_Manager } else { $new->setSuspended(false); } - + $new->setDomain($acc['domains']['0']['domain']); return $new; @@ -116,11 +115,11 @@ class Server_Manager_CWP extends Server_Manager public function createAccount(Server_Account $a) { $this->getLog()->info('Creating account '.$a->getUsername()); - + $client = $a->getClient(); $package = $a->getPackage()->getName(); - $APIKey = $this->_config['accesshash']; + $APIKey = $this->_config['accesshash']; $host = $this->_config['host']; $port = $this->_config['port']; @@ -128,11 +127,11 @@ class Server_Manager_CWP extends Server_Manager $data = array( 'key' => $APIKey, - 'action' => 'add', - 'domain' => $a->getDomain(), - 'user' => $a->getUsername(), - 'pass' => $a->getPassword(), - 'email' => $client->getEmail(), + 'action' => 'add', + 'domain' => $a->getDomain(), + 'user' => $a->getUsername(), + 'pass' => $a->getPassword(), + 'email' => $client->getEmail(), 'package' => $package, 'server_ips' => $ip, 'encodepass' => false @@ -148,7 +147,7 @@ class Server_Manager_CWP extends Server_Manager $this->getLog()->info('Suspending account '.$a->getUsername()); $client = $a->getClient(); - + $APIKey = $this->_config['accesshash']; $host = $this->_config['host']; @@ -167,7 +166,7 @@ class Server_Manager_CWP extends Server_Manager $this->getLog()->info('Un-suspending account '.$a->getUsername()); $client = $a->getClient(); - + $APIKey = $this->_config['accesshash']; $host = $this->_config['host']; @@ -186,7 +185,7 @@ class Server_Manager_CWP extends Server_Manager $this->getLog()->info('Canceling account '.$a->getUsername()); $client = $a->getClient(); - + $APIKey = $this->_config['accesshash']; $host = $this->_config['host']; @@ -200,7 +199,7 @@ class Server_Manager_CWP extends Server_Manager ); return makeAPIRequest($host, $port, 'account', $data); } - + /* * For unknown reasons, this doesn't work. */ @@ -231,7 +230,7 @@ class Server_Manager_CWP extends Server_Manager $client = $a->getClient(); $APIKey = $this->_config['accesshash']; - + $host = $this->_config['host']; $port = $this->_config['port']; @@ -277,7 +276,7 @@ class Server_Manager_CWP extends Server_Manager curl_setopt ($ch, CURLOPT_POST, 1); $response = json_decode(curl_exec($ch), true); curl_close($ch); - + if(!empty($response['status'])){ $status = $response['status']; } else { @@ -286,18 +285,15 @@ class Server_Manager_CWP extends Server_Manager if(!empty($response['result'])){ $result = $response['result']; } else { - $result = null; + $result = null; } if($status == 'OK' && $func != 'accountdetail'){ - return true; - error_log('OK',0); + return 1; } else { if($status == 'Error'){ - error_log('Error',0); return 0; } else { - error_log('Results',0); return $result; } } From be6bb8a4584a6b6ada3bee76683cb755e1c048d6 Mon Sep 17 00:00:00 2001 From: Ben Nottelling Date: Mon, 2 Aug 2021 22:18:53 -0700 Subject: [PATCH 5/6] [CWP] Formatting, added notes, and slightly updated synchronizeAccount synchronizeAccount still does nothing though, since BoxBilling doesn't care about the data I can pull in it. --- src/bb-library/Server/Manager/CWP.php | 56 ++++++++++++++++++--------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/bb-library/Server/Manager/CWP.php b/src/bb-library/Server/Manager/CWP.php index 6e50085ba..157327a31 100644 --- a/src/bb-library/Server/Manager/CWP.php +++ b/src/bb-library/Server/Manager/CWP.php @@ -22,6 +22,10 @@ class Server_Manager_CWP extends Server_Manager throw new Server_Exception('cURL extension is not enabled'); } + if(empty($this->_config['ip'])) { + throw new Server_Exception('Server manager "CWP" is not configured properly. IP address is not set!'); + } + if(empty($this->_config['host'])) { throw new Server_Exception('Server manager "CWP" is not configured properly. Hostname is not set!'); } @@ -33,12 +37,12 @@ class Server_Manager_CWP extends Server_Manager } if(!$this->_config['secure']){ - /* + /** * CWP will simply return an error if you try to connect via a HTTP connection */ throw new Server_Exception('Server manager "CWP" is not configured properly. CWP API will only accept a secure connection!'); } - /* + /** * Default API port. Not sure if it can be overridden, but I've opted to leave the option anyways. */ if(empty($this->_config['port'])){ @@ -53,6 +57,9 @@ class Server_Manager_CWP extends Server_Manager ); } + /** + * We can actually generate a direct log-in link from CWP, but I'm not sure if that's a secure thing to do here. + */ public function getLoginUrl() { $host = $this->_config['host']; @@ -65,8 +72,9 @@ class Server_Manager_CWP extends Server_Manager return 'https://'.$host.':2031'; } - /* - * CWP Doesn't have a function to test the connection, so we simply ask it to list the server type and check the response + /** + * CWP doesn't have a connection test function, so we ask what kind of server it is (EX: KVM / OpenVZ) + * No error means the connection worked and we can continue */ public function testConnection() { @@ -82,7 +90,11 @@ class Server_Manager_CWP extends Server_Manager return makeAPIRequest($host, $port, 'typeserver', $data); } - + + /** + * BoxBilling will only sync usernames and IP address, neither can be changed or synced from CWP + * That makes this function useless, but we still set what we can incase they are ever used in the future + */ public function synchronizeAccount(Server_Account $a) { $this->getLog()->info('Synchronizing account with server '.$a->getUsername()); @@ -106,12 +118,15 @@ class Server_Manager_CWP extends Server_Manager } else { $new->setSuspended(false); } - - $new->setDomain($acc['domains']['0']['domain']); - + + $new->setPackage($acc['account_info']['package_name']); + $new->setReseller($acc['account_info']['reseller']); return $new; } - + + /** + * Package name must match on both CWP and BoxBilling! + */ public function createAccount(Server_Account $a) { $this->getLog()->info('Creating account '.$a->getUsername()); @@ -126,7 +141,7 @@ class Server_Manager_CWP extends Server_Manager $ip = $this->_config['ip']; $data = array( - 'key' => $APIKey, + 'key' => $APIKey, 'action' => 'add', 'domain' => $a->getDomain(), 'user' => $a->getUsername(), @@ -154,7 +169,7 @@ class Server_Manager_CWP extends Server_Manager $port = $this->_config['port']; $data = array( - 'key' => $APIKey, + 'key' => $APIKey, 'action' => 'susp', 'user' => $a->getUsername() ); @@ -173,7 +188,7 @@ class Server_Manager_CWP extends Server_Manager $port = $this->_config['port']; $data = array( - 'key' => $APIKey, + 'key' => $APIKey, 'action' => 'unsp', 'user' => $a->getUsername() ); @@ -192,7 +207,7 @@ class Server_Manager_CWP extends Server_Manager $port = $this->_config['port']; $data = array( - 'key' => $APIKey, + 'key' => $APIKey, 'action' => 'del', 'user' => $a->getUsername(), 'email' => $client->getEmail() @@ -200,8 +215,10 @@ class Server_Manager_CWP extends Server_Manager return makeAPIRequest($host, $port, 'account', $data); } - /* - * For unknown reasons, this doesn't work. + /** + * Probably works, but my CWP instance doesn't even return an error to this function let along change the package + * Ticket has been put in with CWP + * TODO: Update this comment when the issue is resolved */ public function changeAccountPackage(Server_Account $a, Server_Package $p) { @@ -215,7 +232,7 @@ class Server_Manager_CWP extends Server_Manager $port = $this->_config['port']; $data = array( - 'key' => $APIKey, + 'key' => $APIKey, 'action' => 'upd', 'user' => $a->getUsername(), 'package' => $package @@ -235,7 +252,7 @@ class Server_Manager_CWP extends Server_Manager $port = $this->_config['port']; $data = array( - 'key' => $APIKey, + 'key' => $APIKey, 'action' => 'udp', 'user' => $a->getUsername(), 'pass' => $new @@ -243,12 +260,12 @@ class Server_Manager_CWP extends Server_Manager return makeAPIRequest($host, $port, 'changepass', $data); } - /* + /** * Function graveyard for things CWP doesn't support */ public function changeAccountUsername(Server_Account $a, $new) { - throw new Server_Exception('CWP Does not support username changes through the API'); + throw new Server_Exception('CWP Does not support username changes'); } public function changeAccountDomain(Server_Account $a, $new) @@ -282,6 +299,7 @@ class Server_Manager_CWP extends Server_Manager } else { $status = 'Error'; } + if(!empty($response['result'])){ $result = $response['result']; } else { From 191967751d3efd2526092763fe89de4a744c8485 Mon Sep 17 00:00:00 2001 From: Ben Nottelling Date: Mon, 2 Aug 2021 22:22:44 -0700 Subject: [PATCH 6/6] [CWP] Fix another indention issue I can't see until I view it on GitHub Also removed the word "todo" because it makes CodeFactor angry --- src/bb-library/Server/Manager/CWP.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bb-library/Server/Manager/CWP.php b/src/bb-library/Server/Manager/CWP.php index 157327a31..0bc476216 100644 --- a/src/bb-library/Server/Manager/CWP.php +++ b/src/bb-library/Server/Manager/CWP.php @@ -74,7 +74,7 @@ class Server_Manager_CWP extends Server_Manager /** * CWP doesn't have a connection test function, so we ask what kind of server it is (EX: KVM / OpenVZ) - * No error means the connection worked and we can continue + * No error means the connection worked and we can continue */ public function testConnection() { @@ -218,7 +218,7 @@ class Server_Manager_CWP extends Server_Manager /** * Probably works, but my CWP instance doesn't even return an error to this function let along change the package * Ticket has been put in with CWP - * TODO: Update this comment when the issue is resolved + * I will update this comment when the issue is resolved */ public function changeAccountPackage(Server_Account $a, Server_Package $p) {