Skip to content

Commit bf6af29

Browse files
update to use native javascript functionality
1 parent 31b7e80 commit bf6af29

File tree

11 files changed

+612
-399
lines changed

11 files changed

+612
-399
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"image": "mcr.microsoft.com/devcontainers/php:1-8.2-bullseye",
77
"features": {
88
"ghcr.io/devcontainers-extra/features/node-asdf:0": {}
9-
},
9+
}
1010

1111
// Features to add to the dev container. More info: https://containers.dev/features.
1212
// "features": {},

index.php

Lines changed: 116 additions & 100 deletions
Large diffs are not rendered by default.

javascript/main.js

Lines changed: 176 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,207 @@
1-
$(document).ready(function(){
2-
$("#domain").keyup(function(event){
3-
if(event.keyCode == 13){
4-
$("#submit").click();
1+
document.addEventListener('DOMContentLoaded', function() {
2+
// Add keyup event to trigger submit when Enter is pressed
3+
document.getElementById('domain').addEventListener('keyup', function(event) {
4+
if (event.key === 'Enter') {
5+
document.getElementById('submit').click();
56
}
67
});
7-
});
8-
window.onload = function() {
9-
//Counts the number of requests in this session
10-
var requestNum = 0;
11-
//Choose the correct script to run based on dropdown selection
12-
document.getElementById("submit").onclick = function callRoute() {
13-
returnDnsDetails(document.getElementById("domain").value, document.getElementById("file").value, document.getElementById("port").value)
14-
}
158

16-
function requestTitle(callType){
17-
switch(callType){
18-
case "txt":
19-
return "SPF/TXT Lookup";
20-
break;
21-
case "mx":
22-
return "MX Lookup";
23-
break;
24-
case "dmarc":
25-
return "DMARC";
26-
break;
27-
case "a":
28-
return "IP Lookup";
29-
break;
30-
case "all":
31-
return "All available DNS records";
32-
break;
33-
case "aaaa":
34-
return "IPV6 Lookup";
35-
break;
36-
case "whois":
37-
return "Who Is Lookup";
38-
break;
39-
case "hinfo":
40-
return "H Info Lookup";
41-
break;
42-
case "blacklist":
43-
return "Blacklist Lookup";
44-
break;
45-
case "port":
46-
return "Ports Lookup";
47-
break;
48-
case "reverseLookup":
49-
return "Host Lookup";
50-
break;
9+
// Add port input Enter key support
10+
document.getElementById('port').addEventListener('keyup', function(event) {
11+
if (event.key === 'Enter') {
12+
document.getElementById('submit').click();
5113
}
14+
});
15+
16+
// Handle form submission
17+
document.getElementById('submit').addEventListener('click', function() {
18+
const domain = document.getElementById('domain').value;
19+
const callType = document.getElementById('file').value;
20+
const port = document.getElementById('port').value;
21+
22+
returnDnsDetails(domain, callType, port);
23+
});
24+
25+
// Map call type to display title
26+
function requestTitle(callType) {
27+
const titles = {
28+
'txt': 'SPF/TXT Lookup',
29+
'mx': 'MX Lookup',
30+
'dmarc': 'DMARC',
31+
'a': 'IP Lookup',
32+
'all': 'All available DNS records',
33+
'aaaa': 'IPV6 Lookup',
34+
'whois': 'Who Is Lookup',
35+
'hinfo': 'H Info Lookup',
36+
'blacklist': 'Blacklist Lookup',
37+
'port': 'Ports Lookup',
38+
'reverseLookup': 'Host Lookup'
39+
};
40+
41+
return titles[callType] || 'DNS Lookup';
5242
}
5343

54-
//Get DNS Details
44+
// Get DNS details using Fetch API
5545
function returnDnsDetails(domain, callType, port) {
56-
//checks for valid input
57-
if (domain.length == 0) {
58-
document.getElementById("txtHint").innerHTML = " Please enter a valid domain";
46+
// Validate input
47+
if (!domain || domain.trim() === '') {
48+
document.getElementById('txtHint').innerHTML = "Please enter a valid domain";
5949
return;
60-
} else {
61-
var xmlhttp = new XMLHttpRequest();
62-
63-
xmlhttp.onreadystatechange = function () {
64-
var date = new Date();
65-
if (this.readyState == 4 && this.status == 200) {
66-
//Clears the hint field
67-
document.getElementById("txtHint").innerHTML = "";
68-
document.getElementById("loading").innerHTML= '';
69-
//parse the response into a JS Object
70-
dnsResp = JSON.parse(this.responseText);
71-
buildTable(dnsResp, callType);
72-
}
73-
}
74-
document.getElementById("loading").innerHTML = '<div class="sk-three-bounce"><div class="sk-child sk-bounce1"></div><div class="sk-child sk-bounce2"></div><div class="sk-child sk-bounce3"></div></div>'
75-
xmlhttp.open("GET", "operations/?domain=" + domain + "&request=" + callType + "&port=" + port, true);
76-
xmlhttp.send();
77-
7850
}
51+
52+
// Clear previous error message
53+
document.getElementById('txtHint').innerHTML = "";
54+
55+
// Show loading spinner
56+
document.getElementById('loading').innerHTML =
57+
createLoadingTemplate();
58+
59+
// Prepare URL
60+
const url = `operations/?domain=${encodeURIComponent(domain)}&request=${callType}&port=${port}`;
61+
62+
// Fetch data
63+
fetch(url)
64+
.then(response => {
65+
if (!response.ok) {
66+
throw new Error(`HTTP error: ${response.status}`);
67+
}
68+
return response.json();
69+
})
70+
.then(data => {
71+
// Clear loading indicator
72+
document.getElementById('loading').innerHTML = '';
73+
74+
// Build table with data
75+
buildTable(data, callType);
76+
})
77+
.catch(error => {
78+
// Handle error
79+
document.getElementById('loading').innerHTML = '';
80+
document.getElementById('txtHint').innerHTML = `Error: ${error.message}. Please try again.`;
81+
});
7982
}
8083

81-
function buildTable(jsonResp, callType) {
82-
var requestNum = Date.now();
83-
if (jsonResp.length == 0) {
84-
$(".responseTable").prepend("<div class = 'responseRow" + requestNum + "'><table></table></div>");
85-
$(".responseRow" + requestNum + " Table").append("<tr><td colspan='2' class='thead'>" + requestTitle(callType) + "</td></tr>");
86-
$(".responseRow" + requestNum + " Table").append("<tr><td colspan='2' style='text-align:center'>NO DATA FOUND</td></tr>");
87-
} else {
84+
// Create loading spinner template
85+
function createLoadingTemplate() {
86+
return `
87+
<div class="sk-three-bounce">
88+
<div class="sk-child sk-bounce1"></div>
89+
<div class="sk-child sk-bounce2"></div>
90+
<div class="sk-child sk-bounce3"></div>
91+
</div>
92+
`;
93+
}
8894

89-
//creates thes the table to store the response details each table has a unique class
90-
$(".responseTable").prepend("<div class = 'responseRow" + requestNum + "'><table></table></div>");
91-
//Creates title bar
92-
$(".responseRow" + requestNum + " Table").append("<tr><td colspan='2' class='thead'>" + requestTitle(callType) + "</td></tr>");
95+
// Create table header template
96+
function createTableHeaderTemplate(title) {
97+
return `
98+
<tr>
99+
<td class="thead" colspan="2">${title}</td>
100+
</tr>
101+
`;
102+
}
93103

94-
for (i = 0, len = jsonResp.length; i < len; i++) {
95-
var jsonData = jsonResp[i];
104+
// Create no data template
105+
function createNoDataTemplate() {
106+
return `
107+
<tr>
108+
<td colspan="2" style="text-align: center;">NO DATA FOUND</td>
109+
</tr>
110+
`;
111+
}
112+
113+
// Create data row template
114+
function createDataRowTemplate(key, value, isBlacklist) {
115+
const displayValue = isBlacklist ? value : cleanString(String(value));
116+
return `
117+
<tr class="twoCol">
118+
<td class="left-row">${key}:</td>
119+
<td>${displayValue}</td>
120+
</tr>
121+
`;
122+
}
96123

97-
if (i != 0) {$(".responseRow" + (requestNum-1)).append("<Div class = 'responseRow" + requestNum + "'><table></table></div>");}
98-
//iterates through object keys
99-
if(callType === "blacklist.php"){
100-
for (j = 0, len2 = Object.keys(jsonData).length; j < len2; j++) {
101-
$(".responseRow" + requestNum + " Table").append("<tr class='twoCol'><td class='left-row'>" + Object.getOwnPropertyNames(jsonData)[j] + ":</td><td>" + jsonData[Object.keys(jsonData)[j]] + "</td></tr>");
102-
}
124+
// Build results table with templating
125+
function buildTable(jsonResp, callType) {
126+
// Generate unique ID for this result set
127+
const resultId = Date.now();
128+
const responseTable = document.querySelector('.responseTable');
129+
130+
// Create result row container
131+
const resultRow = document.createElement('div');
132+
resultRow.className = 'responseRow' + resultId;
133+
134+
// Check if results exist
135+
if (!jsonResp || jsonResp.length === 0) {
136+
resultRow.innerHTML = `
137+
<table>
138+
${createTableHeaderTemplate(requestTitle(callType))}
139+
${createNoDataTemplate()}
140+
</table>
141+
`;
142+
} else {
143+
// Process results with templating
144+
let tableHtml = '';
145+
146+
jsonResp.forEach((jsonData, index) => {
147+
// Create HTML for each result object
148+
if (index === 0) {
149+
// First result goes in the main table
150+
tableHtml = `<table>${createTableHeaderTemplate(requestTitle(callType))}`;
151+
152+
// Add data rows
153+
Object.entries(jsonData).forEach(([key, value]) => {
154+
tableHtml += createDataRowTemplate(key, value, callType === 'blacklist.php');
155+
});
103156

157+
tableHtml += '</table>';
104158
} else {
105-
for (j = 0, len2 = Object.keys(jsonData).length; j < len2; j++) {
106-
$(".responseRow" + requestNum + " Table").append("<tr class='twoCol'><td class='left-row'>" + Object.getOwnPropertyNames(jsonData)[j] + ":</td><td>" + cleanString(jsonData[Object.keys(jsonData)[j]].toString()) + "</td></tr>");
107-
}
159+
// Additional results get their own tables
160+
tableHtml += `
161+
<div class="responseRow${resultId + index}">
162+
<table>
163+
${createTableHeaderTemplate(requestTitle(callType) + ' (continued)')}
164+
`;
165+
166+
// Add data rows
167+
Object.entries(jsonData).forEach(([key, value]) => {
168+
tableHtml += createDataRowTemplate(key, value, callType === 'blacklist.php');
169+
});
170+
171+
tableHtml += '</table></div>';
108172
}
109-
requestNum++;
110-
}
111-
173+
});
174+
175+
resultRow.innerHTML = tableHtml;
112176
}
177+
178+
// Add the new result to the top of the results area
179+
responseTable.insertBefore(resultRow, responseTable.firstChild);
180+
181+
// Scroll to the results
182+
resultRow.scrollIntoView({ behavior: 'smooth', block: 'start' });
113183
}
114184

185+
// Sanitize strings to prevent XSS
115186
function cleanString(data) {
116187
return data
117188
.replace(/&/g, "&amp;")
118189
.replace(/</g, "&lt;")
119190
.replace(/>/g, "&gt;")
120191
.replace(/"/g, "&quot;")
121192
.replace(/'/g, "&#039;");
122-
}
123-
124-
}
193+
}
194+
});
125195

196+
// Show/hide port input field based on selection
126197
function showAdditionalFields() {
127-
if(document.getElementById("file").value === 'port') {
128-
document.getElementById("port-container").style.visibility="visible" ;
198+
const fileSelect = document.getElementById('file');
199+
const portContainer = document.getElementById('port-container');
200+
201+
if (fileSelect.value === 'port') {
202+
portContainer.style.visibility = 'visible';
203+
document.getElementById('port').focus();
129204
} else {
130-
document.getElementById("port-container").style.visibility="hidden";
205+
portContainer.style.visibility = 'hidden';
131206
}
132-
}
207+
}

libraries/bootstrap/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

libraries/bootstrap/bootstrap.min.css

Lines changed: 0 additions & 7 deletions
This file was deleted.

libraries/bootstrap/bootstrap.min.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

libraries/jquery/LICENSE.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

libraries/jquery/jquery-3.2.1.slim.min.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

libraries/popper/LICENSE

Lines changed: 0 additions & 25 deletions
This file was deleted.

libraries/popper/popper.min.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)