From 5141bcdb0f1d167e12b3315e5b90641b7ec1da91 Mon Sep 17 00:00:00 2001 From: DanailDR Date: Thu, 24 Sep 2026 08:39:26 +0300 Subject: [PATCH] fix delete connection POST request --- deployment/docker-compose.yml | 2 +- src/static/webssh.js | 11 ++++++----- src/webssh_backend/config.py | 21 +++++++++++++++------ src/webssh_backend/database.py | 4 ++++ src/webssh_backend/http_api.py | 2 ++ 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml index a5c47a4..0dcad2c 100644 --- a/deployment/docker-compose.yml +++ b/deployment/docker-compose.yml @@ -38,7 +38,7 @@ services: # Optionally expose code to other services (read-only) # - ./:/srv/webssh:ro healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/"] + test: ["CMD", "python", "-c", "import sys, urllib.request; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/', timeout=5).getcode() == 200 else 1)"] interval: 30s timeout: 10s retries: 3 diff --git a/src/static/webssh.js b/src/static/webssh.js index aa86b39..a099cfa 100644 --- a/src/static/webssh.js +++ b/src/static/webssh.js @@ -776,16 +776,17 @@ function disconnectConnection(id) { } } -function deleteConnection(id) { +async function deleteConnection(id) { if (!confirm('Delete this connection?')) return; const conn = getConnection(id); - if (conn && conn.socket) { - conn.socket.close(); + if (!await deleteConnectionFromServer(id)) { + alert('Failed to delete connection from server. Please try again.'); + return; } - + + if (conn && conn.socket) conn.socket.close(); connections = connections.filter(c => c.id !== id); - deleteConnectionFromServer(id); // Delete from server storage autoSaveConnections(); if (currentConnectionId === id) { diff --git a/src/webssh_backend/config.py b/src/webssh_backend/config.py index 27868ac..494e4ef 100644 --- a/src/webssh_backend/config.py +++ b/src/webssh_backend/config.py @@ -75,18 +75,27 @@ def parse_size(size_str): size_str = size_str.upper().strip() logger.info(f"parse_size called with: '{size_str}'") - if size_str.endswith('M') or size_str.endswith('MB'): - # Remove 'M' or 'MB' and convert to bytes + if size_str.endswith('MB'): + result = int(float(size_str[:-2]) * 1024 * 1024) + logger.info(f"parse_size result: {result} bytes (from {size_str})") + return result + elif size_str.endswith('M'): result = int(float(size_str[:-1]) * 1024 * 1024) logger.info(f"parse_size result: {result} bytes (from {size_str})") return result - elif size_str.endswith('K') or size_str.endswith('KB'): - # Remove 'K' or 'KB' and convert to bytes + elif size_str.endswith('KB'): + result = int(float(size_str[:-2]) * 1024) + logger.info(f"parse_size result: {result} bytes (from {size_str})") + return result + elif size_str.endswith('K'): result = int(float(size_str[:-1]) * 1024) logger.info(f"parse_size result: {result} bytes (from {size_str})") return result - elif size_str.endswith('G') or size_str.endswith('GB'): - # Remove 'G' or 'GB' and convert to bytes + elif size_str.endswith('GB'): + result = int(float(size_str[:-2]) * 1024 * 1024 * 1024) + logger.info(f"parse_size result: {result} bytes (from {size_str})") + return result + elif size_str.endswith('G'): result = int(float(size_str[:-1]) * 1024 * 1024 * 1024) logger.info(f"parse_size result: {result} bytes (from {size_str})") return result diff --git a/src/webssh_backend/database.py b/src/webssh_backend/database.py index daa75b4..8473e31 100644 --- a/src/webssh_backend/database.py +++ b/src/webssh_backend/database.py @@ -208,8 +208,12 @@ class CredentialsManager: "DELETE FROM connections WHERE id = ? AND username = ?", (conn_id, username) ) + deleted = cursor.rowcount conn.commit() conn.close() + if deleted != 1: + logger.warning(f"Connection {conn_id} not found for user {username}") + return False logger.info(f"Deleted connection {conn_id} for user {username}") return True except Exception as e: diff --git a/src/webssh_backend/http_api.py b/src/webssh_backend/http_api.py index ef17961..0c8580d 100644 --- a/src/webssh_backend/http_api.py +++ b/src/webssh_backend/http_api.py @@ -46,6 +46,8 @@ class LoginHandler(BaseHTTPRequestHandler): self.handle_verify() elif parsed.path == '/api/connections': self.handle_save_connection() + elif parsed.path == '/api/connections/delete': + self.handle_delete_connection() elif parsed.path == '/api/connections/status': self.handle_connection_status() elif parsed.path == '/api/config':