Compare commits

..

No commits in common. "f479c5550177a0b1b04d85abd2551032cfc88dfd" and "656c803720c74af51345d71f7cc9f196d2c52f12" have entirely different histories.

4 changed files with 6 additions and 123 deletions

View File

@ -256,12 +256,8 @@ module.exports.create = function (cli, engine/*, dnsd*/) {
if ('SOA' === record.type) { if ('SOA' === record.type) {
// TODO be strict about what can be edited // TODO be strict about what can be edited
engine.zones.save(record, function (err/*, record*/) { engine.zones.save(record, function (err, record) {
if (!err) { res.send({ success: true });
res.send({ success: true });
return;
}
res.send({ error: { message: err.message } });
}); });
} else { } else {
engine.records.save(record, function (err, record) { engine.records.save(record, function (err, record) {
@ -269,39 +265,6 @@ module.exports.create = function (cli, engine/*, dnsd*/) {
}); });
} }
}); });
app.delete('/api/records/:id', jsonParser, hasClaim('+rw@adns.org'), function (req, res) {
var id = req.params.id;
engine.records.one(id, function (err, record) {
if (err) {
res.send({ error: { message: err.message } });
return;
}
if (!record) {
res.send({ error: { message: "no record with id '" + id + "' found" } });
return;
}
if ('SOA' === record.type) {
// TODO be strict about what can be edited
engine.zones.destroy(id, function (err, record) {
if (!err) {
res.send(record);
return;
}
res.send({ error: { message: err.message } });
});
} else {
engine.records.destroy(id, function (err, record) {
if (!err) {
res.send(record || { error: { message: "no record with id '" + id + "' found" } });
return;
}
res.send({ error: { message: err.message } });
});
}
});
});
app.use('/', express.static(path.join(__dirname, 'public'))); app.use('/', express.static(path.join(__dirname, 'public')));

View File

@ -48,7 +48,6 @@
<span class="js-record-refresh">{{ refresh }}</span> <span class="js-record-refresh">{{ refresh }}</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
<li class="js-record-a js-record-aaaa"> <li class="js-record-a js-record-aaaa">
<input type="hidden" class="js-record-id" /> <input type="hidden" class="js-record-id" />
@ -57,7 +56,6 @@
<span class="js-record-address">{{ addr }}</span> <span class="js-record-address">{{ addr }}</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
<li class="js-record-aname js-record-cname js-record-ns"> <li class="js-record-aname js-record-cname js-record-ns">
<input type="hidden" class="js-record-id" /> <input type="hidden" class="js-record-id" />
@ -66,7 +64,6 @@
<span class="js-record-data">{{ target }}</span> <span class="js-record-data">{{ target }}</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
<li class="js-record-caa"> <li class="js-record-caa">
<input type="hidden" class="js-record-id" /> <input type="hidden" class="js-record-id" />
@ -76,7 +73,6 @@
<span class="js-record-value">{{ value }}</span> <span class="js-record-value">{{ value }}</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
<li class="js-record-mx"> <li class="js-record-mx">
<input type="hidden" class="js-record-id" /> <input type="hidden" class="js-record-id" />
@ -86,7 +82,6 @@
<span class="js-record-priority">{{ priority }}</span> <span class="js-record-priority">{{ priority }}</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
<li class="js-record-ptr"> <li class="js-record-ptr">
<input type="hidden" class="js-record-id" /> <input type="hidden" class="js-record-id" />
@ -94,7 +89,6 @@
<span class="js-record-name">example.com</span> <span class="js-record-name">example.com</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
<li class="js-record-srv"> <li class="js-record-srv">
<input type="hidden" class="js-record-id" /> <input type="hidden" class="js-record-id" />
@ -104,7 +98,6 @@
<span class="js-record-priority">{{ priority }}</span> <span class="js-record-priority">{{ priority }}</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
<li class="js-record-txt"> <li class="js-record-txt">
<input type="hidden" class="js-record-id" /> <input type="hidden" class="js-record-id" />
@ -113,7 +106,6 @@
<span class="js-record-data">{{ text data }}</span> <span class="js-record-data">{{ text data }}</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
<li class="js-record-typex"> <li class="js-record-typex">
<input type="hidden" class="js-record-id" /> <input type="hidden" class="js-record-id" />
@ -122,7 +114,6 @@
<span class="js-record-rr">{{ hex }}</span> <span class="js-record-rr">{{ hex }}</span>
<span class="js-record-ttl">{{ ttl }}</span> <span class="js-record-ttl">{{ ttl }}</span>
<button type="button" class="js-record-edit">Edit</button> <button type="button" class="js-record-edit">Edit</button>
<button type="button" class="js-record-destroy">X</button>
</li> </li>
</ul> </ul>

View File

@ -391,40 +391,6 @@
}); });
}); });
}); });
$on('button.js-record-destroy', 'click', function (ev) {
console.log('destroy');
var $pel = ev.target.parentElement;
var id = $qs('.js-record-id', $pel).value;
var existingRecord = cache.recordsMap[id];
return window.fetch(
'/api/records/' + id
, { method: 'DELETE'
, headers: new window.Headers({
'Authorization': 'Bearer ' + auth
, 'Content-Type': 'application/json;charset=UTF-8'
})
}
).then(function (resp) {
return resp.json().then(function (data) {
if (data.error) {
console.error(data);
window.alert(data.error.message);
return;
}
delete cache.recordsMap[id];
cache.records.some(function (r, i) {
if (r === existingRecord) {
cache.records.splice(i, 1);
return true;
}
});
renderRecords();
console.log('result:', data);
});
});
});
$qs('select.js-record-form-type').value = ''; $qs('select.js-record-form-type').value = '';
// Create a new 'change' event and dispatch it. // Create a new 'change' event and dispatch it.

View File

@ -4,10 +4,6 @@ module.exports.create = function (opts) {
// opts = { filepath }; // opts = { filepath };
var engine = { db: null }; var engine = { db: null };
function notDeleted(r) {
return !r.revokedAt && !r.deletedAt;
}
var db = require(opts.filepath); var db = require(opts.filepath);
var stat = require('fs').statSync(opts.filepath); var stat = require('fs').statSync(opts.filepath);
var crypto = require('crypto'); var crypto = require('crypto');
@ -109,7 +105,7 @@ module.exports.create = function (opts) {
engine.zones = { engine.zones = {
all: function (cb) { all: function (cb) {
process.nextTick(function () { process.nextTick(function () {
cb(null, db.zones.slice(0).filter(notDeleted)); cb(null, db.zones.slice(0));
}); });
} }
, get: function (queries, cb) { , get: function (queries, cb) {
@ -120,7 +116,7 @@ module.exports.create = function (opts) {
} }
var myDomains = db.zones.filter(function (d) { var myDomains = db.zones.filter(function (d) {
return queries.some(function (q) { return queries.some(function (q) {
return (d.name.toLowerCase() === q.name) && notDeleted(d); return d.name.toLowerCase() === q.name;
}); });
}); });
process.nextTick(function () { process.nextTick(function () {
@ -195,22 +191,7 @@ module.exports.create = function (opts) {
engine.records = { engine.records = {
all: function (cb) { all: function (cb) {
process.nextTick(function () { process.nextTick(function () {
cb(null, db.records.slice(0).filter(notDeleted)); cb(null, db.records.slice(0));
});
}
, one: function (id, cb) {
var myRecord;
db.records.slice(0).some(function (r) {
if (id && id === r.id) {
if (notDeleted(r)) {
myRecord = r;
return true;
}
return false;
}
});
process.nextTick(function () {
cb(null, myRecord);
}); });
} }
, get: function (query, cb) { , get: function (query, cb) {
@ -223,9 +204,7 @@ module.exports.create = function (opts) {
// TODO use IN in masterquest (or implement OR) // TODO use IN in masterquest (or implement OR)
// Only return single-level wildcard? // Only return single-level wildcard?
if (query.name === r.name || ('*.' + query.name.split('.').slice(1).join('.')) === r.name) { if (query.name === r.name || ('*.' + query.name.split('.').slice(1).join('.')) === r.name) {
if (notDeleted(r)) { return true;
return true;
}
} }
}); });
process.nextTick(function () { process.nextTick(function () {
@ -311,22 +290,6 @@ module.exports.create = function (opts) {
cb(err, record); cb(err, record);
}); });
} }
, destroy: function (id, cb) {
var record;
db.records.some(function (r/*, i*/) {
if (id === r.id) {
record = r;
r.deletedAt = Date.now();
//record = db.records.splice(i, 1);
return true;
}
});
process.nextTick(function () {
db.save(function (err) {
cb(err, record);
});
});
}
}; };
return engine; return engine;