(envConfig)
| 40 | |
| 41 | /* eslint-disable-next-line no-unused-vars */ |
| 42 | export default function utilitiesRouter(envConfig) { |
| 43 | router.route('/utilities/whois') |
| 44 | /** |
| 45 | * Do a local Whois loookup. |
| 46 | */ |
| 47 | .get(function (req, res) { |
| 48 | res.setHeader('Content-Type', 'application/json'); |
| 49 | |
| 50 | if (!is_valid_strings(req.query)) { |
| 51 | res.status(400).json({ 'message': 'Multiple query parameters are not allowed.' }); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | let domain = req.query.domain; |
| 56 | if (!domain) { |
| 57 | res.status(400).send("{'Error': 'Please send a domain!'}"); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | const whois = require('whois'); |
| 62 | let whoisObject = { |
| 63 | 'server': '', // this can be a string ('host:port') or an object with host and port as its keys; leaving it empty makes lookup rely on servers.json |
| 64 | 'follow': 2, // number of times to follow redirects |
| 65 | 'timeout': 0, // socket timeout, excluding this doesn't override any default timeout value |
| 66 | 'verbose': false, // setting this to true returns an array of responses from all servers |
| 67 | }; |
| 68 | |
| 69 | whois.lookup(domain, whoisObject, function (err, data) { |
| 70 | if (!err) { |
| 71 | let myEscapedJSONString = data.replace(/[\\]/g, '\\\\') |
| 72 | .replace(/"/g, '\\"') |
| 73 | .replace(/\//g, '\\/') |
| 74 | .replace(/[\b]/g, '\\b') |
| 75 | .replace(/[\f]/g, '\\f') |
| 76 | .replace(/[\n]/g, '\\n') |
| 77 | .replace(/[\r]/g, '\\r') |
| 78 | .replace(/[\t]/g, '\\t'); |
| 79 | res.status(200).json({ 'result': myEscapedJSONString }); |
| 80 | } else { |
| 81 | res.status(500).send(err); |
| 82 | } |
| 83 | }); |
| 84 | }); |
| 85 | |
| 86 | router.route('/utilities/nslookup') |
| 87 | /** |
| 88 | * Do a local nslookup. |
| 89 | * This should be upgraded to use Google DNS over HTTPS. |
| 90 | */ |
| 91 | .get(function (req, res) { |
| 92 | |
| 93 | if (!is_valid_strings(req.query)) { |
| 94 | res.status(400).json({ 'message': 'Multiple query parameters are not allowed.' }); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | let domain = req.query.target; |
| 99 | if (!domain) { |
no test coverage detected