mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-14 08:37:00 +02:00
Optimized EPP contact info; fixed #170
This commit is contained in:
parent
32d1e9dbbd
commit
621976f11a
2 changed files with 86 additions and 51 deletions
|
@ -569,7 +569,7 @@ class EppWriter {
|
||||||
$trDateFormatted = $trDate->format('Y-m-d\TH:i:s.v\Z');
|
$trDateFormatted = $trDate->format('Y-m-d\TH:i:s.v\Z');
|
||||||
$writer->writeElement('contact:trDate', $trDateFormatted);
|
$writer->writeElement('contact:trDate', $trDateFormatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handling 'contact:authInfo'
|
// Handling 'contact:authInfo'
|
||||||
if ($resp['authInfo'] === 'valid') {
|
if ($resp['authInfo'] === 'valid') {
|
||||||
$writer->startElement('contact:authInfo');
|
$writer->startElement('contact:authInfo');
|
||||||
|
@ -581,6 +581,18 @@ class EppWriter {
|
||||||
$writer->endElement(); // End of 'contact:authInfo'
|
$writer->endElement(); // End of 'contact:authInfo'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($resp['disclose'])) {
|
||||||
|
$writer->startElement('contact:disclose');
|
||||||
|
$writer->writeAttribute('flag', $resp['disclose']['flag']); // 1 = disclose, 0 = restrict
|
||||||
|
|
||||||
|
foreach ($resp['disclose']['fields'] as $field) {
|
||||||
|
$writer->startElement('contact:' . $field);
|
||||||
|
$writer->endElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
$writer->endElement(); // End of contact:disclose
|
||||||
|
}
|
||||||
|
|
||||||
$writer->endElement(); // End of 'contact:infData'
|
$writer->endElement(); // End of 'contact:infData'
|
||||||
$writer->endElement(); // End of 'resData'
|
$writer->endElement(); // End of 'resData'
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ function processContactInfo($conn, $db, $xml, $trans) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validation for contact ID
|
|
||||||
$invalid_identifier = validate_identifier($contactID);
|
$invalid_identifier = validate_identifier($contactID);
|
||||||
if ($invalid_identifier) {
|
if ($invalid_identifier) {
|
||||||
sendEppError($conn, $db, 2005, 'Invalid contact ID', $clTRID, $trans);
|
sendEppError($conn, $db, 2005, 'Invalid contact ID', $clTRID, $trans);
|
||||||
|
@ -17,50 +16,67 @@ function processContactInfo($conn, $db, $xml, $trans) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $db->prepare("SELECT * FROM contact WHERE identifier = :id");
|
// Optimized single query
|
||||||
|
$stmt = $db->prepare("
|
||||||
|
SELECT c.id, c.identifier, c.voice, c.fax, c.email, c.clid, c.crid, c.crdate, c.upid, c.lastupdate,
|
||||||
|
c.disclose_voice, c.disclose_fax, c.disclose_email,
|
||||||
|
p.type AS postal_type, p.name, p.org, p.street1, p.street2, p.street3, p.city, p.sp, p.pc, p.cc,
|
||||||
|
p.disclose_name_int, p.disclose_name_loc, p.disclose_org_int, p.disclose_org_loc,
|
||||||
|
p.disclose_addr_int, p.disclose_addr_loc,
|
||||||
|
a.authtype, a.authinfo
|
||||||
|
FROM contact c
|
||||||
|
LEFT JOIN contact_postalInfo p ON c.id = p.contact_id
|
||||||
|
LEFT JOIN contact_authInfo a ON c.id = a.contact_id
|
||||||
|
WHERE c.identifier = :id
|
||||||
|
");
|
||||||
$stmt->execute(['id' => $contactID]);
|
$stmt->execute(['id' => $contactID]);
|
||||||
|
$contact = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$contact = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
if (!$contact) {
|
if (!$contact) {
|
||||||
sendEppError($conn, $db, 2303, 'Contact does not exist', $clTRID, $trans);
|
sendEppError($conn, $db, 2303, 'Contact does not exist', $clTRID, $trans);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch authInfo
|
|
||||||
$stmt = $db->prepare("SELECT * FROM contact_authInfo WHERE contact_id = :id");
|
|
||||||
$stmt->execute(['id' => $contact['id']]);
|
|
||||||
$authInfo = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
// Fetch status
|
|
||||||
$stmt = $db->prepare("SELECT * FROM contact_status WHERE contact_id = :id");
|
|
||||||
$stmt->execute(['id' => $contact['id']]);
|
|
||||||
$statuses = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
$statusArray = [];
|
|
||||||
foreach($statuses as $status) {
|
|
||||||
$statusArray[] = [$status['status']];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch postal_info
|
// Extract the first row for contact data
|
||||||
$stmt = $db->prepare("SELECT * FROM contact_postalInfo WHERE contact_id = :id");
|
$contactRow = $contact[0];
|
||||||
$stmt->execute(['id' => $contact['id']]);
|
|
||||||
$postals = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
|
// Extract Postal Info
|
||||||
$postalArray = [];
|
$postalArray = [];
|
||||||
foreach ($postals as $postal) {
|
foreach ($contact as $row) {
|
||||||
$postalType = $postal['type']; // 'int' or 'loc'
|
$postalType = $row['postal_type']; // 'int' or 'loc'
|
||||||
|
if ($postalType) {
|
||||||
$postalArray[$postalType] = [
|
$postalArray[$postalType] = [
|
||||||
'name' => $postal['name'],
|
'name' => $row['name'],
|
||||||
'org' => $postal['org'],
|
'org' => $row['org'],
|
||||||
'street' => [$postal['street1'], $postal['street2'], $postal['street3']],
|
'street' => array_filter([$row['street1'], $row['street2'], $row['street3']]),
|
||||||
'city' => $postal['city'],
|
'city' => $row['city'],
|
||||||
'sp' => $postal['sp'],
|
'sp' => $row['sp'],
|
||||||
'pc' => $postal['pc'],
|
'pc' => $row['pc'],
|
||||||
'cc' => $postal['cc']
|
'cc' => $row['cc']
|
||||||
];
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch statuses separately (since multiple statuses exist)
|
||||||
|
$stmt = $db->prepare("SELECT status FROM contact_status WHERE contact_id = :id");
|
||||||
|
$stmt->execute(['id' => $contactRow['id']]);
|
||||||
|
$statuses = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
$statusArray = array_map(fn($status) => [$status], $statuses);
|
||||||
|
|
||||||
|
// Handle Disclose Fields (Only Show When Set to `1`)
|
||||||
|
$disclose_fields = [
|
||||||
|
'voice' => $contactRow['disclose_voice'],
|
||||||
|
'fax' => $contactRow['disclose_fax'],
|
||||||
|
'email' => $contactRow['disclose_email'],
|
||||||
|
'name_int' => $contactRow['disclose_name_int'],
|
||||||
|
'name_loc' => $contactRow['disclose_name_loc'],
|
||||||
|
'org_int' => $contactRow['disclose_org_int'],
|
||||||
|
'org_loc' => $contactRow['disclose_org_loc'],
|
||||||
|
'addr_int' => $contactRow['disclose_addr_int'],
|
||||||
|
'addr_loc' => $contactRow['disclose_addr_loc']
|
||||||
|
];
|
||||||
|
$disclose_required = array_filter($disclose_fields, fn($value) => $value === '1');
|
||||||
|
|
||||||
$svTRID = generateSvTRID();
|
$svTRID = generateSvTRID();
|
||||||
$response = [
|
$response = [
|
||||||
'command' => 'info_contact',
|
'command' => 'info_contact',
|
||||||
|
@ -68,27 +84,34 @@ function processContactInfo($conn, $db, $xml, $trans) {
|
||||||
'svTRID' => $svTRID,
|
'svTRID' => $svTRID,
|
||||||
'resultCode' => 1000,
|
'resultCode' => 1000,
|
||||||
'msg' => 'Command completed successfully',
|
'msg' => 'Command completed successfully',
|
||||||
'id' => $contact['identifier'],
|
'id' => $contactRow['identifier'],
|
||||||
'roid' => 'C' . $contact['id'],
|
'roid' => 'C' . $contactRow['id'],
|
||||||
'status' => $statusArray,
|
'status' => $statusArray,
|
||||||
'postal' => $postalArray,
|
'postal' => $postalArray,
|
||||||
'voice' => $contact['voice'],
|
'voice' => $contactRow['voice'],
|
||||||
'fax' => $contact['fax'],
|
'fax' => $contactRow['fax'],
|
||||||
'email' => $contact['email'],
|
'email' => $contactRow['email'],
|
||||||
'clID' => getRegistrarClid($db, $contact['clid']),
|
'clID' => getRegistrarClid($db, $contactRow['clid']),
|
||||||
'crID' => getRegistrarClid($db, $contact['crid']),
|
'crID' => getRegistrarClid($db, $contactRow['crid']),
|
||||||
'crDate' => $contact['crdate'],
|
'crDate' => $contactRow['crdate'],
|
||||||
'upID' => getRegistrarClid($db, $contact['upid']),
|
'upID' => getRegistrarClid($db, $contactRow['upid']),
|
||||||
'upDate' => $contact['lastupdate'],
|
'upDate' => $contactRow['lastupdate'],
|
||||||
'authInfo' => 'valid',
|
'authInfo' => 'valid',
|
||||||
'authInfo_type' => $authInfo['authtype'],
|
'authInfo_type' => $contactRow['authtype'],
|
||||||
'authInfo_val' => $authInfo['authinfo']
|
'authInfo_val' => $contactRow['authinfo']
|
||||||
];
|
];
|
||||||
|
|
||||||
$epp = new EPP\EppWriter();
|
if (!empty($disclose_required)) {
|
||||||
$xml = $epp->epp_writer($response);
|
$response['disclose'] = [
|
||||||
updateTransaction($db, 'info', 'contact', 'C_'.$contact['id'], 1000, 'Command completed successfully', $svTRID, $xml, $trans);
|
'flag' => '1', // Show when disclosure is enabled
|
||||||
sendEppResponse($conn, $xml);
|
'fields' => array_keys($disclose_required)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$epp = new EPP\EppWriter();
|
||||||
|
$xml = $epp->epp_writer($response);
|
||||||
|
updateTransaction($db, 'info', 'contact', 'C_'.$contactRow['id'], 1000, 'Command completed successfully', $svTRID, $xml, $trans);
|
||||||
|
sendEppResponse($conn, $xml);
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
|
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue