update some templates and fix some bugs

This commit is contained in:
AJ ONeal 2018-06-27 22:58:43 -06:00
parent 83f824a08b
commit b3b44cdd33
6 changed files with 30 additions and 15 deletions

View File

@ -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 // without proper config
// //
@ -133,7 +139,7 @@ function serveControlsHelper() {
var fresh; var fresh;
if (!opts.body) { if (!opts.body) {
res.statusCode = 422; res.statusCode = 422;
res.end('{"error":{"message":"needs more arguments"}}'); res.end('{"error":{"message":"module \'init\' needs more arguments"}}');
return; return;
} }
// relay, email, agree_tos, servernames, ports // relay, email, agree_tos, servernames, ports
@ -263,7 +269,7 @@ function serveControlsHelper() {
if (/http/.test(opts.pathname)) { 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":"module \'http\' needs more arguments"}}');
return; return;
} }
if (opts.body[1]) { if (opts.body[1]) {
@ -285,7 +291,7 @@ function serveControlsHelper() {
if (/tcp/.test(opts.pathname)) { 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":"module \'tcp\' needs more arguments"}}');
return; return;
} }
@ -325,7 +331,7 @@ function serveControlsHelper() {
var sshAuto; var sshAuto;
if (!opts.body) { if (!opts.body) {
res.statusCode = 422; res.statusCode = 422;
res.end('{"error":{"message":"needs more arguments"}}'); res.end('{"error":{"message":"module \'ssh\' needs more arguments"}}');
return; return;
} }

View File

@ -54,8 +54,8 @@
<string>{TELEBIT_PATH}</string> <string>{TELEBIT_PATH}</string>
<key>StandardErrorPath</key> <key>StandardErrorPath</key>
<string>{TELEBIT_PATH}/var/log/error.log</string> <string>{TELEBIT_LOG_DIR}/error.log</string>
<key>StandardOutPath</key> <key>StandardOutPath</key>
<string>{TELEBIT_PATH}/var/log/info.log</string> <string>{TELEBIT_LOG_DIR}/info.log</string>
</dict> </dict>
</plist> </plist>

View File

@ -63,8 +63,8 @@
<string>{TELEBIT_PATH}</string> <string>{TELEBIT_PATH}</string>
<key>StandardErrorPath</key> <key>StandardErrorPath</key>
<string>{TELEBIT_PATH}/var/log/error.log</string> <string>{TELEBIT_LOG_DIR}/error.log</string>
<key>StandardOutPath</key> <key>StandardOutPath</key>
<string>{TELEBIT_PATH}/var/log/info.log</string> <string>{TELEBIT_LOG_DIR}/info.log</string>
</dict> </dict>
</plist> </plist>

View File

@ -39,6 +39,7 @@ Launcher.install = function (things, fn) {
, telebitdJs: path.join(telebitRoot, 'bin/telebitd.js') , telebitdJs: path.join(telebitRoot, 'bin/telebitd.js')
, telebitConfig: path.join(os.homedir(), '.config/telebit/telebit.yml') , telebitConfig: path.join(os.homedir(), '.config/telebit/telebit.yml')
, telebitdConfig: path.join(os.homedir(), '.config/telebit/telebitd.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.telebitBinTpl = path.join(telebitRoot, 'usr/share/dist/bin/telebit.tpl');
vars.telebitNpm = path.resolve(vars.telebitNode, '../npm'); vars.telebitNpm = path.resolve(vars.telebitNode, '../npm');
@ -104,6 +105,7 @@ Launcher.install = function (things, fn) {
try { try {
mkdirp.sync(path.join(os.homedir(), 'Library/LaunchAgents')); mkdirp.sync(path.join(os.homedir(), 'Library/LaunchAgents'));
mkdirp.sync(path.join(vars.telebitPath, 'bin')); mkdirp.sync(path.join(vars.telebitPath, 'bin'));
mkdirp.sync(vars.TELEBIT_LOG_DIR);
installLauncher.sync({ installLauncher.sync({
file: { file: {
tpl: vars.telebitBinTpl tpl: vars.telebitBinTpl
@ -119,12 +121,15 @@ Launcher.install = function (things, fn) {
, vars: vars , vars: vars
}); });
var launcherstr = (vars.userspace ? "" : "sudo ") + "launchctl "; var launcherstr = (vars.userspace ? "" : "sudo ") + "launchctl ";
exec(launcherstr + "unload -w " + launcher, things._execOpts, function (err, stdout, stderr) { var execstr = launcherstr + "unload -w " + launcher;
err = getError(err, stderr); exec(execstr, things._execOpts, function (/*err, stdout, stderr*/) {
if (err) { fn(err); return; } // 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((stdout||'').trim());
//console.log('unload worked?'); //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); err = getError(err, stderr);
if (err) { fn(err); return; } if (err) { fn(err); return; }
//console.log((stdout||'').trim()); //console.log((stdout||'').trim());

View File

@ -282,17 +282,18 @@ set -e
export TELEBIT_USER export TELEBIT_USER
export TELEBIT_GROUP export TELEBIT_GROUP
export TELEBIT_PATH 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 # TODO check both expected sock paths in client by default
if [ "yes" == "$TELEBIT_USERSPACE" ]; then if [ "yes" == "$TELEBIT_USERSPACE" ]; then
TELEBIT_TMP_CONFIGD=$HOME/.config/$my_app/$my_daemon.yml TELEBIT_TMP_CONFIGD=$HOME/.config/$my_app/$my_daemon.yml
TELEBITD_CONFIG=$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 else
TELEBIT_TMP_CONFIGD=$TELEBIT_TMP/etc/$my_daemon.yml TELEBIT_TMP_CONFIGD=$TELEBIT_TMP/etc/$my_daemon.yml
TELEBITD_CONFIG=$TELEBIT_REAL_PATH/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 fi
export TELEBITD_CONFIG
export TELEBIT_SOCK export TELEBIT_SOCK
export TELEBIT_NODE=$TELEBIT_REAL_PATH/bin/node export TELEBIT_NODE=$TELEBIT_REAL_PATH/bin/node
export TELEBIT_NPM=$TELEBIT_REAL_PATH/bin/npm 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 TELEBITD_BIN=$TELEBIT_REAL_PATH/bin/telebitd
export TELEBIT_JS=$TELEBIT_REAL_PATH/bin/telebit.js export TELEBIT_JS=$TELEBIT_REAL_PATH/bin/telebit.js
export TELEBITD_JS=$TELEBIT_REAL_PATH/bin/telebitd.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 NODE_PATH="$TELEBIT_REAL_PATH/lib/node_modules"
export NPM_CONFIG_PREFIX="$TELEBIT_REAL_PATH" export NPM_CONFIG_PREFIX="$TELEBIT_REAL_PATH"

View File

@ -32,6 +32,7 @@ module.exports.sync = function (opts) {
.replace(/{TELEBIT_RW_DIRS}/g, vars.telebitRwDirs || '{TELEBIT_RW_DIRS}') .replace(/{TELEBIT_RW_DIRS}/g, vars.telebitRwDirs || '{TELEBIT_RW_DIRS}')
.replace(/{TELEBIT_CONFIG}/g, vars.telebitConfig || '{TELEBIT_CONFIG}') .replace(/{TELEBIT_CONFIG}/g, vars.telebitConfig || '{TELEBIT_CONFIG}')
.replace(/{TELEBITD_CONFIG}/g, vars.telebitdConfig || '{TELEBITD_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'); fs.writeFileSync(f.launcher, text, 'utf8');
}; };
@ -70,6 +71,7 @@ function run() {
, telebitGroup: process.env.TELEBIT_GROUP || ('darwin' === os.platform() ? 'staff' : os.userInfo().username) , 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') , 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') , 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.telebitNpm = process.env.TELEBIT_NPM || path.resolve(vars.telebitNode, '../npm');
vars.nodePath = process.env.NODE_PATH || path.resolve(vars.telebitNode, '../lib/node_modules'); vars.nodePath = process.env.NODE_PATH || path.resolve(vars.telebitNode, '../lib/node_modules');