From 51c58e22a02d508198a3198c099659363e687c16 Mon Sep 17 00:00:00 2001 From: "Satur@it-depot.ru" Date: Wed, 5 Mar 2025 09:43:53 +0300 Subject: [PATCH] icons --- app.py | 25 ++++++++++++------------ templates/index.html | 46 +++++++++++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/app.py b/app.py index 8dc1ddd..8badfb8 100644 --- a/app.py +++ b/app.py @@ -11,7 +11,7 @@ app = FastAPI() conn = sqlite3.connect("/db/rustdesk.db", check_same_thread=False) cursor = conn.cursor() -# Создаем таблицы +# Создаем таблицы (добавляем поле protocol) cursor.execute(""" CREATE TABLE IF NOT EXISTS folders ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -23,10 +23,11 @@ CREATE TABLE IF NOT EXISTS folders ( cursor.execute(""" CREATE TABLE IF NOT EXISTS installs ( id INTEGER PRIMARY KEY AUTOINCREMENT, - rust_id TEXT, + rust_id TEXT, -- Оставляем название поля для совместимости, но оно теперь универсальное (ID подключения) computer_name TEXT, install_time TEXT, folder_id INTEGER, + protocol TEXT DEFAULT 'rustdesk', -- Новое поле с протоколом, по умолчанию RustDesk FOREIGN KEY (folder_id) REFERENCES folders(id) ) """) @@ -55,6 +56,7 @@ class InstallData(BaseModel): computer_name: str | None = None install_time: str | None = None folder_id: int | None = None + protocol: str | None = 'rustdesk' # По умолчанию RustDesk # Монтируем папку templates как статические файлы app.mount("/templates", StaticFiles(directory="templates"), name="templates") @@ -98,44 +100,43 @@ def delete_folder(folder_id: int): @app.get("/api/installs") def get_installs(): cursor.execute(""" - SELECT i.id, i.rust_id, i.computer_name, i.install_time, i.folder_id, f.name as folder_name + SELECT i.id, i.rust_id, i.computer_name, i.install_time, i.folder_id, f.name as folder_name, i.protocol FROM installs i LEFT JOIN folders f ON i.folder_id = f.id """) rows = cursor.fetchall() return [{"id": row[0], "rust_id": row[1], "computer_name": row[2], - "install_time": row[3], "folder_id": row[4], "folder_name": row[5]} + "install_time": row[3], "folder_id": row[4], "folder_name": row[5], "protocol": row[6]} for row in rows] @app.post("/api/install") def add_install(data: InstallData): install_time = data.install_time or datetime.datetime.now().isoformat() - # Если folder_id не указан (например, от скрипта), используем "Несортированные" folder_id = data.folder_id if data.folder_id is not None else unsorted_folder_id - cursor.execute("INSERT INTO installs (rust_id, computer_name, install_time, folder_id) VALUES (?, ?, ?, ?)", - (data.rust_id, data.computer_name, install_time, folder_id)) + protocol = data.protocol or 'rustdesk' # По умолчанию RustDesk для POST-запросов + cursor.execute("INSERT INTO installs (rust_id, computer_name, install_time, folder_id, protocol) VALUES (?, ?, ?, ?, ?)", + (data.rust_id, data.computer_name, install_time, folder_id, protocol)) conn.commit() return {"status": "success"} @app.put("/api/install/{install_id}") def update_install(install_id: int, data: InstallData): - # Получаем текущие данные записи - cursor.execute("SELECT rust_id, computer_name, install_time, folder_id FROM installs WHERE id = ?", (install_id,)) + cursor.execute("SELECT rust_id, computer_name, install_time, folder_id, protocol FROM installs WHERE id = ?", (install_id,)) current = cursor.fetchone() if not current: raise HTTPException(status_code=404, detail="Запись не найдена") - # Обновляем только те поля, которые переданы new_rust_id = data.rust_id if data.rust_id is not None else current[0] new_computer_name = data.computer_name if data.computer_name is not None else current[1] new_install_time = data.install_time if data.install_time is not None else current[2] new_folder_id = data.folder_id if data.folder_id is not None else current[3] + new_protocol = data.protocol if data.protocol is not None else current[4] cursor.execute(""" UPDATE installs - SET rust_id = ?, computer_name = ?, install_time = ?, folder_id = ? + SET rust_id = ?, computer_name = ?, install_time = ?, folder_id = ?, protocol = ? WHERE id = ? - """, (new_rust_id, new_computer_name, new_install_time, new_folder_id, install_id)) + """, (new_rust_id, new_computer_name, new_install_time, new_folder_id, new_protocol, install_id)) conn.commit() return {"status": "success"} diff --git a/templates/index.html b/templates/index.html index 7361695..7e59193 100644 --- a/templates/index.html +++ b/templates/index.html @@ -21,6 +21,7 @@ .header div { flex: 1; text-align: center; } .header div:hover { background: #e0e0e0; } .sort-arrow { font-size: 12px; margin-left: 5px; } + .protocol-icon { margin-right: 5px; } @@ -42,13 +43,21 @@

Добавить запись

- + +
-
Rust ID
+
ID подключения
Имя компьютера
Время установки
Действия
@@ -63,6 +72,15 @@ let sortField = null; let sortDirection = 'asc'; + const protocolIcons = { + 'rustdesk': '🖥️', // Эмодзи для RustDesk + 'anydesk': '🔴', // Эмодзи для AnyDesk + 'ammyy': '🟢', // Эмодзи для Ammyy Admin + 'teamviewer': '🔵', // Эмодзи для TeamViewer + 'vnc': '🟡', // Эмодзи для VNC + 'rdp': '🟣' // Эмодзи для RDP + }; + $(document).ready(function () { $('#folder-tree').jstree({ 'core': { @@ -120,12 +138,12 @@ function displayInstalls(installs) { $('#installs-list').html(installs.map(item => `
-
${item.rust_id}
+
${protocolIcons[item.protocol]}${item.rust_id}
${item.computer_name}
${item.install_time}
- Подключиться - + Подключиться +
@@ -173,7 +191,7 @@ function updateSortArrows() { $('.sort-arrow').text(''); if (sortField) { - $(`.header div:contains("${sortField === 'rust_id' ? 'Rust ID' : sortField === 'computer_name' ? 'Имя компьютера' : 'Время установки'}") .sort-arrow`) + $(`.header div:contains("${sortField === 'rust_id' ? 'ID подключения' : sortField === 'computer_name' ? 'Имя компьютера' : 'Время установки'}") .sort-arrow`) .text(sortDirection === 'asc' ? '↑' : '↓'); } } @@ -231,27 +249,29 @@ const rustId = $('#rustId').val(); const computerName = $('#computerName').val(); const installTime = $('#installTime').val() || new Date().toISOString(); + const protocol = $('#protocol').val(); $.ajax({ url: `${API_URL}/install`, type: 'POST', contentType: 'application/json', - data: JSON.stringify({ rust_id: rustId, computer_name: computerName, install_time: installTime, folder_id: selectedFolderId }), + data: JSON.stringify({ rust_id: rustId, computer_name: computerName, install_time: installTime, folder_id: selectedFolderId, protocol: protocol }), success: function () { loadInstalls(selectedFolderId); } }); } - function editInstall(id, rustId, computerName, installTime) { - const newRustId = prompt("Rust ID:", rustId); + function editInstall(id, rustId, computerName, installTime, protocol) { + const newRustId = prompt("ID подключения:", rustId); const newComputerName = prompt("Имя компьютера:", computerName); const newInstallTime = prompt("Время установки:", installTime); + const newProtocol = prompt("Протокол (rustdesk, anydesk, ammyy, teamviewer, vnc, rdp):", protocol); if (newRustId && newComputerName) { $.ajax({ url: `${API_URL}/install/${id}`, type: 'PUT', contentType: 'application/json', - data: JSON.stringify({ rust_id: newRustId, computer_name: newComputerName, install_time: newInstallTime, folder_id: selectedFolderId }), + data: JSON.stringify({ rust_id: newRustId, computer_name: newComputerName, install_time: newInstallTime, folder_id: selectedFolderId, protocol: newProtocol }), success: function () { loadInstalls(selectedFolderId); } @@ -286,9 +306,9 @@ }); } - function openRustDesk(rustId) { - if (confirm("Подключиться к " + rustId + "?")) { - window.location.href = `rustdesk://${rustId}`; + function openRemote(id, protocol) { + if (confirm(`Подключиться к ${id} через ${protocol}?`)) { + window.location.href = `${protocol}://${id}`; } }