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,18 +18,15 @@
<div v-if="hasAccount"> <div v-if="hasAccount">
<h1>Account</h1> <h1>Account</h1>
<button v-on:click.prevent.stop="logout()" type="click">Logout</button> <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 --> <!-- not yet -->
<!--form v-on:submit.prevent="challengeEmail()"> <!--form v-on:submit.prevent="challengeEmail()">
Authorize another email: Authorize another email:
<input v-model="newEmail" placeholder="jon@example.com" type="email" required/> <input v-model="newEmail" placeholder="jon@example.com" type="email" required/>
<button type="submit">Next</button> <button type="submit">Next</button>
</form--> </form-->
<h3>Claims</h3>
<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 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> <p>If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.</p>
<ol> <ol>
@ -43,12 +40,39 @@
<button v-on:click.prevent="checkDns(claim)">Check</button> <button v-on:click.prevent="checkDns(claim)">Check</button>
</li> </li>
</ol> </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> <h3>Domains</h3>
<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> <ol>
<li v-for="domain in domains"> <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> <span v-if="domain.wildcard">*.</span>{{ domain.name }} <span v-if="domain.hostname">- {{domain.hostname}} ({{domain.os}} {{domain.arch}})</span>
</li> </li>
</ol> </ol>
</div>
<h3>Debug: Token</h3>
<pre><code v-text="token"></code></pre> <pre><code v-text="token"></code></pre>
</div> </div>

View File

@ -24,6 +24,7 @@
var vueData = { var vueData = {
claims: [] claims: []
, domains: [] , domains: []
, devices: []
, newDomain: null , newDomain: null
, newDomainWildcard: false , newDomainWildcard: false
, newEmail: null , newEmail: null
@ -88,6 +89,7 @@
//window.alert("TODO: show authorized devices, domains, and connectivity information"); //window.alert("TODO: show authorized devices, domains, and connectivity information");
vueData.hasAccount = true; vueData.hasAccount = true;
vueData.domains = data.domains; vueData.domains = data.domains;
vueData.devices = data.devices;
vueData.claims = data.claims; vueData.claims = data.claims;
} }
function loadAccount(session) { function loadAccount(session) {

View File

@ -19,6 +19,7 @@ var requestAsync = util.promisify(require('@coolaj86/urequest'));
var mkdirpAsync = util.promisify(require('mkdirp')); var mkdirpAsync = util.promisify(require('mkdirp'));
var TRUSTED_ISSUERS = [ 'oauth3.org' ]; var TRUSTED_ISSUERS = [ 'oauth3.org' ];
var DB = require('./db.js'); var DB = require('./db.js');
var Devices = require('../device-tracker');
var Claims = {}; var Claims = {};
Claims.publicize = function publicizeClaim(claim) { Claims.publicize = function publicizeClaim(claim) {
if (!claim) { if (!claim) {
@ -779,6 +780,7 @@ app.get('/api/telebit.cloud/account', function (req, res) {
var domainsMap = {}; var domainsMap = {};
var portsMap = {}; var portsMap = {};
var claimsMap = {}; var claimsMap = {};
var devsMap = {};
var result = JSON.parse(JSON.stringify(acc)); var result = JSON.parse(JSON.stringify(acc));
result.domains.length = 0; result.domains.length = 0;
result.ports.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) { result.claims = Object.keys(claimsMap).map(function (k) {
return Claims.publicize(claimsMap[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; return result;
}); });
} }