From b3b44cdd3393613f8250afa882c4213616e399fb Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 27 Jun 2018 22:58:43 -0600 Subject: [PATCH] update some templates and fix some bugs --- bin/telebitd.js | 14 ++++++++++---- .../LaunchDaemons/cloud.telebit.remote.plist.tpl | 4 ++-- .../LaunchAgents/cloud.telebit.remote.plist.tpl | 4 ++-- usr/share/install-launcher.js | 13 +++++++++---- usr/share/install_helper.sh | 8 +++++--- usr/share/template-launcher.js | 2 ++ 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/bin/telebitd.js b/bin/telebitd.js index d2b5910..7087c1e 100755 --- a/bin/telebitd.js +++ b/bin/telebitd.js @@ -125,6 +125,12 @@ function serveControlsHelper() { }); } + if (/\b(config)\b/.test(opts.pathname) && /get/i.test(req.method)) { + res.setHeader('Content-Type', 'appliCation/json'); + res.end(JSON.stringify(state.config)); + return; + } + // // without proper config // @@ -133,7 +139,7 @@ function serveControlsHelper() { var fresh; if (!opts.body) { res.statusCode = 422; - res.end('{"error":{"message":"needs more arguments"}}'); + res.end('{"error":{"message":"module \'init\' needs more arguments"}}'); return; } // relay, email, agree_tos, servernames, ports @@ -263,7 +269,7 @@ function serveControlsHelper() { if (/http/.test(opts.pathname)) { if (!opts.body) { res.statusCode = 422; - res.end('{"error":{"message":"needs more arguments"}}'); + res.end('{"error":{"message":"module \'http\' needs more arguments"}}'); return; } if (opts.body[1]) { @@ -285,7 +291,7 @@ function serveControlsHelper() { if (/tcp/.test(opts.pathname)) { if (!opts.body) { res.statusCode = 422; - res.end('{"error":{"message":"needs more arguments"}}'); + res.end('{"error":{"message":"module \'tcp\' needs more arguments"}}'); return; } @@ -325,7 +331,7 @@ function serveControlsHelper() { var sshAuto; if (!opts.body) { res.statusCode = 422; - res.end('{"error":{"message":"needs more arguments"}}'); + res.end('{"error":{"message":"module \'ssh\' needs more arguments"}}'); return; } diff --git a/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl b/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl index 513db78..936ff20 100644 --- a/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl +++ b/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl @@ -54,8 +54,8 @@ {TELEBIT_PATH} StandardErrorPath - {TELEBIT_PATH}/var/log/error.log + {TELEBIT_LOG_DIR}/error.log StandardOutPath - {TELEBIT_PATH}/var/log/info.log + {TELEBIT_LOG_DIR}/info.log diff --git a/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl b/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl index cca30d3..837f0da 100644 --- a/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl +++ b/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl @@ -63,8 +63,8 @@ {TELEBIT_PATH} StandardErrorPath - {TELEBIT_PATH}/var/log/error.log + {TELEBIT_LOG_DIR}/error.log StandardOutPath - {TELEBIT_PATH}/var/log/info.log + {TELEBIT_LOG_DIR}/info.log diff --git a/usr/share/install-launcher.js b/usr/share/install-launcher.js index 5616770..8c7fdaf 100644 --- a/usr/share/install-launcher.js +++ b/usr/share/install-launcher.js @@ -39,6 +39,7 @@ Launcher.install = function (things, fn) { , telebitdJs: path.join(telebitRoot, 'bin/telebitd.js') , telebitConfig: path.join(os.homedir(), '.config/telebit/telebit.yml') , telebitdConfig: path.join(os.homedir(), '.config/telebit/telebitd.yml') + , TELEBIT_LOG_DIR: path.join(os.homedir(), '.local/share/telebit/var/log') }; vars.telebitBinTpl = path.join(telebitRoot, 'usr/share/dist/bin/telebit.tpl'); vars.telebitNpm = path.resolve(vars.telebitNode, '../npm'); @@ -104,6 +105,7 @@ Launcher.install = function (things, fn) { try { mkdirp.sync(path.join(os.homedir(), 'Library/LaunchAgents')); mkdirp.sync(path.join(vars.telebitPath, 'bin')); + mkdirp.sync(vars.TELEBIT_LOG_DIR); installLauncher.sync({ file: { tpl: vars.telebitBinTpl @@ -119,12 +121,15 @@ Launcher.install = function (things, fn) { , vars: vars }); var launcherstr = (vars.userspace ? "" : "sudo ") + "launchctl "; - exec(launcherstr + "unload -w " + launcher, things._execOpts, function (err, stdout, stderr) { - err = getError(err, stderr); - if (err) { fn(err); return; } + var execstr = launcherstr + "unload -w " + launcher; + exec(execstr, things._execOpts, function (/*err, stdout, stderr*/) { + // we probably only need to skip the stderr (saying that it can't stop something that isn't started) + //err = getError(err, stderr); + //if (err) { fn(err); return; } //console.log((stdout||'').trim()); //console.log('unload worked?'); - exec(launcherstr + "load -w " + launcher, things._execOpts, function (err, stdout, stderr) { + execstr = launcherstr + "load -w " + launcher; + exec(execstr, things._execOpts, function (err, stdout, stderr) { err = getError(err, stderr); if (err) { fn(err); return; } //console.log((stdout||'').trim()); diff --git a/usr/share/install_helper.sh b/usr/share/install_helper.sh index 1cf48df..97879ee 100644 --- a/usr/share/install_helper.sh +++ b/usr/share/install_helper.sh @@ -282,17 +282,18 @@ set -e export TELEBIT_USER export TELEBIT_GROUP export TELEBIT_PATH -TELEBIT_CONFIG=$HOME/.config/$my_app/$my_app.yml +export TELEBIT_CONFIG=$HOME/.config/$my_app/$my_app.yml # TODO check both expected sock paths in client by default if [ "yes" == "$TELEBIT_USERSPACE" ]; then TELEBIT_TMP_CONFIGD=$HOME/.config/$my_app/$my_daemon.yml TELEBITD_CONFIG=$HOME/.config/$my_app/$my_daemon.yml - TELEBIT_SOCK=$HOME/.local/share/$my_app/var/run/$my_app.sock + TELEBIT_SOCK=${TELEBIT_SOCK:-$HOME/.local/share/$my_app/var/run/$my_app.sock} else TELEBIT_TMP_CONFIGD=$TELEBIT_TMP/etc/$my_daemon.yml TELEBITD_CONFIG=$TELEBIT_REAL_PATH/etc/$my_daemon.yml - TELEBIT_SOCK=$TELEBIT_REAL_PATH/var/run/$my_app.sock + TELEBIT_SOCK=${TELEBIT_SOCK:-$TELEBIT_REAL_PATH/var/run/$my_app.sock} fi +export TELEBITD_CONFIG export TELEBIT_SOCK export TELEBIT_NODE=$TELEBIT_REAL_PATH/bin/node export TELEBIT_NPM=$TELEBIT_REAL_PATH/bin/npm @@ -300,6 +301,7 @@ export TELEBIT_BIN=$TELEBIT_REAL_PATH/bin/telebit export TELEBITD_BIN=$TELEBIT_REAL_PATH/bin/telebitd export TELEBIT_JS=$TELEBIT_REAL_PATH/bin/telebit.js export TELEBITD_JS=$TELEBIT_REAL_PATH/bin/telebitd.js +export TELEBIT_LOG_DIR=${TELEBIT_LOG_DIR:-$TELEBIT_REAL_PATH/var/log} export NODE_PATH="$TELEBIT_REAL_PATH/lib/node_modules" export NPM_CONFIG_PREFIX="$TELEBIT_REAL_PATH" diff --git a/usr/share/template-launcher.js b/usr/share/template-launcher.js index 94a3110..bd5d41d 100644 --- a/usr/share/template-launcher.js +++ b/usr/share/template-launcher.js @@ -32,6 +32,7 @@ module.exports.sync = function (opts) { .replace(/{TELEBIT_RW_DIRS}/g, vars.telebitRwDirs || '{TELEBIT_RW_DIRS}') .replace(/{TELEBIT_CONFIG}/g, vars.telebitConfig || '{TELEBIT_CONFIG}') .replace(/{TELEBITD_CONFIG}/g, vars.telebitdConfig || '{TELEBITD_CONFIG}') + .replace(/{TELEBIT_LOG_DIR}/g, vars.TELEBIT_LOG_DIR || '{TELEBIT_LOG_DIR}') ; fs.writeFileSync(f.launcher, text, 'utf8'); }; @@ -70,6 +71,7 @@ function run() { , telebitGroup: process.env.TELEBIT_GROUP || ('darwin' === os.platform() ? 'staff' : os.userInfo().username) , telebitConfig: process.env.TELEBIT_CONFIG || path.join(os.homedir(), '.config/telebit/telebit.yml') , telebitdConfig: process.env.TELEBITD_CONFIG || path.join(os.homedir(), '.config/telebit/telebitd.yml') + , TELEBIT_LOG_DIR: process.env.TELEBIT_LOG_DIR || path.join(os.homedir(), '.local/share/telebit/var/log') }; vars.telebitNpm = process.env.TELEBIT_NPM || path.resolve(vars.telebitNode, '../npm'); vars.nodePath = process.env.NODE_PATH || path.resolve(vars.telebitNode, '../lib/node_modules');