Domain registry project http://reg.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/config.php';
$pdo = (new App\DB($options))->pdo;
$util = new App\Utils;
$error = "";
$f = @fopen("hosts.txt", "r");
if ($f) {
$pdo->beginTransaction();
$STH = $pdo->prepare("INSERT IGNORE INTO hosts (host, base64, base32) VALUES (:host, :base64, :base32)");
$STH->bindParam('host', $domain);
$STH->bindParam('base64', $base64);
$STH->bindParam('base32', $base32);
while (($buffer = fgets($f, 4096)) !== false) {
$domain = "";
$record = $util->parseHostRecord($buffer);
if (!$util->isValidDomain($record['host'], $error)) {
echo "Error while validating " . $record['host'] . ": " . $error . PHP_EOL;
continue;
} else {
if($util->isPunycodeDomain($record['host'])) {
$domain = idn_to_utf8($record['host']);
} else {
$domain = $record['host'];
}
}
if (!$util->isValidBase64($record['b64'])) {
echo "Error while validating " . $record['host'] . ": incorrect base64: " . $record['b64'] . PHP_EOL;
continue;
}
$base64 = $record['b64'];
$base32 = $util->b32from64($record['b64']);
$STH->execute();
}
if (!feof($f)) {
echo "Error: fgets() ended earlier than needed" . PHP_EOL;
}
if (!$pdo->commit()) {
echo "Error while saving records to database";
}
fclose($f);
}
$pdo = null;