import paramiko, sys
sys.stdout.reconfigure(encoding="utf-8")

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("192.168.1.76", username="root", password="7309208104")

CONF = "/config/nginx/proxy-confs/msgreceiver.subdomain.conf"

# Načti aktuální obsah
_, out, _ = ssh.exec_command(f"docker exec swag cat {CONF}")
content = out.read().decode()
print("=== PŘED ===")
print(content)

# Nahraď limit
new_content = content.replace("client_max_body_size 50M;", "client_max_body_size 200M;")

# Zapiš zpět
_, out, err = ssh.exec_command(f"docker exec -i swag tee {CONF}")
out.channel.sendall(new_content.encode())
out.channel.shutdown_write()
print("=== PO ===")
print(new_content)

# Reload nginx
_, out, err = ssh.exec_command("docker exec swag nginx -s reload 2>&1")
result = out.read().decode() + err.read().decode()
print(f"=== nginx reload: {result.strip() or 'OK'} ===")

# Ověř
_, out, _ = ssh.exec_command(f"docker exec swag grep client_max_body_size {CONF}")
print(f"=== ověření: {out.read().decode().strip()} ===")

ssh.close()
