diff --git a/RadWebHosting/Calls/CheckAvailability.php b/RadWebHosting/Calls/CheckAvailability.php new file mode 100644 index 0000000..1e6e53e --- /dev/null +++ b/RadWebHosting/Calls/CheckAvailability.php @@ -0,0 +1,15 @@ + + */ +class RegisterDomain extends Call +{ + public $action = "order/domains/register"; + + public $type = parent::TYPE_POST; +} diff --git a/RadWebHosting/Calls/RegisterNameServer.php b/RadWebHosting/Calls/RegisterNameServer.php new file mode 100644 index 0000000..29d9896 --- /dev/null +++ b/RadWebHosting/Calls/RegisterNameServer.php @@ -0,0 +1,15 @@ + + */ +class TransferDomain extends Call +{ + public $action = "order/domains/transfer"; + + public $type = parent::TYPE_POST; +} \ No newline at end of file diff --git a/RadWebHosting/Calls/TransferSync.php b/RadWebHosting/Calls/TransferSync.php new file mode 100644 index 0000000..6111829 --- /dev/null +++ b/RadWebHosting/Calls/TransferSync.php @@ -0,0 +1,15 @@ + + */ +abstract class Call +{ + const TYPE_GET = "GET"; + + const TYPE_POST = "POST"; + + const TYPE_PUT = "PUT"; + + const TYPE_DELETE = "DELETE"; + + /** + * Action path + * + * @var string + */ + public $action; + + /** + * Request type + * + * @var string + */ + public $type; + + /** + * Configuration + * + * @var Configuration + */ + public $config; + + /** + * params to send trough API + * + * @var mixed + */ + public $params; + + /** + * AbstractCall constructor + * + * @param Configuration $config + * @param $params + */ + public function __construct(Configuration $config, $params) + { + $this->config = $config; + $this->params = $params; + } + + /** + * Make request to API + * + * @return array|bool|mixed|\stdClass|string + */ + public function process() + { + try + { + $this->setVariablesInActionString(); + $url = "{$this->config->ApiEndpoint}/{$this->action}"; + + $client = new Client(); + $request = $client->createRequest($this->type, $url, ["headers" => $this->config->getAuthHeaders(), $this->getParamKeyName() => $this->params]); + + $output = $client->send($request)->getBody()->getContents(); + } + catch (\GuzzleHttp\Exception\ClientException $ex) + { + $response = $ex->getResponse(); + $output = $response->getBody()->getContents(); + } + catch (\GuzzleHttp\Exception\ServerException $ex) + { + $response = $ex->getResponse(); + $output = $response->getBody()->getContents(); + } + catch (\Exception $ex) + { + $output = $ex->getMessage(); + } + + $result = json_decode($output, true); + if($result === null && is_string($output)) + { + $result = ["error" => $output]; + } + + return $result; + } + + /** + * Put variables from params to action string if possible + */ + protected function setVariablesInActionString() + { + //Check if params needs to be filled + if(strpos($this->action, ":") !== false) + { + //Get params names + $pos = 0; + $names = []; + while(($pos = strpos($this->action, ":", $pos)) !== false) + { + $pos++; + + $slash = strpos($this->action, "/", $pos); + $names[] = substr($this->action, $pos, $slash - $pos); + } + + foreach($names as $name) + { + $this->action = str_replace(":{$name}", $this->params[$name], $this->action); + } + } + } + + /** + * Get correct param name depending on the request type + * + * @return string + */ + protected function getParamKeyName() + { + $result = "query"; + if($this->type == self::TYPE_POST) + { + $result = "body"; + } + + return $result; + } +} \ No newline at end of file diff --git a/RadWebHosting/Core/Configuration.php b/RadWebHosting/Core/Configuration.php new file mode 100644 index 0000000..e3c91c0 --- /dev/null +++ b/RadWebHosting/Core/Configuration.php @@ -0,0 +1,81 @@ + + */ +class Configuration +{ + const FIELD_USERNAME = "Username"; + const FIELD_API_KEY = "ApiKey"; + const FIELD_API_ENDPOINT = "ApiEndpoint"; + + /** + * @var mixed + */ + protected $configuration; + + /** + * Get configuration values and create params + * + * @param $params + */ + public static function create($params) + { + //Get configuration fields from params + $config = [self::FIELD_USERNAME, self::FIELD_API_KEY, self::FIELD_API_ENDPOINT]; + foreach($config as $name) + { + $result[$name] = $params[$name]; + } + + return new Configuration($result); + } + + /** + * Create Configuration + * + * @param $params + * @throws \Exception + */ + public function __construct($params) + { + //Check if registrar is enabled in WHMCS configuration + if($params[self::FIELD_API_ENDPOINT] === null) + { + throw new \Exception("Domain registrar is deactivated in WHMCS configuration"); + } + + $this->configuration = $params; + } + + /** + * Get values from configuration array + * + * @param $name + * @return mixed + */ + public function __get($name) + { + return $this->configuration[$name]; + } + + /** + * Create authorization headers + * + * @return array + */ + public function getAuthHeaders() + { + $time = gmdate("y-m-d H"); + $token = base64_encode(hash_hmac("sha256", $this->ApiKey, "{$this->Username}:$time")); + + return + [ + "username" => $this->Username, + "token" => $token + ]; + } +} \ No newline at end of file diff --git a/RadWebHosting/Core/Loader.php b/RadWebHosting/Core/Loader.php new file mode 100644 index 0000000..51dbc8b --- /dev/null +++ b/RadWebHosting/Core/Loader.php @@ -0,0 +1,37 @@ + + */ +class Loader +{ + private $rootdir; + + public function __construct($dir) + { + $this->rootdir = $dir; + $this->register(); + } + + protected function register() + { + spl_autoload_register(function($className) + { + $namespace = str_replace("\\Core","", __NAMESPACE__); + if (strpos($className, $namespace) === 0) + { + $className = str_replace("\\", DIRECTORY_SEPARATOR, $className); + $file = str_replace("ModulesGarden".DIRECTORY_SEPARATOR."DomainsReseller".DIRECTORY_SEPARATOR."Registrar".DIRECTORY_SEPARATOR."RadWebHosting", $this->rootdir, $className) . '.php'; + + if (file_exists($file)) + { + require_once $file; + } + } + }); + } +} diff --git a/RadWebHosting/RadWebHosting.php b/RadWebHosting/RadWebHosting.php new file mode 100644 index 0000000..63101cc --- /dev/null +++ b/RadWebHosting/RadWebHosting.php @@ -0,0 +1,634 @@ + [ + "Type" => "System", + "Value" => "RadWebHosting" + ], + "Description" => [ + "Type" => "System", + "Value" => "WHMCS registrar module for Rad Web Hosting Domain API integration." + ], + "Username" => [ + "FriendlyName" => "API Username", + "Type" => "text", + "Size" => "40", + "Description" => "Enter your email used in the main WHMCS" + ], + "ApiKey" => [ + "FriendlyName" => "API Key", + "Type" => "text", + "Size" => "40", + "Description" => "Enter your API key received from provider" + ], + "ApiEndpoint" => [ + "FriendlyName" => "API Endpoint", + "Type" => "text", + "Size" => "40", + "Description" => "Enter API endpoint", + "Default" => "https://radwebhosting.com/client_area/modules/addons/DomainsReseller/api/index.php" + ], + ]; + + return $configarray; +} + +/** + * Register Domain + * + * @param array $params + * @return array $return + */ +function RadWebHosting_RegisterDomain($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "regperiod" => (int)$params["regperiod"], + "domainfields" => base64_encode(serialize($params["additionalfields"])), + "originalvars" => $params, + "addons" => + [ + "dnsmanagement" => $params['dnsmanagement'] ? 1 : 0, + "emailforwarding" => $params['emailforwarding'] ? 1 : 0, + "idprotection" => $params['idprotection'] ? 1 : 0, + ], + "nameservers" => + [ + $params["ns1"], + $params["ns2"], + $params["ns3"], + $params["ns4"], + $params["ns5"], + ], + "contacts" => + [ + "registrant" => + [ + 'firstname' => $params["firstname"], + 'lastname' => $params["lastname"], + 'fullname' => $params["firstname"]." ".$params["lastname"], + 'companyname' => $params["companyname"], + 'email' => $params["email"], + 'address1' => $params["address1"], + 'address2' => $params["address2"], + 'city' => $params["city"], + 'state' => $params["state"], + 'zipcode' => $params["zipcode"], + 'country' => $params["country"], + 'phonenumber' => $params["phonenumber"], + ], + + "tech" => + [ + "firstname" => $params["adminfirstname"], + "lastname" => $params["adminlastname"], + 'fullname' => $params["adminfirstname"]." ".$params["adminlastname"], + "companyname" => $params["admincompanyname"], + "email" => $params["adminemail"], + "address1" => $params["adminaddress1"], + "address2" => $params["adminaddress2"], + "city" => $params["admincity"], + "fullstate" => $params["adminfullstate"], + "postcode" => $params["adminpostcode"], + "phonenumber" => $params["adminphonenumber"], + "phonecc" => $params["adminphonecc"], + "phonenumber" => $params["adminfullphonenumber"], + ], + ] + ]; + + $call = new Calls\RegisterDomain(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Transfer Domain + * + * @param array $params + * @return array $return + */ +function RadWebHosting_TransferDomain($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "regperiod" => (int)$params["regperiod"], + "eppcode" => $params["eppcode"], + 'domainfields' => base64_encode(serialize($params["additionalfields"])), + "addons" => + [ + "dnsmanagement" => $params['dnsmanagement'] ? 1 : 0, + "emailforwarding" => $params['emailforwarding'] ? 1 : 0, + "idprotection" => $params['idprotection'] ? 1 : 0, + ], + "nameservers" => + [ + $params["ns1"], + $params["ns2"], + $params["ns3"], + $params["ns4"], + $params["ns5"], + ], + "contacts" => + [ + "registrant" => + [ + 'firstname' => $params["firstname"], + 'lastname' => $params["lastname"], + 'fullname' => $params["firstname"]." ".$params["lastname"], + 'companyname' => $params["companyname"], + 'email' => $params["email"], + 'address1' => $params["address1"], + 'address2' => $params["address2"], + 'city' => $params["city"], + 'state' => $params["state"], + 'zipcode' => $params["zipcode"], + 'country' => $params["country"], + 'phonenumber' => $params["phonenumber"], + ], + + "tech" => + [ + "firstname" => $params["adminfirstname"], + "lastname" => $params["adminlastname"], + 'fullname' => $params["adminfirstname"]." ".$params["adminlastname"], + "companyname" => $params["admincompanyname"], + "email" => $params["adminemail"], + "address1" => $params["adminaddress1"], + "address2" => $params["adminaddress2"], + "city" => $params["admincity"], + "fullstate" => $params["adminfullstate"], + "postcode" => $params["adminpostcode"], + "phonenumber" => $params["adminphonenumber"], + "phonecc" => $params["adminphonecc"], + "phonenumber" => $params["adminfullphonenumber"], + ], + ] + ]; + + $call = new Calls\TransferDomain(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Renew Domain + * + * @param array $params + * @return array $return + */ +function RadWebHosting_RenewDomain($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "regperiod" => (int)$params["regperiod"], + "addons" => + [ + "dnsmanagement" => $params['dnsmanagement'] ? 1 : 0, + "emailforwarding" => $params['emailforwarding'] ? 1 : 0, + "idprotection" => $params['idprotection'] ? 1 : 0, + ], + ]; + + $call = new Calls\RenewDomain(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Get name servers + * + * @param array $params + * @return array $return + */ +function RadWebHosting_GetNameservers($params) +{ + $postfields = + [ + "domain" => $params["domainname"] + ]; + + $call = new Calls\GetNameServers(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Save nameservers + * + * @param array $params + * @return array $return + */ +function RadWebHosting_SaveNameservers($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + + "ns1" => $params["ns1"], + "ns2" => $params["ns2"], + "ns3" => $params["ns3"], + "ns4" => $params["ns4"], + "ns5" => $params["ns5"], + ]; + + $call = new Calls\SaveNameServers(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Release Domain + * + * @param array $params + * @return array $return + */ +function RadWebHosting_ReleaseDomain($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "transfertag" => $params["transfertag"] + ]; + + $call = new Calls\ReleaseDomain(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Get EPP Code + * + * @param array $params + * @return array $return + */ +function RadWebHosting_GetEPPCode($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + ]; + + $call = new Calls\GetEppCode(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Get Contact Details + * + * @param array $params + * @return array $return + */ +function RadWebHosting_GetContactDetails($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + ]; + + $call = new Calls\GetContactDetails(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Save Contact Details + * + * @param array $params + * @return array $return + */ +function RadWebHosting_SaveContactDetails($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "contactdetails" => $params["contactdetails"] + ]; + + $call = new Calls\SaveContactDetails(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Get Lock Status + * + * @param array $params + * @return array $return + */ +function RadWebHosting_GetRegistrarLock($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + ]; + + $call = new Calls\GetRegistrarLock(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Update Lock Status + * + * @param array $params + * @return array $return + */ +function RadWebHosting_SaveRegistrarLock($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "lockstatus" => $params["lockenabled"] + ]; + + $call = new Calls\SaveRegistrarLock(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Get DNS Records + * + * @param array $params + * @return array $return + */ +function RadWebHosting_GetDNS($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + ]; + + $call = new Calls\GetDns(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Save DNS Records + * + * @param array $params + * @return array $return + */ +function RadWebHosting_SaveDNS($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "dnsrecords" => $params["dnsrecords"] + ]; + + $call = new Calls\SaveDns(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Register Name Server + * + * @param array $params + * @return array $return + */ +function RadWebHosting_RegisterNameserver($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + + "nameserver" => $params["nameserver"], + "ipaddress" => $params["ipaddress"], + ]; + + $call = new Calls\RegisterNameServer(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Update Name Server + * + * @param array $params + * @return array $return + */ +function RadWebHosting_ModifyNameserver($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + + "nameserver" => $params["nameserver"], + "currentipaddress" => $params["currentipaddress"], + "newipaddress" => $params["newipaddress"], + ]; + + $call = new Calls\ModifyNameServer(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Delete Name Server + * + * @param array $params + * @return array $return + */ +function RadWebHosting_DeleteNameserver($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "nameserver" => $params["nameserver"], + ]; + + $call = new Calls\DeleteNameServer(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Delete Domain + * + * @param array $params + * @return array $return + */ +function RadWebHosting_RequestDelete($params) +{ + $postfields = + [ + "domain" => $params["domainname"] + ]; + + $call = new Calls\RequestDelete(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Synchronize transfer domain + * + * @param array $params + * @return array $return + */ +function RadWebHosting_TransferSync($params) +{ + $postfields = + [ + "domain" => "{$params["sld"]}.{$params["tld"]}" + ]; + + $call = new Calls\TransferSync(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Synchronize Registered Domains + * + * @param array $params + * @return array $return + */ +function RadWebHosting_Sync($params) +{ + $postfields = + [ + "domain" => "{$params["sld"]}.{$params["tld"]}" + ]; + + $call = new Calls\Sync(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Get list of emails aliases + * + * @param array $params + * @return array $return + */ +function RadWebHosting_GetEmailForwarding($params) +{ + $postfields = + [ + "domain" => $params["domainname"] + ]; + + $call = new Calls\GetEmailForwarding(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * Save list of emails aliases + * + * @param array $params + * @return array $return + */ +function RadWebHosting_SaveEmailForwarding($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "prefix" => $params["prefix"], + "forwardto" => $params["forwardto"] + ]; + + $call = new Calls\SaveEmailForwarding(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * This function is called when the ID Protection setting is toggled on or off + * + * @param array $params + * @return array $return + */ +function RadWebHosting_IDProtectionToggle($params) +{ + $postfields = + [ + "domain" => $params["domainname"], + "status" => $params["protectenable"] + ]; + + $call = new Calls\ToggleIdProtect(Configuration::create($params), $postfields); + $result = $call->process(); + + return $result; +} + +/** + * This function is called when the ID Protection setting is toggled on or off + * + * @param $params + * @return array + */ +function RadWebHosting_IDProtectToggle($params) +{ + return RadWebHosting_IDProtectionToggle($params); +} + + +/** + * Send domain lookup request + * + * @param $params + * @return array|bool|mixed|stdClass|string + */ +function RadWebHosting_CheckAvailability($params) +{ + $postfields = + [ + "searchTerm" => $params["searchTerm"], + "punyCodeSearchTerm" => $params["punyCodeSearchTerm"], + "tldsToInclude" => $params["tldsToInclude"], + "isIdnDomain" => $params['isIdnDomain'], + "premiumEnabled" => $params['premiumEnabled'], + "isWhmcs" => 1 + ]; + + $call = new Calls\CheckAvailability(Configuration::create($params), $postfields); + $result = $call->process(); + + return unserialize($result); +} \ No newline at end of file diff --git a/RadWebHosting/logo.png b/RadWebHosting/logo.png new file mode 100644 index 0000000..ce3a84a Binary files /dev/null and b/RadWebHosting/logo.png differ diff --git a/RadWebHosting/whmcs.json b/RadWebHosting/whmcs.json new file mode 100644 index 0000000..99630c9 --- /dev/null +++ b/RadWebHosting/whmcs.json @@ -0,0 +1,28 @@ +{ + "schema": "1.0", + "type": "whmcs-registrars", + "name": "RadWebHosting", + "category": "domains", + "description": { + "name": "Rad Web Hosting", + "tagline": "Industry-leading domain registrar with over 500+ TLDs available.", + "long": "Rad Web Hosting powers the world\u2019s largest cloud platform. With thousands of websites hosted and thousands of domain names under management, Rad Web Hosting is the registrar of choice for more WHMCS resellers.\n\nNow with the Rad Web Hosting module for WHMCS, you can resell domains using the Rad Web Hosting domain reseller platform. To get started, download the module from the WHMCS Marketplace using the link to the right.\n\nSignup for a Rad Web Hosting account @ [https:\/\/radwebhosting.com\/domain-reseller](https:\/\/radwebhosting.com\/domain-reseller)\n\n## Reasons to Choose Rad Web Hosting\n* Trusted partner and champion of our customers.\n* Large, high growth business with attractive unit economics.\n* Industry-leading products built on a single cloud platform & distinctive customer care.\n* Proven growth strategy with team purpose built to execute.\n* Market Leading Wholesale Domain Pricing." + }, + "marketplace": { + "url": "https:\/\/marketplace.whmcs.com\/product\/3983" + }, + "logo": { + "filename": "logo.png" + }, + "support": { + "homepage": "https:\/\/radwebhosting.com\/", + "learn_more": "https:\/\/github.com\/Rad-Web-Hosting", + "docs_url": "https:\/\/docs.radwebhosting.com\/domains-reseller" + }, + "authors": [ + { + "name": "Rad Web Hosting", + "homepage": "https:\/\/radwebhosting.com\/" + } + ] +} \ No newline at end of file