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.
 
 
 
 

143 lines
4.3 KiB

<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/config.php';
set_time_limit (0);
date_default_timezone_set ('UTC');
$pdo = (new App\DB($options))->pdo;
$util = new App\Utils;
$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen`, `approved`, `initial`, `disabled`, `hidden`, `blacklisted` FROM hosts");
$hosts = $STH->fetchAll(PDO::FETCH_ASSOC);
$curr_time = time();
// for automatic approving
$approffs = $options["approvedelay"] * 3600;
$apprseen = $options["approveseen"] * 3600;
// for managing export and disabling
$newregoffs = $options["newdays"] * 86400;
$oldregoffs = $options["olddays"] * 86400;
$newseenlim = $options["delnewdays"] * 86400;
$appseenlim = $options["delapprdays"] * 86400;
$staseenlim = $options["delstabdays"] * 86400;
$hideoffs = $options["hidedays"] * 86400;
$export_full = $export_live = $export_init = [];
$export_addr_full = $export_addr_live = $export_addr_init = [];
foreach ($hosts as $host)
{
/* Convert UTF-8 domains to Punycode */
$domain = $util->isASCII ($host["host"]) ? $host["host"] : idn_to_ascii ($host["host"]);
$add_date = strtotime ($host["add_date"]);
$last_seen = strtotime ($host["last_seen"]);
array_push($export_full, $domain . "=" . $host["base64"]);
array_push($export_addr_full, $domain . "," . $host["base32"]);
if (($options["approval"] == false || $host["approved"] == 1) && $host["hidden"] == 0 && $host["disabled"] == 0 && $host["blacklisted"] == 0)
{
if (($last_seen + $hideoffs) > $curr_time) {
array_push($export_live, $domain . "=" . $host["base64"]);
array_push($export_addr_live, $domain . "," . $host["base32"]);
if ($host["initial"] == 1)
{
array_push($export_init, $domain . "=" . $host["base64"]);
array_push($export_addr_init, $domain . "," . $host["base32"]);
}
}
else // hide because not available for X days
{
$pdo->exec ("UPDATE `hosts` SET `hidden` = 1 WHERE `host` = '" . $host["host"] . "'");
}
}
else if (
$host["approved"] == 0 && (
(($add_date + $approffs) < $curr_time && ($last_seen + $apprseen) > $curr_time)
)
)
{
$pdo->exec ("UPDATE `hosts` SET `approved` = 1 WHERE `host` = '" . $host["host"] . "'");
array_push($export_live, $domain . "=" . $host["base64"]);
array_push($export_addr_live, $domain . "," . $host["base32"]);
}
if (
$host["disabled"] == 0 &&
(
(($last_seen - $add_date) < $newregoffs && ($last_seen + $newseenlim) < $curr_time) ||
(($last_seen - $add_date) < $oldregoffs && ($last_seen + $appseenlim) < $curr_time) ||
(($last_seen - $add_date) > $oldregoffs && ($last_seen + $staseenlim) < $curr_time)
)
)
{
$pdo->exec ("UPDATE `hosts` SET `disabled` = 1 WHERE `host` = '" . $host["host"] . "'");
}
}
$STH = null;
$pdo = null;
/* Sort records */
sort ($export_full);
sort ($export_addr_full);
sort ($export_live);
sort ($export_addr_live);
sort ($export_init);
sort ($export_addr_init);
/* Export all records */
$f = fopen (__DIR__ . "/public/export/hosts-all.txt", "w");
foreach ($export_full as $l) {
$toWrite = print_r ($l, true);
fwrite ($f, $toWrite . "\n");
}
fclose ($f);
$f = fopen (__DIR__ . "/public/export/addresses-all.csv", "w");
foreach ($export_addr_full as $l) {
$toWrite = print_r ($l, true);
fwrite ($f, $toWrite . "\n");
}
fclose ($f);
/* Export alive records */
$f = fopen (__DIR__ . "/public/export/hosts.txt", "w");
foreach ($export_live as $l) {
$toWrite = print_r ($l, true);
fwrite ($f, $toWrite . "\n");
}
fclose ($f);
$f = fopen (__DIR__ . "/public/export/addresses.csv", "w");
foreach ($export_addr_live as $l) {
$toWrite = print_r ($l, true);
fwrite ($f, $toWrite . "\n");
}
fclose ($f);
/* Export initial records */
$f = fopen (__DIR__ . "/public/export/hosts-basic.txt", "w");
foreach ($export_init as $l) {
$toWrite = print_r ($l, true);
fwrite ($f, $toWrite . "\n");
}
fclose ($f);
$f = fopen (__DIR__ . "/public/export/addresses-basic.csv", "w");
foreach ($export_addr_init as $l) {
$toWrite = print_r ($l, true);
fwrite ($f, $toWrite . "\n");
}
fclose ($f);