function hook_stregistrar_ClientAreaHeaderOutput($params) { $errors = array(); if ($params['clientareaaction'] == 'domainregisterns') { global $smarty; global $db_host; if (($status = __initConnectionAndAuthorize(__getSTRegistrarModuleConfig())) === false) { return $errors[] = $status; } $filter = new SearchCriteria(); $filter->name->like("%." . $params['domain']); $json = STRegistry::Hosts()->search($filter, 30); if (!ResponseHelper::isSuccess($json)) { return $errors[] = ResponseHelper::fromJSON($json)->message; } $hosts = ResponseHelper::fromJSON($json, 'searchRes')->result; $gluerecords = array(); foreach ($hosts as $host) { if (count($host['addr'])) { foreach ($host['addr'] as $record) { $keys = array_keys($record); $type = array_shift($keys); $addr = array_shift($record); $gluerecords[] = array('hostname' => $host['name'], 'address' => $addr, 'type' => $type == Host::IP_VERSION_4 ? 'IPv4' : 'IPv6'); } } else { $gluerecords[] = array('hostname' => $host['name']); } } $smarty->assign('module', "stregistry"); $smarty->assign('gluerecords', $gluerecords); } }
/** * init wrapper and send authorization request * * @param array $params module configurations * * @return mixed true if authorization was sucessfull, error message in other case */ function __initConnectionAndAuthorize($params) { if (!class_exists('STRegistry')) { require_once sprintf('%s%2$sclasses%2$swrapper%2$sSTRegistry.php', dirname(__FILE__), DIRECTORY_SEPARATOR); require_once sprintf('%s%2$sclasses%2$swrapper%2$sResponseHelper.php', dirname(__FILE__), DIRECTORY_SEPARATOR); require_once sprintf('%s%2$sclasses%2$sSTRegistryPrivacyContact.php', dirname(__FILE__), DIRECTORY_SEPARATOR); } STRegistry::Init($params['apiHost'], $params['apiHost'], $params['apiUseSSL'] === 'on', $params['apiVersion'] ?: '1.0', $params['apiUserAgent']); $json = STRegistry::Session()->login($params['apiUsername'], $params['apiPassword']); if (!ResponseHelper::isSuccess($json)) { return ResponseHelper::fromJSON($json)->message; } return true; }
function stregistry_Sync($params) { // init connection if (($status = __initConnectionAndAuthorize($params)) !== true) { return __errorArray($status); } // fetch domain $json = STRegistry::Domains()->query($params['domain']); if (!ResponseHelper::isSuccess($json)) { $response = ResponseHelper::fromJSON($json); if ($response->code == 2303 || $response->code == 2203) { // domain does not already exists or not own by current registarar __markWHMCSDomainCancelled($params['domainid']); return array('active' => false, 'expired' => false); } else { return __errorArray($response->message); } } $domain = Domain::fromJSON($json); if ($domain->getDateExpire() < time()) { return array('expired' => true); } return array('active' => true, 'expired' => false, 'expirydate' => $domain->getDateExpire('Y-m-d')); }