/** * @link http://docs.whmcs.com/Hooks:ClientEdit * @param array $vars */ function hook_coza_client_update($vars) { $params = getRegistrarConfigOptions('coza'); $contact = getClientsDetails($vars['userid'], 0); $epp_client = \COZA\Factory::build($params); try { $epp_client->connect(); try { \COZA\Factory::updateContactIfExists($epp_client, \COZA\Factory::getContactHandle($params, (int) $vars['userid']), $contact); } catch (Exception $e) { unset($epp_client); logActivity($e->getMessage(), $vars['userid']); return; } unset($epp_client); return; } catch (Exception $e) { unset($epp_client); logActivity('COZA/ContactUpdate: ' . $e->getMessage(), $vars['userid']); return; } }
function coza_TransferSync($params) { // currently we can only figure out if a transfer was rejected, by reading // the poll messages. Until I implemented some log-parser and hooks, it is // up to the admin to read the poll messages and do manual action on failed // transfer requests. // https://www.registry.net.za/content.php?wiki=1&contentid=25&title=Transfer%20Cleanup // get our consistent contact-id by getting it from the tblorders <> tbldomains $result = select_query('tblorders', 'tblorders.userid, tblorders.contactid, tblorders.nameservers', ['tbldomains.id' => (int) $params['domainid']], null, null, null, 'tbldomains ON tblorders.id = tbldomains.orderid'); if ($result === false || mysql_num_rows($result) !== 1) { // this should only happen on forged POST-request return ['error' => 'COZA/TransferSync: unknown order']; } $data = mysql_fetch_array($result); $user_id = (int) $data['userid']; $contact_id = (int) $data['contactid']; $nameservers = explode(',', $data['nameservers']); $nameservers = array_flip($nameservers); $contact_handle = \COZA\Factory::getContactHandle($params, $user_id, $contact_id); $epp_client = \COZA\Factory::build($params); try { $epp_client->connect(); // verify if domain is ours $frame = new \AfriCC\EPP\Frame\Command\Info\Domain(); $frame->setDomain(\COZA\Factory::getDomain($params)); $response = $epp_client->request($frame); unset($frame); if (!$response instanceof \AfriCC\EPP\Frame\Response) { unset($epp_client); return ['error' => 'COZA/TransferSync: unable to get response']; } // permanent fail, domain is available // @todo register domain for the client if ($response->code() === 2303) { unset($epp_client); return ['failed' => true, 'reason' => $response->message()]; } // other reasons if (!$response->success()) { unset($epp_client); return ['error' => sprintf('COZA/TransferSync: %s (%d)', $response->message(), $response->code())]; } $data = $response->data(); if (empty($data['infData']['clID']) || empty($data['infData']['exDate'])) { unset($epp_client); return ['error' => 'COZA/TransferSync: unable to parse response']; } // transfer not yet completed (tempfail) if ($data['infData']['clID'] !== \COZA\Factory::getRegistrarId($params)) { unset($epp_client); return ['error' => 'COZA/TransferSync: transfer not yet completed']; } // @todo if the transfer was rejected, the status should be anything else // OTHER than "pendingTransfer" AND have losing registrar as clID // meaning the transfer was then rejected - in this case we also need // to return a permfail $contact = getClientsDetails($user_id, $contact_id); // create contact if not exists try { \COZA\Factory::createContactIfNotExists($epp_client, $contact_handle, $contact); } catch (Exception $e) { unset($epp_client); return ['error' => $e->getMessage()]; } // prepare domain update $frame = new \AfriCC\EPP\Frame\Command\Update\Domain(); $frame->setDomain(\COZA\Factory::getDomain($params)); // override nameservers $ns_add = $ns_rem = []; if (!empty($data['infData']['ns']['hostAttr']) && is_array($data['infData']['ns']['hostAttr'])) { foreach ($data['infData']['ns']['hostAttr'] as $host_attr) { if (!isset($nameservers[$host_attr['hostName']])) { $ns_rem[] = $host_attr['hostName']; } else { $ns_add[] = $host_attr['hostName']; unset($nameservers[$host_attr['hostName']]); } } } $ns_add = array_merge($ns_add, array_keys($nameservers)); if (!empty($ns_add)) { foreach ($ns_add as $host) { $frame->addHostAttr($host); } } if (!empty($ns_rem)) { foreach ($ns_rem as $host) { $frame->removeHostAttr($host); } } // apply new contact if ($data['infData']['registrant'] !== $contact_handle) { $frame->changeRegistrant($contact_handle); } $response = $epp_client->request($frame); unset($frame); if (!$response instanceof \AfriCC\EPP\Frame\Response) { unset($epp_client); return ['error' => 'COZA/TransferSync: unable to get response']; } if (!$response->success()) { unset($epp_client); return ['error' => 'COZA/TransferSync: ' . $response->message()]; } // delete old contact if ($data['infData']['registrant'] !== $contact_handle) { // we can not delete contact handles right away, as it takes 5 days // until the old contact was replaced by the new contact. So lets // put in a queue and let a cronjob handle it insert_query('mod_coza_contact_deletequeue', ['next_due' => date('Y-m-d H:i:s', strtotime('+6 day')), 'contact_handle' => $data['infData']['registrant'], 'deleted' => 0]); } unset($epp_client); return ['completed' => true, 'expirydate' => date('Y-m-d', strtotime($data['infData']['exDate']))]; } catch (Exception $e) { unset($epp_client); return ['error' => sprintf('COZA/TransferSync: %s', $e->getMessage())]; } }