diff --git a/package.json b/package.json index b6d4bc5..b234da0 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "md5": "^2.3.0", "serverline": "^1.5.0", "ssh2": "^1.5.0", - "telnet": "^0.0.1", + "telnet": "git+https://github.com/TooTallNate/node-telnet.git#780340617e1f223de384cdfcb7cecf0a1a6f1159", "ts-node": "^10.4.0", "tsconfig-paths": "^3.12.0", "typescript": "^4.5.3", diff --git a/src/commands/ls.ts b/src/commands/ls.ts index f3229f3..ebc5610 100644 --- a/src/commands/ls.ts +++ b/src/commands/ls.ts @@ -9,7 +9,7 @@ export default function ls(flags: any) { console.log( ' ' + autoColorString(k.substring(0, 4)) - + ':', JSON.stringify(v.config, null, 2).replace('\n', ' ').trim() + + ':', JSON.stringify(v.config, null, 2).replace('\n', '\n ').trim() ); } } \ No newline at end of file diff --git a/src/externals.d.ts b/src/externals.d.ts index 847853f..23a0863 100644 --- a/src/externals.d.ts +++ b/src/externals.d.ts @@ -1,6 +1,7 @@ declare module "serverline"; declare module "telnet"; declare module "@kernel:base"; +declare module "@kernel:log-hook"; declare module "@commands:executor"; declare module "@commands:create"; declare module "@commands:ls"; diff --git a/src/modules/sshd.ts b/src/modules/sshd.ts index 9fb61c2..5d9ecea 100644 --- a/src/modules/sshd.ts +++ b/src/modules/sshd.ts @@ -1,34 +1,33 @@ import telnet from 'telnet'; - import { exec } from '@kernel:base'; +import log from '@kernel:log-hook'; -export default { - start() { - var telnet = require('telnet'); +export function start() { + telnet.createServer(function (client: any) { + + // 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 + client.on('window size', function (e: any) { + if (e.command === 'sb') { + // console.log('telnet window resized to %d x %d', e.width, e.height) + } + }) + + console.log('Telnet client connected'); - telnet.createServer(function (client: any) { - - // 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 - client.on('window size', function (e: any) { - 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 - client.on('data', function (b: any) { - exec(b); - client.write(b) - }) - - client.write('connected to Telnet server!') - - }).listen(23) - } + // listen for the actual data from the client + client.on('data', function (b: any) { + exec(b.toString().trim()); + }) + + log.on('data', (e: any) => { + client.write(e) + }) + + }).listen(this.config.port ?? 2323) } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index bfc7fb6..1bf3904 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,8 @@ "baseUrl": "./src", "outDir": "./dist", "declaration": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "target": "ESNext" }, "paths": { "@commands:executor": [""] diff --git a/yarn.lock b/yarn.lock index 4bb3718..e5f6f38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -220,6 +220,10 @@ telnet@^0.0.1: buffers "*" debug "*" +"telnet@git+https://github.com/TooTallNate/node-telnet.git#780340617e1f223de384cdfcb7cecf0a1a6f1159": + version "0.0.1" + resolved "git+https://github.com/TooTallNate/node-telnet.git#780340617e1f223de384cdfcb7cecf0a1a6f1159" + "traverse@>=0.3.0 <0.4": version "0.3.9" resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9"