/** * make request to update host ip addresses * * @param array $params whmcs data * * @return mixed array containig error message will return if error was ocurred, 'success' string in other case */ function stregistry_ModifyNameserver($params) { // init connection if (($status = __initConnectionAndAuthorize($params)) !== true) { return __errorArray($status); } $json = STRegistry::Hosts()->query($params['nameserver']); if (!ResponseHelper::isSuccess($json)) { return __errorArray(ResponseHelper::fromJSON($json)->message); } $host = Host::fromJSON($json); if (!empty($params['currentipaddress'])) { $host->removeIP($params['currentipaddress'], CommonFunctions::detectIPType($params['currentipaddress'])); } if (!empty($params['newipaddress'])) { $host->addIP($params['newipaddress'], CommonFunctions::detectIPType($params['newipaddress'])); } $json = STRegistry::Hosts()->update($host); if (!ResponseHelper::isSuccess($json)) { return __errorArray(ResponseHelper::fromJSON($json)->message); } return 'success'; }
private function getRequestDataForUpdate(Host $host) { $data = array('add' => array(), 'rem' => array()); $json = STRegistry::Hosts()->query($host->getName()); $currentHost = Host::fromJSON($json); foreach (array_merge($host->getIPv4(), $host->getIPv6()) as $id => $ip) { if (!in_array($ip, array_merge($currentHost->getIPv4(), $currentHost->getIPv6()))) { if (!isset($data['add']['addr'])) { $data['add']['addr'] = array(); } $data['add']['addr'][] = array($id => array('version' => CommonFunctions::detectIPType($ip), 'address' => $ip)); } } foreach (array_merge($currentHost->getIPv4(), $currentHost->getIPv6()) as $id => $ip) { if (!in_array($ip, array_merge($host->getIPv4(), $host->getIPv6()))) { if (!isset($data['rem']['addr'])) { $data['rem']['addr'] = array(); } $data['rem']['addr'][] = array($id => array('version' => CommonFunctions::detectIPType($ip), 'address' => $ip)); } } foreach ($host->getStatuses() as $status) { if (!in_array($status, $currentHost->getStatuses())) { if (!isset($data['add']['status'])) { $data['add']['status'] = array(); } $data['add']['status'][] = $status; } } foreach ($currentHost->getStatuses() as $status) { if (!in_array($status, $host->getStatuses())) { if (!isset($data['rem']['status'])) { $data['rem']['status'] = array(); } $data['rem']['status'][] = $status; } } return $data; }