From f17619efd24d10d14c4c914ff9570b485fb7f700 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 13 Jun 2018 13:12:38 -0600 Subject: [PATCH] output and whitespace --- bin/telebit.js | 28 ++++++++++++++++++++-------- bin/telebitd.js | 3 ++- usr/share/install_helper.sh | 19 +++++++++---------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/bin/telebit.js b/bin/telebit.js index 5233da2..26c5a50 100644 --- a/bin/telebit.js +++ b/bin/telebit.js @@ -359,15 +359,27 @@ function parseConfig(err, text) { + " Consider peaking at the logs either with 'journalctl -xeu telebit' or /opt/telebit/var/log/error.log"); console.warn(resp.statusCode, body); //cb(new Error("not okay"), body); + return; + } + + if (!body) { + console.info("👌"); + return; + } + + try { + body = JSON.parse(body); + } catch(e) { + // ignore + } + + if ("AWAIT_AUTH" === body.code) { + console.info(body.message); + } else if ("CONFIG" === body.code) { + delete body.code; + YAML.safeDump(body); } else { - if (body) { - console.info('Response'); - console.info(body); - //cb(null, body); - } else { - console.info("👌"); - //cb(null, ""); - } + console.info(JSON.stringify(body, null, 2)); } } diff --git a/bin/telebitd.js b/bin/telebitd.js index e56fb11..2efe39b 100755 --- a/bin/telebitd.js +++ b/bin/telebitd.js @@ -97,6 +97,7 @@ function serveControls() { servernames: state.servernames , ports: state.ports , ssh: state.config.sshAuto || 'disabled' + , code: 'CONFIG' }; if (/\btelebit\.cloud\b/i.test(state.config.relay) && state.config.email && !state.token) { @@ -104,7 +105,7 @@ function serveControls() { dumpy.message = "Check your email. You must verify your email address to activate this device."; } - res.end(YAML.safeDump(dumpy)); + res.end(JSON.stringify(dumpy)); } function sshSuccess() { diff --git a/usr/share/install_helper.sh b/usr/share/install_helper.sh index d55dc47..d709e94 100644 --- a/usr/share/install_helper.sh +++ b/usr/share/install_helper.sh @@ -172,15 +172,15 @@ rm -rf ~/.config/$my_app ~/.local/share/$my_app EOF chmod a+x $TELEBIT_PATH/bin/${my_app}_uninstall -echo " > ${sudo_cmde}ln -sf $TELEBIT_PATH/bin/$my_app /usr/local/bin/$my_app" +echo " > ${sudo_cmde}ln -sf $TELEBIT_PATH/bin/$my_app /usr/local/bin/$my_app" $sudo_cmd ln -sf $TELEBIT_PATH/bin/$my_app /usr/local/bin/$my_app -echo " > ${sudo_cmde}ln -sf $TELEBIT_PATH/bin/$my_daemon /usr/local/bin/$my_daemon" +echo " > ${sudo_cmde}ln -sf $TELEBIT_PATH/bin/$my_daemon /usr/local/bin/$my_daemon" $sudo_cmd ln -sf $TELEBIT_PATH/bin/$my_daemon /usr/local/bin/$my_daemon set +e if type -p setcap >/dev/null 2>&1; then #echo "Setting permissions to allow $my_app to run on port 80 and port 443 without sudo or root" - echo " > ${sudo_cmde}setcap cap_net_bind_service=+ep $TELEBIT_PATH/bin/node" + echo " > ${sudo_cmde}setcap cap_net_bind_service=+ep $TELEBIT_PATH/bin/node" $sudo_cmd setcap cap_net_bind_service=+ep $TELEBIT_PATH/bin/node fi set -e @@ -216,22 +216,22 @@ my_system_launcher="" if [ -d "/Library/LaunchDaemons" ]; then my_system_launcher="launchd" my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist" - echo " > ${sudo_cmde}$rsync_cmd $TELEBIT_PATH/usr/share/dist/$my_app_launchd_service /$my_app_launchd_service" + echo " > ${sudo_cmde}$rsync_cmd $TELEBIT_PATH/usr/share/dist/$my_app_launchd_service /$my_app_launchd_service" $sudo_cmd $rsync_cmd "$TELEBIT_PATH/usr/share/dist/$my_app_launchd_service" "/$my_app_launchd_service" - echo " > ${sudo_cmde}chown root:wheel $my_root/$my_app_launchd_service" + echo " > ${sudo_cmde}chown root:wheel $my_root/$my_app_launchd_service" $sudo_cmd chown root:wheel "$my_root/$my_app_launchd_service" - echo " > ${sudo_cmde}launchctl unload -w $my_root/$my_app_launchd_service >/dev/null 2>/dev/null" + echo " > ${sudo_cmde}launchctl unload -w $my_root/$my_app_launchd_service >/dev/null 2>/dev/null" $sudo_cmd launchctl unload -w "$my_root/$my_app_launchd_service" >/dev/null 2>/dev/null elif [ -d "$my_root/etc/systemd/system" ]; then my_system_launcher="systemd" - echo " > ${sudo_cmde}$rsync_cmd $TELEBIT_PATH/usr/share/dist/etc/systemd/system/$my_app.service /etc/systemd/system/$my_app.service" + echo " > ${sudo_cmde}$rsync_cmd $TELEBIT_PATH/usr/share/dist/etc/systemd/system/$my_app.service /etc/systemd/system/$my_app.service" $sudo_cmd $rsync_cmd "$TELEBIT_PATH/usr/share/dist/etc/systemd/system/$my_app.service" "/etc/systemd/system/$my_app.service" $sudo_cmd systemctl daemon-reload - echo " > ${sudo_cmde}systemctl enable $my_app" - $sudo_cmd systemctl enable $my_app + echo " > ${sudo_cmde}systemctl enable $my_app" + $sudo_cmd systemctl enable $my_app >/dev/null fi sleep 1 @@ -320,7 +320,6 @@ if [ "systemd" == "$my_system_launcher" ]; then $sudo_cmd systemctl restart $my_app fi -echo "" echo " > telebit init --tty" echo "" sleep 0.25