updates for config file

This commit is contained in:
AJ ONeal 2018-10-23 00:44:59 -06:00
parent ce20b058e6
commit 2679a20d1c
3 changed files with 150 additions and 16 deletions

View File

@ -135,9 +135,9 @@ controllers.http = function (req, res, opts) {
return; return;
} }
var active = true; var active = true;
var portOrPath = opts.body[0]; var portOrPath = opts.body.handler || opts.body[0];
var appname = getAppname(portOrPath); var appname = getAppname(portOrPath);
var subdomain = opts.body[1]; var subdomain = opts.body.name || opts.body[1];
var remoteHost; var remoteHost;
// Assign an FQDN to brief subdomains // Assign an FQDN to brief subdomains
@ -310,8 +310,9 @@ controllers.ssh = function (req, res, opts) {
}); });
} }
var sshAuto = opts.body[0]; var rawSshAuto = opts.body.port || opts.body[0];
if (-1 !== [ 'false', 'none', 'off', 'disable' ].indexOf(sshAuto)) { var sshAuto = rawSshAuto;
if (-1 !== [ -1, 'false', 'none', 'off', 'disable' ].indexOf(sshAuto)) {
state.config.sshAuto = false; state.config.sshAuto = false;
sshSuccess(); sshSuccess();
return; return;
@ -325,7 +326,7 @@ controllers.ssh = function (req, res, opts) {
if (!sshAuto || sshAuto <= 0 || sshAuto > 65535) { if (!sshAuto || sshAuto <= 0 || sshAuto > 65535) {
res.statusCode = 400; res.statusCode = 400;
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ error: { message: "bad ssh_auto option '" + opts.body[0] + "'" } })); res.end(JSON.stringify({ error: { message: "bad ssh_auto option '" + rawSshAuto + "'" } }));
return; return;
} }
state.config.sshAuto = sshAuto; state.config.sshAuto = sshAuto;
@ -640,6 +641,7 @@ function handleApi(req, res) {
, runtime: isConnected && connectTimes.length && (now - connectTimes[0]) || 0 , runtime: isConnected && connectTimes.length && (now - connectTimes[0]) || 0
, reconnects: connectTimes.length , reconnects: connectTimes.length
, servernames: state.servernames , servernames: state.servernames
, ssh: state.config.sshAuto
} }
)); ));
} }

View File

@ -115,10 +115,64 @@
</section> </section>
<section v-if="views.section.status"> <section v-if="views.section.status">
<button v-if="!status.enabled" v-on:click="enable">Enable</button> <button v-if="!status.enabled" v-on:click="enable">Enable Traffic</button>
<button v-if="status.enabled" v-on:click="disable">Disable</button> <button v-if="status.enabled" v-on:click="disable">Disable Traffic</button>
<br> <br>
<br>
http://localhost:{{ status.port }} 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>
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>
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>
<br> <br>
Proctime: {{ statusProctime }} Proctime: {{ statusProctime }}
<br> <br>

View File

@ -37,6 +37,36 @@ api.status = function apiStatus() {
return json; return json;
}); });
}; };
api.http = function apiHttp(name, handler) {
var opts = {
url: "/api/http"
, method: "POST"
, headers: { 'Content-Type': 'application/json' }
, json: { name: name, handler: handler }
};
return Telebit.reqLocalAsync(opts).then(function (resp) {
var json = resp.body;
appData.initResult = json;
return json;
}).catch(function (err) {
window.alert("Error: [init] " + (err.message || JSON.stringify(err, null, 2)));
});
};
api.ssh = function apiSsh(port) {
var opts = {
url: "/api/ssh"
, method: "POST"
, headers: { 'Content-Type': 'application/json' }
, json: { port: port }
};
return Telebit.reqLocalAsync(opts).then(function (resp) {
var json = resp.body;
appData.initResult = json;
return json;
}).catch(function (err) {
window.alert("Error: [init] " + (err.message || JSON.stringify(err, null, 2)));
});
};
api.enable = function apiEnable() { api.enable = function apiEnable() {
var opts = { var opts = {
url: "/api/enable" url: "/api/enable"
@ -45,11 +75,10 @@ api.enable = function apiEnable() {
}; };
return Telebit.reqLocalAsync(opts).then(function (resp) { return Telebit.reqLocalAsync(opts).then(function (resp) {
var json = resp.body; var json = resp.body;
appData.initResult = json; console.log('enable', json);
window.alert("Error: [success] " + JSON.stringify(json, null, 2));
return json; return json;
}).catch(function (err) { }).catch(function (err) {
window.alert("Error: [init] " + (err.message || JSON.stringify(err, null, 2))); window.alert("Error: [enable] " + (err.message || JSON.stringify(err, null, 2)));
}); });
}; };
api.disable = function apiDisable() { api.disable = function apiDisable() {
@ -60,11 +89,10 @@ api.disable = function apiDisable() {
}; };
return Telebit.reqLocalAsync(opts).then(function (resp) { return Telebit.reqLocalAsync(opts).then(function (resp) {
var json = resp.body; var json = resp.body;
appData.initResult = json; console.log('disable', json);
window.alert("Error: [success] " + JSON.stringify(json, null, 2));
return json; return json;
}).catch(function (err) { }).catch(function (err) {
window.alert("Error: [init] " + (err.message || JSON.stringify(err, null, 2))); window.alert("Error: [disable] " + (err.message || JSON.stringify(err, null, 2)));
}); });
}; };
@ -129,9 +157,7 @@ var appData = {
, telemetry: true , telemetry: true
, acmeServer: PRODUCTION_ACME , acmeServer: PRODUCTION_ACME
} }
, http: null , state: {}
, tcp: null
, ssh: null
, views: { , views: {
flash: { flash: {
error: "" error: ""
@ -144,6 +170,7 @@ var appData = {
, status: false , status: false
} }
} }
, newHttp: {}
}; };
var telebitState = {}; var telebitState = {};
var appMethods = { var appMethods = {
@ -199,6 +226,28 @@ var appMethods = {
, disable: function () { , disable: function () {
api.disable(); api.disable();
} }
, ssh: function (port) {
// -1 to disable
// 0 is auto (22)
// 1-65536
api.ssh(port || 22);
}
, createHttp: function (domain, handler) {
api.http(domain.name, handler);
appData.newHttp = {};
}
, changePortForward: function (domain, port) {
api.http(domain.name, port);
}
, deletePortForward: function (domain) {
api.http(domain.name, 'none');
}
, changePathHost: function (domain, path) {
api.http(domain.name, path);
}
, deletePathHost: function (domain) {
api.http(domain.name, 'none');
}
}; };
var appStates = { var appStates = {
setup: function () { setup: function () {
@ -214,7 +263,36 @@ var appStates = {
appData.views.section = { status: true }; appData.views.section = { status: true };
var tok = setInterval(function () { var tok = setInterval(function () {
api.status().then(function (status) { api.status().then(function (status) {
var wilddomains = [];
var rootdomains = [];
var subdomains = [];
var directories = [];
var portforwards = [];
var free = [];
appData.status = status; 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;
}); });
}, 2000); }, 2000);