This repository has been archived by the owner on May 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 257
/
dns_server.js
48 lines (36 loc) · 1.59 KB
/
dns_server.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
41
42
43
44
45
46
47
48
// Generated by CoffeeScript 1.6.2
(function() {
var DnsServer, NS_C_IN, NS_RCODE_NXDOMAIN, NS_T_A, dnsserver,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
dnsserver = require("dnsserver");
NS_T_A = 1;
NS_C_IN = 1;
NS_RCODE_NXDOMAIN = 3;
module.exports = DnsServer = (function(_super) {
__extends(DnsServer, _super);
function DnsServer(configuration) {
this.configuration = configuration;
this.handleRequest = __bind(this.handleRequest, this);
DnsServer.__super__.constructor.apply(this, arguments);
this.on("request", this.handleRequest);
}
DnsServer.prototype.listen = function(port, callback) {
this.bind(port);
return typeof callback === "function" ? callback() : void 0;
};
DnsServer.prototype.handleRequest = function(req, res) {
var pattern, q, _ref;
pattern = this.configuration.dnsDomainPattern;
q = (_ref = req.question) != null ? _ref : {};
if (q.type === NS_T_A && q["class"] === NS_C_IN && pattern.test(q.name)) {
res.addRR(q.name, NS_T_A, NS_C_IN, 600, "127.0.0.1");
} else {
res.header.rcode = NS_RCODE_NXDOMAIN;
}
return res.send();
};
return DnsServer;
})(dnsserver.Server);
}).call(this);