Search now manages URLs

parent ac520829
......@@ -5,19 +5,31 @@ import isAsn from "is-asn";
import isCidr from "is-cidr";
import punycode from "punycode";
import isDomainName from "is-domain-name";
import { URL } from "url";
const { Resolver } = require('dns').promises;
const resolver = new Resolver();
const router: Router = Router();
function isUrl(input: string): URL | false {
try {
const myURL = new URL(input);
return myURL;
} catch {
return false;
}
}
/**
* Index
*/
router.get("/", (req: Request, res: Response, next: NextFunction) => {
const query: string = req.query.q;
let query: string = req.query.q;
if(query) {
if(isIp(query)) {
res.redirect(`/ip/${query}`);
} else if(isAsn(query.toUpperCase())) {
......@@ -27,10 +39,25 @@ router.get("/", (req: Request, res: Response, next: NextFunction) => {
} else if(domainNameRegex.test(punycode.toASCII(query))) {
res.redirect(`/dns/${punycode.toASCII(query)}`);
} else {
let skip_tld_check: boolean = false;
/**
* URL check
*/
const url = isUrl(query);
if(url) {
res.redirect(`/search?q=${url.hostname}`);
skip_tld_check = true;
}
/**
* TLD check
*/
if(req.query.ignore_tld == "true") {
if(skip_tld_check) {
// Do nothing.
} else if(req.query.ignore_tld == "true") {
continue_search(query);
} else if(isDomainName(punycode.toASCII(query))) {
const tld = punycode.toASCII(query);
......
......@@ -22,9 +22,13 @@
<p class="mb-2">The JSON version currently has the following extra features that are not available on the original/TXT version:
<ul>
<li>Tor relay fingerprint</li>
<li><a href="https://en.wikipedia.org/wiki/Forward-confirmed_reverse_DNS">Forward-confirmed reverse DNS</a> records</li>
<li>Array containing <a href="https://metrics.torproject.org/glossary.html#relay-flag">relay flags</a> in English</li>
<li><a href="https://metrics.torproject.org/onionoo.html#details_relay_fingerprint">
Relay fingerprint</a></li>
<li><a href="https://en.wikipedia.org/wiki/Forward-confirmed_reverse_DNS">
Forward-confirmed reverse DNS</a> records
(sourced from <a href="https://metrics.torproject.org/onionoo.html#details_relay_verified_host_names">
Onionoo</a>)</li>
<li><a href="https://metrics.torproject.org/onionoo.html#uptime_relay_flags">An array of strings</a> containing <a href="https://metrics.torproject.org/glossary.html#relay-flag">relay flags</a> in English</li>
</ul></p>
<p>The data is automatically updated to the forementioned endpoints,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment