Browse Source

add debug statement

pull/126/head
butlerx 7 years ago
parent
commit
ef64451a36
No known key found for this signature in database GPG Key ID: B37CA765BAA89170
  1. 17
      lib/command.mjs
  2. 1
      lib/emitter.mjs
  3. 3
      lib/index.mjs
  4. 12
      lib/logger.mjs
  5. 1
      lib/server.mjs
  6. 2
      package.json

17
lib/command.mjs

@ -1,10 +1,21 @@
const localhost = host => const localhost = host =>
process.getuid() === 0 && (host === 'localhost' || host === '0.0.0.0' || host === '127.0.0.1'); process.getuid() === 0 &&
(host === 'localhost' || host === '0.0.0.0' || host === '127.0.0.1');
export default ({ request: { headers }, client: { conn } }, { user, host, port, auth }) => ({ export default (
{ request: { headers }, client: { conn } },
{ user, host, port, auth },
) => ({
args: localhost(host) args: localhost(host)
? ['login', '-h', conn.remoteAddress.split(':')[3]] ? ['login', '-h', conn.remoteAddress.split(':')[3]]
: ['ssh', address(headers, user, host), '-p', port, '-o', `PreferredAuthentications=${auth}`], : [
'ssh',
address(headers, user, host),
'-p',
port,
'-o',
`PreferredAuthentications=${auth}`,
],
user: localhost(host) || user !== '' || user.includes('@'), user: localhost(host) || user !== '' || user.includes('@'),
}); });

1
lib/emitter.mjs

@ -53,6 +53,7 @@ class WeTTy extends EventEmitter {
auth, auth,
port, port,
}); });
this.emit('debug', `sshUser: ${sshUser}, args: ${args}`);
if (sshUser) { if (sshUser) {
term.spawn(socket, args); term.spawn(socket, args);
} else { } else {

3
lib/index.mjs

@ -61,7 +61,8 @@ export default class {
}) })
.on('spawn', ({ msg }) => logger.info(msg)) .on('spawn', ({ msg }) => logger.info(msg))
.on('connection', ({ msg, date }) => logger.info(`${date} ${msg}`)) .on('connection', ({ msg, date }) => logger.info(`${date} ${msg}`))
.on('server', ({ msg }) => logger.info(msg)); .on('server', ({ msg }) => logger.info(msg))
.on('debug', msg => logger.debug(msg));
return wetty.start( return wetty.start(
{ {
user: sshuser, user: sshuser,

12
lib/logger.mjs

@ -7,9 +7,17 @@ const logger = createLogger({
colorize({ all: true }), colorize({ all: true }),
label({ label: 'Wetty' }), label({ label: 'Wetty' }),
timestamp(), timestamp(),
printf(info => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`), printf(
info =>
`${info.timestamp} [${info.label}] ${info.level}: ${info.message}`,
),
), ),
transports: [new transports.Console({ handleExceptions: true })], transports: [
new transports.Console({
level: process.env.NODE_ENV === 'development' ? 'debug' : 'info',
handleExceptions: true,
}),
],
}); });
export default logger; export default logger;

1
lib/server.mjs

@ -12,6 +12,7 @@ import events from './emitter.mjs';
const pubDir = path.join(__dirname, '..', 'public'); const pubDir = path.join(__dirname, '..', 'public');
export default function createServer(port, { key, cert }) { export default function createServer(port, { key, cert }) {
events.emit('debug', `key: ${key}, cert: ${cert}, port: ${port}`);
const app = express(); const app = express();
const wetty = (req, res) => res.sendFile(path.join(pubDir, 'index.html')); const wetty = (req, res) => res.sendFile(path.join(pubDir, 'index.html'));
app app

2
package.json

@ -15,7 +15,7 @@
}, },
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"lint": "eslint .", "lint": "eslint --ext .js,.mjs .",
"build": "webpack", "build": "webpack",
"start": "node .", "start": "node .",
"dev": "dev":

Loading…
Cancel
Save