WIP show ADNS data

This commit is contained in:
AJ ONeal 2018-01-10 14:54:08 -07:00
parent 96dd311fc5
commit b2ced1a492
4 changed files with 107 additions and 7 deletions

View File

@ -1,6 +1,6 @@
'use strict';
module.exports.create = function (cli, engine, dnsd) {
module.exports.create = function (cli, engine/*, dnsd*/) {
function runHttp() {
var path = require('path');
@ -10,16 +10,62 @@ module.exports.create = function (cli, engine, dnsd) {
app.use('/', express.static(path.join(__dirname, 'public')));
app.get('/api/peers', function (req, res) {
res.send({ nameservers: [] });
engine.peers.all(function (err, peers) {
res.send({ peers: peers });
});
});
app.get('/api/zones', function (req, res) {
engine.zones.all(function (err, zones) {
res.send({ zones: zones });
});
});
app.get('/api/records/:zone', function (req, res) {
function mapRecord(r) {
return {
id: r.id
, zone: r.zone
, name: r.name
, tld: r.tld
, type: r.type
, class: r.class
, ttl: r.ttl
, data: r.data
, address: r.address
, exchange: r.exchange
, priority: r.priority
, value: r.value
, aname: r.aname
, flag: r.flag
, tag: r.tag
, weight: r.weight
, port: r.port
, target: r.target
};
}
app.get('/api/zones/:zone/records', function (req, res) {
engine.records.all(function (err, records) {
res.send({ records: records });
res.send({ records: records.filter(function (r) {
return r.zone === req.params.zone;
}).map(mapRecord) });
});
});
app.get('/api/records', function (req, res) {
engine.records.all(function (err, records) {
res.send({ records: records.map(mapRecord) });
});
});
app.get('/api/records/:name', function (req, res) {
engine.records.all(function (err, records) {
res.send({ records: records.filter(function (r) {
if (r.name === req.params.name) {
return true;
}
var parts = req.params.name.split('.');
parts.shift();
if ('*.' + parts.join('.') === r.name) {
return true;
}
}).map(mapRecord) });
});
});

View File

@ -1,3 +1,20 @@
<p><a href="/api/peers">/api/peers</p>
<p><a href="/api/zones">/api/zones</p>
<p><a href="/api/records">/api/records/:zone</p>
<!DOCTYPE html>
<html>
<head>
<title>ADNS</title>
</head>
<body>
<p><a href="/api/peers">/api/peers</a></p>
<p><a href="/api/zones">/api/zones</a></p>
<p><a data-href="/api/zones/:zone/records" class="js-zone">/api/zones/<code
class="js-zone">:zone</code>/records</a>
<input class="js-zone"
type="text" placeholder="example.com" /></p>
<p><a href="/api/records">/api/records</a></p>
<p><a data-href="/api/records/:name" class="js-name">/api/records/<code class="js-name">:name</code></a>
<input class="js-name"
type="text" placeholder="example.com"/></p>
<script src="/js/app.js"></script>
</body>
</html>

28
lib/public/js/app.js Normal file
View File

@ -0,0 +1,28 @@
(function () {
'use strict';
function $qs(qs) {
return document.querySelector(qs);
}
document.body.addEventListener('keyup', function (ev) {
console.log('ev.target.tagName:');
console.log(ev.target.tagName);
console.log('/\\bjs-zone\\b/.test(ev.target.className):');
console.log(/\bjs-zone\b/.test(ev.target.className));
if ('INPUT' === ev.target.tagName && /\bjs-zone\b/.test(ev.target.className)) {
$qs('code.js-zone').innerHTML = ev.target.value || ':zone';
// $qs('a.js-zone').setAttribute('data-href', ...)
$qs('a.js-zone').href =
$qs('a.js-zone').dataset.href.replace(/:zone/, ev.target.value || ':zone');
return;
}
if ('INPUT' === ev.target.tagName && /\bjs-name\b/.test(ev.target.className)) {
$qs('code.js-name').innerHTML = ev.target.value || ':name';
$qs('a.js-name').href =
$qs('a.js-name').dataset.href.replace(/:name/, ev.target.value || ':name');
return;
}
});
}());

View File

@ -7,6 +7,15 @@ module.exports.create = function (opts) {
var db = require(opts.filepath);
engine.primaryNameservers = db.primaryNameservers;
engine.peers = {
all: function (cb) {
process.nextTick(function () {
cb(null, db.primaryNameservers.map(function (ns) {
return { name: ns };
}));
});
}
};
engine.zones = {
all: function (cb) {
process.nextTick(function () {