diff --git a/config.php.dist b/config.php.dist index 2963b9c..de8f49e 100644 --- a/config.php.dist +++ b/config.php.dist @@ -25,12 +25,14 @@ $options = [ 'tableitems' => 30, // records limit on alive, all, search pages /* Records processing options */ - 'approvedelay' => 24, // check host for availability before publishing for this time (hours) - 'approveseen' => 3, // host must be seen lesser than this amount of hours for approving (hours) + 'approvedelay' => 24, // check host for availability before publishing for this time (hours) + 'approveseen' => 3, // host must be seen lesser than this amount of hours for approving (hours) 'newdays' => 14, // assume host as new for that amout of days + 'olddays' => 45, // assume host as approved if seen less than that amount of days, and stable if seen more than that amount of days 'delnewdays' => 3, // if new host not seen more than X days, disable it and disapprove - 'delolddays' => 45, // same as above, but for old hosts + 'delapprdays' => 45, // same as above, but for old hosts + 'delstabdays' => 180, // same as above, but for old hosts 'hidedays' => 3, // days before domain will be marked as hidden in period before disabling diff --git a/export.php b/export.php index a5bffdc..bd6c0de 100644 --- a/export.php +++ b/export.php @@ -11,38 +11,39 @@ $util = new App\Utils; $STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen`, `approved`, `initial`, `disabled`, `hidden` FROM hosts"); $hosts = $STH->fetchAll(PDO::FETCH_ASSOC); +$curr_time = time(); + // for automatic approving -$approffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["approvedelay"] . " hour")); // approval offset -$apprseen = date ("Y-m-d H:i:s", strtotime ("-" . $options["approveseen"] . " hour")); // approval maxseen offset +$approffs = $options["approvedelay"] * 3600; +$apprseen = $options["approveseen"] * 3600; + +// for managing export and disabling +$newregoffs = $options["newdays"] * 86400; +$oldregoffs = $options["olddays"] * 86400; -$newregoffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["newdays"] . " day")); -$newseenlim = date ("Y-m-d H:i:s", strtotime ("-" . $options["delnewdays"] . " day")); -$oldseenlim = date ("Y-m-d H:i:s", strtotime ("-" . $options["delolddays"] . " day")); +$newseenlim = $options["delnewdays"] * 86400; +$appseenlim = $options["delapprdays"] * 86400; +$staseenlim = $options["delstabdays"] * 86400; -$hideoffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["hidedays"] . " day")); // hide offset +$hideoffs = $options["hidedays"] * 86400; $export_full = $export_live = $export_init = []; $export_addr_full = $export_addr_live = $export_addr_init = []; foreach ($hosts as $host) { - /* Convert UFT-8 domains to Punycode */ + /* 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["add_date"] > $newregoffs && $host["last_seen"] > $newseenlim) || - ($host["add_date"] < $newregoffs && $host["last_seen"] > $oldseenlim) // is seen till disabling date - ) - ) - ) + if (($options["approval"] == false || $host["approved"] == 1) && $host["hidden"] == 0 && $host["disabled"] == 0) { - if ($host["last_seen"] > $hideoffs) { // if seen not earlier than hide offset + if (($last_seen + $hideoffs) > $curr_time) { array_push($export_live, $domain . "=" . $host["base64"]); array_push($export_addr_live, $domain . "," . $host["base32"]); @@ -52,14 +53,14 @@ foreach ($hosts as $host) array_push($export_addr_init, $domain . "," . $host["base32"]); } } - else // hide because not available for "hidedays" days + else // hide because not available for X days { $pdo->exec ("UPDATE `hosts` SET `hidden` = 1 WHERE `host` = '" . $host["host"] . "'"); } } else if ( $host["approved"] == 0 && ( - ($host["add_date"] < $approffs && $host["last_seen"] > $apprseen) // if host were registered more then X days ago and seen lesser than X hours ago + (($add_date + $approffs) < $curr_time && ($last_seen + $apprseen) > $curr_time) ) ) { @@ -70,8 +71,11 @@ foreach ($hosts as $host) if ( $host["disabled"] == 0 && - ($host["add_date"] > $newregoffs && $host["last_seen"] < $newseenlim) || - ($host["add_date"] < $newregoffs && $host["last_seen"] < $oldseenlim) // is seen more that disabling period days + ( + (($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"] . "'"); @@ -85,10 +89,10 @@ $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); diff --git a/fetch.php b/fetch.php index aceda46..3a752f1 100644 --- a/fetch.php +++ b/fetch.php @@ -55,7 +55,7 @@ foreach ($lists as $list) { $domain = ""; $record = $util->parseHostRecord($buffer); - if (!$util->isValidAddress($record['host'], $error)) { + if (!$util->isValidDomain($record['host'], $error)) { echo "Error while validating " . $record['host'] . ": " . $error . PHP_EOL; continue; diff --git a/import.php b/import.php index f07fba7..feac334 100644 --- a/import.php +++ b/import.php @@ -20,7 +20,7 @@ if ($f) { $domain = ""; $record = $util->parseHostRecord($buffer); - if (!$util->isValidAddress($record['host'], $error)) { + if (!$util->isValidDomain($record['host'], $error)) { echo "Error while validating " . $record['host'] . ": " . $error . PHP_EOL; continue; diff --git a/lib/utils.php b/lib/utils.php index 248efa4..7b9d946 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -144,41 +144,6 @@ class Utils { return self::b32encode(hash('sha256', self::b64decode($data), true)); } - /** - * Domain validation function for registration. - * @param string $data - * @return bool - */ - public static function isValidAddress(string $data, string &$result): bool - { - $len = strlen($data); - - if($len < 5 || $len > 255) // rfc2181, section 11 - { - $result = "Domain must be longer than 5 and lesser than 255 chars."; - return false; - } - - if(preg_match('/\.b32\.i2p$/', $data)) - { - $result = "Domain can't end with .b32.i2p."; - return false; - } - - if(filter_var($data, FILTER_VALIDATE_DOMAIN) !== false && preg_match('/\.i2p$/', $data) - && (static::isPunycodeDomain($data) || static::isAscii($data))) - { - return true; - } - else - { - $result = "Domain is not valid. Check if you domain label is lesser than 63 chars, and uses only ASCII or Punycode format."; - return false; - } - - return false; - } - /** * Domain validation function. * @param string $data @@ -204,12 +169,8 @@ class Utils { { return true; } - else - { - $result = "Inputed data or domain is not valid."; - return false; - } + $result = "Domain is not valid. Check if you domain label is lesser than 63 chars and it ends with .i2p."; return false; } @@ -217,6 +178,9 @@ class Utils { { $retval = null; + if (strpos($data, "&") !== false) + return false; // registration string can't have ampersands + $cmd = dirname(__FILE__) . "/../bin/verifyhost '" . $data . "'"; exec($cmd, $output, $retval); diff --git a/templates/add.twig b/templates/add.twig index 829a565..084a738 100644 --- a/templates/add.twig +++ b/templates/add.twig @@ -13,7 +13,15 @@ {% else %}
Rules:
Although there are no specific rules for domain registration, we do have the policy on dead domain records.
- Your domain will become open for registration again if it is dead for:
+ Your domain will become open for registration again (disabled) if it is dead for: