Started work on EPP transaction log

This commit is contained in:
Pinga 2023-08-25 12:05:48 +03:00
parent 4b77b53555
commit 9c97f3077a
2 changed files with 79 additions and 9 deletions

View file

@ -205,4 +205,56 @@ function normalize_v6_address($v6) {
$v6 = preg_replace('/:(:0)+/', ':', $v6); $v6 = preg_replace('/:(:0)+/', ':', $v6);
return $v6; return $v6;
}
function createTransaction($db, $clid, $clTRID, $clTRIDframe) {
// Prepare the statement for insertion
$stmt = $db->prepare("INSERT INTO `registryTransaction`.`transaction_identifier` (`registrar_id`,`clTRID`,`clTRIDframe`,`cldate`,`clmicrosecond`) VALUES(?,?,?,?,?)");
// Get date and microsecond for cl transaction
$dateForClTransaction = microtime(true);
$cldate = date("Y-m-d H:i:s", $dateForClTransaction);
$clmicrosecond = sprintf("%06d", ($dateForClTransaction - floor($dateForClTransaction)) * 1000000);
// Execute the statement
if (!$stmt->execute([
$clid,
$clTRID,
$clTRIDframe,
$cldate,
$clmicrosecond
])) {
throw new Exception("Failed to execute createTransaction: " . implode(", ", $stmt->errorInfo()));
}
// Return the ID of the newly created transaction
return $db->lastInsertId();
}
function updateTransaction($db, $cmd, $obj_type, $obj_id, $code, $msg, $svTRID, $svTRIDframe, $transaction_id) {
// Prepare the statement
$stmt = $db->prepare("UPDATE `registryTransaction`.`transaction_identifier` SET `cmd` = ?, `obj_type` = ?, `obj_id` = ?, `code` = ?, `msg` = ?, `svTRID` = ?, `svTRIDframe` = ?, `svdate` = ?, `svmicrosecond` = ? WHERE `id` = ?");
// Get date and microsecond for sv transaction
$dateForSvTransaction = microtime(true);
$svdate = date("Y-m-d H:i:s", $dateForSvTransaction);
$svmicrosecond = sprintf("%06d", ($dateForSvTransaction - floor($dateForSvTransaction)) * 1000000);
// Execute the statement
if (!$stmt->execute([
$cmd,
$obj_type,
$obj_id,
$code,
$msg,
$svTRID,
$svTRIDframe,
$svdate,
$svmicrosecond,
$transaction_id
])) {
throw new Exception("Failed to execute updateTransaction: " . implode(", ", $stmt->errorInfo()));
}
return true;
} }

View file

@ -91,20 +91,29 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
$clID = (string) $xml->command->login->clID; $clID = (string) $xml->command->login->clID;
$pw = (string) $xml->command->login->pw; $pw = (string) $xml->command->login->pw;
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$stmt = $db->prepare("SELECT id FROM registrar WHERE clid = :clid LIMIT 1");
$stmt->bindParam(':clid', $clID, PDO::PARAM_STR);
$stmt->execute();
$clid = $stmt->fetch(PDO::FETCH_ASSOC);
$clid = $clid['id'];
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
if (checkLogin($db, $clID, $pw)) { if (checkLogin($db, $clID, $pw)) {
$table->set($connId, ['clid' => $clID, 'logged_in' => 1]); $table->set($connId, ['clid' => $clID, 'logged_in' => 1]);
$svTRID = generateSvTRID();
$response = [ $response = [
'command' => 'login', 'command' => 'login',
'resultCode' => 1000, 'resultCode' => 1000,
'lang' => 'en-US', 'lang' => 'en-US',
'message' => 'Login successful', 'message' => 'Login successful',
'clTRID' => $clTRID, 'clTRID' => $clTRID,
'svTRID' => generateSvTRID(), 'svTRID' => $svTRID,
]; ];
$epp = new EPP\EppWriter(); $epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response); $xml = $epp->epp_writer($response);
updateTransaction($db, 'login', null, null, 1000, 'Login successful', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml); sendEppResponse($conn, $xml);
} else { } else {
sendEppError($conn, 2200, 'Authentication error', $clTRID); sendEppError($conn, 2200, 'Authentication error', $clTRID);
@ -114,19 +123,28 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
case isset($xml->command->logout): case isset($xml->command->logout):
{ {
$data = $table->get($connId);
$stmt = $db->prepare("SELECT id FROM registrar WHERE clid = :clid LIMIT 1");
$stmt->bindParam(':clid', $data['clid'], PDO::PARAM_STR);
$stmt->execute();
$clid = $stmt->fetch(PDO::FETCH_ASSOC);
$clid = $clid['id'];
$table->del($connId); $table->del($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$svTRID = generateSvTRID();
$response = [ $response = [
'command' => 'logout', 'command' => 'logout',
'resultCode' => 1500, 'resultCode' => 1500,
'lang' => 'en-US', 'lang' => 'en-US',
'clTRID' => $clTRID, 'clTRID' => $clTRID,
'svTRID' => generateSvTRID(), 'svTRID' => $svTRID,
]; ];
$epp = new EPP\EppWriter(); $epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response); $xml = $epp->epp_writer($response);
updateTransaction($db, 'logout', null, null, 1500, 'Logout successful', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml); sendEppResponse($conn, $xml);
$conn->close(); $conn->close();
break; break;
@ -185,7 +203,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processContactInfo($conn, $db, $xml); processContactInfo($conn, $db, $xml);
break; break;
} }
case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:contact-1.0')->update): case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:contact-1.0')->update):
{ {
$data = $table->get($connId); $data = $table->get($connId);
@ -209,7 +227,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processContactDelete($conn, $db, $xml, $data['clid'], $c['db_type']); processContactDelete($conn, $db, $xml, $data['clid'], $c['db_type']);
break; break;
} }
case isset($xml->command->transfer) && isset($xml->command->transfer->children('urn:ietf:params:xml:ns:contact-1.0')->transfer): case isset($xml->command->transfer) && isset($xml->command->transfer->children('urn:ietf:params:xml:ns:contact-1.0')->transfer):
{ {
$data = $table->get($connId); $data = $table->get($connId);
@ -245,7 +263,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processDomainInfo($conn, $db, $xml); processDomainInfo($conn, $db, $xml);
break; break;
} }
case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:domain-1.0')->update): case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:domain-1.0')->update):
{ {
$data = $table->get($connId); $data = $table->get($connId);
@ -257,7 +275,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processDomainUpdate($conn, $db, $xml, $data['clid'], $c['db_type']); processDomainUpdate($conn, $db, $xml, $data['clid'], $c['db_type']);
break; break;
} }
case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:domain-1.0')->create): case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:domain-1.0')->create):
{ {
$data = $table->get($connId); $data = $table->get($connId);
@ -281,7 +299,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processDomainDelete($conn, $db, $xml, $data['clid'], $c['db_type']); processDomainDelete($conn, $db, $xml, $data['clid'], $c['db_type']);
break; break;
} }
case isset($xml->command->transfer) && isset($xml->command->transfer->children('urn:ietf:params:xml:ns:domain-1.0')->transfer): case isset($xml->command->transfer) && isset($xml->command->transfer->children('urn:ietf:params:xml:ns:domain-1.0')->transfer):
{ {
$data = $table->get($connId); $data = $table->get($connId);
@ -329,7 +347,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processHostInfo($conn, $db, $xml); processHostInfo($conn, $db, $xml);
break; break;
} }
case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:host-1.0')->update): case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:host-1.0')->update):
{ {
$data = $table->get($connId); $data = $table->get($connId);