WIP edit records
This commit is contained in:
		
							parent
							
								
									4f5f330862
								
							
						
					
					
						commit
						7118cb6852
					
				@ -276,7 +276,7 @@ module.exports.query = function (engine, query, cb) {
 | 
			
		||||
    var qarr = qname.split('.');
 | 
			
		||||
    var qnames = [];
 | 
			
		||||
    while (qarr.length) {
 | 
			
		||||
      qnames.push(qarr.join('.').toLowerCase());
 | 
			
		||||
      qnames.push({ name: qarr.join('.').toLowerCase() });
 | 
			
		||||
      qarr.shift(); // first
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -286,7 +286,7 @@ module.exports.query = function (engine, query, cb) {
 | 
			
		||||
    console.log(qnames);
 | 
			
		||||
 | 
			
		||||
    // getSoas
 | 
			
		||||
    return engine.zones.get({ names: qnames }, function (err, myDomains) {
 | 
			
		||||
    return engine.zones.get(qnames, function (err, myDomains) {
 | 
			
		||||
      console.log('[SOA] looking for', qnames, 'and proudly serving', err, myDomains);
 | 
			
		||||
      if (err) { cb(err); return; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -43,19 +43,7 @@
 | 
			
		||||
        <span class="js-record-retry">{{ retry }}</span>
 | 
			
		||||
        <span class="js-record-refresh">{{ refresh }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-custom">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">type000</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-rr">{{ hex }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-any">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">ANY</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-a js-record-aaaa">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
@ -63,6 +51,7 @@
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-address">{{ addr }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-aname js-record-cname js-record-ns">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
@ -70,6 +59,7 @@
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-data">{{ target }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-caa">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
@ -78,6 +68,7 @@
 | 
			
		||||
        <span class="js-record-flag">{{ flag }}</span>
 | 
			
		||||
        <span class="js-record-value">{{ value }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-mx">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
@ -86,12 +77,14 @@
 | 
			
		||||
        <span class="js-record-exchange">{{ target }}</span>
 | 
			
		||||
        <span class="js-record-priority">{{ priority }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-ptr">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">PTR</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-srv">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
@ -100,6 +93,7 @@
 | 
			
		||||
        <span class="js-record-port">{{ port }}</span>
 | 
			
		||||
        <span class="js-record-priority">{{ priority }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li class="js-record-txt">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
@ -107,88 +101,110 @@
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-data">{{ text data }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
    </ul>
 | 
			
		||||
 | 
			
		||||
    <div class="js-record-form-tpl">
 | 
			
		||||
      <form class="js-record-form-soa">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">SOA</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-primary">{{ primary }}</span>
 | 
			
		||||
        <span class="js-record-admin">admin.example.com</span>
 | 
			
		||||
        <span class="js-record-expiration">{{ seconds until expiration }}</span>
 | 
			
		||||
        <span class="js-record-minimum">{{ minimum }}</span>
 | 
			
		||||
        <span class="js-record-serial">{{ serial }}</span>
 | 
			
		||||
        <span class="js-record-retry">{{ retry }}</span>
 | 
			
		||||
        <span class="js-record-refresh">{{ refresh }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-custom">
 | 
			
		||||
      <li class="js-record-typex">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">type000</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-rr">{{ hex }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-any">
 | 
			
		||||
        <button type="button" class="js-record-edit">Edit</button>
 | 
			
		||||
      </li>
 | 
			
		||||
    </ul>
 | 
			
		||||
 | 
			
		||||
    <label>Select Type:</label>
 | 
			
		||||
    <select class="js-record-form-type">
 | 
			
		||||
      <option value="" selected disabled>Record Type</option>
 | 
			
		||||
      <option value="soa">SOA</option>
 | 
			
		||||
      <option value="ns">NS</option>
 | 
			
		||||
      <option value="a">A</option>
 | 
			
		||||
      <option value="aaaa">AAAA</option>
 | 
			
		||||
      <option value="aname">ANAME</option>
 | 
			
		||||
      <option value="cname">CNAME</option>
 | 
			
		||||
      <option value="caa">CAA</option>
 | 
			
		||||
      <option value="mx">MX</option>
 | 
			
		||||
      <option value="ptr">PTR</option>
 | 
			
		||||
      <option value="srv">SRV</option>
 | 
			
		||||
      <option value="txt">TXT</option>
 | 
			
		||||
      <option value="typex">typeX</option>
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
    <div class="js-record-form-tpl">
 | 
			
		||||
      <form class="js-record-form-soa">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">ANY</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <span class="js-record-type">SOA</span>
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-primary">
 | 
			
		||||
        <input type="text" class="js-record-admin">
 | 
			
		||||
        <input type="text" class="js-record-expiration">
 | 
			
		||||
        <input type="text" class="js-record-minimum">
 | 
			
		||||
        <input type="text" class="js-record-serial">
 | 
			
		||||
        <input type="text" class="js-record-retry">
 | 
			
		||||
        <input type="text" class="js-record-refresh">
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-a js-record-form-aaaa">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">A / AAAA</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-address">{{ addr }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-address">
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-aname js-record-form-cname js-record-form-ns">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">ANAME / CNAME</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-data">{{ target }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-data">
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-caa">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">CAA</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-flag">{{ flag }}</span>
 | 
			
		||||
        <span class="js-record-value">{{ value }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-flag">
 | 
			
		||||
        <input type="text" class="js-record-value">
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-mx">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">MX</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-exchange">{{ target }}</span>
 | 
			
		||||
        <span class="js-record-priority">{{ priority }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-exchange">
 | 
			
		||||
        <input type="text" class="js-record-priority">
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-ptr">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">PTR</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-srv">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">SRV</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-port">{{ port }}</span>
 | 
			
		||||
        <span class="js-record-priority">{{ priority }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-port">
 | 
			
		||||
        <input type="text" class="js-record-priority">
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
      <form class="js-record-form-txt">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <span class="js-record-type">TXT</span>
 | 
			
		||||
        <span class="js-record-name">example.com</span>
 | 
			
		||||
        <span class="js-record-data">{{ text data }}</span>
 | 
			
		||||
        <span class="js-record-ttl">{{ ttl }}</span>
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-data">
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
    </ul>
 | 
			
		||||
      <form class="js-record-form-typex">
 | 
			
		||||
        <input type="hidden" class="js-record-id" />
 | 
			
		||||
        <label>typeX</label>
 | 
			
		||||
        <input type="number" class="js-record-type" value="0x0000" />
 | 
			
		||||
        <input type="text" class="js-record-host">.<span class="js-record-zone">example.com</span>
 | 
			
		||||
        <input type="text" class="js-record-rr">
 | 
			
		||||
        <input type="text" class="js-record-ttl">
 | 
			
		||||
      </form>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <script src="/js/app.js"></script>
 | 
			
		||||
  </body>
 | 
			
		||||
</html>
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,8 @@
 | 
			
		||||
(function () {
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
  var cache = { recordsMap: {} };
 | 
			
		||||
 | 
			
		||||
  if (!Element.prototype.matches) {
 | 
			
		||||
    Element.prototype.matches = Element.prototype.msMatchesSelector;
 | 
			
		||||
  }
 | 
			
		||||
@ -131,6 +133,8 @@
 | 
			
		||||
    , headers: new window.Headers({ 'Authorization': 'Bearer ' + auth })
 | 
			
		||||
    }).then(function (resp) {
 | 
			
		||||
      return resp.json().then(function (data) {
 | 
			
		||||
        cache.records = data.records;
 | 
			
		||||
 | 
			
		||||
        var tpl = '';
 | 
			
		||||
        var el;
 | 
			
		||||
        if (!tpls.recordsMap) {
 | 
			
		||||
@ -138,7 +142,6 @@
 | 
			
		||||
          //.innerHTML;
 | 
			
		||||
          tpls.recordsMap = {};
 | 
			
		||||
          tpls.recordsMap.soa = $qs('.js-record-soa').outerHTML;
 | 
			
		||||
          tpls.recordsMap.any = $qs('.js-record-any').outerHTML;
 | 
			
		||||
          tpls.recordsMap.ns = $qs('.js-record-ns').outerHTML;
 | 
			
		||||
          tpls.recordsMap.a = $qs('.js-record-a').outerHTML;
 | 
			
		||||
          tpls.recordsMap.aaaa = $qs('.js-record-aaaa').outerHTML;
 | 
			
		||||
@ -149,22 +152,30 @@
 | 
			
		||||
          tpls.recordsMap.mx = $qs('.js-record-mx').outerHTML;
 | 
			
		||||
          tpls.recordsMap.txt = $qs('.js-record-txt').outerHTML;
 | 
			
		||||
          tpls.recordsMap.srv = $qs('.js-record-srv').outerHTML;
 | 
			
		||||
          //tpls.recordsMap.typex = $qs('.js-record-typex').outerHTML;
 | 
			
		||||
        }
 | 
			
		||||
        console.log('tpls.recordsMap:');
 | 
			
		||||
        console.log(tpls.recordsMap);
 | 
			
		||||
        data.records.forEach(function (record) {
 | 
			
		||||
        cache.records.forEach(function (record) {
 | 
			
		||||
          el = document.createElement('div');
 | 
			
		||||
          console.log('record.type:');
 | 
			
		||||
          console.log(record.type);
 | 
			
		||||
          el.innerHTML = tpls.recordsMap[record.type.toLowerCase()];
 | 
			
		||||
          console.log(el);
 | 
			
		||||
          console.log($qs('.js-record-name', el));
 | 
			
		||||
          var xid = '';
 | 
			
		||||
          Object.keys(record).forEach(function (key) {
 | 
			
		||||
            var x = $qs('.js-record-' + key, el);
 | 
			
		||||
            if (x) {
 | 
			
		||||
              xid += record[key];
 | 
			
		||||
              x.innerText = record[key];
 | 
			
		||||
            }
 | 
			
		||||
          });
 | 
			
		||||
          record.id = record.id || xid;
 | 
			
		||||
          el.dataset.recordId = record.id;
 | 
			
		||||
          $qs('input.js-record-id', el).value = record.id;
 | 
			
		||||
          cache.recordsMap[record.id] = record;
 | 
			
		||||
 | 
			
		||||
          //$qs('.js-record-type', el).innerText = record.type;
 | 
			
		||||
          //$qs('.js-record-name', el).innerText = record.name;
 | 
			
		||||
          //$qs('.js-record-address', el).innerText = record.address;
 | 
			
		||||
@ -212,4 +223,37 @@
 | 
			
		||||
    });*/
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $on('select.js-record-form-type', 'change', function (ev) {
 | 
			
		||||
    var type = ev.target.value;
 | 
			
		||||
    console.log("form type:", type);
 | 
			
		||||
    if (!tpls.formsMap) {
 | 
			
		||||
      tpls.formsMap = {};
 | 
			
		||||
      tpls.formsMap.soa = $qs('.js-record-form-soa').outerHTML;
 | 
			
		||||
      tpls.formsMap.ns = $qs('.js-record-form-ns').outerHTML;
 | 
			
		||||
      tpls.formsMap.a = $qs('.js-record-form-a').outerHTML;
 | 
			
		||||
      tpls.formsMap.aaaa = $qs('.js-record-form-aaaa').outerHTML;
 | 
			
		||||
      tpls.formsMap.aname = $qs('.js-record-form-aname').outerHTML;
 | 
			
		||||
      tpls.formsMap.caa = $qs('.js-record-form-caa').outerHTML;
 | 
			
		||||
      tpls.formsMap.cname = $qs('.js-record-form-cname').outerHTML;
 | 
			
		||||
      tpls.formsMap.mx = $qs('.js-record-form-mx').outerHTML;
 | 
			
		||||
      tpls.formsMap.ptr = $qs('.js-record-form-ptr').outerHTML;
 | 
			
		||||
      tpls.formsMap.srv = $qs('.js-record-form-srv').outerHTML;
 | 
			
		||||
      tpls.formsMap.txt = $qs('.js-record-form-txt').outerHTML;
 | 
			
		||||
      tpls.formsMap.typex = $qs('.js-record-form-typex').outerHTML;
 | 
			
		||||
    }
 | 
			
		||||
    $qs('.js-record-form-tpl').innerHTML = tpls.formsMap[type] || '';
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $on('button.js-record-edit', 'click', function (ev) {
 | 
			
		||||
    console.log(ev.target);
 | 
			
		||||
    var id = ev.target.parentElement.querySelector('.js-record-id').value;
 | 
			
		||||
    console.log(id);
 | 
			
		||||
    var record = cache.recordsMap[id];
 | 
			
		||||
    console.log(record);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $qs('select.js-record-form-type').value = '';
 | 
			
		||||
  // Create a new 'change' event and dispatch it.
 | 
			
		||||
  $qs('select.js-record-form-type').dispatchEvent(new Event('change', { bubbles: true }));
 | 
			
		||||
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
@ -62,9 +62,16 @@ module.exports.create = function (opts) {
 | 
			
		||||
        cb(null, db.domains.slice(0));
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  , get: function (query, cb) {
 | 
			
		||||
  , get: function (queries, cb) {
 | 
			
		||||
      if (!Array.isArray(queries)) {
 | 
			
		||||
        queries = queries.names.map(function (n) {
 | 
			
		||||
          return { name: n };
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
      var myDomains = db.domains.filter(function (d) {
 | 
			
		||||
        return -1 !== query.names.indexOf(d.id.toLowerCase());
 | 
			
		||||
        return queries.some(function (q) {
 | 
			
		||||
          return d.id.toLowerCase() === q.name;
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
      process.nextTick(function () {
 | 
			
		||||
        cb(null, myDomains);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user