source/main.py aktualisiert
This commit is contained in:
@@ -298,7 +298,7 @@ async def handle_telegram_message(update: Update, context: ContextTypes.DEFAULT_
|
|||||||
if n:
|
if n:
|
||||||
try:
|
try:
|
||||||
proc = await asyncio.create_subprocess_shell(
|
proc = await asyncio.create_subprocess_shell(
|
||||||
f"ssh -o StrictHostKeyChecking=no {n['user']}@{n['ip']} '{cmd}'",
|
f"ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR {n['user']}@{n['ip']} '{cmd}'",
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.STDOUT
|
stderr=asyncio.subprocess.STDOUT
|
||||||
)
|
)
|
||||||
@@ -371,7 +371,7 @@ async def get_remote_info(ip, user):
|
|||||||
"""Versucht Linux/Mac-Infos zu lesen, falls fehlgeschlagen, dann Windows."""
|
"""Versucht Linux/Mac-Infos zu lesen, falls fehlgeschlagen, dann Windows."""
|
||||||
# 1. Versuch: Linux/Mac
|
# 1. Versuch: Linux/Mac
|
||||||
linux_cmd = "uname -m && (sw_vers -productName 2>/dev/null || grep PRETTY_NAME /etc/os-release 2>/dev/null | cut -d= -f2 || uname -s) && (command -v docker >/dev/null 2>&1 && echo 1 || echo 0)"
|
linux_cmd = "uname -m && (sw_vers -productName 2>/dev/null || grep PRETTY_NAME /etc/os-release 2>/dev/null | cut -d= -f2 || uname -s) && (command -v docker >/dev/null 2>&1 && echo 1 || echo 0)"
|
||||||
ssh_cmd = f"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=3 {user}@{ip} \"{linux_cmd}\""
|
ssh_cmd = f"ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o ConnectTimeout=3 {user}@{ip} \"{linux_cmd}\""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(ssh_cmd, shell=True, stderr=subprocess.DEVNULL).decode().strip().split('\n')
|
output = subprocess.check_output(ssh_cmd, shell=True, stderr=subprocess.DEVNULL).decode().strip().split('\n')
|
||||||
@@ -387,7 +387,7 @@ async def get_remote_info(ip, user):
|
|||||||
# 2. Versuch: Windows (CMD)
|
# 2. Versuch: Windows (CMD)
|
||||||
# ver = OS Version, echo %PROCESSOR_ARCHITECTURE% = Arch, where docker = Docker Check
|
# ver = OS Version, echo %PROCESSOR_ARCHITECTURE% = Arch, where docker = Docker Check
|
||||||
win_cmd = 'ver && echo %PROCESSOR_ARCHITECTURE% && (where docker >nul 2>&1 && echo 1 || echo 0)'
|
win_cmd = 'ver && echo %PROCESSOR_ARCHITECTURE% && (where docker >nul 2>&1 && echo 1 || echo 0)'
|
||||||
ssh_cmd = f"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=3 {user}@{ip} \"{win_cmd}\""
|
ssh_cmd = f"ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o ConnectTimeout=3 {user}@{ip} \"{win_cmd}\""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(ssh_cmd, shell=True).decode().strip().split('\n')
|
output = subprocess.check_output(ssh_cmd, shell=True).decode().strip().split('\n')
|
||||||
@@ -422,7 +422,7 @@ async def bootstrap_node(ip, user, password):
|
|||||||
cmd_universal = f'mkdir .ssh & echo {pub_key} >> .ssh/authorized_keys'
|
cmd_universal = f'mkdir .ssh & echo {pub_key} >> .ssh/authorized_keys'
|
||||||
|
|
||||||
# sshpass direkt mit dem simplen Befehl
|
# sshpass direkt mit dem simplen Befehl
|
||||||
setup_cmd = f"sshpass -p '{password}' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {user}@{ip} \"{cmd_universal}\""
|
setup_cmd = f"sshpass -p '{password}' ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR -o UserKnownHostsFile=/dev/null {user}@{ip} \"{cmd_universal}\""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Wir führen es aus. Das "2x Passwort"-Problem kommt oft von TTY-Anfragen.
|
# Wir führen es aus. Das "2x Passwort"-Problem kommt oft von TTY-Anfragen.
|
||||||
@@ -687,7 +687,7 @@ async def chat_endpoint(websocket: WebSocket):
|
|||||||
async def run_remote_task(ip, user, cmd, history_key="private"): # history_key als Parameter
|
async def run_remote_task(ip, user, cmd, history_key="private"): # history_key als Parameter
|
||||||
await manager.broadcast(f"🚀 Task: {cmd} auf {ip}")
|
await manager.broadcast(f"🚀 Task: {cmd} auf {ip}")
|
||||||
proc = await asyncio.create_subprocess_shell(
|
proc = await asyncio.create_subprocess_shell(
|
||||||
f"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {user}@{ip} '{cmd}'",
|
f"ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR -o UserKnownHostsFile=/dev/null {user}@{ip} '{cmd}'",
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.STDOUT
|
stderr=asyncio.subprocess.STDOUT
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user