mirror of
https://github.com/PurpleI2P/regi2p.git
synced 2025-01-28 14:14:23 +00:00
66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?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->isValidAddress($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;
|