-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (31 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const express = require('express');
const dns = require('dns');
const app = express();
const config = require('./config.json');
const blockList = new Set(config.blockList || []);
app.get('/', (req, res) => {
const domain = req.query.domain;
if (!domain || blockList.has(domain)) {
return res.status(400).send('Disallowed');
}
dns.resolve4(domain, (err, addresses) => {
if (err) {
return res.status(403).send('DNS resolution failed');
}
const predefinedIPs = config.ips;
const subdomainCount = (domain.match(/\./g) || []).length;
if (subdomainCount > config.subdomainAmount) {
return res.status(403).send('Too many subdomains');
}
const isValid = predefinedIPs.some(ip => addresses.includes(ip));
if (isValid) {
return res.status(200).send('DNS is pointing to the predefined IP');
} else {
return res.status(403).send('DNS is not pointing to the predefined IP');
}
});
});
const PORT = config.port || 5555;
app.listen(PORT, () => {
console.log(`TLS check server is running on port ${PORT}`);
});