use pathname not path, update token state
This commit is contained in:
parent
aa35402c22
commit
7da7e4f07e
|
@ -309,8 +309,9 @@ function askForConfig(answers, mainCb) {
|
||||||
var q = nextSet.shift();
|
var q = nextSet.shift();
|
||||||
if (!q) {
|
if (!q) {
|
||||||
// https://github.com/nodejs/node/issues/21319
|
// https://github.com/nodejs/node/issues/21319
|
||||||
|
rl.close();
|
||||||
if (useTty) { stdin.close(); }
|
if (useTty) { stdin.close(); }
|
||||||
rl.close(); mainCb(null, answers);
|
mainCb(null, answers);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
q(next);
|
q(next);
|
||||||
|
@ -354,6 +355,7 @@ function parseConfig(err, text) {
|
||||||
}, function (resp) {
|
}, function (resp) {
|
||||||
|
|
||||||
function finish() {
|
function finish() {
|
||||||
|
console.info("");
|
||||||
if (200 !== resp.statusCode) {
|
if (200 !== resp.statusCode) {
|
||||||
console.warn("'" + service + "' may have failed."
|
console.warn("'" + service + "' may have failed."
|
||||||
+ " Consider peaking at the logs either with 'journalctl -xeu telebit' or /opt/telebit/var/log/error.log");
|
+ " Consider peaking at the logs either with 'journalctl -xeu telebit' or /opt/telebit/var/log/error.log");
|
||||||
|
|
|
@ -119,7 +119,7 @@ function serveControls() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/\b(init|config)\b/.test(opts.path)) {
|
if (/\b(init|config)\b/.test(opts.pathname)) {
|
||||||
var conf = {};
|
var conf = {};
|
||||||
var fresh;
|
var fresh;
|
||||||
if (!opts.body) {
|
if (!opts.body) {
|
||||||
|
@ -231,7 +231,7 @@ function serveControls() {
|
||||||
//
|
//
|
||||||
// With proper config
|
// With proper config
|
||||||
//
|
//
|
||||||
if (/http/.test(opts.path)) {
|
if (/http/.test(opts.pathname)) {
|
||||||
if (!opts.body) {
|
if (!opts.body) {
|
||||||
res.statusCode = 422;
|
res.statusCode = 422;
|
||||||
res.end('{"error":{"message":"needs more arguments"}}');
|
res.end('{"error":{"message":"needs more arguments"}}');
|
||||||
|
@ -253,7 +253,7 @@ function serveControls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/tcp/.test(opts.path)) {
|
if (/tcp/.test(opts.pathname)) {
|
||||||
if (!opts.body) {
|
if (!opts.body) {
|
||||||
res.statusCode = 422;
|
res.statusCode = 422;
|
||||||
res.end('{"error":{"message":"needs more arguments"}}');
|
res.end('{"error":{"message":"needs more arguments"}}');
|
||||||
|
@ -278,7 +278,7 @@ function serveControls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/save|commit/.test(opts.path)) {
|
if (/save|commit/.test(opts.pathname)) {
|
||||||
state.config.servernames = state.servernames;
|
state.config.servernames = state.servernames;
|
||||||
state.config.ports = state.ports;
|
state.config.ports = state.ports;
|
||||||
fs.writeFile(confpath, YAML.safeDump(snakeCopy(state.config)), function (err) {
|
fs.writeFile(confpath, YAML.safeDump(snakeCopy(state.config)), function (err) {
|
||||||
|
@ -292,7 +292,7 @@ function serveControls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/ssh/.test(opts.path)) {
|
if (/ssh/.test(opts.pathname)) {
|
||||||
var sshAuto;
|
var sshAuto;
|
||||||
if (!opts.body) {
|
if (!opts.body) {
|
||||||
res.statusCode = 422;
|
res.statusCode = 422;
|
||||||
|
@ -322,13 +322,17 @@ function serveControls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/enable/.test(opts.path)) {
|
if (/enable/.test(opts.pathname)) {
|
||||||
delete state.config.disable;// = undefined;
|
delete state.config.disable;// = undefined;
|
||||||
if (!tun) { tun = rawTunnel(); }
|
if (tun) {
|
||||||
|
listSuccess();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tun = rawTunnel();
|
||||||
fs.writeFile(confpath, YAML.safeDump(snakeCopy(state.config)), function (err) {
|
fs.writeFile(confpath, YAML.safeDump(snakeCopy(state.config)), function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.statusCode = 500;
|
res.statusCode = 500;
|
||||||
res.end('{"error":{"message":"Could not save config file. Perhaps you\'re not running as root?"}}');
|
res.end('{"error":{"message":"Could not save config file. Perhaps you\'re user doesn\'t have permission?"}}');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
listSuccess();
|
listSuccess();
|
||||||
|
@ -336,7 +340,7 @@ function serveControls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/disable/.test(opts.path)) {
|
if (/disable/.test(opts.pathname)) {
|
||||||
state.config.disable = true;
|
state.config.disable = true;
|
||||||
if (tun) { tun.end(); tun = null; }
|
if (tun) { tun.end(); tun = null; }
|
||||||
fs.writeFile(confpath, YAML.safeDump(snakeCopy(state.config)), function (err) {
|
fs.writeFile(confpath, YAML.safeDump(snakeCopy(state.config)), function (err) {
|
||||||
|
@ -350,7 +354,7 @@ function serveControls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/status/.test(opts.path)) {
|
if (/status/.test(opts.pathname)) {
|
||||||
res.end(JSON.stringify(
|
res.end(JSON.stringify(
|
||||||
{ status: (state.config.disable ? 'disabled' : 'enabled')
|
{ status: (state.config.disable ? 'disabled' : 'enabled')
|
||||||
, ready: ((state.config.relay && (state.config.token || state.config.agreeTos)) ? true : false)
|
, ready: ((state.config.relay && (state.config.token || state.config.agreeTos)) ? true : false)
|
||||||
|
@ -359,7 +363,7 @@ function serveControls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/restart/.test(opts.path)) {
|
if (/restart/.test(opts.pathname)) {
|
||||||
tun.end();
|
tun.end();
|
||||||
res.end('{"success":true}');
|
res.end('{"success":true}');
|
||||||
controlServer.close(function () {
|
controlServer.close(function () {
|
||||||
|
@ -372,7 +376,7 @@ function serveControls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/list/.test(opts.path)) {
|
if (/list/.test(opts.pathname)) {
|
||||||
listSuccess();
|
listSuccess();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -531,6 +535,8 @@ function connectTunnel() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
, access_token: function (opts) {
|
, access_token: function (opts) {
|
||||||
|
state.token = opts.jwt;
|
||||||
|
state.config.token = opts.jwt;
|
||||||
console.info("Updating '" + tokenpath + "' with new token:");
|
console.info("Updating '" + tokenpath + "' with new token:");
|
||||||
try {
|
try {
|
||||||
require('fs').writeFileSync(tokenpath, opts.jwt);
|
require('fs').writeFileSync(tokenpath, opts.jwt);
|
||||||
|
|
|
@ -325,4 +325,6 @@ echo ""
|
||||||
sleep 0.25
|
sleep 0.25
|
||||||
|
|
||||||
$TELEBIT_PATH/bin/node $TELEBIT_PATH/bin/telebit.js init --tty
|
$TELEBIT_PATH/bin/node $TELEBIT_PATH/bin/telebit.js init --tty
|
||||||
|
|
||||||
$TELEBIT_PATH/bin/node $TELEBIT_PATH/bin/telebit.js enable
|
$TELEBIT_PATH/bin/node $TELEBIT_PATH/bin/telebit.js enable
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue