MAJOR: Updates for Authenticated Web UI and CLI #30
| @ -637,7 +637,7 @@ function handleApi(req, res) { | ||||
|         , active: !!myRemote | ||||
|         , initialized: (state.config.relay && state.config.token && state.config.agreeTos) ? true : false | ||||
|         , connected: isConnected | ||||
|         , proctime: Math.round(process.uptime() * 1000) | ||||
|         //, proctime: Math.round(process.uptime() * 1000)
 | ||||
|         , uptime: now - startTime | ||||
|         , runtime: isConnected && connectTimes.length && (now - connectTimes[0]) || 0 | ||||
|         , reconnects: connectTimes.length | ||||
|  | ||||
| @ -115,74 +115,95 @@ | ||||
|     </section> | ||||
| 
 | ||||
|     <section v-if="views.section.status"> | ||||
|       <button v-if="!status.enabled" v-on:click="enable">Enable Traffic</button> | ||||
|       <button v-if="status.enabled" v-on:click="disable">Disable Traffic</button> | ||||
|       <br> | ||||
|       <br> | ||||
| 
 | ||||
|       http://localhost:{{ status.port }} | ||||
|       <br> | ||||
|       <br> | ||||
| 
 | ||||
|       SSH: | ||||
|       <span v-if="status.ssh">{{ status.ssh }} | ||||
|         <button v-on:click="ssh(-1)">Disable SSH</button></span> | ||||
|       <span v-if="!status.ssh"><input type="text" v-model="state.ssh" placeholder="22"> | ||||
|         <button v-on:click="ssh(state.ssh)">Enable SSH</button></span> | ||||
|       <br> | ||||
|       <br> | ||||
|       <section v-if="views.section.status_chooser"> | ||||
|         <button v-on:click.prevent.stop="changeState('status/share')">Share Files & Folders</button> | ||||
|         <button v-on:click.prevent.stop="changeState('status/host')">Host a Website or Webapp</button> | ||||
|         <button v-on:click.prevent.stop="changeState('status/access')">Remote Access via SSH</button> | ||||
|       </section> | ||||
| 
 | ||||
|       Path Hosting: | ||||
|       <ul> | ||||
|         <li v-for="domain in status.pathHosting"> | ||||
|           {{ domain.name }} | ||||
|           <input type="text" v-model="domain.path" v-bind:placeholder="domain.handler"> | ||||
|           <button | ||||
|             v-if="domain.handler == domain.path" | ||||
|             v-on:click="changePathHost(domain, domain.path)">Save</button> | ||||
|           <button v-on:click="deletePathHost(domain)">X</button> | ||||
|         </li> | ||||
|       </ul> | ||||
|       <form v-on:submit="createHttp(newHttp.name, newHttp.handler)"> | ||||
|         <input v-model="newHttp.sub" type="text" placeholder="subdomain (ex: api)"> | ||||
|         <select v-model="newHttp.name"> | ||||
|           <option v-for="w in status.wildDomains" v-bind:value="w.name">{{ w.name }}</option> | ||||
|         </select> | ||||
|         <input v-model="newHttp.handler" type="text" placeholder="path (ex: ~/Public)" required> | ||||
|         <button>Add</button> | ||||
|       </form> | ||||
|       <br> | ||||
|       <section v-if="views.section.status_access"> | ||||
|         SSH: | ||||
|         <span v-if="status.ssh">{{ status.ssh }} | ||||
|           <button v-on:click="ssh(-1)">Disable SSH</button></span> | ||||
|         <span v-if="!status.ssh"><input type="text" v-model="state.ssh" placeholder="22"> | ||||
|           <button v-on:click="ssh(state.ssh)">Enable SSH</button></span> | ||||
|         <br> | ||||
|         <br> | ||||
|         <div v-if="state.ssh_active">SSH is currently running</div> | ||||
|         <div v-if="!state.ssh_active">SSH is not currently running</div> | ||||
|         <br> | ||||
|         <div v-if="state.ssh_insecure">Password Authentication is NOT disabled. | ||||
|           Please consider updating your <code>sshd_config</code> and restarting ssh. | ||||
|           <pre><code>{{ status }}</code></pre> | ||||
|         </div> | ||||
|         <div v-if="!state.ssh_insecure">Key-Only Authentication is enabled :)</div> | ||||
|         <br> | ||||
|       </section> | ||||
| 
 | ||||
|       Port Forwarding: | ||||
|       <ul> | ||||
|         <li v-for="domain in status.portForwards"> | ||||
|           {{ domain.name }} | ||||
|           <input type="text" v-model="domain._port" v-bind:placeholder="domain.handler"> | ||||
|           <button | ||||
|             v-if="domain.handler == domain._port" | ||||
|             v-on:click="changePortForward(domain, domain._port)">Save</button> | ||||
|           <button v-on:click="deletePortForward(domain)">X</button> | ||||
|         </li> | ||||
|       </ul> | ||||
|       <form v-on:submit="createHttp(newHttp.name, newHttp.handler)"> | ||||
|         <input v-model="newHttp.sub" type="text" placeholder="subdomain (ex: api)"> | ||||
|         <select v-model="newHttp.name"> | ||||
|           <option v-for="w in status.wildDomains" v-bind:value="w.name">{{ w.name }}</option> | ||||
|         </select> | ||||
|         <input v-model="newHttp.handler" type="number" placeholder="port (ex: 3000)" required> | ||||
|         <button>Add</button> | ||||
|       </form> | ||||
|       <section v-if="views.section.status_share"> | ||||
|         Path Hosting: | ||||
|         <ul> | ||||
|           <li v-for="domain in status.pathHosting"> | ||||
|             {{ domain.name }} | ||||
|             <input type="text" v-model="domain.path" v-bind:placeholder="domain.handler"> | ||||
|             <button | ||||
|               v-if="domain.handler == domain.path" | ||||
|               v-on:click="changePathHost(domain, domain.path)">Save</button> | ||||
|             <button v-on:click="deletePathHost(domain)">X</button> | ||||
|           </li> | ||||
|         </ul> | ||||
|         <form v-on:submit="createHttp(newHttp.name, newHttp.handler)"> | ||||
|           <input v-model="newHttp.sub" type="text" placeholder="subdomain (ex: api)"> | ||||
|           <select v-model="newHttp.name"> | ||||
|             <option v-for="w in status.wildDomains" v-bind:value="w.name">{{ w.name }}</option> | ||||
|           </select> | ||||
|           <input v-model="newHttp.handler" type="text" placeholder="path (ex: ~/Public)" required> | ||||
|           <button>Add</button> | ||||
|         </form> | ||||
|         <br> | ||||
|       </section> | ||||
| 
 | ||||
|       <section v-if="views.section.status_host"> | ||||
|         Port Forwarding: | ||||
|         <ul> | ||||
|           <li v-for="domain in status.portForwards"> | ||||
|             {{ domain.name }} | ||||
|             <input type="text" v-model="domain._port" v-bind:placeholder="domain.handler"> | ||||
|             <button | ||||
|               v-if="domain.handler == domain._port" | ||||
|               v-on:click="changePortForward(domain, domain._port)">Save</button> | ||||
|             <button v-on:click="deletePortForward(domain)">X</button> | ||||
|           </li> | ||||
|         </ul> | ||||
|         <form v-on:submit="createHttp(newHttp.name, newHttp.handler)"> | ||||
|           <input v-model="newHttp.sub" type="text" placeholder="subdomain (ex: api)"> | ||||
|           <select v-model="newHttp.name"> | ||||
|             <option v-for="w in status.wildDomains" v-bind:value="w.name">{{ w.name }}</option> | ||||
|           </select> | ||||
|           <input v-model="newHttp.handler" type="number" placeholder="port (ex: 3000)" required> | ||||
|           <button>Add</button> | ||||
|         </form> | ||||
|       </section> | ||||
| 
 | ||||
|       <br> | ||||
|       Proctime: {{ statusProctime }} | ||||
|       <br> | ||||
|       Uptime: {{ statusUptime }} | ||||
|       <br> | ||||
|       Runtime: {{ statusRuntime }} | ||||
|       <br> | ||||
|       Reconnects: {{ status.reconnects }} | ||||
| 
 | ||||
|       <details><summary><small>Advanced</small></summary> | ||||
|       <button v-if="!status.enabled" v-on:click="enable">Enable Traffic</button> | ||||
|       <button v-if="status.enabled" v-on:click="disable">Disable Traffic</button> | ||||
|       <br> | ||||
|       <br> | ||||
| 
 | ||||
|       <pre><code>{{ status }}</code></pre> | ||||
|       </details> | ||||
|     </section> | ||||
| 
 | ||||
|   </div> | ||||
|  | ||||
| @ -247,6 +247,7 @@ var appMethods = { | ||||
| , deletePathHost: function (domain) { | ||||
|     api.http(domain.name, 'none'); | ||||
|   } | ||||
| , changeState: changeState | ||||
| }; | ||||
| var appStates = { | ||||
|   setup: function () { | ||||
| @ -263,51 +264,113 @@ var appStates = { | ||||
|       clearInterval(tok); | ||||
|     } | ||||
| 
 | ||||
|     function updateStatus() { | ||||
|       return api.status().then(function (status) { | ||||
|         if (status.error) { | ||||
|           appData.views.flash.error = status.error.message || JSON.stringify(status.error, null, 2); | ||||
|         } | ||||
|         var wilddomains = []; | ||||
|         var rootdomains = []; | ||||
|         var subdomains = []; | ||||
|         var directories = []; | ||||
|         var portforwards = []; | ||||
|         var free = []; | ||||
|         appData.status = status; | ||||
|         Object.keys(appData.status.servernames).forEach(function (k) { | ||||
|           var s = appData.status.servernames[k]; | ||||
|           s.name = k; | ||||
|           if (s.wildcard) { wilddomains.push(s); } | ||||
|           if (!s.sub && !s.wildcard) { rootdomains.push(s); } | ||||
|           if (s.sub) { subdomains.push(s); } | ||||
|           if (s.handler) { | ||||
|             if (s.handler.toString() === parseInt(s.handler, 10).toString()) { | ||||
|               s._port = s.handler; | ||||
|               portforwards.push(s); | ||||
|             } else { | ||||
|               s.path = s.handler; | ||||
|               directories.push(s); | ||||
|             } | ||||
|           } else { | ||||
|             free.push(s); | ||||
|           } | ||||
|         }); | ||||
|         appData.status.portForwards = portforwards; | ||||
|         appData.status.pathHosting = directories; | ||||
|         appData.status.wildDomains = wilddomains; | ||||
|         appData.newHttp.name = (appData.status.wildDomains[0] || {}).name; | ||||
|         appData.state.ssh = (appData.status.ssh > 0) && appData.status.ssh || undefined; | ||||
|       }); | ||||
|     } | ||||
|     var tok = setInterval(updateStatus, 2000); | ||||
| 
 | ||||
|     return updateStatus().then(function () { | ||||
|       appData.views.section = { status: true }; | ||||
|       appData.views.section = { status: true, status_chooser: true }; | ||||
|       return exitState; | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
| appStates.status.share = function () { | ||||
|   function exitState() { | ||||
|     clearInterval(tok); | ||||
|   } | ||||
| 
 | ||||
|   var tok = setInterval(updateStatus, 2000); | ||||
| 
 | ||||
|   appData.views.section = { status: true, status_share: true }; | ||||
|   return updateStatus().then(function () { | ||||
|     return exitState; | ||||
|   }); | ||||
| }; | ||||
| appStates.status.host = function () { | ||||
|   function exitState() { | ||||
|     clearInterval(tok); | ||||
|   } | ||||
| 
 | ||||
|   var tok = setInterval(updateStatus, 2000); | ||||
| 
 | ||||
|   appData.views.section = { status: true, status_host: true }; | ||||
|   return updateStatus().then(function () { | ||||
|     return exitState; | ||||
|   }); | ||||
| }; | ||||
| appStates.status.access = function () { | ||||
|   function exitState() { | ||||
|     clearInterval(tok); | ||||
|   } | ||||
| 
 | ||||
|   var tok = setInterval(updateStatus, 2000); | ||||
| 
 | ||||
|   appData.views.section = { status: true, status_access: true }; | ||||
|   return updateStatus().then(function () { | ||||
|     return exitState; | ||||
|   }); | ||||
| }; | ||||
| 
 | ||||
| function updateStatus() { | ||||
|   return api.status().then(function (status) { | ||||
|     if (status.error) { | ||||
|       appData.views.flash.error = status.error.message || JSON.stringify(status.error, null, 2); | ||||
|     } | ||||
|     var wilddomains = []; | ||||
|     var rootdomains = []; | ||||
|     var subdomains = []; | ||||
|     var directories = []; | ||||
|     var portforwards = []; | ||||
|     var free = []; | ||||
|     appData.status = status; | ||||
|     if ('maybe' === status.ssh_requests_password) { | ||||
|       appData.status.ssh_active = false; | ||||
|     } else { | ||||
|       appData.status.ssh_active = true; | ||||
|       if ('yes' === status.ssh_requests_password) { | ||||
|         appData.status.ssh_insecure = true; | ||||
|       } | ||||
|     } | ||||
|     if ('yes' === status.ssh_password_authentication) { | ||||
|       appData.status.ssh_insecure = true; | ||||
|     } | ||||
|     if ('yes' === status.ssh_permit_root_login) { | ||||
|       appData.status.ssh_insecure = true; | ||||
|     } | ||||
| 
 | ||||
|     // only update what's changed
 | ||||
|     if (appData.state.ssh !== appData.status.ssh) { | ||||
|       appData.state.ssh = appData.status.ssh; | ||||
|     } | ||||
|     if (appData.state.ssh_insecure !== appData.status.ssh_insecure) { | ||||
|       appData.state.ssh_insecure = appData.status.ssh_insecure; | ||||
|     } | ||||
|     if (appData.state.ssh_active !== appData.status.ssh_active) { | ||||
|       appData.state.ssh_active = appData.status.ssh_active; | ||||
|     } | ||||
|     Object.keys(appData.status.servernames).forEach(function (k) { | ||||
|       var s = appData.status.servernames[k]; | ||||
|       s.name = k; | ||||
|       if (s.wildcard) { wilddomains.push(s); } | ||||
|       if (!s.sub && !s.wildcard) { rootdomains.push(s); } | ||||
|       if (s.sub) { subdomains.push(s); } | ||||
|       if (s.handler) { | ||||
|         if (s.handler.toString() === parseInt(s.handler, 10).toString()) { | ||||
|           s._port = s.handler; | ||||
|           portforwards.push(s); | ||||
|         } else { | ||||
|           s.path = s.handler; | ||||
|           directories.push(s); | ||||
|         } | ||||
|       } else { | ||||
|         free.push(s); | ||||
|       } | ||||
|     }); | ||||
|     appData.status.portForwards = portforwards; | ||||
|     appData.status.pathHosting = directories; | ||||
|     appData.status.wildDomains = wilddomains; | ||||
|     appData.newHttp.name = (appData.status.wildDomains[0] || {}).name; | ||||
|     appData.state.ssh = (appData.status.ssh > 0) && appData.status.ssh || undefined; | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
| function changeState(newstate) { | ||||
|   var newhash = '#/' + newstate + '/'; | ||||
| @ -325,13 +388,14 @@ function setState(/*ev*/) { | ||||
|   //ev.oldURL
 | ||||
|   //ev.newURL
 | ||||
|   if (appData.exit) { | ||||
|     console.log('previous state exiting'); | ||||
|     appData.exit.then(function (exit) { | ||||
|       if ('function' === typeof appData.exit) { | ||||
|         exit(); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|   var parts = location.hash.substr(1).replace(/^\//, '').replace(/\/$/, '').split('/'); | ||||
|   var parts = location.hash.substr(1).replace(/^\//, '').replace(/\/$/, '').split('/').filter(Boolean); | ||||
|   var fn = appStates; | ||||
|   parts.forEach(function (s) { | ||||
|     console.log("state:", s); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user