Compress IPv6 address on Tor relay list

parent b76cccc5
......@@ -75,6 +75,9 @@ twig.extendFunction("base64Decode", (input: string): string => {
return Buffer.from(input, 'base64').toString('utf8');
})
import compressIp from "./functions/compressIp";
twig.extendFunction("compressIp", compressIp);
/**
* Is server in production mode?
*/
......
import isIp from "is-ip";
import { Address6 } from "ip-address";
function compressIp(ipAddress: string): string {
if(isIp.v6(ipAddress)) {
return new Address6(ipAddress).correctForm();
} else if(isIp.v4(ipAddress)) {
return ipAddress;
}
throw "Not a valid IP address";
}
export default compressIp;
\ No newline at end of file
......@@ -21,7 +21,7 @@
{% for relay in data %}
<tr>
<td>
<a href="/ip/{{ relay.ip|e }}" class="ipRecord add-parenthesis" data-ip="{{ relay.ip|e }}">{{ relay.ip|e }}</a>
<a href="/ip/{{ compressIp(relay.ip)|e }}" class="ipRecord add-parenthesis" data-ip="{{ compressIp(relay.ip)|e }}">{{ compressIp(relay.ip)|e }}</a>
</td>
<td>{{ relay.name|e }}</td>
<td>{{ relay.router_port|e }}</td>
......
......@@ -692,6 +692,18 @@
"@types/express-serve-static-core" "*"
"@types/serve-static" "*"
"@types/ip-address@^5.8.2":
version "5.8.2"
resolved "https://registry.yarnpkg.com/@types/ip-address/-/ip-address-5.8.2.tgz#5e413c477f78b3a264745eac937538a6e6e0c1f6"
integrity sha512-LFlDGRjJDnahfPyNCZGXvlaevSmZTi/zDxjTdXeTs8TQ9pQkNZKbCWaJXW29a3bGPRsASqeO+jGgZlaTUi9jTw==
dependencies:
"@types/jsbn" "*"
"@types/jsbn@*":
version "1.2.29"
resolved "https://registry.yarnpkg.com/@types/jsbn/-/jsbn-1.2.29.tgz#28229bc0262c704a1506c3ed69a7d7e115bd7832"
integrity sha512-2dVz9LTEGWVj9Ov9zaDnpvqHFV+W4bXtU0EUEGAzWfdRNO3dlUuosdHpENI6/oQW+Kejn0hAjk6P/czs9h/hvg==
"@types/lusca@^1.6.1":
version "1.6.1"
resolved "https://registry.yarnpkg.com/@types/lusca/-/lusca-1.6.1.tgz#39c352ad0a8597566d7beeb28ba8343bf450d21d"
......@@ -2019,6 +2031,15 @@ ip-address@^5.9.4:
lodash "^4.17.15"
sprintf-js "1.1.2"
ip-address@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/ip-address/-/ip-address-6.1.0.tgz#3c3335bc90f22b3545a6eca5bffefabeb2ea6fd2"
integrity sha512-u9YYtb1p2fWSbzpKmZ/b3QXWA+diRYPxc2c4y5lFB/MMk5WZ7wNZv8S3CFcIGVJ5XtlaCAl/FQy/D3eQ2XtdOA==
dependencies:
jsbn "1.1.0"
lodash "^4.17.15"
sprintf-js "1.1.2"
ip-cidr@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/ip-cidr/-/ip-cidr-2.0.6.tgz#64c9a695a720e63c1b3f98a455cbef1ef0fcb626"
......
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