Commit ac0d5e40 authored by Elias Ojala's avatar Elias Ojala

Tor relay page and minor improvements

parent bd132d56
......@@ -62,8 +62,12 @@ twig.extendFunction("portSizeProcessor", (rawSize: string) => {
import txtParser from "./view-functions/txtParser";
twig.extendFunction("txtParser", txtParser);
import hostnamePortSplitter from "./view-functions/hostnamePortSplitter";
import hostnamePortSplitter, { splitHostname } from "./view-functions/hostnamePortSplitter";
twig.extendFunction("hostnamePortSplitter", hostnamePortSplitter);
twig.extendFunction("splitHostname", splitHostname);
import removeBrackets from "./view-functions/removeBrackets";
twig.extendFunction("removeBrackets", removeBrackets);
twig.extendFunction("getReverse", (ipAddr: string): string => {
return "";
......
......@@ -5,6 +5,7 @@ import axios from "axios";
import compressIp from "../functions/compressIp";
import dnsbl from "dnsbl";
import { dnsblConfiguration } from "../app";
import removeBrackets from "../view-functions/removeBrackets";
const router: Router = Router();
......@@ -114,6 +115,8 @@ router.get("/:ip", (req: Request, res: Response, next: NextFunction) => {
})
.catch(next);
}
} else if(isIp.v6(removeBrackets(ipAddress))) {
res.redirect(301, `/ip/${removeBrackets(ipAddress)}`);
} else {
next();
}
......
......@@ -7,6 +7,7 @@ import punycode from "punycode";
import isDomainName from "is-domain-name";
import { URL } from "url";
import compressIp from "../functions/compressIp";
import removeBrackets from "../view-functions/removeBrackets";
const { Resolver } = require('dns').promises;
const resolver = new Resolver();
......@@ -33,6 +34,8 @@ router.get("/", (req: Request, res: Response, next: NextFunction) => {
if(isIp(query)) {
res.redirect(`/ip/${compressIp(query)}`);
} else if(isIp.v6(removeBrackets(query))) {
res.redirect(`/ip/${compressIp(removeBrackets(query))}`)
} else if(isAsn(query.toUpperCase())) {
res.redirect(`/${query}`);
} else if(isCidr(query)) {
......
function split(input: string): { hostname: string, port } {
const x = input.split(":");
import isIp = require("is-ip");
function splitHostname(input: string): { hostname: string, port } {
let x: string[] = [];
if(input.includes("[")) {
// IPv6
x = input.split("]:");
x[0] += "]";
} else {
// IPv4 or hostname
x = input.split(":");
}
return {
hostname: x[0],
......@@ -8,9 +19,10 @@ function split(input: string): { hostname: string, port } {
}
function hostnamePortSplitter(input: string): string {
const data = split(input);
const data = splitHostname(input);
return `<a href="/search?q=${data.hostname}">${data.hostname}</a>:${data.port}`;
}
export default hostnamePortSplitter;
\ No newline at end of file
export default hostnamePortSplitter;
export { splitHostname };
\ No newline at end of file
/**
* Removes brackets from string
* @param input Input
*/
function removeBrackets(input: string): string {
return input.replace("[", "").replace("]", "");
}
export default removeBrackets;
\ No newline at end of file
......@@ -3,5 +3,33 @@
{% block body %}
<h1>{{ title|e }}</h1>
{% if data.or_addresses %}
<h2>ORPorts</h2>
<ul class="pl-3">
{% for ipAndPort in data.or_addresses|sort %}
{% set ipAddress = splitHostname(ipAndPort).hostname %}
{% set port = splitHostname(ipAndPort).port %}
<li class="ipRecord" data-ip="{{ removeBrackets(ipAddress) }}">
<a href="/ip/{{ removeBrackets(ipAddress) }}">{{ ipAddress }}</a>:{{ port }}
</li>
{% endfor %}
</ul>
{% endif %}
{% if data.exit_addresses %}
<h2>Exit Addresses</h2>
<ul class="pl-3">
{% for ipAddress in data.exit_addresses|sort %}
<li class="ipRecord" data-ip="{{ removeBrackets(ipAddress) }}">
<a href="/ip/{{ removeBrackets(ipAddress) }}">{{ ipAddress }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
<pre><code>{{ json_data|e }}</code></pre>
{% endblock %}
{% block javascripts %}
<script src="/assets/js/pages/dns/show/reverse-fetch.js" async defer></script>
{% endblock %}
\ No newline at end of file
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