serverline-sim/src/modules/sshd.ts

34 lines
833 B
TypeScript
Raw Normal View History

2021-12-12 10:53:26 -05:00
import telnet from 'telnet';
2021-12-12 17:09:52 -05:00
import { exec } from '@kernel:base';
2021-12-12 10:53:26 -05:00
export default {
start() {
2021-12-12 11:23:03 -05:00
var telnet = require('telnet');
2021-12-12 10:53:26 -05:00
2021-12-12 11:23:03 -05:00
telnet.createServer(function (client: any) {
2021-12-12 10:53:26 -05:00
// make unicode characters work properly
client.do.transmit_binary()
// make the client emit 'window size' events
client.do.window_size()
// listen for the window size events from the client
2021-12-12 11:23:03 -05:00
client.on('window size', function (e: any) {
2021-12-12 10:53:26 -05:00
if (e.command === 'sb') {
console.log('telnet window resized to %d x %d', e.width, e.height)
}
})
// listen for the actual data from the client
2021-12-12 11:23:03 -05:00
client.on('data', function (b: any) {
2021-12-12 10:53:26 -05:00
exec(b);
client.write(b)
})
client.write('connected to Telnet server!')
}).listen(23)
}
}