Updated epp domain create; added secdns extension

This commit is contained in:
Pinga 2023-08-26 23:47:41 +03:00
parent 1c2c147601
commit fc1d1b844f
2 changed files with 233 additions and 168 deletions

View file

@ -609,7 +609,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
sendEppError($conn, 2302, 'Domain name is reserved or restricted', $clTRID); sendEppError($conn, 2302, 'Domain name is reserved or restricted', $clTRID);
return; return;
} }
$periodElements = $xml->xpath("//domain:create/domain:period"); $periodElements = $xml->xpath("//domain:create/domain:period");
$periodElement = $periodElements[0]; $periodElement = $periodElements[0];
$period = (int) $periodElement; $period = (int) $periodElement;
@ -642,12 +642,12 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
sendEppError($conn, 2306, 'A domain name can initially be registered for 1-10 years period', $clTRID); sendEppError($conn, 2306, 'A domain name can initially be registered for 1-10 years period', $clTRID);
return; return;
} }
$stmt = $db->prepare("SELECT id FROM registrar WHERE clid = :clid LIMIT 1"); $stmt = $db->prepare("SELECT id FROM registrar WHERE clid = :clid LIMIT 1");
$stmt->bindParam(':clid', $clid, PDO::PARAM_STR); $stmt->bindParam(':clid', $clid, PDO::PARAM_STR);
$stmt->execute(); $stmt->execute();
$clid = $stmt->fetch(PDO::FETCH_ASSOC); $clid = $stmt->fetch(PDO::FETCH_ASSOC);
$clid = $clid['id']; $clid = $clid['id'];
$stmt = $db->prepare("SELECT `accountBalance`, `creditLimit` FROM `registrar` WHERE `id` = :registrar_id LIMIT 1"); $stmt = $db->prepare("SELECT `accountBalance`, `creditLimit` FROM `registrar` WHERE `id` = :registrar_id LIMIT 1");
$stmt->bindParam(':registrar_id', $clid, PDO::PARAM_INT); $stmt->bindParam(':registrar_id', $clid, PDO::PARAM_INT);
@ -760,7 +760,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
} }
if ($internal_host) { if ($internal_host) {
if (preg_match('/\.' . preg_quote($domainName, '/') . '$/i', $hostName)) { if (preg_match('/\.' . preg_quote($domainName, '/') . '$/i', $hostName)) {
$hostAddrNodes = $node->xpath('//domain:hostAddr'); $hostAddrNodes = $node->xpath('//domain:hostAddr');
if (count($hostAddrNodes) > 13) { if (count($hostAddrNodes) > 13) {
@ -782,7 +782,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
sendEppError($conn, 2003, 'Missing domain:hostAddr', $clTRID); sendEppError($conn, 2003, 'Missing domain:hostAddr', $clTRID);
return; return;
} }
foreach ($hostAddrNodes as $node) { foreach ($hostAddrNodes as $node) {
$hostAddr = (string) $node; $hostAddr = (string) $node;
$addr_type = (string) ($node['ip'] ?? 'v4'); $addr_type = (string) ($node['ip'] ?? 'v4');
@ -920,20 +920,20 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
} }
} }
} else { } else {
// External host // External host
if (preg_match('/^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9]){0,1}\.){1,125}[A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])$/i', $hostName) && strlen($hostName) < 254) { if (preg_match('/^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9]){0,1}\.){1,125}[A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])$/i', $hostName) && strlen($hostName) < 254) {
} else { } else {
sendEppError($conn, 2005, 'Invalid domain:hostName', $clTRID); sendEppError($conn, 2005, 'Invalid domain:hostName', $clTRID);
return; return;
} }
} }
} }
} }
// Registrant // Registrant
$registrant = $xml->xpath('//domain:registrant[1]'); $registrant = $xml->xpath('//domain:registrant[1]');
$registrant_id = (string)$registrant[0][0]; $registrant_id = (string)$registrant[0][0];
if ($registrant) { if ($registrant) {
$validRegistrant = validate_identifier($registrant_id); $validRegistrant = validate_identifier($registrant_id);
@ -985,7 +985,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
} }
} }
} }
$authInfo_pw = $xml->xpath('//domain:authInfo/domain:pw[1]')[0] ?? null; $authInfo_pw = $xml->xpath('//domain:authInfo/domain:pw[1]')[0] ?? null;
if (!$authInfo_pw) { if (!$authInfo_pw) {
@ -1007,194 +1007,258 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
sendEppError($conn, 2005, 'Password should contain one or more numbers', $clTRID); sendEppError($conn, 2005, 'Password should contain one or more numbers', $clTRID);
return; return;
} }
$registrantStmt = $db->prepare("SELECT `id` FROM `contact` WHERE `identifier` = :registrant LIMIT 1"); $registrantStmt = $db->prepare("SELECT `id` FROM `contact` WHERE `identifier` = :registrant LIMIT 1");
$registrantStmt->execute([':registrant' => $registrant_id]); $registrantStmt->execute([':registrant' => $registrant_id]);
$registrant_id = $registrantStmt->fetchColumn(); $registrant_id = $registrantStmt->fetchColumn();
$domainSql = "INSERT INTO `domain` (`name`,`tldid`,`registrant`,`crdate`,`exdate`,`update`,`clid`,`crid`,`upid`,`trdate`,`trstatus`,`reid`,`redate`,`acid`,`acdate`,`rgpstatus`,`addPeriod`) try {
VALUES(:name, :tld_id, :registrant_id, CURRENT_TIMESTAMP, DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :date_add MONTH), NULL, :registrar_id, :registrar_id, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'addPeriod', :date_add2)"; $db->beginTransaction();
$domainSql = "INSERT INTO `domain` (`name`,`tldid`,`registrant`,`crdate`,`exdate`,`update`,`clid`,`crid`,`upid`,`trdate`,`trstatus`,`reid`,`redate`,`acid`,`acdate`,`rgpstatus`,`addPeriod`)
VALUES(:name, :tld_id, :registrant_id, CURRENT_TIMESTAMP, DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :date_add MONTH), NULL, :registrar_id, :registrar_id, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'addPeriod', :date_add2)";
$domainStmt = $db->prepare($domainSql); $domainStmt = $db->prepare($domainSql);
$domainStmt->execute([ $domainStmt->execute([
':name' => $domainName, ':name' => $domainName,
':tld_id' => $tld_id, ':tld_id' => $tld_id,
':registrant_id' => $registrant_id, ':registrant_id' => $registrant_id,
':date_add' => $date_add, ':date_add' => $date_add,
':date_add2' => $date_add, ':date_add2' => $date_add,
':registrar_id' => $clid ':registrar_id' => $clid
]); ]);
$domain_id = $db->lastInsertId(); $domain_id = $db->lastInsertId();
$authInfoStmt = $db->prepare("INSERT INTO `domain_authInfo` (`domain_id`,`authtype`,`authinfo`) VALUES(:domain_id,'pw',:authInfo_pw)"); $authInfoStmt = $db->prepare("INSERT INTO `domain_authInfo` (`domain_id`,`authtype`,`authinfo`) VALUES(:domain_id,'pw',:authInfo_pw)");
$authInfoStmt->execute([ $authInfoStmt->execute([
':domain_id' => $domain_id, ':domain_id' => $domain_id,
':authInfo_pw' => $authInfo_pw ':authInfo_pw' => $authInfo_pw
]); ]);
$secDNSDataSet = $xml->xpath('//secDNS:dsData');
$updateRegistrarStmt = $db->prepare("UPDATE `registrar` SET `accountBalance` = (`accountBalance` - :price) WHERE `id` = :registrar_id"); if ($secDNSDataSet) {
$updateRegistrarStmt->execute([ foreach ($secDNSDataSet as $secDNSData) {
':price' => $price, // Extract dsData elements
':registrar_id' => $clid $keyTag = (int) $secDNSData->xpath('secDNS:keyTag')[0] ?? null;
]); $alg = (int) $secDNSData->xpath('secDNS:alg')[0] ?? null;
$digestType = (int) $secDNSData->xpath('secDNS:digestType')[0] ?? null;
$digest = (string) $secDNSData->xpath('secDNS:digest')[0] ?? null;
$maxSigLife = $secDNSData->xpath('secDNS:maxSigLife') ? (int) $secDNSData->xpath('secDNS:maxSigLife')[0] : null;
$paymentHistoryStmt = $db->prepare("INSERT INTO `payment_history` (`registrar_id`,`date`,`description`,`amount`) VALUES(:registrar_id,CURRENT_TIMESTAMP,:description,:amount)");
$paymentHistoryStmt->execute([
':registrar_id' => $clid,
':description' => "create domain $domainName for period $date_add MONTH",
':amount' => "-$price"
]);
$selectDomainDatesStmt = $db->prepare("SELECT `crdate`,`exdate` FROM `domain` WHERE `name` = :name LIMIT 1"); // Data sanity checks
$selectDomainDatesStmt->execute([':name' => $domainName]); if (!$keyTag || !$alg || !$digestType || !$digest) {
[$from, $to] = $selectDomainDatesStmt->fetch(PDO::FETCH_NUM); sendEppError($conn, 2005, 'Incomplete or invalid dsData provided', $clTRID);
return;
$statementStmt = $db->prepare("INSERT INTO `statement` (`registrar_id`,`date`,`command`,`domain_name`,`length_in_months`,`from`,`to`,`amount`) VALUES(:registrar_id,CURRENT_TIMESTAMP,:cmd,:name,:date_add,:from,:to,:price)");
$statementStmt->execute([
':registrar_id' => $clid,
':cmd' => 'create',
':name' => $domainName,
':date_add' => $date_add,
':from' => $from,
':to' => $to,
':price' => $price
]);
foreach ($hostObj_list as $node) {
$hostObj = strtoupper((string)$node);
$hostExistStmt = $db->prepare("SELECT `id` FROM `host` WHERE `name` = :hostObj LIMIT 1");
$hostExistStmt->execute([':hostObj' => $hostObj]);
$hostObj_already_exist = $hostExistStmt->fetchColumn();
if ($hostObj_already_exist) {
$domainHostMapStmt = $db->prepare("SELECT `domain_id` FROM `domain_host_map` WHERE `domain_id` = :domain_id AND `host_id` = :host_id LIMIT 1");
$domainHostMapStmt->execute([':domain_id' => $domain_id, ':host_id' => $hostObj_already_exist]);
$domain_host_map_id = $domainHostMapStmt->fetchColumn();
if (!$domain_host_map_id) {
$insertDomainHostMapStmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(:domain_id,:host_id)");
$insertDomainHostMapStmt->execute([':domain_id' => $domain_id, ':host_id' => $hostObj_already_exist]);
} else {
$errorLogStmt = $db->prepare("INSERT INTO `error_log` (`registrar_id`,`log`,`date`) VALUES(:registrar_id,:log,CURRENT_TIMESTAMP)");
$errorLogStmt->execute([':registrar_id' => $clid, ':log' => "Domain : $domainName ; hostObj : $hostObj - se dubleaza"]);
}
} else {
$internal_host = false;
$stmt = $db->prepare("SELECT `tld` FROM `domain_tld`");
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tld = strtoupper($row['tld']);
$tld = str_replace('.', '\\.', $tld); // Escape the dot for regex pattern matching
if (preg_match("/$tld$/i", $hostObj)) {
$internal_host = true;
break;
} }
}
$stmt->closeCursor();
if ($internal_host) { // Extract keyData elements if available
if (preg_match("/\.$domainName$/i", $hostObj)) { $flags = null;
$stmt = $db->prepare("INSERT INTO `host` (`name`,`domain_id`,`clid`,`crid`,`crdate`) VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP)"); $protocol = null;
$stmt->execute([$hostObj, $domain_id, $clid, $clid]); $algKeyData = null;
$pubKey = null;
if ($secDNSData->xpath('secDNS:keyData')) {
$flags = (int) $secDNSData->xpath('secDNS:keyData/secDNS:flags')[0];
$protocol = (int) $secDNSData->xpath('secDNS:keyData/secDNS:protocol')[0];
$algKeyData = (int) $secDNSData->xpath('secDNS:keyData/secDNS:alg')[0];
$pubKey = (string) $secDNSData->xpath('secDNS:keyData/secDNS:pubKey')[0];
// Data sanity checks for keyData
if (!$flags || !$protocol || !$algKeyData || !$pubKey) {
sendEppError($conn, 2005, 'Incomplete or invalid keyData provided', $clTRID);
return;
}
}
$stmt = $db->prepare("INSERT INTO `secdns` (`domain_id`, `maxsiglife`, `interface`, `keytag`, `alg`, `digesttype`, `digest`, `flags`, `protocol`, `keydata_alg`, `pubkey`) VALUES (:domain_id, :maxsiglife, :interface, :keytag, :alg, :digesttype, :digest, :flags, :protocol, :keydata_alg, :pubkey)");
$stmt->execute([
':domain_id' => $domain_id,
':maxsiglife' => $maxSigLife,
':interface' => 'dsData',
':keytag' => $keyTag,
':alg' => $alg,
':digesttype' => $digestType,
':digest' => $digest,
':flags' => $flags ?? null,
':protocol' => $protocol ?? null,
':keydata_alg' => $algKeyData ?? null,
':pubkey' => $pubKey ?? null
]);
}
}
$updateRegistrarStmt = $db->prepare("UPDATE `registrar` SET `accountBalance` = (`accountBalance` - :price) WHERE `id` = :registrar_id");
$updateRegistrarStmt->execute([
':price' => $price,
':registrar_id' => $clid
]);
$paymentHistoryStmt = $db->prepare("INSERT INTO `payment_history` (`registrar_id`,`date`,`description`,`amount`) VALUES(:registrar_id,CURRENT_TIMESTAMP,:description,:amount)");
$paymentHistoryStmt->execute([
':registrar_id' => $clid,
':description' => "create domain $domainName for period $date_add MONTH",
':amount' => "-$price"
]);
$selectDomainDatesStmt = $db->prepare("SELECT `crdate`,`exdate` FROM `domain` WHERE `name` = :name LIMIT 1");
$selectDomainDatesStmt->execute([':name' => $domainName]);
[$from, $to] = $selectDomainDatesStmt->fetch(PDO::FETCH_NUM);
$statementStmt = $db->prepare("INSERT INTO `statement` (`registrar_id`,`date`,`command`,`domain_name`,`length_in_months`,`from`,`to`,`amount`) VALUES(:registrar_id,CURRENT_TIMESTAMP,:cmd,:name,:date_add,:from,:to,:price)");
$statementStmt->execute([
':registrar_id' => $clid,
':cmd' => 'create',
':name' => $domainName,
':date_add' => $date_add,
':from' => $from,
':to' => $to,
':price' => $price
]);
foreach ($hostObj_list as $node) {
$hostObj = strtoupper((string)$node);
$hostExistStmt = $db->prepare("SELECT `id` FROM `host` WHERE `name` = :hostObj LIMIT 1");
$hostExistStmt->execute([':hostObj' => $hostObj]);
$hostObj_already_exist = $hostExistStmt->fetchColumn();
if ($hostObj_already_exist) {
$domainHostMapStmt = $db->prepare("SELECT `domain_id` FROM `domain_host_map` WHERE `domain_id` = :domain_id AND `host_id` = :host_id LIMIT 1");
$domainHostMapStmt->execute([':domain_id' => $domain_id, ':host_id' => $hostObj_already_exist]);
$domain_host_map_id = $domainHostMapStmt->fetchColumn();
if (!$domain_host_map_id) {
$insertDomainHostMapStmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(:domain_id,:host_id)");
$insertDomainHostMapStmt->execute([':domain_id' => $domain_id, ':host_id' => $hostObj_already_exist]);
} else {
$errorLogStmt = $db->prepare("INSERT INTO `error_log` (`registrar_id`,`log`,`date`) VALUES(:registrar_id,:log,CURRENT_TIMESTAMP)");
$errorLogStmt->execute([':registrar_id' => $clid, ':log' => "Domain : $domainName ; hostObj : $hostObj - se dubleaza"]);
}
} else {
$internal_host = false;
$stmt = $db->prepare("SELECT `tld` FROM `domain_tld`");
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tld = strtoupper($row['tld']);
$tld = str_replace('.', '\\.', $tld); // Escape the dot for regex pattern matching
if (preg_match("/$tld$/i", $hostObj)) {
$internal_host = true;
break;
}
}
$stmt->closeCursor();
if ($internal_host) {
if (preg_match("/\.$domainName$/i", $hostObj)) {
$stmt = $db->prepare("INSERT INTO `host` (`name`,`domain_id`,`clid`,`crid`,`crdate`) VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP)");
$stmt->execute([$hostObj, $domain_id, $clid, $clid]);
$host_id = $db->lastInsertId();
$stmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(?, ?)");
$stmt->execute([$domain_id, $host_id]);
}
} else {
$stmt = $db->prepare("INSERT INTO `host` (`name`,`clid`,`crid`,`crdate`) VALUES(?, ?, ?, CURRENT_TIMESTAMP)");
$stmt->execute([$hostObj, $clid, $clid]);
$host_id = $db->lastInsertId(); $host_id = $db->lastInsertId();
$stmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(?, ?)"); $stmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(?, ?)");
$stmt->execute([$domain_id, $host_id]); $stmt->execute([$domain_id, $host_id]);
} }
}
}
foreach ($hostAttr_list as $element) {
foreach ($element->children() as $node) {
$hostName = strtoupper($node->xpath('//domain:hostName')[0]);
$stmt = $db->prepare("SELECT `id` FROM `host` WHERE `name` = ? LIMIT 1");
$stmt->execute([$hostName]);
$hostName_already_exist = $stmt->fetchColumn();
if ($hostName_already_exist) {
$stmt = $db->prepare("SELECT `domain_id` FROM `domain_host_map` WHERE `domain_id` = ? AND `host_id` = ? LIMIT 1");
$stmt->execute([$domain_id, $hostName_already_exist]);
$domain_host_map_id = $stmt->fetchColumn();
if (!$domain_host_map_id) {
$stmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(?,?)");
$stmt->execute([$domain_id, $hostName_already_exist]);
} else {
$stmt = $db->prepare("INSERT INTO `error_log` (`registrar_id`,`log`,`date`) VALUES(?, ?, CURRENT_TIMESTAMP)");
$stmt->execute([$clid, "Domain : $domainName ; hostName : $hostName - se dubleaza"]);
}
} else { } else {
$stmt = $db->prepare("INSERT INTO `host` (`name`,`clid`,`crid`,`crdate`) VALUES(?, ?, ?, CURRENT_TIMESTAMP)"); $stmt = $db->prepare("INSERT INTO `host` (`name`,`domain_id`,`clid`,`crid`,`crdate`) VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP)");
$stmt->execute([$hostObj, $clid, $clid]); $stmt->execute([$hostName, $domain_id, $clid, $clid]);
$host_id = $db->lastInsertId(); $host_id = $db->lastInsertId();
$stmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(?, ?)");
$stmt->execute([$domain_id, $host_id]);
}
}
}
foreach ($hostAttr_list as $element) {
foreach ($element->children() as $node) {
$hostName = strtoupper($node->xpath('//domain:hostName')[0]);
$stmt = $db->prepare("SELECT `id` FROM `host` WHERE `name` = ? LIMIT 1");
$stmt->execute([$hostName]);
$hostName_already_exist = $stmt->fetchColumn();
if ($hostName_already_exist) {
$stmt = $db->prepare("SELECT `domain_id` FROM `domain_host_map` WHERE `domain_id` = ? AND `host_id` = ? LIMIT 1");
$stmt->execute([$domain_id, $hostName_already_exist]);
$domain_host_map_id = $stmt->fetchColumn();
if (!$domain_host_map_id) {
$stmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(?,?)"); $stmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(?,?)");
$stmt->execute([$domain_id, $hostName_already_exist]); $stmt->execute([$domain_id, $host_id]);
} else {
$stmt = $db->prepare("INSERT INTO `error_log` (`registrar_id`,`log`,`date`) VALUES(?, ?, CURRENT_TIMESTAMP)");
$stmt->execute([$clid, "Domain : $domainName ; hostName : $hostName - se dubleaza"]);
}
} else {
$stmt = $db->prepare("INSERT INTO `host` (`name`,`domain_id`,`clid`,`crid`,`crdate`) VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP)");
$stmt->execute([$hostName, $domain_id, $clid, $clid]);
$host_id = $db->lastInsertId();
$stmt = $db->prepare("INSERT INTO `domain_host_map` (`domain_id`,`host_id`) VALUES(?,?)"); foreach ($node->xpath('//domain:hostAddr') as $nodeAddr) {
$stmt->execute([$domain_id, $host_id]); $hostAddr = (string)$nodeAddr;
$addr_type = $nodeAddr->attributes()->ip ?? 'v4';
foreach ($node->xpath('//domain:hostAddr') as $nodeAddr) { if ($addr_type == 'v6') {
$hostAddr = (string)$nodeAddr; $hostAddr = normalize_v6_address($hostAddr);
$addr_type = $nodeAddr->attributes()->ip ?? 'v4'; } else {
$hostAddr = normalize_v4_address($hostAddr);
}
if ($addr_type == 'v6') { $stmt = $db->prepare("INSERT INTO `host_addr` (`host_id`,`addr`,`ip`) VALUES(?,?,?)");
$hostAddr = normalize_v6_address($hostAddr); $stmt->execute([$host_id, $hostAddr, $addr_type]);
} else {
$hostAddr = normalize_v4_address($hostAddr);
} }
$stmt = $db->prepare("INSERT INTO `host_addr` (`host_id`,`addr`,`ip`) VALUES(?,?,?)");
$stmt->execute([$host_id, $hostAddr, $addr_type]);
} }
} }
} }
}
$contact_admin_list = $xml->xpath("//domain:contact[@type='admin']");
$contact_admin_list = $xml->xpath("//domain:contact[@type='admin']"); $contact_billing_list = $xml->xpath("//domain:contact[@type='billing']");
$contact_billing_list = $xml->xpath("//domain:contact[@type='billing']"); $contact_tech_list = $xml->xpath("//domain:contact[@type='tech']");
$contact_tech_list = $xml->xpath("//domain:contact[@type='tech']");
$contactTypes = [ $contactTypes = [
'admin' => $contact_admin_list, 'admin' => $contact_admin_list,
'billing' => $contact_billing_list, 'billing' => $contact_billing_list,
'tech' => $contact_tech_list 'tech' => $contact_tech_list
]; ];
foreach ($contactTypes as $type => $contact_list) { foreach ($contactTypes as $type => $contact_list) {
foreach ($contact_list as $element) { foreach ($contact_list as $element) {
$contact = (string)$element; $contact = (string)$element;
$stmt = $db->prepare("SELECT `id` FROM `contact` WHERE `identifier` = ? LIMIT 1"); $stmt = $db->prepare("SELECT `id` FROM `contact` WHERE `identifier` = ? LIMIT 1");
$stmt->execute([$contact]); $stmt->execute([$contact]);
$contact_id = $stmt->fetchColumn(); $contact_id = $stmt->fetchColumn();
$stmt = $db->prepare("INSERT INTO `domain_contact_map` (`domain_id`,`contact_id`,`type`) VALUES(?,?,?)"); $stmt = $db->prepare("INSERT INTO `domain_contact_map` (`domain_id`,`contact_id`,`type`) VALUES(?,?,?)");
$stmt->execute([$domain_id, $contact_id, $type]); $stmt->execute([$domain_id, $contact_id, $type]);
} }
} }
$stmt = $db->prepare("SELECT `crdate`,`exdate` FROM `domain` WHERE `name` = ? LIMIT 1"); $stmt = $db->prepare("SELECT `crdate`,`exdate` FROM `domain` WHERE `name` = ? LIMIT 1");
$stmt->execute([$domainName]); $stmt->execute([$domainName]);
[$crdate, $exdate] = $stmt->fetch(PDO::FETCH_NUM); [$crdate, $exdate] = $stmt->fetch(PDO::FETCH_NUM);
$stmt = $db->prepare("SELECT `id` FROM `statistics` WHERE `date` = CURDATE()"); $stmt = $db->prepare("SELECT `id` FROM `statistics` WHERE `date` = CURDATE()");
$stmt->execute();
$curdate_id = $stmt->fetchColumn();
if (!$curdate_id) {
$stmt = $db->prepare("INSERT IGNORE INTO `statistics` (`date`) VALUES(CURDATE())");
$stmt->execute(); $stmt->execute();
} $curdate_id = $stmt->fetchColumn();
$db->exec("UPDATE `statistics` SET `created_domains` = `created_domains` + 1 WHERE `date` = CURDATE()");
if (!$curdate_id) {
$stmt = $db->prepare("INSERT IGNORE INTO `statistics` (`date`) VALUES(CURDATE())");
$stmt->execute();
}
$db->exec("UPDATE `statistics` SET `created_domains` = `created_domains` + 1 WHERE `date` = CURDATE()");
$db->commit();
} catch (Exception $e) {
$db->rollBack();
sendEppError($conn, 2400, "Database failure: " . $e->getMessage(), $clTRID);
}
$svTRID = generateSvTRID(); $svTRID = generateSvTRID();
$response = [ $response = [
'command' => 'create_domain', 'command' => 'create_domain',
@ -1211,5 +1275,5 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
$epp = new EPP\EppWriter(); $epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response); $xml = $epp->epp_writer($response);
updateTransaction($db, 'create', 'domain', $domainName, 1000, 'Command completed successfully', $svTRID, $xml, $trans); updateTransaction($db, 'create', 'domain', $domainName, 1000, 'Command completed successfully', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml); sendEppResponse($conn, $xml);
} }

View file

@ -75,6 +75,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
$xml->registerXPathNamespace('domain', 'urn:ietf:params:xml:ns:domain-1.0'); $xml->registerXPathNamespace('domain', 'urn:ietf:params:xml:ns:domain-1.0');
$xml->registerXPathNamespace('contact', 'urn:ietf:params:xml:ns:contact-1.0'); $xml->registerXPathNamespace('contact', 'urn:ietf:params:xml:ns:contact-1.0');
$xml->registerXPathNamespace('host', 'urn:ietf:params:xml:ns:host-1.0'); $xml->registerXPathNamespace('host', 'urn:ietf:params:xml:ns:host-1.0');
$xml->registerXPathNamespace('secDNS', 'urn:ietf:params:xml:ns:secDNS-1.1');
if ($xml === false) { if ($xml === false) {
sendEppError($conn, 2001, 'Invalid XML'); sendEppError($conn, 2001, 'Invalid XML');