diff --git a/server/lambda/get-dns.js b/server/lambda/get-dns.js new file mode 100644 index 0000000..6f80ae9 --- /dev/null +++ b/server/lambda/get-dns.js @@ -0,0 +1,59 @@ +const dns = require('dns'); +const util = require('util'); + +exports.handler = async function(event, context) { + let hostname = event.queryStringParameters.url; + + // Handle URLs by extracting hostname + if (hostname.startsWith('http://') || hostname.startsWith('https://')) { + hostname = new URL(hostname).hostname; + } + + try { + const lookupPromise = util.promisify(dns.lookup); + const resolve4Promise = util.promisify(dns.resolve4); + const resolve6Promise = util.promisify(dns.resolve6); + const resolveMxPromise = util.promisify(dns.resolveMx); + const resolveTxtPromise = util.promisify(dns.resolveTxt); + const resolveNsPromise = util.promisify(dns.resolveNs); + const resolveCnamePromise = util.promisify(dns.resolveCname); + const resolveSoaPromise = util.promisify(dns.resolveSoa); + const resolveSrvPromise = util.promisify(dns.resolveSrv); + const resolvePtrPromise = util.promisify(dns.resolvePtr); + + const [a, aaaa, mx, txt, ns, cname, soa, srv, ptr] = await Promise.all([ + lookupPromise(hostname), + resolve4Promise(hostname).catch(() => []), // A record + resolve6Promise(hostname).catch(() => []), // AAAA record + resolveMxPromise(hostname).catch(() => []), // MX record + resolveTxtPromise(hostname).catch(() => []), // TXT record + resolveNsPromise(hostname).catch(() => []), // NS record + resolveCnamePromise(hostname).catch(() => []), // CNAME record + resolveSoaPromise(hostname).catch(() => []), // SOA record + resolveSrvPromise(hostname).catch(() => []), // SRV record + resolvePtrPromise(hostname).catch(() => []) // PTR record + ]); + + return { + statusCode: 200, + body: JSON.stringify({ + A: a, + AAAA: aaaa, + MX: mx, + TXT: txt, + NS: ns, + CNAME: cname, + SOA: soa, + SRV: srv, + PTR: ptr + }) + }; + } catch (error) { + return { + statusCode: 500, + body: JSON.stringify({ + error: error.message + }) + }; + } +}; diff --git a/server/lambda/read-robots-txt.js b/server/lambda/read-robots-txt.js new file mode 100644 index 0000000..2b977fe --- /dev/null +++ b/server/lambda/read-robots-txt.js @@ -0,0 +1,37 @@ +const fetch = require('node-fetch'); + +exports.handler = async function(event, context) { + const siteURL = event.queryStringParameters.url; + + if (!siteURL) { + return { + statusCode: 400, + body: 'Missing URL parameter', + }; + } + + const parsedURL = new URL(siteURL); + const robotsURL = `${parsedURL.protocol}//${parsedURL.hostname}/robots.txt`; + + try { + const response = await fetch(robotsURL); + const text = await response.text(); + + if (response.ok) { + return { + statusCode: 200, + body: text, + }; + } else { + return { + statusCode: response.status, + body: `Failed to fetch robots.txt`, + }; + } + } catch (error) { + return { + statusCode: 500, + body: `Error fetching robots.txt: ${error.toString()}`, + }; + } +};