Allow sending messages by directly providing them as a ssh commandline argument, by reading process.command

This commit is contained in:
ChaoticByte 2024-06-16 08:55:52 +02:00
parent 00b73bfa46
commit aca4f8c0be
No known key found for this signature in database

View file

@ -55,18 +55,24 @@ async def handle_connection(process: asyncssh.SSHServerProcess):
connected_msg = f"[connected] {username}\n" connected_msg = f"[connected] {username}\n"
stderr.write(connected_msg) stderr.write(connected_msg)
broadcast(connected_msg, True) broadcast(connected_msg, True)
while True: if process.command is not None:
try: line = process.command.strip("\r\n")
async for line in process.stdin: msg = f"{username}: {line}\n"
if line == "": raise asyncssh.BreakReceived(0) stdout.write(msg)
line = line.strip('\r\n') broadcast(msg)
msg = f"{username}: {line}\n" else:
stdout.write(msg) while True:
broadcast(msg) try:
except asyncssh.TerminalSizeChanged: async for line in process.stdin:
continue if line == "": raise asyncssh.BreakReceived(0)
finally: line = line.strip('\r\n')
break msg = f"{username}: {line}\n"
stdout.write(msg)
broadcast(msg)
except asyncssh.TerminalSizeChanged:
continue
finally:
break
except asyncssh.BreakReceived: except asyncssh.BreakReceived:
pass pass
except Exception as e: except Exception as e: