complete merge

This commit is contained in:
AJ ONeal 2018-10-15 22:04:32 -06:00
當前提交 311e82b9b6
共有 4 個文件被更改,包括 11091 次插入3 次删除

查看文件

@ -588,7 +588,8 @@ function handleApi(req, res) {
function getStatus() {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(
{ status: (state.config.disable ? 'disabled' : 'enabled')
{ module: 'status'
, status: (state.config.disable ? 'disabled' : 'enabled')
, ready: ((state.config.relay && (state.config.token || state.config.agreeTos)) ? true : false)
, active: !!myRemote
, connected: 'maybe (todo)'
@ -697,15 +698,30 @@ 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 (state._ipc.port) {
if ('port' === state.config.ipc.type) {
serverOpts.host = 'localhost';
serverOpts.port = state._ipc.port;
serverOpts.port = state._ipc.port || 0;
} else {
serverOpts.path = state._ipc.path;
}
@ -718,6 +734,21 @@ 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() {

60
lib/admin/index.html Normal file
查看文件

@ -0,0 +1,60 @@
<!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>

50
lib/admin/js/app.js Normal file
查看文件

@ -0,0 +1,50 @@
;(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 Normal file

文件差異過大導致無法顯示 Load Diff