feat: initial webssh tooling
This commit is contained in:
parent
f6d8ad25e1
commit
7dfcbef774
16 changed files with 792 additions and 83 deletions
36
app/server/agent/dispatcher.ts
Normal file
36
app/server/agent/dispatcher.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import type { Writable } from 'node:stream';
|
||||
import { decode, encode } from 'cbor2';
|
||||
|
||||
interface Command {
|
||||
op: string;
|
||||
payload: unknown;
|
||||
}
|
||||
|
||||
interface SSHConnectCommand extends Command {
|
||||
op: 'ssh_conn';
|
||||
payload: {
|
||||
sessionId: string;
|
||||
username: string;
|
||||
hostname: string;
|
||||
port: number;
|
||||
};
|
||||
}
|
||||
|
||||
type AgentCommand = SSHConnectCommand;
|
||||
|
||||
export async function dispatchCommand(
|
||||
dispatcher: Writable,
|
||||
command: AgentCommand,
|
||||
) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const encodedCommand = Buffer.concat([encode(command), Buffer.from('\n')]);
|
||||
dispatcher.write(encodedCommand, (err) => {
|
||||
console.log('Command dispatched:', command, err);
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue