Compare commits
No commits in common. "f479c5550177a0b1b04d85abd2551032cfc88dfd" and "656c803720c74af51345d71f7cc9f196d2c52f12" have entirely different histories.
f479c55501
...
656c803720
39
lib/httpd.js
39
lib/httpd.js
@ -256,12 +256,8 @@ module.exports.create = function (cli, engine/*, dnsd*/) {
|
||||
|
||||
if ('SOA' === record.type) {
|
||||
// TODO be strict about what can be edited
|
||||
engine.zones.save(record, function (err/*, record*/) {
|
||||
if (!err) {
|
||||
engine.zones.save(record, function (err, record) {
|
||||
res.send({ success: true });
|
||||
return;
|
||||
}
|
||||
res.send({ error: { message: err.message } });
|
||||
});
|
||||
} else {
|
||||
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')));
|
||||
|
||||
|
@ -48,7 +48,6 @@
|
||||
<span class="js-record-refresh">{{ refresh }}</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
<li class="js-record-a js-record-aaaa">
|
||||
<input type="hidden" class="js-record-id" />
|
||||
@ -57,7 +56,6 @@
|
||||
<span class="js-record-address">{{ addr }}</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
<li class="js-record-aname js-record-cname js-record-ns">
|
||||
<input type="hidden" class="js-record-id" />
|
||||
@ -66,7 +64,6 @@
|
||||
<span class="js-record-data">{{ target }}</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
<li class="js-record-caa">
|
||||
<input type="hidden" class="js-record-id" />
|
||||
@ -76,7 +73,6 @@
|
||||
<span class="js-record-value">{{ value }}</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
<li class="js-record-mx">
|
||||
<input type="hidden" class="js-record-id" />
|
||||
@ -86,7 +82,6 @@
|
||||
<span class="js-record-priority">{{ priority }}</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
<li class="js-record-ptr">
|
||||
<input type="hidden" class="js-record-id" />
|
||||
@ -94,7 +89,6 @@
|
||||
<span class="js-record-name">example.com</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
<li class="js-record-srv">
|
||||
<input type="hidden" class="js-record-id" />
|
||||
@ -104,7 +98,6 @@
|
||||
<span class="js-record-priority">{{ priority }}</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
<li class="js-record-txt">
|
||||
<input type="hidden" class="js-record-id" />
|
||||
@ -113,7 +106,6 @@
|
||||
<span class="js-record-data">{{ text data }}</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
<li class="js-record-typex">
|
||||
<input type="hidden" class="js-record-id" />
|
||||
@ -122,7 +114,6 @@
|
||||
<span class="js-record-rr">{{ hex }}</span>
|
||||
<span class="js-record-ttl">{{ ttl }}</span>
|
||||
<button type="button" class="js-record-edit">Edit</button>
|
||||
<button type="button" class="js-record-destroy">X</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
@ -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 = '';
|
||||
// Create a new 'change' event and dispatch it.
|
||||
|
@ -4,10 +4,6 @@ module.exports.create = function (opts) {
|
||||
// opts = { filepath };
|
||||
var engine = { db: null };
|
||||
|
||||
function notDeleted(r) {
|
||||
return !r.revokedAt && !r.deletedAt;
|
||||
}
|
||||
|
||||
var db = require(opts.filepath);
|
||||
var stat = require('fs').statSync(opts.filepath);
|
||||
var crypto = require('crypto');
|
||||
@ -109,7 +105,7 @@ module.exports.create = function (opts) {
|
||||
engine.zones = {
|
||||
all: function (cb) {
|
||||
process.nextTick(function () {
|
||||
cb(null, db.zones.slice(0).filter(notDeleted));
|
||||
cb(null, db.zones.slice(0));
|
||||
});
|
||||
}
|
||||
, get: function (queries, cb) {
|
||||
@ -120,7 +116,7 @@ module.exports.create = function (opts) {
|
||||
}
|
||||
var myDomains = db.zones.filter(function (d) {
|
||||
return queries.some(function (q) {
|
||||
return (d.name.toLowerCase() === q.name) && notDeleted(d);
|
||||
return d.name.toLowerCase() === q.name;
|
||||
});
|
||||
});
|
||||
process.nextTick(function () {
|
||||
@ -195,22 +191,7 @@ module.exports.create = function (opts) {
|
||||
engine.records = {
|
||||
all: function (cb) {
|
||||
process.nextTick(function () {
|
||||
cb(null, db.records.slice(0).filter(notDeleted));
|
||||
});
|
||||
}
|
||||
, 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);
|
||||
cb(null, db.records.slice(0));
|
||||
});
|
||||
}
|
||||
, get: function (query, cb) {
|
||||
@ -223,10 +204,8 @@ module.exports.create = function (opts) {
|
||||
// TODO use IN in masterquest (or implement OR)
|
||||
// Only return single-level wildcard?
|
||||
if (query.name === r.name || ('*.' + query.name.split('.').slice(1).join('.')) === r.name) {
|
||||
if (notDeleted(r)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
process.nextTick(function () {
|
||||
cb(null, myRecords);
|
||||
@ -311,22 +290,6 @@ module.exports.create = function (opts) {
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user