Skip to content

Commit

Permalink
DNS, record type label
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Aug 19, 2024
1 parent 66ef9a3 commit db0e977
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Protest/Front/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class About extends Tabs {
}

const formData = new FormData();
formData.append('file', file);
formData.append("file", file);

isBusy = true;
message.textContent = "Uploading file... This might take a minute.";
Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Backup extends List {
if (this.args.select === null) return;

let link = document.createElement("a");
link.download = 'name';
link.download = "name";
link.href = `config/backup/download?name=${encodeURIComponent(this.args.select)}`;
link.click();
link.remove();
Expand Down
4 changes: 2 additions & 2 deletions Protest/Front/certificates.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class Certificates extends List {
}

const formData = new FormData();
formData.append('file', file);
formData.append("file", file);

isBusy = true;
message.textContent = "Uploading file... This might take a second.";
Expand Down Expand Up @@ -322,7 +322,7 @@ class Certificates extends List {

Download() {
let link = document.createElement("a");
link.download = 'name';
link.download = "name";
link.href = `config/cert/download?name=${encodeURIComponent(this.args.select)}`;
link.click();
link.remove();
Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/deviceview.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class DeviceView extends View {
setTimeout(async ()=>{
if (this.isClosed) return;

const query = this.pingIndicators.map(indicator => indicator.target).join(';');
const query = this.pingIndicators.map(indicator => indicator.target).join(";");

try {
const response = await fetch(`tools/bulkping?query=${query}`);
Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/dns-sd.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class DnsSD extends Console {
static RECORD_TYPES = [
["A", "IPv4 Address", "hsl(20,85%,50%)", 1],
["AAAA", "IPv6 Address", "hsl(50,85%,50%)", 28],
["NS", "Name Server", "hsl(80,85%,50%)", 2],
["CNAME", "Canonical Name", "hsl(140,85%,50%)", 5],
["SOA", "Start Of Authority", "hsl(200,85%,55%)", 6] ,
["PTR", "Pointer", "hsl(230,95%,65%)", 12],
["MX", "Mail Exchange", "hsl(260,95%,65%)", 15],
["TXT", "Text", "hsl(290,85%,55%)", 16],
["AAAA", "IPv6 Address", "hsl(50,85%,50%)", 28],
["SRV", "Service", "hsl(320,85%,50%)", 33],
["NSEC", "Next secure", "hsl(0,85%,50%)", 47],
["ANY", "All types known", "hsl(0,85%,100%)", 255]
Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/documentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Documentation extends Window {
sel.removeAllRanges();
sel.addRange(range);
document.execCommand("createLink", false, linkInput.value);
document.getSelection().anchorNode.parentElement.target = '_blank';
document.getSelection().anchorNode.parentElement.target = "_blank";
Ok_onclick();
}
};
Expand Down
4 changes: 2 additions & 2 deletions Protest/Front/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Encoder extends Window {
break;

case "HTML entity":
let div = document.createElement('div');
let div = document.createElement("div");
div.appendChild(document.createTextNode(this.txtA.textContent));
this.txtB.textContent = div.textContent;
break;
Expand Down Expand Up @@ -179,7 +179,7 @@ class Encoder extends Window {
break;

case "HTML entity":
let txt = document.createElement('textarea');
let txt = document.createElement("textarea");
txt.textContent = this.txtB.textContent;
this.txtA.textContent = txt.value;
break;
Expand Down
12 changes: 12 additions & 0 deletions Protest/Front/hexviewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@
height: 2px;
}

.hexviewer-record-type-label {
display: inline;
margin-left: 8px;
padding : 4px;
background-color: rgb(34,34,34);
font-family: monospace;
font-weight: 600;
height: 18px;
line-height: 20px;
border-radius: 8px;
}

@container hexviewer-container (max-width: 720px) {
.hexviewer-list {
display: none;
Expand Down
36 changes: 30 additions & 6 deletions Protest/Front/hexviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ class HexViewer extends Window {
255: "ANY",
};

static DNS_RECORD_COLORS = {
1 : "hsl(20,85%,50%)",
2 : "hsl(80,85%,50%)",
5 : "hsl(140,85%,50%)",
6 : "hsl(200,85%,55%)",
12: "hsl(230,95%,65%)",
15: "hsl(260,95%,65%)",
16: "hsl(290,85%,55%)",
28: "hsl(50,85%,50%)",
33: "hsl(320,85%,50%)",
47: "hsl(0,85%,50%)",
255: "hsl(0,85%,100%)"
};

static DNS_CLASSES = {
1: "Internet",
2: "CSNET",
Expand Down Expand Up @@ -574,8 +588,16 @@ class HexViewer extends Window {
index = end;

const type = (stream[index] << 8) | stream[index+1];
this.PopulateLabel(`Type: ${type} ${HexViewer.DNS_RECORD_TYPES[type] ? `(${HexViewer.DNS_RECORD_TYPES[type]})` : ""}`, 1, hexContainer, charContainer, index, 2);
const typeLabel = this.PopulateLabel(`Type: ${type}`, 1, hexContainer, charContainer, index, 2);
index += 2;

if (HexViewer.DNS_RECORD_TYPES[type]) {
const recordTypeLabel = document.createElement("div");
recordTypeLabel.className = "hexviewer-record-type-label";
recordTypeLabel.style.color = HexViewer.DNS_RECORD_COLORS[type];
recordTypeLabel.textContent = HexViewer.DNS_RECORD_TYPES[type];
typeLabel.firstChild.appendChild(recordTypeLabel);
}

const cacheFlashFlag = stream[index] & 0x80;
if (cacheFlashFlag > 0) {
Expand Down Expand Up @@ -617,13 +639,15 @@ class HexViewer extends Window {
index = end;

const type = (stream[index] << 8) | stream[index+1];
const x = this.PopulateLabel(`Type: ${type}`, 1, hexContainer, charContainer, index, 2);
const typeLabel = this.PopulateLabel(`Type: ${type}`, 1, hexContainer, charContainer, index, 2);
index += 2;

if (HexViewer.DNS_RECORD_TYPES[type]) {
const typeLabel = document.createElement("div");
typeLabel.textContent = HexViewer.DNS_RECORD_TYPES[type];
x.appendChild(typeLabel);
const recordTypeLabel = document.createElement("div");
recordTypeLabel.className = "hexviewer-record-type-label";
recordTypeLabel.style.color = HexViewer.DNS_RECORD_COLORS[type];
recordTypeLabel.textContent = HexViewer.DNS_RECORD_TYPES[type];
typeLabel.firstChild.appendChild(recordTypeLabel);
}

const cacheFlashFlag = stream[index] & 0x80;
Expand Down Expand Up @@ -660,7 +684,7 @@ class HexViewer extends Window {
data += stream[index + j].toString(16).padStart(2, "0");
data += stream[index + j + 1].toString(16).padStart(2, "0");
}
this.PopulateLabel(data, 1, hexContainer, charContainer, index, len);
this.PopulateLabel(UI.CompressIPv6(data), 1, hexContainer, charContainer, index, len);
}
break;

Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/mictester.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class MicTester extends Window {
ctx.fillStyle = "#c0c0c0";
ctx.font = "14px Consolas";
ctx.textAlign = "right";
ctx.textBaseline = 'middle';
ctx.textBaseline = "middle";

const step = this.canvas.height > 800 ? 32 : this.canvas.height > 400 ? 64 : 128;
for (let i=step; i<256; i+=step) {
Expand Down
34 changes: 33 additions & 1 deletion Protest/Front/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const UI = {
}

//automatically disable animations if prefers-reduced-motion
if (window.matchMedia('(prefers-reduced-motion)').matches && localStorage.getItem("animations") === null) {
if (window.matchMedia("(prefers-reduced-motion)").matches && localStorage.getItem("animations") === null) {
localStorage.setItem("animations", "false");
}

Expand Down Expand Up @@ -294,6 +294,38 @@ const UI = {
return `${prefix}-${"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, ()=>(window.crypto.getRandomValues(new Uint8Array(1))[0] & 0b00001111).toString(16))}`;
}
return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, ()=>(window.crypto.getRandomValues(new Uint8Array(1))[0] & 0b00001111).toString(16));
},

CompressIPv6: ipv6 => {
let blocks = ipv6.split(":");

blocks = blocks.map(block => block.replace(/^0+/, "") || "0");

let zeroSequence = blocks.reduce((longest, current, index) => {
if (current === "0") {
let length = longest.currentLength + 1;
if (length > longest.maxLength) {
longest.maxLength = length;
longest.maxStart = index - length + 1;
}
longest.currentLength = length;
}
else {
longest.currentLength = 0;
}
return longest;
}, { maxLength: 0, maxStart: -1, currentLength: 0 });

if (zeroSequence.maxLength > 1) {
blocks.splice(zeroSequence.maxStart, zeroSequence.maxLength, "");
}

let compressedAddress = blocks.join(":");

if (compressedAddress.startsWith(":")) compressedAddress = ":" + compressedAddress;
if (compressedAddress.endsWith(":")) compressedAddress += ":";

return compressedAddress.replace(":::", "::");
}
};

Expand Down
17 changes: 17 additions & 0 deletions Protest/Misc/Data.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Lextm.SharpSnmpLib;
using Microsoft.Extensions.Hosting;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

namespace Protest;

Expand Down Expand Up @@ -436,4 +439,18 @@ public static void ReplaceAllBytesSequence(byte[] source, byte[] target, byte[]
}
}

public static string CompressIPv6(string ipv6) {
string removedExtraZeros = ipv6.Replace("0000","*");

string[] blocks = ipv6.Split(':');

Regex regex = new Regex(":0+");
removedExtraZeros = regex.Replace(removedExtraZeros, ":");

Regex regex2 = new Regex(":\\*:\\*(:\\*)+:");
removedExtraZeros = regex2.Replace(removedExtraZeros, "::");

return removedExtraZeros.Replace("*", "0");
}

}
2 changes: 1 addition & 1 deletion Protest/Protocols/Dns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private static byte[] Serialize(byte[] query, string replaced, byte[] response,
for (int j = 0; j < 16; j += 2) {
if (j > 0) builder.Append(':');
ushort word = (ushort)((deconstructed[i].name[j] << 8) | deconstructed[i].name[j + 1]);
builder.Append(word.ToString("x4"));
builder.Append(Data.CompressIPv6(word.ToString("x4")));
}

builder.Append("\",");
Expand Down
4 changes: 2 additions & 2 deletions Protest/Protocols/Mdns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ private static Answer[] ParseAnswers(byte[] response, RecordType queryType, IPAd

case RecordType.AAAA:
if (answer.length == 16 && index + 16 <= response.Length) {
answer.answerString = string.Join(":", Enumerable.Range(0, 8)
.Select(j => ((response[index + 2 * j] << 8) | response[index + 2 * j + 1]).ToString("x4")));
string answerString = string.Join(":", Enumerable.Range(0, 8).Select(j => ((response[index + 2 * j] << 8) | response[index + 2 * j + 1]).ToString("x4")));
answer.answerString = Data.CompressIPv6(answerString);
}
break;

Expand Down
2 changes: 1 addition & 1 deletion Protest/Workers/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public static ConcurrentDictionary<string, string[]> SingleDevice(string target,
if (ipNumber >= 2886729728 && ipNumber >= 2887778303) continue; //172.16.0.0 <> 172.31.255.255
if (ipNumber >= 3232235520 && ipNumber >= 3232301055) continue; //192.168.0.0 <> 192.168.255.255
if (ipNumber >= 2851995648 && ipNumber >= 184549375) continue; //169.254.0.0 <> 169.254.255.255
if (ipNumber >= 3758096384) continue; // > 224.0.0.0
if (ipNumber >= 3758096384) continue; // >= 224.0.0.0

string ipLocation = Encoding.UTF8.GetString(LocateIp.Locate(ipAddress?.ToString(), true));
if (ipLocation is null) continue;
Expand Down

0 comments on commit db0e977

Please sign in to comment.