From 29d0c42adf6ec6178af05ed216cb05be4710ebd9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 8 Feb 2026 22:31:05 +0100 Subject: [PATCH] starting backend code --- backend.py | 33 +++++++ compose.yaml | 68 -------------- misc/clean.sh | 4 - misc/run.sh | 10 --- misc/sources.txt | 4 - nginx/nginx.conf | 110 ----------------------- {nginx/site => site}/config.js | 0 {nginx/site => site}/css/input.css | 0 {nginx/site => site}/css/minirt.css | 0 {nginx/site => site}/css/style.css | 0 {nginx/site => site}/css/tailwind.css | 0 {nginx/site => site}/html/minirt.html | 0 {nginx/site => site}/html/minishell.html | 0 {nginx/site => site}/index.html | 0 {nginx/site => site}/js/minirt.js | 0 {nginx/site => site}/js/minishell.js | 0 {nginx/site => site}/json/password.json | 0 {nginx/site => site}/tailwind.config.js | 0 18 files changed, 33 insertions(+), 196 deletions(-) create mode 100644 backend.py delete mode 100644 compose.yaml delete mode 100755 misc/clean.sh delete mode 100755 misc/run.sh delete mode 100644 misc/sources.txt delete mode 100644 nginx/nginx.conf rename {nginx/site => site}/config.js (100%) rename {nginx/site => site}/css/input.css (100%) rename {nginx/site => site}/css/minirt.css (100%) rename {nginx/site => site}/css/style.css (100%) rename {nginx/site => site}/css/tailwind.css (100%) rename {nginx/site => site}/html/minirt.html (100%) rename {nginx/site => site}/html/minishell.html (100%) rename {nginx/site => site}/index.html (100%) rename {nginx/site => site}/js/minirt.js (100%) rename {nginx/site => site}/js/minishell.js (100%) rename {nginx/site => site}/json/password.json (100%) rename {nginx/site => site}/tailwind.config.js (100%) diff --git a/backend.py b/backend.py new file mode 100644 index 0000000..f05d889 --- /dev/null +++ b/backend.py @@ -0,0 +1,33 @@ +import asyncio +import websockets +import aiohttp + +async def proxy_handler(websocket, path): + target_url = await websocket.recv() + + async with aiohttp.ClientSession() as session: + async with session.ws_connect(target_url) as target_ws: + async def forward_to_target(): + async for msg in websocket: + if isinstance(msg, str): + await target_ws.send_str(msg) + else: + await target_ws.send_bytes(msg) + + async def forward_to_client(): + async for msg in target_ws: + if msg.type == aiohttp.WSMsgType.TEXT: + await websocket.send(msg.data) + elif msg.type == aiohttp.WSMsgType.BINARY: + await websocket.send(msg.data) + + await asyncio.gather( + forward_to_target(), + forward_to_client() + ) + +async def main(): + async with websockets.serve(proxy_handler, "localhost", 8765): + await asyncio.Future() + +asyncio.run(main()) diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index 1454c11..0000000 --- a/compose.yaml +++ /dev/null @@ -1,68 +0,0 @@ -services: - minishell: - - container_name: "minishell" - restart: always - - build: - context: ./minishell - dockerfile: Dockerfile - - cap_drop: - - ALL - cap_add: - - SETGID - - FSETID - - SETUID - - devices: - - /dev/kvm - - # Prevents gaining new privileges - security_opt: - - no-new-privileges - - networks: - website_net: - - nginx-site: - container_name: "nginx-site" - image: nginx - - restart: always - volumes: - - ./nginx/nginx.conf:/etc/nginx/nginx.conf - - ./nginx/certs:/certs - - ./nginx/site:/var/www/html - - novnc:/opt/noVNC/ - - networks: - website_net: - - - ports: - - 5080:80 - - 5443:443 - - minirt: - container_name: "minirt-site" - restart: always - build: ./miniRT - - environment: - - DISPLAY=:1 - - networks: - website_net: - - volumes: - - novnc:/opt/noVNC/ - - -volumes: - novnc: - -networks: - website_net: - external: true - driver: bridge diff --git a/misc/clean.sh b/misc/clean.sh deleted file mode 100755 index e922b83..0000000 --- a/misc/clean.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -make fclean -C minishell -make fclean -C miniRT diff --git a/misc/run.sh b/misc/run.sh deleted file mode 100755 index 40bae58..0000000 --- a/misc/run.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -e - -# Compile the minishell project -make -C minishell -make -C miniRT - -# start the containers -docker compose up --build diff --git a/misc/sources.txt b/misc/sources.txt deleted file mode 100644 index 39c87f8..0000000 --- a/misc/sources.txt +++ /dev/null @@ -1,4 +0,0 @@ -# Website Creation sources - -# Compile the kernel - - https://itsfoss.com/compile-linux-kernel/ diff --git a/nginx/nginx.conf b/nginx/nginx.conf deleted file mode 100644 index 077d60f..0000000 --- a/nginx/nginx.conf +++ /dev/null @@ -1,110 +0,0 @@ -#user nobody; -worker_processes 1; -#error_log logs/error.log; -#error_log logs/error.log notice; -#error_log logs/error.log info; -#pid logs/nginx.pid; - -events { - worker_connections 1024; -} - -http { - # Include MIME types - include /etc/nginx/mime.types; - default_type application/octet-stream; - - # Rate limiting with connection limits for noVNC - limit_req_zone $binary_remote_addr zone=one:10m rate=30r/m; - limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m; - - # Upstream for miniRT with connection limiting - upstream minirt_backend { - server minirt:6080 max_conns=2; # Limit to 2 concurrent connections - } - - server { - listen 80; - listen [::]:80; - - charset utf-8; - server_name victorvobis.org www.victorvobis.org; - root /var/www/html; - - limit_conn conn_limit_per_ip 2; - - location / { - index index.html index.htm; - } - - location /minishell/vnc { - proxy_pass http://minishell:8006/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - - location /minirt/password { - add_header Content-Type application/json; - try_files /json/password.json =404; - } - - location /minirt/vnc { - index vnc.html; - try_files $uri $uri/ /vnc.html; - - # Ensure proper MIME types for JavaScript modules - location ~* \.js$ { - add_header Content-Type "application/javascript" always; - expires 1h; - } - location ~* \.css$ { - add_header Content-Type "text/css" always; - expires 1h; - } - location ~* \.(png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { - expires 1d; - add_header Cache-Control "public, immutable"; - } - } - - location /vnc { - alias /opt/noVNC/; - index vnc.html; - try_files $uri $uri/ /vnc.html; - - # Ensure proper MIME types for JavaScript modules - location ~* \.js$ { - add_header Content-Type "application/javascript" always; - expires 1h; - } - location ~* \.css$ { - add_header Content-Type "text/css" always; - expires 1h; - } - location ~* \.(png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { - expires 1d; - add_header Cache-Control "public, immutable"; - } - } - - # Proxy ONLY WebSocket connections to the minirt container - location /websockify { - proxy_pass http://minirt_backend; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_read_timeout 3600s; - proxy_send_timeout 3600s; - proxy_connect_timeout 60s; - proxy_buffering off; - } - - } -} diff --git a/nginx/site/config.js b/site/config.js similarity index 100% rename from nginx/site/config.js rename to site/config.js diff --git a/nginx/site/css/input.css b/site/css/input.css similarity index 100% rename from nginx/site/css/input.css rename to site/css/input.css diff --git a/nginx/site/css/minirt.css b/site/css/minirt.css similarity index 100% rename from nginx/site/css/minirt.css rename to site/css/minirt.css diff --git a/nginx/site/css/style.css b/site/css/style.css similarity index 100% rename from nginx/site/css/style.css rename to site/css/style.css diff --git a/nginx/site/css/tailwind.css b/site/css/tailwind.css similarity index 100% rename from nginx/site/css/tailwind.css rename to site/css/tailwind.css diff --git a/nginx/site/html/minirt.html b/site/html/minirt.html similarity index 100% rename from nginx/site/html/minirt.html rename to site/html/minirt.html diff --git a/nginx/site/html/minishell.html b/site/html/minishell.html similarity index 100% rename from nginx/site/html/minishell.html rename to site/html/minishell.html diff --git a/nginx/site/index.html b/site/index.html similarity index 100% rename from nginx/site/index.html rename to site/index.html diff --git a/nginx/site/js/minirt.js b/site/js/minirt.js similarity index 100% rename from nginx/site/js/minirt.js rename to site/js/minirt.js diff --git a/nginx/site/js/minishell.js b/site/js/minishell.js similarity index 100% rename from nginx/site/js/minishell.js rename to site/js/minishell.js diff --git a/nginx/site/json/password.json b/site/json/password.json similarity index 100% rename from nginx/site/json/password.json rename to site/json/password.json diff --git a/nginx/site/tailwind.config.js b/site/tailwind.config.js similarity index 100% rename from nginx/site/tailwind.config.js rename to site/tailwind.config.js