mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-23 19:10:30 +02:00
Migration scripts will be in private repository for now
This commit is contained in:
parent
c3abc8758f
commit
ee9f4c4032
7 changed files with 0 additions and 416 deletions
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
$c = require_once 'config.php';
|
||||
require_once 'helpers.php';
|
||||
|
||||
// Connect to the database
|
||||
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']}";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
|
||||
try {
|
||||
$pdo = new PDO($dsn, $c['db_username'], $c['db_password'], $options);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
}
|
||||
|
||||
$inputFile = fopen('clients.csv', 'r');
|
||||
$headers = fgetcsv($inputFile);
|
||||
|
||||
while (($row = fgetcsv($inputFile)) !== false) {
|
||||
$data = array_combine($headers, $row);
|
||||
|
||||
// Inserting into the 'registrar' table
|
||||
$sql = "INSERT INTO registrar (name, iana_id, clid, pw, prefix, email, whois_server, rdap_server, url, abuse_email, abuse_phone, accountBalance, creditLimit, creditThreshold, thresholdType, currency, crdate, update) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$data['Name'], $data['ROID'], 'example_clid', 'example_pw', 'EX', $data['E-mail'], 'whois.example.com', 'rdap.example.com', 'http://example.com', 'abuse@example.com', '0', 1000.00, 0.00, 0.00, 'fixed', 'USD']);
|
||||
|
||||
$registrarId = $pdo->lastInsertId();
|
||||
|
||||
// Inserting into the 'registrar_contact' table
|
||||
$contactSql = "INSERT INTO registrar_contact (registrar_id, type, title, first_name, middle_name, last_name, org, street1, street2, street3, city, sp, pc, cc, voice, fax, email) VALUES (?, 'owner', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
$contactStmt = $pdo->prepare($contactSql);
|
||||
$contactStmt->execute([$registrarId, '', '', '', '', $data['Name'], $data['Address'], '', '', '', '', '', '', $data['Country'], $data['Phone'], $data['Fax'], $data['E-mail']]);
|
||||
}
|
||||
|
||||
fclose($inputFile);
|
|
@ -1,91 +0,0 @@
|
|||
<?php
|
||||
|
||||
$c = require_once 'config.php';
|
||||
require_once 'helpers.php';
|
||||
|
||||
// Connect to the database
|
||||
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']}";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
|
||||
try {
|
||||
$pdo = new PDO($dsn, $c['db_username'], $c['db_password'], $options);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Reading CSV file
|
||||
$inputFile = fopen('Registry_Contacts.csv', 'r');
|
||||
|
||||
// Skip the header row
|
||||
$headers = fgetcsv($inputFile);
|
||||
|
||||
while (($row = fgetcsv($inputFile)) !== false) {
|
||||
$data = array_combine($headers, $row);
|
||||
|
||||
// Preparing data for `contact` table
|
||||
$contactData = [
|
||||
$data['roid'], // identifier
|
||||
formatPhoneNumber($data['Voice']), // voice
|
||||
null, // voice_x (not provided in CSV)
|
||||
formatPhoneNumber($data['Fax']), // fax
|
||||
null, // fax_x (not provided in CSV)
|
||||
$data['E-mail'], // email
|
||||
null, // nin (not provided in CSV)
|
||||
null, // nin_type (not provided in CSV)
|
||||
$data['registrar'], // clid
|
||||
$data['registrar'], // crid
|
||||
formatTimestamp($data['createdate']) // crdate
|
||||
];
|
||||
|
||||
// Inserting into `contact` table
|
||||
$stmt = $pdo->prepare("INSERT INTO contact (identifier, voice, voice_x, fax, fax_x, email, nin, nin_type, clid, crid, crdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute($contactData);
|
||||
|
||||
// Getting the last inserted contact_id
|
||||
$contactId = $pdo->lastInsertId();
|
||||
|
||||
// Preparing data for `contact_postalInfo` table
|
||||
$postalInfoData = [
|
||||
$contactId, // contact_id
|
||||
'int', // type (assuming 'int' for international)
|
||||
$data['International Name'] ?: $data['Local Name'], // name
|
||||
$data['International Organisation'] ?: $data['Local Organisation'], // org
|
||||
$data['International Street1'] ?: $data['Local Street1'], // street1
|
||||
$data['International Street2'] ?: $data['Local Street2'], // street2
|
||||
$data['International Street3'] ?: $data['Local Street3'], // street3
|
||||
$data['International City'] ?: $data['Local City'], // city
|
||||
$data['International State/Province'] ?: $data['Local State/Province'], // sp
|
||||
$data['International Postal Code'] ?: $data['Local Postal Code'], // pc
|
||||
formatCountryCode($data['International Country Code'] ?: $data['Local Country Code']) // cc
|
||||
];
|
||||
|
||||
// Inserting into `contact_postalInfo` table
|
||||
$stmt = $pdo->prepare("INSERT INTO contact_postalInfo (contact_id, type, name, org, street1, street2, street3, city, sp, pc, cc) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute($postalInfoData);
|
||||
|
||||
// Inserting into `contact_authInfo` table
|
||||
$authInfoData = [
|
||||
$contactId, // contact_id
|
||||
'pw', // authtype
|
||||
generateRandomString() // authinfo
|
||||
];
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO contact_authInfo (contact_id, authtype, authinfo) VALUES (?, ?, ?)");
|
||||
$stmt->execute($authInfoData);
|
||||
|
||||
// Inserting into `contact_status` table
|
||||
$statusData = [
|
||||
$contactId, // contact_id
|
||||
'ok' // status
|
||||
];
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO contact_status (contact_id, status) VALUES (?, ?)");
|
||||
$stmt->execute($statusData);
|
||||
}
|
||||
|
||||
fclose($inputFile);
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
|
||||
$c = require_once 'config.php';
|
||||
require_once 'helpers.php';
|
||||
|
||||
// Connect to the database
|
||||
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']}";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
|
||||
try {
|
||||
$pdo = new PDO($dsn, $c['db_username'], $c['db_password'], $options);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
}
|
||||
|
||||
$inputFile = fopen('Domains.csv', 'r');
|
||||
|
||||
// Skip the header row of the input file
|
||||
$headers = fgetcsv($inputFile);
|
||||
|
||||
while (($row = fgetcsv($inputFile)) !== false) {
|
||||
$data = array_combine($headers, $row);
|
||||
|
||||
// Inserting into the 'domain' table
|
||||
$tldId = getTldId($pdo, $data['name']);
|
||||
$createdOn = formatTimestamp($data['create_date']);
|
||||
$expiryDate = formatTimestamp($data['expiry_date']);
|
||||
$registrarId = $data['registrar_id'];
|
||||
|
||||
$sql = "INSERT INTO domain (name, tldid, crdate, exdate, clid, crid) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$data['name'], $tldId, $createdOn, $expiryDate, $registrarId, $registrarId]);
|
||||
|
||||
$domainId = $pdo->lastInsertId();
|
||||
|
||||
// Inserting into the 'secdns' table
|
||||
$sql = "INSERT INTO secdns (domain_id, maxsiglife, interface, keytag, alg, digesttype, digest, flags, protocol, keydata_alg, pubkey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
// Assuming default values for some fields as they are not provided in the CSV
|
||||
$maxSigLife = 604800;
|
||||
$interface = 'dsData';
|
||||
$alg = 5; // Default algorithm
|
||||
$digestType = 1; // Default digest type
|
||||
$flags = null;
|
||||
$protocol = null;
|
||||
$keydataAlg = null;
|
||||
$pubkey = null;
|
||||
|
||||
// Extract DNSSEC data from the current row
|
||||
$keyTag = $data['key_tag'] ?? ''; // Using null coalescing operator for default value
|
||||
$digestValue = $data['digest_value'] ?? '';
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$domainId, $maxSigLife, $interface, $keyTag, $alg, $digestType, $digestValue, $flags, $protocol, $keydataAlg, $pubkey]);
|
||||
|
||||
// Inserting domain status into 'domain_status' table
|
||||
$status = $data['status'] ?? 'ok';
|
||||
$sql = "INSERT INTO domain_status (domain_id, status) VALUES (?, ?)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$domainId, $status]);
|
||||
|
||||
// Inserting hosts into 'host' table
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (isset($data["NameServer_$i"]) && !empty($data["NameServer_$i"])) {
|
||||
$hostName = $data["NameServer_$i"];
|
||||
$registrarId = $data['registrar_id'];
|
||||
$createdOn = formatTimestamp($data['create_date']);
|
||||
|
||||
$sql = "INSERT INTO host (name, domain_id, clid, crid, crdate) VALUES (?, ?, ?, ?, ?)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$hostName, null, $registrarId, $registrarId, $createdOn]);
|
||||
|
||||
$hostId = $pdo->lastInsertId();
|
||||
|
||||
// Inserting 'ok' status into 'host_status' table
|
||||
$statusSql = "INSERT INTO host_status (host_id, status) VALUES (?, ?)";
|
||||
$statusStmt = $pdo->prepare($statusSql);
|
||||
$statusStmt->execute([$hostId, 'ok']);
|
||||
}
|
||||
}
|
||||
|
||||
// Insert into domain_contact_map
|
||||
$contactTypes = ['admin' => 'admin_contact_id', 'billing' => 'billing_contact_id', 'tech' => 'tech_contact_id'];
|
||||
foreach ($contactTypes as $type => $field) {
|
||||
$contactIds = explode(',', $data[$field]);
|
||||
foreach ($contactIds as $roid) {
|
||||
$contactId = getContactIdByROID($pdo, trim($roid));
|
||||
if ($contactId !== null) {
|
||||
$contactSql = "INSERT INTO domain_contact_map (domain_id, contact_id, type) VALUES (?, ?, ?)";
|
||||
$contactStmt = $pdo->prepare($contactSql);
|
||||
$contactStmt->execute([$domainId, $contactId, $type]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insert into domain_host_map
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
if (!empty($data["NameServer_$i"])) {
|
||||
$hostId = getHostIdByName($pdo, $data["NameServer_$i"]);
|
||||
if ($hostId !== null) {
|
||||
$hostSql = "INSERT INTO domain_host_map (domain_id, host_id) VALUES (?, ?)";
|
||||
$hostStmt = $pdo->prepare($hostSql);
|
||||
$hostStmt->execute([$domainId, $hostId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose($inputFile);
|
||||
|
||||
// Updating the 'host' table with domain_id
|
||||
$hostsStmt = $pdo->query("SELECT id, name FROM host WHERE domain_id IS NULL");
|
||||
while ($host = $hostsStmt->fetch()) {
|
||||
$domainName = strstr($host['name'], '.', true);
|
||||
$domainId = getDomainIdByName($pdo, $domainName);
|
||||
|
||||
if ($domainId !== null) {
|
||||
$updateStmt = $pdo->prepare("UPDATE host SET domain_id = ? WHERE id = ?");
|
||||
$updateStmt->execute([$domainId, $host['id']]);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
$c = require_once 'config.php';
|
||||
require_once 'helpers.php';
|
||||
|
||||
// Connect to the database
|
||||
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']}";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
|
||||
try {
|
||||
$pdo = new PDO($dsn, $c['db_username'], $c['db_password'], $options);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Fetching all hosts
|
||||
$hostsStmt = $pdo->query("SELECT id, name FROM host");
|
||||
while ($host = $hostsStmt->fetch()) {
|
||||
$hostId = $host['id'];
|
||||
$hostName = $host['name'];
|
||||
|
||||
// Get IPv4 address
|
||||
$ipv4 = gethostbyname($hostName);
|
||||
if ($ipv4 !== $hostName) { // Check if a valid IPv4 address is returned
|
||||
$sql = "INSERT INTO host_addr (host_id, addr, ip) VALUES (?, ?, 'v4')";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$hostId, $ipv4]);
|
||||
}
|
||||
|
||||
// Get IPv6 address
|
||||
$dnsRecords = dns_get_record($hostName, DNS_AAAA);
|
||||
foreach ($dnsRecords as $record) {
|
||||
if (isset($record['ipv6'])) {
|
||||
$ipv6 = $record['ipv6'];
|
||||
$sql = "INSERT INTO host_addr (host_id, addr, ip) VALUES (?, ?, 'v6')";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$hostId, $ipv6]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once 'helpers.php';
|
||||
|
||||
$inputFile = fopen('Domains.csv', 'r');
|
||||
$outputFile = fopen('renewals.csv', 'w');
|
||||
|
||||
$fields = ['domain_name', 'txn_on', 'charge', 'renewal_years', 'client_charged', 'client_trid', 'autorenewal', 'vat_amount'];
|
||||
|
||||
// Write the header to the output file
|
||||
fputcsv($outputFile, $fields);
|
||||
|
||||
$headers = fgetcsv($inputFile);
|
||||
|
||||
while (($row = fgetcsv($inputFile)) !== false) {
|
||||
$data = array_combine($headers, $row);
|
||||
|
||||
$status = $data['status'];
|
||||
if (isEligibleForRenewal($status)) {
|
||||
$filteredRow = [
|
||||
'domain_name' => $data['name'] ?? '',
|
||||
'txn_on' => $data['charge_on'] ? date('c', strtotime($data['charge_on'])) : null,
|
||||
'charge' => floatval($data['charge'] ?? 0.0),
|
||||
'renewal_years' => intval($data['renewal_years'] ?? 0),
|
||||
'client_charged' => $data['new_client'] ?? '',
|
||||
'client_trid' => $data['client_trid'] ?? '',
|
||||
'autorenewal' => parseBool($data['autorenewal'] ?? ''),
|
||||
'vat_amount' => intval($data['vat_amount'] ?? 0),
|
||||
];
|
||||
|
||||
fputcsv($outputFile, $filteredRow);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($inputFile);
|
||||
fclose($outputFile);
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
// Database Configuration
|
||||
'db_type' => 'mysql',
|
||||
'db_host' => 'localhost',
|
||||
'db_port' => 3306,
|
||||
'db_database' => 'your_database_name',
|
||||
'db_username' => 'your_username',
|
||||
'db_password' => 'your_password',
|
||||
];
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
|
||||
function formatPhoneNumber($phoneNumber) {
|
||||
return str_replace('-', '', $phoneNumber);
|
||||
}
|
||||
|
||||
function formatCountryCode($countryCode) {
|
||||
return strtoupper($countryCode);
|
||||
}
|
||||
|
||||
function generateRandomString($length = 16) {
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
function formatTimestamp($timestamp) {
|
||||
try {
|
||||
$dt = new DateTime($timestamp);
|
||||
} catch (Exception $e) {
|
||||
$dt = DateTime::createFromFormat('Y-m-d', $timestamp);
|
||||
$dt->setTime(0, 0, 0);
|
||||
}
|
||||
return $dt->format('Y-m-d H:i:s'); // MySQL datetime format
|
||||
}
|
||||
|
||||
function getTldId($pdo, $domainName) {
|
||||
$tld = strrchr($domainName, '.');
|
||||
$stmt = $pdo->prepare("SELECT id FROM domain_tld WHERE tld = ?");
|
||||
$stmt->execute([$tld]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ? $row['id'] : null;
|
||||
}
|
||||
|
||||
function getDomainIdByName($pdo, $domainName) {
|
||||
$stmt = $pdo->prepare("SELECT id FROM domain WHERE name = ?");
|
||||
$stmt->execute([$domainName]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ? $row['id'] : null;
|
||||
}
|
||||
|
||||
function getContactIdByROID($pdo, $roid) {
|
||||
$stmt = $pdo->prepare("SELECT id FROM contact WHERE roid = ?");
|
||||
$stmt->execute([$roid]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ? $row['id'] : null;
|
||||
}
|
||||
|
||||
function getHostIdByName($pdo, $hostName) {
|
||||
$stmt = $pdo->prepare("SELECT id FROM host WHERE name = ?");
|
||||
$stmt->execute([$hostName]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ? $row['id'] : null;
|
||||
}
|
||||
|
||||
function isEligibleForRenewal($status) {
|
||||
$pendingStatuses = ['domain_status_pending_purge', 'domain_status_pending_delete'];
|
||||
return in_array($status, $pendingStatuses);
|
||||
}
|
||||
|
||||
function parseBool($value) {
|
||||
$value = strtolower($value);
|
||||
if ($value === 'true') return true;
|
||||
if ($value === 'false') return false;
|
||||
return null;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue