butlerx
7 years ago
No known key found for this signature in database
GPG Key ID: B37CA765BAA89170
6 changed files with
29 additions and
7 deletions
-
lib/command.mjs
-
lib/emitter.mjs
-
lib/index.mjs
-
lib/logger.mjs
-
lib/server.mjs
-
package.json
|
|
@ -1,10 +1,21 @@ |
|
|
|
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) |
|
|
|
? ['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('@'), |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@ -53,6 +53,7 @@ class WeTTy extends EventEmitter { |
|
|
|
auth, |
|
|
|
port, |
|
|
|
}); |
|
|
|
this.emit('debug', `sshUser: ${sshUser}, args: ${args}`); |
|
|
|
if (sshUser) { |
|
|
|
term.spawn(socket, args); |
|
|
|
} else { |
|
|
|
|
|
@ -61,7 +61,8 @@ export default class { |
|
|
|
}) |
|
|
|
.on('spawn', ({ msg }) => logger.info(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( |
|
|
|
{ |
|
|
|
user: sshuser, |
|
|
|
|
|
@ -7,9 +7,17 @@ const logger = createLogger({ |
|
|
|
colorize({ all: true }), |
|
|
|
label({ label: 'Wetty' }), |
|
|
|
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; |
|
|
|
|
|
@ -12,6 +12,7 @@ import events from './emitter.mjs'; |
|
|
|
const pubDir = path.join(__dirname, '..', 'public'); |
|
|
|
|
|
|
|
export default function createServer(port, { key, cert }) { |
|
|
|
events.emit('debug', `key: ${key}, cert: ${cert}, port: ${port}`); |
|
|
|
const app = express(); |
|
|
|
const wetty = (req, res) => res.sendFile(path.join(pubDir, 'index.html')); |
|
|
|
app |
|
|
|
|
|
@ -15,7 +15,7 @@ |
|
|
|
}, |
|
|
|
"main": "index.js", |
|
|
|
"scripts": { |
|
|
|
"lint": "eslint .", |
|
|
|
"lint": "eslint --ext .js,.mjs .", |
|
|
|
"build": "webpack", |
|
|
|
"start": "node .", |
|
|
|
"dev": |
|
|
|