feat: add frontend
This commit is contained in:
parent
4a723d75d3
commit
74b11b8df0
|
@ -1,19 +1,21 @@
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const dns = require('dns');
|
const dns = require('dns');
|
||||||
const swipl = require('swipl');
|
const swipl = require('swipl');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const PORT = 3000
|
const PORT = 3000
|
||||||
|
|
||||||
const spf = (req, res) => {
|
const spf = (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
const { domain } = req.query;
|
const { domain } = req.query;
|
||||||
console.log(domain)
|
console.log(domain)
|
||||||
let spf = ""
|
let spf = ""
|
||||||
dns.resolveTxt(domain, (err, address) => {
|
dns.resolveTxt(domain, (err, address) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("ERROR", err)
|
console.error("ERROR", err)
|
||||||
return res.status(400).send("ERROR: occur on resolving SPF")
|
return res.status(400).json("ERROR: occur on resolving SPF")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(address)
|
console.log(address)
|
||||||
|
@ -28,14 +30,14 @@ const spf = (req, res) => {
|
||||||
}
|
}
|
||||||
if (!spf) {
|
if (!spf) {
|
||||||
console.error("ERROR: not spf")
|
console.error("ERROR: not spf")
|
||||||
return res.status(400).send(`ERROR: No SPF record found in ${domain}`)
|
return res.status(400).json(`ERROR: No SPF record found in ${domain}`)
|
||||||
}
|
}
|
||||||
const spfArray = spf.split(" ");
|
const spfArray = spf.split(" ");
|
||||||
console.log(spfArray)
|
console.log(spfArray)
|
||||||
return parseSPF(domain, spfArray, swipl, domain, (err) => {
|
return parseSPF(domain, spfArray, swipl, domain, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("ERROR", err)
|
console.error("ERROR", err)
|
||||||
return res.status(err.code).send(err.message)
|
return res.status(err.code).json(err.message)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
swipl.call('assert(ip4("_", "_"))');
|
swipl.call('assert(ip4("_", "_"))');
|
||||||
|
@ -63,7 +65,7 @@ const spf = (req, res) => {
|
||||||
query.close();
|
query.close();
|
||||||
swipl.cleanup()
|
swipl.cleanup()
|
||||||
swipl.initialise()
|
swipl.initialise()
|
||||||
return res.status(200).send({spf: spf, allowedIP4: [...new Set(allowedIP4)], allowedIP6: [...new Set(allowedIP6)]})
|
return res.status(200).json({spf: spf, allowedIP4: [...new Set(allowedIP4)], allowedIP6: [...new Set(allowedIP6)]})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -75,15 +77,16 @@ const spf = (req, res) => {
|
||||||
|
|
||||||
const a = (req, res) => {
|
const a = (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
const { domain } = req.query;
|
const { domain } = req.query;
|
||||||
console.log(domain)
|
console.log(domain)
|
||||||
dns.resolve4(domain, (err, address) => {
|
dns.resolve4(domain, (err, address) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
return res.status(400).send("ERROR: No a record found")
|
return res.status(400).json("ERROR: No a record found")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return res.status(200).send(address)
|
return res.status(200).json(address)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -94,15 +97,16 @@ const a = (req, res) => {
|
||||||
|
|
||||||
const mx = (req, res) => {
|
const mx = (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
const { domain } = req.query;
|
const { domain } = req.query;
|
||||||
console.log(domain)
|
console.log(domain)
|
||||||
dns.resolveMx(domain, (err, address) => {
|
dns.resolveMx(domain, (err, address) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
return res.status(400).send("ERROR: No mx record found")
|
return res.status(400).json("ERROR: No mx record found")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return res.status(200).send(address)
|
return res.status(200).json(address)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -329,6 +333,7 @@ const parseSPF = (domain, spf, swipl, curr, callback) => {
|
||||||
app.get('/spf', spf)
|
app.get('/spf', spf)
|
||||||
app.get('/a', a)
|
app.get('/a', a)
|
||||||
app.get('/mx', mx)
|
app.get('/mx', mx)
|
||||||
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
app.listen(PORT, (err) => {
|
app.listen(PORT, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
42
Project/public/index.html
Normal file
42
Project/public/index.html
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<label for="inputText">Enter Domain Name: </label>
|
||||||
|
<input type="text" id="inputText">
|
||||||
|
<button onclick="sendGetRequest()">Send</button>
|
||||||
|
|
||||||
|
<h3>Results: </h3>
|
||||||
|
<h5>a:</h5>
|
||||||
|
<pre id="result1"></pre>
|
||||||
|
<h5>mx: </h5>
|
||||||
|
<pre id="result2"></pre>
|
||||||
|
<h5>spf: </h5>
|
||||||
|
<pre id="result3"></pre>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
async function sendGetRequest() {
|
||||||
|
const inputText = document.getElementById('inputText').value;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await fetch(`/a?domain=${encodeURIComponent(inputText)}`);
|
||||||
|
const result1 = await response1.json();
|
||||||
|
document.getElementById('result1').textContent = JSON.stringify(result1, undefined, 4);
|
||||||
|
|
||||||
|
const response2 = await fetch(`/mx?domain=${encodeURIComponent(inputText)}`);
|
||||||
|
const result2 = await response2.json();
|
||||||
|
document.getElementById('result2').textContent = JSON.stringify(result2, undefined, 4);
|
||||||
|
|
||||||
|
const response3 = await fetch(`/spf?domain=${encodeURIComponent(inputText)}`);
|
||||||
|
const result3 = await response3.json();
|
||||||
|
document.getElementById('result3').textContent = JSON.stringify(result3, undefined, 4);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('ERROR:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user