From ec3f6265607d09dbe59f537c0699ea7a58cce5ee Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 20 Aug 2018 19:38:58 +0000 Subject: [PATCH] show devices --- lib/extensions/admin/account.html | 72 ++++++++++++++++++++---------- lib/extensions/admin/js/account.js | 2 + lib/extensions/index.js | 36 +++++++++++++++ 3 files changed, 86 insertions(+), 24 deletions(-) diff --git a/lib/extensions/admin/account.html b/lib/extensions/admin/account.html index a8e9d8c..4792923 100644 --- a/lib/extensions/admin/account.html +++ b/lib/extensions/admin/account.html @@ -18,37 +18,61 @@

Account

-
- Add a custom domain: - - -
-

Claims

-

If your DNS host supports ANAME records, please use those instead of CNAMEs.

-

If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.

-
    -
  1. - {{ claim.value }} -
    - CNAME *.{{ claim.value }}: {{ site.deviceDomain }} -
    - TXT _claim-challenge.{{ claim.value }}: {{ claim.challenge }} -
    - -
  2. -
+ +
+

Pending Claims

+

If your DNS host supports ANAME records, please use those instead of CNAMEs.

+

If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.

+
    +
  1. + {{ claim.value }} +
    + CNAME *.{{ claim.value }}: {{ site.deviceDomain }} +
    + TXT _claim-challenge.{{ claim.value }}: {{ claim.challenge }} +
    + +
  2. +
+
+ +

Devices

+
+ You can add up to 5 devices: +
curl -sf https://get.telebit.io/ | bash
+
+
+
    +
  1. + {{ device.id }} {{ device.socketId }} +
      +
    1. {{ name }}
    2. +
    +
  2. +
+
+

Domains

-
    -
  1. - *.{{ domain.name }} - {{domain.hostname}} ({{domain.os}} {{domain.arch}}) -
  2. -
+
+ Add a custom domain: + + +
+
+
    +
  1. + *.{{ domain.name }} - {{domain.hostname}} ({{domain.os}} {{domain.arch}}) +
  2. +
+
+ +

Debug: Token

diff --git a/lib/extensions/admin/js/account.js b/lib/extensions/admin/js/account.js index 61fcd57..85b1fe1 100644 --- a/lib/extensions/admin/js/account.js +++ b/lib/extensions/admin/js/account.js @@ -24,6 +24,7 @@ var vueData = { claims: [] , domains: [] + , devices: [] , newDomain: null , newDomainWildcard: false , newEmail: null @@ -88,6 +89,7 @@ //window.alert("TODO: show authorized devices, domains, and connectivity information"); vueData.hasAccount = true; vueData.domains = data.domains; + vueData.devices = data.devices; vueData.claims = data.claims; } function loadAccount(session) { diff --git a/lib/extensions/index.js b/lib/extensions/index.js index f454e0c..ee247d0 100644 --- a/lib/extensions/index.js +++ b/lib/extensions/index.js @@ -19,6 +19,7 @@ var requestAsync = util.promisify(require('@coolaj86/urequest')); var mkdirpAsync = util.promisify(require('mkdirp')); var TRUSTED_ISSUERS = [ 'oauth3.org' ]; var DB = require('./db.js'); +var Devices = require('../device-tracker'); var Claims = {}; Claims.publicize = function publicizeClaim(claim) { if (!claim) { @@ -779,6 +780,7 @@ app.get('/api/telebit.cloud/account', function (req, res) { var domainsMap = {}; var portsMap = {}; var claimsMap = {}; + var devsMap = {}; var result = JSON.parse(JSON.stringify(acc)); result.domains.length = 0; result.ports.length = 0; @@ -806,6 +808,40 @@ app.get('/api/telebit.cloud/account', function (req, res) { result.claims = Object.keys(claimsMap).map(function (k) { return Claims.publicize(claimsMap[k]); }); + + // TODO assign devices by public key, not domain name + result.domains.map(function (domain) { + console.log("[debug] Domain", domain); + var devs = Devices.list(req._state.deviceLists, domain.name); + console.log("[debug] Devs", devs.map(function (d) { return d.socketId; })); + if (!devs.length) { return null; } + devs.forEach(function (dev) { + // eventually we should implement so that a new connection + // with the same public key results in booting the prior session + // then we could use device.id instead of socketId + if (!devsMap[dev.socketId]) { + devsMap[dev.socketId] = { + id: dev.id + , socketId: dev.socketId + , active: true + , names: [] + }; + } + devsMap[dev.socketId].names.push(domain.name); + return devsMap[dev.socketId]; + }); + }).filter(Boolean); + result.devices = Object.keys(devsMap).map(function (sid) { + return devsMap[sid]; + }); + + // Help the garbage collector out a little + domainsMap = null; + portsMap = null; + claimsMap = null; + devsMap = null; + + // The data is useful! Send it away! return result; }); }