diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..86b1e36 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.9 +WORKDIR /app +COPY . . +RUN pip install fastapi uvicorn +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "6661"] diff --git a/backend/main.py b/backend/main.py new file mode 100644 index 0000000..e6127c2 --- /dev/null +++ b/backend/main.py @@ -0,0 +1,73 @@ +from fastapi import FastAPI, HTTPException +from pydantic import BaseModel +import sqlite3 +import datetime + +app = FastAPI() + +# Создаем соединение с базой данных +conn = sqlite3.connect("/db/rustdesk.db", check_same_thread=False) +cursor = conn.cursor() + +# Создаем таблицу, если её нет +cursor.execute(""" +CREATE TABLE IF NOT EXISTS installs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + rust_id TEXT, + computer_name TEXT, + install_time TEXT +) +""") +conn.commit() + +# Модель данных +class InstallData(BaseModel): + rust_id: str + computer_name: str + install_time: str + +# Маршрут для получения всех записей +@app.get("/api/installs") +def get_installs(): + cursor.execute("SELECT * FROM installs") + rows = cursor.fetchall() + # Преобразуем результаты в список словарей + result = [] + for row in rows: + result.append({ + "id": row[0], + "rust_id": row[1], + "computer_name": row[2], + "install_time": row[3] + }) + return result + +# Маршрут для добавления новой записи +@app.post("/api/install") +def add_install(data: InstallData): + cursor.execute("INSERT INTO installs (rust_id, computer_name, install_time) VALUES (?, ?, ?)", + (data.rust_id, data.computer_name, data.install_time)) + conn.commit() + return {"status": "success"} + +# Добавляем маршрут для удаления записи +@app.delete("/api/delete/{install_id}") +async def delete_install(install_id: int): + try: + cursor.execute("DELETE FROM installs WHERE id = ?", (install_id,)) + conn.commit() + if cursor.rowcount == 0: + raise HTTPException(status_code=404, detail="Запись не найдена") + return {"status": "success"} + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + +from fastapi.middleware.cors import CORSMiddleware + +app.add_middleware( + CORSMiddleware, + allow_origins=["http://10.0.0.10:8080", "http://localhost:8080"], # Добавляем localhost + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) \ No newline at end of file diff --git a/db/rustdesk.db b/db/rustdesk.db new file mode 100644 index 0000000..cf8b418 Binary files /dev/null and b/db/rustdesk.db differ diff --git a/db_v2.sqlite3 b/db_v2.sqlite3 new file mode 100644 index 0000000..720caf9 Binary files /dev/null and b/db_v2.sqlite3 differ diff --git a/db_v2.sqlite3-shm b/db_v2.sqlite3-shm new file mode 100644 index 0000000..620e856 Binary files /dev/null and b/db_v2.sqlite3-shm differ diff --git a/db_v2.sqlite3-wal b/db_v2.sqlite3-wal new file mode 100644 index 0000000..9debe7a Binary files /dev/null and b/db_v2.sqlite3-wal differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e3d028f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.8' + +services: + backend: + build: ./backend + ports: + - "6661:6661" + volumes: + - ./db:/db + + frontend: + build: ./frontend + ports: + - "8080:8080" + volumes: + - ./db:/db diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..7eccc31 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.9 +WORKDIR /app +COPY . . +RUN pip install flask +CMD ["python", "app.py"] diff --git a/frontend/app.py b/frontend/app.py new file mode 100644 index 0000000..0799dd0 --- /dev/null +++ b/frontend/app.py @@ -0,0 +1,16 @@ +from flask import Flask, render_template +import sqlite3 + +app = Flask(__name__) + +@app.route("/") +def index(): + conn = sqlite3.connect("/db/rustdesk.db") + cursor = conn.cursor() + cursor.execute("SELECT * FROM installs") + data = cursor.fetchall() + conn.close() + return render_template("index.html", installs=data) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8080, debug=True) diff --git a/frontend/templates/index.html b/frontend/templates/index.html new file mode 100644 index 0000000..a66cbb4 --- /dev/null +++ b/frontend/templates/index.html @@ -0,0 +1,69 @@ + + +
+ +| ID | +Rust ID | +Имя компьютера | +Время установки | +Действие | +
|---|