show devices

This commit is contained in:
AJ ONeal 2018-08-20 19:38:58 +00:00
parent 168b2edfd6
commit ec3f626560
3 changed files with 86 additions and 24 deletions

View File

@ -18,37 +18,61 @@
<div v-if="hasAccount">
<h1>Account</h1>
<button v-on:click.prevent.stop="logout()" type="click">Logout</button>
<form v-on:submit.prevent="challengeDns()">
Add a custom domain:
<input v-model="newDomain" placeholder="example.com" type="text" required/>
<button type="submit">Next</button>
</form>
<!-- not yet -->
<!--form v-on:submit.prevent="challengeEmail()">
Authorize another email:
<input v-model="newEmail" placeholder="jon@example.com" type="email" required/>
<button type="submit">Next</button>
</form-->
<h3>Claims</h3>
<p>If your DNS host supports ANAME records, please use those instead of CNAMEs.</p>
<p>If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.</p>
<ol>
<li v-for="claim in claims">
<span>{{ claim.value }}</span>
<br>
<span v-if="'dns' === claim.type">CNAME <span v-if="claim.wildcard">*.</span>{{ claim.value }}: {{ site.deviceDomain }}</span>
<br>
<span v-if="'dns' === claim.type">TXT _claim-challenge.{{ claim.value }}: {{ claim.challenge }}</span>
<br>
<button v-on:click.prevent="checkDns(claim)">Check</button>
</li>
</ol>
<div v-if="claims.length">
<h3>Pending Claims</h3>
<p>If your DNS host supports ANAME records, please use those instead of CNAMEs.</p>
<p>If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.</p>
<ol>
<li v-for="claim in claims">
<span>{{ claim.value }}</span>
<br>
<span v-if="'dns' === claim.type">CNAME <span v-if="claim.wildcard">*.</span>{{ claim.value }}: {{ site.deviceDomain }}</span>
<br>
<span v-if="'dns' === claim.type">TXT _claim-challenge.{{ claim.value }}: {{ claim.challenge }}</span>
<br>
<button v-on:click.prevent="checkDns(claim)">Check</button>
</li>
</ol>
</div>
<h3>Devices</h3>
<div v-if="!devices.length">
You can add up to 5 devices:
<pre><code>curl -sf https://get.telebit.io/ | bash</code></pre>
</div>
<div v-if="devices.length">
<ol>
<li v-for="device in devices">
<span v-if="device.id">{{ device.id }}</span> {{ device.socketId }}
<ol>
<li v-for="name in device.names">{{ name }}</li>
</ol>
</li>
</ol>
</div>
<h3>Domains</h3>
<ol>
<li v-for="domain in domains">
<span v-if="domain.wildcard">*.</span>{{ domain.name }} <span v-if="domain.hostname">- {{domain.hostname}} ({{domain.os}} {{domain.arch}})</span>
</li>
</ol>
<form v-on:submit.prevent="challengeDns()">
Add a custom domain:
<input v-model="newDomain" placeholder="example.com" type="text" required/>
<button type="submit">Next</button>
</form>
<div v-if="domains.length">
<ol>
<li v-for="domain in domains">
<span v-if="domain.wildcard">*.</span>{{ domain.name }} <span v-if="domain.hostname">- {{domain.hostname}} ({{domain.os}} {{domain.arch}})</span>
</li>
</ol>
</div>
<h3>Debug: Token</h3>
<pre><code v-text="token"></code></pre>
</div>

View File

@ -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) {

View File

@ -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;
});
}