From b0a12260ea25dea102b8d9bd1daaf5125ff3c10a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 1 Feb 2018 11:10:55 -0700 Subject: [PATCH] WIP authority vs regular records, fix query param --- lib/httpd.js | 4 +++- lib/public/js/app.js | 50 ++++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/httpd.js b/lib/httpd.js index 3218ff3..7594286 100644 --- a/lib/httpd.js +++ b/lib/httpd.js @@ -98,7 +98,7 @@ module.exports.create = function (cli, engine/*, dnsd*/) { } app.use('/api', function (req, res, next) { - var auth = (req.headers.authorization || req.query.token || '').split(/\s+/)[1]; + var auth = ((req.headers.authorization || '').split(/\s+/)[1] || req.query.access_token); var token; if (!auth) { @@ -200,6 +200,7 @@ module.exports.create = function (cli, engine/*, dnsd*/) { function mapRecord(r) { return { id: r.id + , soa: r.soa , zone: r.zone , name: r.name , tld: r.tld @@ -228,6 +229,7 @@ module.exports.create = function (cli, engine/*, dnsd*/) { var zone = engine.zones._toSoa(zones[0]); zone.class = zone.className; zone.type = zone.typeName; + zone.soa = true; engine.records.all(function (err, records) { records = records.filter(function (r) { return r.zone === zonename; diff --git a/lib/public/js/app.js b/lib/public/js/app.js index 1b8b629..449d2f5 100644 --- a/lib/public/js/app.js +++ b/lib/public/js/app.js @@ -160,6 +160,9 @@ console.log('tpls.recordsMap:'); console.log(tpls.recordsMap); cache.records.forEach(function (record) { + if (record.soa) { + return; + } el = document.createElement('div'); console.log('record.type:', record.type); el.innerHTML = tpls.recordsMap[record.type.toLowerCase()]; @@ -288,15 +291,27 @@ }); $qs('.js-zone-form-tpl .js-recordx-primary').value = 'nsx.' + zone; } - function openZoneForm() { + function openZoneForm(myZone, ns) { var d = new Date(); - myZone = $qs('.js-zone-form-name').value; + var zone = { + name: myZone.name || myZone + , admin: myZone.admin || ('admin.' + myZone) + , expiration: myZone.expiration || 2419200 // 4 weeks + , minimum: myZone.expiration || 5 + , serial: myZone.serial || (d.getFullYear() + + '' + (d.getMonth() + 1) + + '' + d.getDate() + + '' + (Math.round(Math.random() * 99))) + , retry: myZone.retry || 1800 + , refresh: myZone.refresh || 7200 + , ttl: myZone.ttl || 300 + }; $qs('.js-zone-form-tpl').innerHTML = tpls.newZone; - cache.peers.forEach(function () { + ns.forEach(function () { $qs('.js-zone-form-vns-tpl').innerHTML += tpls.newNs; }); - cache.peers.forEach(function (p, i) { + ns.forEach(function (p, i) { var $vns = $qsa('.js-zone-form-tpl .js-zone-form-vns')[i]; $qs('.js-record-host', $vns).value = 'ns' + (i + 1); //$qs('.js-record-name', $vns).value = 'ns' + (i + 1) + '.' + myZone; @@ -307,18 +322,9 @@ $qs('.js-record-ttl', $vns).value = 7200; }); - $qs('.js-zone-form-tpl .js-record-name').value = myZone; - $qs('.js-zone-form-tpl .js-record-admin').value = 'admin.' + myZone; - $qs('.js-zone-form-tpl .js-record-expiration').value = 2419200; // 4 weeks - $qs('.js-zone-form-tpl .js-record-minimum').value = 5; - $qs('.js-zone-form-tpl .js-recordx-serial').value = d.getFullYear() - + '' + (d.getMonth() + 1) - + '' + d.getDate() - + '' + (Math.round(Math.random() * 99)) - ; - $qs('.js-zone-form-tpl .js-record-retry').value = 1800; - $qs('.js-zone-form-tpl .js-record-refresh').value = 7200; - $qs('.js-zone-form-tpl .js-record-ttl').value = 300; + [ 'name', 'admin', 'expiration', 'minimum', 'serial', 'retry', 'refresh', 'ttl' ].forEach(function (key) { + $qs('.js-zone-form-tpl .js-record-' + key).value = zone[key]; + }); $qs('input.js-zone-form-vanityns').dispatchEvent(new Event('change', { bubbles: true })); @@ -338,16 +344,20 @@ ev.preventDefault(); ev.stopPropagation(); console.log('form submit enter'); - openZoneForm(); + var myZone = $qs('.js-zone-form-name').value; + openZoneForm(myZone, cache.peers); }); $on('button.js-zone-new', 'click', function (/*ev*/) { //$qs('select.js-record-form-type').value = 'SOA'; //$qs('select.js-record-form-type').dispatchEvent(new Event('change', { bubbles: true })); console.log('form submit click'); - openZoneForm(); + var myZone = $qs('.js-zone-form-name').value; + openZoneForm(myZone, cache.peers); }); - $on('button.js-zone-edit', 'click', function (/*ev*/) { - openZoneForm(); + $on('button.js-zone-edit', 'click', function (ev) { + //var zoneId = ev.target.parentElement.dataset.id; + var zoneName = ev.target.parentElement.dataset.name; + openZoneForm(zoneName, cache.peers); }); $on('button.js-zone-save', 'click', function (/*ev*/) { var zone = {};