show devices
This commit is contained in:
		
							parent
							
								
									168b2edfd6
								
							
						
					
					
						commit
						ec3f626560
					
				| @ -18,37 +18,61 @@ | |||||||
|       <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> | 
 | ||||||
|         <p>If your DNS host supports ANAME records, please use those instead of CNAMEs.</p> |         <div v-if="claims.length"> | ||||||
|         <p>If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.</p> |           <h3>Pending Claims</h3> | ||||||
|         <ol> |           <p>If your DNS host supports ANAME records, please use those instead of CNAMEs.</p> | ||||||
|           <li v-for="claim in claims"> |           <p>If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.</p> | ||||||
|             <span>{{ claim.value }}</span> |           <ol> | ||||||
|             <br> |             <li v-for="claim in claims"> | ||||||
|             <span v-if="'dns' === claim.type">CNAME <span v-if="claim.wildcard">*.</span>{{ claim.value }}: {{ site.deviceDomain }}</span> |               <span>{{ claim.value }}</span> | ||||||
|             <br> |               <br> | ||||||
|             <span v-if="'dns' === claim.type">TXT _claim-challenge.{{ claim.value }}: {{ claim.challenge }}</span> |               <span v-if="'dns' === claim.type">CNAME <span v-if="claim.wildcard">*.</span>{{ claim.value }}: {{ site.deviceDomain }}</span> | ||||||
|             <br> |               <br> | ||||||
|             <button v-on:click.prevent="checkDns(claim)">Check</button> |               <span v-if="'dns' === claim.type">TXT _claim-challenge.{{ claim.value }}: {{ claim.challenge }}</span> | ||||||
|           </li> |               <br> | ||||||
|         </ol> |               <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> |         <h3>Domains</h3> | ||||||
|         <ol> |         <form v-on:submit.prevent="challengeDns()"> | ||||||
|           <li v-for="domain in domains"> |           Add a custom domain: | ||||||
|             <span v-if="domain.wildcard">*.</span>{{ domain.name }} <span v-if="domain.hostname">- {{domain.hostname}} ({{domain.os}} {{domain.arch}})</span> |           <input v-model="newDomain" placeholder="example.com" type="text" required/> | ||||||
|           </li> |           <button type="submit">Next</button> | ||||||
|         </ol> |         </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> |         <pre><code v-text="token"></code></pre> | ||||||
|       </div> |       </div> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -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) { | ||||||
|  | |||||||
| @ -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; | ||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user