File size: 2,995 Bytes
55f5cc0
8e4fdaa
5e79f51
8e4fdaa
 
 
5e79f51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e4fdaa
5e79f51
8e4fdaa
 
 
 
 
5e79f51
8e4fdaa
5e79f51
8e4fdaa
55f5cc0
20bc127
8e4fdaa
 
 
 
5e79f51
 
 
 
 
 
 
 
 
8e4fdaa
5e79f51
8e4fdaa
5e79f51
8e4fdaa
 
5e79f51
 
 
 
 
 
 
8e4fdaa
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from flask import Flask, request, jsonify, render_template_string, send_from_directory
import subprocess
import os

app = Flask(__name__)

# HTML para la interfaz web
html_form = """
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>SteamCMD Workshop Downloader</title>
  </head>
  <body>
    <h1>Bienvenido al descargador de la Steam Workshop con SteamCMD!</h1>
    <form action="/execute" method="post">
      <label for="command">Ingresa el comando de SteamCMD:</label><br>
      <input type="text" id="command" name="command" required><br><br>
      <input type="submit" value="Ejecutar">
    </form>
    <div id="output">
      {% if output %}
      <h3>Resultado:</h3>
      <pre>{{ output }}</pre>
      {% endif %}
      {% if downloads %}
      <h3>Archivos descargados:</h3>
      <ul>
        {% for file in downloads %}
        <li><a href="/download/{{ file }}" download>{{ file }}</a></li>
        {% endfor %}
      </ul>
      {% endif %}
    </div>
  </body>
</html>
"""

# Ruta principal para mostrar el formulario HTML
@app.route('/', methods=['GET'])
def home():
    return render_template_string(html_form)

# Ruta para ejecutar comandos de steamcmd
@app.route('/execute', methods=['POST'])
def execute():
    try:
        command = request.form.get('command')
        if not command:
            return render_template_string(html_form, output='No se proporcionó ningún comando')

        # Añadir el comando base para steamcmd y asegurar que se ejecuta en el directorio correcto
        steamcmd_command = f"cd /steamcmd && chmod -R 755 ./linux32 && ./steamcmd.sh +login anonymous {command} +quit"
        
        # Ejecutar el comando en la terminal
        result = subprocess.run(steamcmd_command, shell=True, capture_output=True, text=True)

        # Obtener la lista de archivos descargados
        download_path = "/steamcmd/steamapps/workshop/content"
        downloads = []
        if os.path.exists(download_path):
            for root, dirs, files in os.walk(download_path):
                for file in files:
                    downloads.append(os.path.relpath(os.path.join(root, file), start=download_path))

        # Retornar la salida del comando y los archivos descargados
        if result.returncode == 0:
            return render_template_string(html_form, output=result.stdout, downloads=downloads)
        else:
            return render_template_string(html_form, output=result.stderr, downloads=downloads)

    except Exception as e:
        return render_template_string(html_form, output=str(e))

# Ruta para descargar los archivos
@app.route('/download/<path:filename>', methods=['GET'])
def download_file(filename):
    download_path = "/steamcmd/steamapps/workshop/content"
    return send_from_directory(download_path, filename, as_attachment=True)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)