diff --git a/lib/httpd.js b/lib/httpd.js index 43d3d30..3b53ee4 100644 --- a/lib/httpd.js +++ b/lib/httpd.js @@ -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) }); }); }); diff --git a/lib/public/index.html b/lib/public/index.html index b2f74f5..12b7a3e 100644 --- a/lib/public/index.html +++ b/lib/public/index.html @@ -1,3 +1,20 @@ -
- - + + + +