From a928decbd8af797c077d2fd4649ebb2fd8f0ca42 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 29 Jun 2018 15:53:55 -0600 Subject: [PATCH] renable parseCli --- bin/telebit.js | 20 ++++++++++---------- bin/telebitd.js | 12 +++++++++--- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/bin/telebit.js b/bin/telebit.js index 4a4eed7..9174b59 100755 --- a/bin/telebit.js +++ b/bin/telebit.js @@ -335,7 +335,7 @@ var utils = { request: function request(opts, fn) { if (!opts) { opts = {}; } var service = opts.service || 'config'; - var req = http.get({ + var req = http.request({ socketPath: state._ipc.path , method: opts.method || 'GET' , path: '/rpc/' + service @@ -395,11 +395,10 @@ var utils = { console.error(err); return; }); + req.end(); } , putConfig: function putConfig(service, args, fn) { - //console.log('debug path:'); - //console.log('/rpc/' + service + '?_body=' + JSON.stringify(args)); - var req = http.get({ + var req = http.request({ socketPath: state._ipc.path , method: 'POST' , path: '/rpc/' + service + '?_body=' + JSON.stringify(args) @@ -458,6 +457,7 @@ var utils = { console.error(err); return; }); + req.end(); } }; @@ -546,7 +546,7 @@ function getToken(err, state) { console.error(err); return; } - console.log("waiting..."); + console.info("waiting..."); next(); }); } @@ -557,10 +557,9 @@ function getToken(err, state) { return; } state._connecting = true; - console.log("Token Offered:"); - console.log(token); try { - console.log(require('jsonwebtoken').decode(token)); + require('jsonwebtoken').decode(token); + //console.log(require('jsonwebtoken').decode(token)); } catch(e) { console.warn("[warning] could not decode token"); } @@ -603,6 +602,8 @@ function getToken(err, state) { } function parseCli(/*state*/) { + //console.log(parseCli); + //console.log(argv); if (-1 !== argv.indexOf('init')) { utils.putConfig('list', []/*, function (err) { }*/); @@ -619,8 +620,7 @@ function parseCli(/*state*/) { } return true; })) { - help(); - process.exit(13); + process.exit(0); return; } diff --git a/bin/telebitd.js b/bin/telebitd.js index 1243501..24c72e7 100755 --- a/bin/telebitd.js +++ b/bin/telebitd.js @@ -459,13 +459,19 @@ function serveControlsHelper() { require('mkdirp').sync(path.resolve(state._ipc.path, '..')); controlServer.listen({ path: state._ipc.path + , host: 'localhost' + //, port: 0 , writableAll: true , readableAll: true , exclusive: false }, function () { process.umask(oldUmask); + var address = this.address(); + if (address.port) { + common.setPort(state.config, address.port); + } //console.log(this.address()); - console.info("[info] Listening for commands on " + state._ipc.path); + console.info("[info] Listening for commands on " + address); }); } @@ -689,7 +695,7 @@ state.handlers = { state.config.token = opts.jwt || opts.access_token; console.info("Updating '" + tokenpath + "' with new token:"); try { - require('fs').writeFileSync(tokenpath, opts.jwt); + fs.writeFileSync(tokenpath, opts.jwt); fs.writeFileSync(confpath, YAML.safeDump(snakeCopy(state.config))); } catch (e) { console.error("Token not saved:"); @@ -728,6 +734,6 @@ state.net = state.net || { } }; -require('fs').readFile(confpath, 'utf8', parseConfig); +fs.readFile(confpath, 'utf8', parseConfig); }());