diff --git a/onedrive/cron/Dockerfile b/onedrive/cron/Dockerfile index 76019b4..8838d59 100644 --- a/onedrive/cron/Dockerfile +++ b/onedrive/cron/Dockerfile @@ -1,21 +1,10 @@ -FROM ubuntu +FROM python:3.9-slim WORKDIR /app -RUN apt update && apt upgrade -y && apt autoremove -y && apt install python3 python3-pip -y && apt install git nano wget curl -y +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt -RUN pip install schedule +COPY script.py . -COPY . . - -ENV IP_PING="http://127.0.0.1:8080/call" - -ENV TOKEN="token" - -ENV PASSWORD_WEB="pass" - -ENV SUPERCOMANDO='curl -X POST -H "Content-Type: application/json" -d '{"password": "$PASSWORD_WEB" ,"refresh_token": "$TOKEN"}' "$IP_PING"' - -RUN chmod +x run.sh - -ENTRYPOINT ./run.sh +CMD ["python", "script.py"] \ No newline at end of file diff --git a/onedrive/cron/README.md b/onedrive/cron/README.md index 9f40230..4cb70d2 100644 --- a/onedrive/cron/README.md +++ b/onedrive/cron/README.md @@ -1,6 +1,3 @@ -## actualmente da error +## Actualizado, puede contener errores + -#### manual -```sh -apt update && apt install wget -y && bash -c "$(wget -qLO - https://raw.githubusercontent.com/kadma/pruebasdocker/main/onedrive/cron/script.sh)" -``` diff --git a/onedrive/cron/cron1m.py b/onedrive/cron/cron1m.py deleted file mode 100644 index 055c41b..0000000 --- a/onedrive/cron/cron1m.py +++ /dev/null @@ -1,21 +0,0 @@ -import os -import schedule -import time -import subprocess - -def ejecutar_comando(): - comando = os.environ.get('SUPERCOMANDO', default=None) - - if comando is not None: - subprocess.run(comando, shell=True) - else: - print("La variable de entorno no tiene un valor definido.") - -schedule.every(1).minutes.do(ejecutar_comando) - -while True: - # Ejecuta las tareas pendientes - schedule.run_pending() - - # Espera 1 segundo antes de volver a verificar - time.sleep(1) diff --git a/onedrive/cron/cron7h.py b/onedrive/cron/cron7h.py deleted file mode 100644 index 615e425..0000000 --- a/onedrive/cron/cron7h.py +++ /dev/null @@ -1,21 +0,0 @@ -import os -import schedule -import time -import subprocess - -def ejecutar_comando(): - comando = os.environ.get('SUPERCOMANDO', default=None) - - if comando is not None: - subprocess.run(comando, shell=True) - else: - print("La variable de entorno no tiene un valor definido.") - -schedule.every(7).hours.do(ejecutar_comando) - -while True: - # Ejecuta las tareas pendientes - schedule.run_pending() - - # Espera 1 segundo antes de volver a verificar - time.sleep(1) diff --git a/onedrive/cron/docker-compose.yml b/onedrive/cron/docker-compose.yml new file mode 100644 index 0000000..670aaf4 --- /dev/null +++ b/onedrive/cron/docker-compose.yml @@ -0,0 +1,12 @@ +--- +services: + odcron: + build: . + container_name: odcron + environment: + - IP=host:8080 # Cambia esto por la IP y puerto deseado + - PASSWORD=pass # Cambia esto por la contraseña deseada + - REFRESH_TOKEN=tokenit # Cambia esto por el token deseado + restart: unless-stopped + hostname: odcron + network_mode: bridge \ No newline at end of file diff --git a/onedrive/cron/requirements.txt b/onedrive/cron/requirements.txt new file mode 100644 index 0000000..56ae43f --- /dev/null +++ b/onedrive/cron/requirements.txt @@ -0,0 +1,2 @@ +requests +schedule \ No newline at end of file diff --git a/onedrive/cron/run.sh b/onedrive/cron/run.sh deleted file mode 100644 index b1787ad..0000000 --- a/onedrive/cron/run.sh +++ /dev/null @@ -1 +0,0 @@ -python3 cron7h.py diff --git a/onedrive/cron/script.sh b/onedrive/cron/script.sh index baaa72a..281f404 100644 --- a/onedrive/cron/script.sh +++ b/onedrive/cron/script.sh @@ -1,4 +1,46 @@ -apt update && apt upgrade -y && apt autoremove -y && apt install python3 python3-pip -y && apt install git nano curl -y -pip3 install schedule -wget -b -P /app/ https://raw.githubusercontent.com/kadma/pruebasdocker/main/onedrive/cron/cron1m.py -wget -b -P /app/ https://raw.githubusercontent.com/kadma/pruebasdocker/main/onedrive/cron/cron7h.py +import requests +import schedule +import time +import logging +import os + +# Configuración del logging +logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + +# Leer variables de entorno +IP = os.getenv("IP", "127.0.0.0:8080") # IP y puerto por defecto +PASSWORD = os.getenv("PASSWORD", "pass") # Password por defecto +REFRESH_TOKEN = os.getenv("REFRESH_TOKEN", "tokenit") # Token por defecto + +# Construir la URL correctamente +URL = f"http://{IP}/call" # Incluye el protocolo y la ruta +HEADERS = {"Content-Type": "application/json"} +DATA = {"password": PASSWORD, "refresh_token": REFRESH_TOKEN} + +def perform_curl(): + try: + # Realiza la solicitud POST + response = requests.post(URL, headers=HEADERS, json=DATA) + response.raise_for_status() # Lanza una excepción si la respuesta no es exitosa + logging.info(f"Success: {response.status_code} - {response.text[:100]}...") # Muestra solo los primeros 100 caracteres + except requests.exceptions.RequestException as e: + logging.error(f"Error: {e}") + +def initial_test(): + logging.info("Running initial test...") + perform_curl() + +def main(): + # Ejecuta la prueba inicial + initial_test() + + # Programa la ejecución cada minuto + schedule.every(1).minutes.do(perform_curl) + + # Bucle para mantener el script en ejecución + while True: + schedule.run_pending() + time.sleep(1) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/onedrive/engine/Dockerfile b/onedrive/engine/Dockerfile index bc4f3a9..30ffb71 100644 --- a/onedrive/engine/Dockerfile +++ b/onedrive/engine/Dockerfile @@ -1,25 +1,26 @@ -FROM ubuntu +# Usar una imagen base más ligera y específica +FROM python:3.9-slim +# Establecer el directorio de trabajo WORKDIR /app -RUN apt update && apt upgrade -y && apt autoremove -y && apt install python3 python3-pip -y && apt install git nano wget -y +# Instalar dependencias del sistema y limpiar caché en un solo RUN +RUN apt-get update && \ + apt-get install -y --no-install-recommends git wget && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +# Clonar el repositorio RUN git clone https://github.com/TheCaduceus/Microsoft-E5-Auto-Renewal /app -RUN pip install -r requirements.txt +# Instalar dependencias de Python +RUN pip install --no-cache-dir -r requirements.txt +# Copiar el resto de los archivos COPY . . -ENV E5_CLIENT_ID="id" - -ENV E5_CLIENT_SECRET="secret" - -ENV E5_REFRESH_TOKEN="token" - -ENV WEB_APP_PASSWORD="pass" - +# Exponer el puerto EXPOSE 8080 -RUN chmod +x run.sh - -ENTRYPOINT ./run.sh +# Establecer el comando de entrada +CMD ["python", "main.py"] \ No newline at end of file diff --git a/onedrive/engine/README.md b/onedrive/engine/README.md index 16ed9ad..92bf325 100644 --- a/onedrive/engine/README.md +++ b/onedrive/engine/README.md @@ -1,6 +1,2 @@ ## sin actualizar -#### manual -```sh -apt update && apt install wget -y && bash -c "$(wget -qLO - https://raw.githubusercontent.com/kadma/pruebasdocker/main/onedrive/engine/script.sh)" -``` diff --git a/onedrive/engine/docker-compose.yml b/onedrive/engine/docker-compose.yml new file mode 100644 index 0000000..e84055e --- /dev/null +++ b/onedrive/engine/docker-compose.yml @@ -0,0 +1,16 @@ +--- +services: + odengin: + build: . + container_name: odengin + environment: + - E5_CLIENT_ID=id + - E5_CLIENT_SECRET=secret + - E5_REFRESH_TOKEN=tokenit + - WEB_APP_PASSWORD=123 + - E5_WEB_APP_PASSWORD=123 + ports: + - 8089:8080 + restart: unless-stopped + hostname: odengin + network_mode: bridge \ No newline at end of file diff --git a/onedrive/engine/run.sh b/onedrive/engine/run.sh deleted file mode 100644 index eb7516b..0000000 --- a/onedrive/engine/run.sh +++ /dev/null @@ -1 +0,0 @@ -python3 main.py diff --git a/onedrive/engine/script.sh b/onedrive/engine/script.sh deleted file mode 100644 index cdac882..0000000 --- a/onedrive/engine/script.sh +++ /dev/null @@ -1,4 +0,0 @@ -apt update && apt upgrade -y && apt autoremove -y && apt install python3 python3-pip -y && apt install git nano curl -y -git clone https://github.com/TheCaduceus/Microsoft-E5-Auto-Renewal /app -pip3 install -r /app/requirements.txt -python3 /app/main.py