rearrange a few things
This commit is contained in:
		
							parent
							
								
									34bcf79d98
								
							
						
					
					
						commit
						535c9732c6
					
				@ -637,7 +637,7 @@ function handleApi(req, res) {
 | 
				
			|||||||
        , active: !!myRemote
 | 
					        , active: !!myRemote
 | 
				
			||||||
        , initialized: (state.config.relay && state.config.token && state.config.agreeTos) ? true : false
 | 
					        , initialized: (state.config.relay && state.config.token && state.config.agreeTos) ? true : false
 | 
				
			||||||
        , connected: isConnected
 | 
					        , connected: isConnected
 | 
				
			||||||
        , proctime: Math.round(process.uptime() * 1000)
 | 
					        //, proctime: Math.round(process.uptime() * 1000)
 | 
				
			||||||
        , uptime: now - startTime
 | 
					        , uptime: now - startTime
 | 
				
			||||||
        , runtime: isConnected && connectTimes.length && (now - connectTimes[0]) || 0
 | 
					        , runtime: isConnected && connectTimes.length && (now - connectTimes[0]) || 0
 | 
				
			||||||
        , reconnects: connectTimes.length
 | 
					        , reconnects: connectTimes.length
 | 
				
			||||||
 | 
				
			|||||||
@ -115,15 +115,17 @@
 | 
				
			|||||||
    </section>
 | 
					    </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <section v-if="views.section.status">
 | 
					    <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 }}
 | 
					      http://localhost:{{ status.port }}
 | 
				
			||||||
      <br>
 | 
					      <br>
 | 
				
			||||||
      <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>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <section v-if="views.section.status_access">
 | 
				
			||||||
        SSH:
 | 
					        SSH:
 | 
				
			||||||
        <span v-if="status.ssh">{{ status.ssh }}
 | 
					        <span v-if="status.ssh">{{ status.ssh }}
 | 
				
			||||||
          <button v-on:click="ssh(-1)">Disable SSH</button></span>
 | 
					          <button v-on:click="ssh(-1)">Disable SSH</button></span>
 | 
				
			||||||
@ -131,7 +133,18 @@
 | 
				
			|||||||
          <button v-on:click="ssh(state.ssh)">Enable SSH</button></span>
 | 
					          <button v-on:click="ssh(state.ssh)">Enable SSH</button></span>
 | 
				
			||||||
        <br>
 | 
					        <br>
 | 
				
			||||||
        <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>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <section v-if="views.section.status_share">
 | 
				
			||||||
        Path Hosting:
 | 
					        Path Hosting:
 | 
				
			||||||
        <ul>
 | 
					        <ul>
 | 
				
			||||||
          <li v-for="domain in status.pathHosting">
 | 
					          <li v-for="domain in status.pathHosting">
 | 
				
			||||||
@ -152,7 +165,9 @@
 | 
				
			|||||||
          <button>Add</button>
 | 
					          <button>Add</button>
 | 
				
			||||||
        </form>
 | 
					        </form>
 | 
				
			||||||
        <br>
 | 
					        <br>
 | 
				
			||||||
 | 
					      </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <section v-if="views.section.status_host">
 | 
				
			||||||
        Port Forwarding:
 | 
					        Port Forwarding:
 | 
				
			||||||
        <ul>
 | 
					        <ul>
 | 
				
			||||||
          <li v-for="domain in status.portForwards">
 | 
					          <li v-for="domain in status.portForwards">
 | 
				
			||||||
@ -172,17 +187,23 @@
 | 
				
			|||||||
          <input v-model="newHttp.handler" type="number" placeholder="port (ex: 3000)" required>
 | 
					          <input v-model="newHttp.handler" type="number" placeholder="port (ex: 3000)" required>
 | 
				
			||||||
          <button>Add</button>
 | 
					          <button>Add</button>
 | 
				
			||||||
        </form>
 | 
					        </form>
 | 
				
			||||||
 | 
					      </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <br>
 | 
					 | 
				
			||||||
      Proctime: {{ statusProctime }}
 | 
					 | 
				
			||||||
      <br>
 | 
					      <br>
 | 
				
			||||||
      Uptime: {{ statusUptime }}
 | 
					      Uptime: {{ statusUptime }}
 | 
				
			||||||
      <br>
 | 
					      <br>
 | 
				
			||||||
      Runtime: {{ statusRuntime }}
 | 
					      Runtime: {{ statusRuntime }}
 | 
				
			||||||
      <br>
 | 
					      <br>
 | 
				
			||||||
      Reconnects: {{ status.reconnects }}
 | 
					      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>
 | 
				
			||||||
 | 
					      <br>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <pre><code>{{ status }}</code></pre>
 | 
					      <pre><code>{{ status }}</code></pre>
 | 
				
			||||||
 | 
					      </details>
 | 
				
			||||||
    </section>
 | 
					    </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
 | 
				
			|||||||
@ -247,6 +247,7 @@ var appMethods = {
 | 
				
			|||||||
, deletePathHost: function (domain) {
 | 
					, deletePathHost: function (domain) {
 | 
				
			||||||
    api.http(domain.name, 'none');
 | 
					    api.http(domain.name, 'none');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					, changeState: changeState
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
var appStates = {
 | 
					var appStates = {
 | 
				
			||||||
  setup: function () {
 | 
					  setup: function () {
 | 
				
			||||||
@ -263,6 +264,51 @@ var appStates = {
 | 
				
			|||||||
      clearInterval(tok);
 | 
					      clearInterval(tok);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var tok = setInterval(updateStatus, 2000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return updateStatus().then(function () {
 | 
				
			||||||
 | 
					      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() {
 | 
					function updateStatus() {
 | 
				
			||||||
  return api.status().then(function (status) {
 | 
					  return api.status().then(function (status) {
 | 
				
			||||||
    if (status.error) {
 | 
					    if (status.error) {
 | 
				
			||||||
@ -275,6 +321,31 @@ var appStates = {
 | 
				
			|||||||
    var portforwards = [];
 | 
					    var portforwards = [];
 | 
				
			||||||
    var free = [];
 | 
					    var free = [];
 | 
				
			||||||
    appData.status = status;
 | 
					    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) {
 | 
					    Object.keys(appData.status.servernames).forEach(function (k) {
 | 
				
			||||||
      var s = appData.status.servernames[k];
 | 
					      var s = appData.status.servernames[k];
 | 
				
			||||||
      s.name = k;
 | 
					      s.name = k;
 | 
				
			||||||
@ -300,14 +371,6 @@ var appStates = {
 | 
				
			|||||||
    appData.state.ssh = (appData.status.ssh > 0) && appData.status.ssh || undefined;
 | 
					    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 };
 | 
					 | 
				
			||||||
      return exitState;
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function changeState(newstate) {
 | 
					function changeState(newstate) {
 | 
				
			||||||
  var newhash = '#/' + newstate + '/';
 | 
					  var newhash = '#/' + newstate + '/';
 | 
				
			||||||
@ -325,13 +388,14 @@ function setState(/*ev*/) {
 | 
				
			|||||||
  //ev.oldURL
 | 
					  //ev.oldURL
 | 
				
			||||||
  //ev.newURL
 | 
					  //ev.newURL
 | 
				
			||||||
  if (appData.exit) {
 | 
					  if (appData.exit) {
 | 
				
			||||||
 | 
					    console.log('previous state exiting');
 | 
				
			||||||
    appData.exit.then(function (exit) {
 | 
					    appData.exit.then(function (exit) {
 | 
				
			||||||
      if ('function' === typeof appData.exit) {
 | 
					      if ('function' === typeof appData.exit) {
 | 
				
			||||||
        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;
 | 
					  var fn = appStates;
 | 
				
			||||||
  parts.forEach(function (s) {
 | 
					  parts.forEach(function (s) {
 | 
				
			||||||
    console.log("state:", s);
 | 
					    console.log("state:", s);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user