diff --git a/scripts/deploy_remote.py b/scripts/deploy_remote.py new file mode 100644 index 0000000..9fd1580 --- /dev/null +++ b/scripts/deploy_remote.py @@ -0,0 +1,73 @@ +""" +Script de despliegue remoto a contenedor LXC Proxmox (10.0.0.217). +Lee credenciales de .credenciales sin exponerlas en logs. +""" +import os +import re +import paramiko +import requests + +CREDS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".credenciales")) + +def parse_credentials(): + creds = {"host": "10.0.0.217", "user": "root", "password": ""} + if os.path.exists(CREDS_PATH): + with open(CREDS_PATH, "r", encoding="utf-8") as f: + content = f.read() + m_pass = re.search(r"password[:=]\s*([^\r\n]+)", content, re.IGNORECASE) + if not m_pass: + m_pass = re.search(r"clave[:=]\s*([^\r\n]+)", content, re.IGNORECASE) + if not m_pass: + m_pass = re.search(r"pass[:=]\s*([^\r\n]+)", content, re.IGNORECASE) + if m_pass: + creds["password"] = m_pass.group(1).strip() + + m_host = re.search(r"host[:=]\s*([^\r\n]+)", content, re.IGNORECASE) + if m_host: + creds["host"] = m_host.group(1).strip() + + m_user = re.search(r"user[:=]\s*([^\r\n]+)", content, re.IGNORECASE) + if m_user: + creds["user"] = m_user.group(1).strip() + return creds + +def run_remote(): + creds = parse_credentials() + if not creds["password"]: + print("[!] No se encontró contraseña en .credenciales") + return + + print(f"[*] Conectando vía SSH a {creds['user']}@{creds['host']}...") + client = paramiko.SSHClient() + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + client.connect(creds["host"], username=creds["user"], password=creds["password"], timeout=15) + + commands = [ + "cd /opt/admin-edu-space && git fetch origin dev && git reset --hard origin/dev", + "systemctl restart admin-edu-space-backend admin-edu-space-frontend", + "systemctl is-active admin-edu-space-backend admin-edu-space-frontend" + ] + + for cmd in commands: + print(f"[*] Ejecutando: {cmd}") + stdin, stdout, stderr = client.exec_command(cmd) + out = stdout.read().decode("utf-8").strip() + err = stderr.read().decode("utf-8").strip() + if out: + print(f" Salida:\n{out}") + if err: + print(f" Avisos:\n{err}") + + client.close() + print("[+] Conexión SSH cerrada.") + + print("[*] Verificando endpoint público https://eduspace.oemspot.com.ar/version ...") + try: + r = requests.get("https://eduspace.oemspot.com.ar/version", timeout=10, verify=False) + print(f"[+] Estado HTTP: {r.status_code}") + print(f"[+] Respuesta: {r.text.strip()}") + except Exception as e: + print(f"[!] Error al verificar endpoint público: {e}") + +if __name__ == "__main__": + run_remote()