Compare commits
No commits in common. "311e82b9b68edece4cf22d9bedca980b23f686e4" and "8f7e865d491af2c04a78c4a1b31206f975dd31fe" have entirely different histories.
311e82b9b6
...
8f7e865d49
@ -546,10 +546,6 @@ function parseConfig(err, text) {
|
||||
} else {
|
||||
console.info('> Rejecting SSH-over-HTTPS for now');
|
||||
}
|
||||
} else if ('status' === body.module) {
|
||||
// TODO funny one this one
|
||||
console.info('http://localhost:' + (body.port || state.config.ipc.port));
|
||||
console.info(JSON.stringify(body, null, 2));
|
||||
} else {
|
||||
console.info(JSON.stringify(body, null, 2));
|
||||
}
|
||||
|
@ -326,15 +326,8 @@ controllers.ssh = function (req, res, opts) {
|
||||
state.config.sshAuto = sshAuto;
|
||||
sshSuccess();
|
||||
};
|
||||
|
||||
var serveStatic = require('serve-static')(path.join(__dirname, '../lib/admin/'));
|
||||
function handleRemoteClient(req, res) {
|
||||
if (/^\/(rpc|api)\//.test(req.url)) {
|
||||
return handleApi(req, res);
|
||||
}
|
||||
serveStatic(req, res, require('finalhandler')(req, res));
|
||||
}
|
||||
function handleApi(req, res) {
|
||||
function serveControlsHelper() {
|
||||
controlServer = http.createServer(function (req, res) {
|
||||
var opts = url.parse(req.url, true);
|
||||
if (false && opts.query._body) {
|
||||
try {
|
||||
@ -588,8 +581,7 @@ function handleApi(req, res) {
|
||||
function getStatus() {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(
|
||||
{ module: 'status'
|
||||
, status: (state.config.disable ? 'disabled' : 'enabled')
|
||||
{ status: (state.config.disable ? 'disabled' : 'enabled')
|
||||
, ready: ((state.config.relay && (state.config.token || state.config.agreeTos)) ? true : false)
|
||||
, active: !!myRemote
|
||||
, connected: 'maybe (todo)'
|
||||
@ -683,9 +675,7 @@ function handleApi(req, res) {
|
||||
}
|
||||
route();
|
||||
});
|
||||
}
|
||||
function serveControlsHelper() {
|
||||
controlServer = http.createServer(handleRemoteClient);
|
||||
});
|
||||
|
||||
if (fs.existsSync(state._ipc.path)) {
|
||||
fs.unlinkSync(state._ipc.path);
|
||||
@ -698,30 +688,15 @@ function serveControlsHelper() {
|
||||
, readableAll: true
|
||||
, exclusive: false
|
||||
};
|
||||
if (!state.config.ipc) {
|
||||
state.config.ipc = {};
|
||||
}
|
||||
if (!state.config.ipc.path) {
|
||||
state.config.ipc.path = path.dirname(state._ipc.path);
|
||||
}
|
||||
require('mkdirp').sync(state.config.ipc.path);
|
||||
if (!state.config.ipc.type) {
|
||||
state.config.ipc.type = 'port';
|
||||
}
|
||||
var portFile = path.join(state.config.ipc.path, 'telebit.port');
|
||||
if (fs.existsSync(portFile)) {
|
||||
state._ipc.port = parseInt(fs.readFileSync(portFile, 'utf8').trim(), 10);
|
||||
}
|
||||
|
||||
if ('socket' === state._ipc.type) {
|
||||
require('mkdirp').sync(path.dirname(state._ipc.path));
|
||||
}
|
||||
// https://nodejs.org/api/net.html#net_server_listen_options_callback
|
||||
// path is ignore if port is defined
|
||||
// https://git.coolaj86.com/coolaj86/telebit.js/issues/23#issuecomment-326
|
||||
if ('port' === state.config.ipc.type) {
|
||||
if (state._ipc.port) {
|
||||
serverOpts.host = 'localhost';
|
||||
serverOpts.port = state._ipc.port || 0;
|
||||
serverOpts.port = state._ipc.port;
|
||||
} else {
|
||||
serverOpts.path = state._ipc.path;
|
||||
}
|
||||
@ -734,21 +709,6 @@ function serveControlsHelper() {
|
||||
//console.log(this.address());
|
||||
console.info("[info] Listening for commands on", address);
|
||||
});
|
||||
controlServer.on('error', function (err) {
|
||||
if ('EADDRINUSE' === err.code) {
|
||||
try {
|
||||
fs.unlinkSync(portFile);
|
||||
} catch(e) {
|
||||
// nada
|
||||
}
|
||||
setTimeout(function () {
|
||||
console.log("trying again");
|
||||
serveControlsHelper();
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
console.error('failed to start c&c server:', err);
|
||||
});
|
||||
}
|
||||
|
||||
function serveControls() {
|
||||
|
@ -1,60 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Telebit Admin</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="v-app">
|
||||
<h1>Telebit Admin</h1>
|
||||
|
||||
<section>
|
||||
<h2>GET /api/config</h2>
|
||||
<pre><code>{{ config }}</code></pre>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>GET /api/status</h2>
|
||||
<pre><code>{{ status }}</code></pre>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>POST /api/init</h2>
|
||||
<form v-on:submit.stop.prevent="initialize">
|
||||
|
||||
<label for="-email">Email:</label>
|
||||
<input id="-email" v-model="init.email" type="text" placeholder="john@example.com">
|
||||
<br>
|
||||
|
||||
<label for="-teletos"><input id="-teletos" v-model="init.teletos" type="checkbox">
|
||||
Accept Telebit Terms of Service</label>
|
||||
<br>
|
||||
|
||||
<label for="-letos"><input id="-letos" v-model="init.letos" type="checkbox">
|
||||
Accept Let's Encrypt Terms of Service</label>
|
||||
<br>
|
||||
|
||||
</form>
|
||||
<pre><code>{{ init }}</code></pre>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>POST /api/http</h2>
|
||||
<pre><code>{{ http }}</code></pre>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>POST /api/tcp</h2>
|
||||
<pre><code>{{ tcp }}</code></pre>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>POST /api/ssh</h2>
|
||||
<pre><code>{{ ssh }}</code></pre>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="js/vue.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,50 +0,0 @@
|
||||
;(function () {
|
||||
'use strict';
|
||||
|
||||
console.log("hello");
|
||||
|
||||
var Vue = window.Vue;
|
||||
var api = {};
|
||||
|
||||
api.config = function apiConfig() {
|
||||
return window.fetch("/api/config", { method: "GET" }).then(function (resp) {
|
||||
return resp.json().then(function (json) {
|
||||
appData.config = json;
|
||||
return json;
|
||||
});
|
||||
});
|
||||
};
|
||||
api.status = function apiStatus() {
|
||||
return window.fetch("/api/status", { method: "GET" }).then(function (resp) {
|
||||
return resp.json().then(function (json) {
|
||||
appData.status = json;
|
||||
return json;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var appData = {
|
||||
config: null
|
||||
, status: null
|
||||
, init: {}
|
||||
, http: null
|
||||
, tcp: null
|
||||
, ssh: null
|
||||
};
|
||||
var appMethods = {
|
||||
initialize: function () {
|
||||
console.log("call initialize");
|
||||
}
|
||||
};
|
||||
|
||||
new Vue({
|
||||
el: ".v-app"
|
||||
, data: appData
|
||||
, methods: appMethods
|
||||
});
|
||||
|
||||
api.config();
|
||||
api.status();
|
||||
|
||||
window.api = api;
|
||||
}());
|
10947
lib/admin/js/vue.js
10947
lib/admin/js/vue.js
File diff suppressed because it is too large
Load Diff
@ -59,7 +59,7 @@ Use \"telebit help [command]\" for more information about a command, including f
|
||||
|
||||
Copyright 2015-2018 AJ ONeal https://telebit.cloud MPL-2.0 Licensed (RAWR!)"
|
||||
|
||||
status = "usage: telebit status
|
||||
status = "usage: telebit status <path/port/none> [subdomain]
|
||||
|
||||
'telebit status' shows details about the current connections (or lack thereof).
|
||||
|
||||
|
@ -79,25 +79,11 @@ module.exports.create = function (state) {
|
||||
url += ('?_body=' + encodeURIComponent(json));
|
||||
}
|
||||
var method = opts.method || (args && 'POST') || 'GET';
|
||||
var reqOpts = {
|
||||
method: method
|
||||
var req = http.request({
|
||||
socketPath: state._ipc.path
|
||||
, method: method
|
||||
, path: url
|
||||
};
|
||||
var fs = require('fs');
|
||||
var portFile = path.join(path.dirname(state._ipc.path), 'telebit.port');
|
||||
if (fs.existsSync(portFile)) {
|
||||
reqOpts.host = 'localhost';
|
||||
reqOpts.port = parseInt(fs.readFileSync(portFile, 'utf8').trim(), 10);
|
||||
if (!state.config.ipc) {
|
||||
state.config.ipc = {};
|
||||
}
|
||||
state.config.ipc.type = 'port';
|
||||
state.config.ipc.path = path.dirname(state._ipc.path);
|
||||
state.config.ipc.port = reqOpts.port;
|
||||
} else {
|
||||
reqOpts.socketPath = state._ipc.path;
|
||||
}
|
||||
var req = http.request(reqOpts, function (resp) {
|
||||
}, function (resp) {
|
||||
makeResponder(service, resp, fn);
|
||||
});
|
||||
|
||||
|
@ -84,8 +84,8 @@ Launcher.install = function (things, fn) {
|
||||
};
|
||||
vars.telebitBinTpl = path.join(telebitRoot, 'usr/share/dist/bin/telebit.tpl');
|
||||
vars.telebitNpm = path.resolve(vars.telebitNode, '../npm');
|
||||
vars.nodePath = path.resolve(vars.telebitNode, '../../lib/node_modules');
|
||||
vars.npmConfigPrefix = path.resolve(vars.telebitNode, '..', '..');
|
||||
vars.nodePath = path.resolve(vars.telebitNode, '../lib/node_modules');
|
||||
vars.npmConfigPrefix = path.resolve(vars.telebitNode, '..');
|
||||
vars.userspace = (!things.telebitUser || (things.telebitUser === os.userInfo().username)) ? true : false;
|
||||
if (-1 === vars.telebitRwDirs.indexOf(vars.npmConfigPrefix)) {
|
||||
vars.telebitRwDirs.push(vars.npmConfigPrefix);
|
||||
|
@ -224,20 +224,16 @@ pushd $TELEBIT_TMP >/dev/null
|
||||
else
|
||||
echo -n "."
|
||||
fi
|
||||
set +e
|
||||
$tmp_npm install >/dev/null 2>/dev/null &
|
||||
# ursa is now an entirely optional dependency for key generation
|
||||
# but very much needed on ARM devices
|
||||
$tmp_npm install ursa >/dev/null 2>/dev/null &
|
||||
tmp_npm_pid=$!
|
||||
while [ -n "$tmp_npm_pid" ]; do
|
||||
sleep 2
|
||||
echo -n "."
|
||||
kill -s 0 $tmp_npm_pid >/dev/null 2>/dev/null || tmp_npm_pid=""
|
||||
done
|
||||
set -e
|
||||
echo -n "."
|
||||
$tmp_npm install >/dev/null 2>/dev/null
|
||||
# ursa is now an entirely optional dependency for key generation
|
||||
# but very much needed on ARM devices
|
||||
$tmp_npm install ursa >/dev/null 2>/dev/null || true
|
||||
popd >/dev/null
|
||||
|
||||
if [ -n "${TELEBIT_DEBUG}" ]; then
|
||||
@ -429,8 +425,8 @@ if [ -d "/Library/LaunchDaemons" ]; then
|
||||
|
||||
if [ -n "${TELEBIT_DEBUG}" ]; then
|
||||
echo " > launchctl unload -w $my_app_launchd_service >/dev/null 2>/dev/null"
|
||||
fi
|
||||
launchctl unload -w "$my_app_launchd_service" >/dev/null 2>/dev/null
|
||||
fi
|
||||
else
|
||||
my_app_launchd_service_skel="usr/share/dist/Library/LaunchDaemons/${my_app_pkg_name}.plist"
|
||||
my_app_launchd_service="$my_root/Library/LaunchDaemons/${my_app_pkg_name}.plist"
|
||||
|
@ -79,8 +79,8 @@ function run() {
|
||||
, 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');
|
||||
vars.npmConfigPrefix = process.env.NPM_CONFIG_PREFIX || path.resolve(vars.telebitNode, '..', '..');
|
||||
vars.nodePath = process.env.NODE_PATH || path.resolve(vars.telebitNode, '../lib/node_modules');
|
||||
vars.npmConfigPrefix = process.env.NPM_CONFIG_PREFIX || path.resolve(vars.telebitNode, '..');
|
||||
if (-1 === vars.telebitRwDirs.indexOf(vars.npmConfigPrefix)) {
|
||||
vars.telebitRwDirs.push(vars.npmConfigPrefix);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user