starting backend code
This commit is contained in:
parent
bd52695d14
commit
29d0c42adf
33
backend.py
Normal file
33
backend.py
Normal file
@ -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())
|
||||||
68
compose.yaml
68
compose.yaml
@ -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
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
make fclean -C minishell
|
|
||||||
make fclean -C miniRT
|
|
||||||
10
misc/run.sh
10
misc/run.sh
@ -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
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
# Website Creation sources
|
|
||||||
|
|
||||||
# Compile the kernel
|
|
||||||
- https://itsfoss.com/compile-linux-kernel/
|
|
||||||
110
nginx/nginx.conf
110
nginx/nginx.conf
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user