Bug fixes and additional checks

This commit is contained in:
DomySh
2022-06-14 08:31:25 +02:00
parent 4abb7e2746
commit 8eb077efa2
9 changed files with 57 additions and 40 deletions

1
.gitignore vendored
View File

@@ -12,6 +12,7 @@
/backend/db/firegex.db
/backend/db/firegex.db-journal
/backend/proxy/proxy
docker-compose.yml
# production
/frontend/build

View File

@@ -3,11 +3,6 @@
# Firegex-API Documentation
### This is a short description of the API
## TODO
1. back and frontend password
2. compile c++ -O3
#
# Documentation
## Index

View File

@@ -1,4 +1,4 @@
import sqlite3, subprocess, sys, threading, bcrypt, secrets, time
import sqlite3, subprocess, sys, threading, bcrypt, secrets, time, re
from flask import Flask, jsonify, request, abort, session
from functools import wraps
from flask_cors import CORS
@@ -278,7 +278,9 @@ def post_regexes_add():
"is_blacklist" : {"type" : "boolean"},
"mode" : {"type" : "string"},
},
})
})
if not re.match("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$",req["regex"]):
return abort(400)
except Exception:
return abort(400)
db.query("INSERT INTO regexes (service_id, regex, is_blacklist, mode) VALUES (?, ?, ?, ?);",

View File

@@ -76,13 +76,14 @@ class ProxyManager:
self.lock = threading.Lock()
def __clear_proxy_table(self):
for key in self.proxy_table.keys():
if not self.proxy_table[key]["thread"].is_alive():
del self.proxy_table[key]
with self.lock:
for key in list(self.proxy_table.keys()):
if not self.proxy_table[key]["thread"].is_alive():
del self.proxy_table[key]
def reload(self):
with self.lock:
self.__clear_proxy_table()
self.__clear_proxy_table()
with self.lock:
for srv_id in self.db.query('SELECT service_id, status FROM services;'):
srv_id, n_status = srv_id
if srv_id in self.proxy_table:

View File

@@ -1,13 +0,0 @@
version: '3.9'
services:
firewall:
restart: unless-stopped
build: .
ports:
- 80:80
environment:
- NGINX_PORT=80
volumes:
- /execute/db

View File

@@ -1,12 +0,0 @@
version: '3.9'
services:
firewall:
restart: unless-stopped
build: .
network_mode: "host"
environment:
- NGINX_PORT=4444
volumes:
- /execute/db

View File

@@ -69,7 +69,7 @@ function App() {
return <div className='center-flex-row' style={{padding:"100px"}}>
<Title order={3} align="center">Choose the password for access to the firewall 🔒</Title>
<Title order={3} align="center">Setup: Choose the password for access to the firewall 🔒</Title>
<Space h="xl" />
<form onSubmit={form.onSubmit(submitRequest)} style={{width:"80%"}}>
<TextInput
@@ -104,7 +104,7 @@ function App() {
return <div className='center-flex-row' style={{padding:"100px"}}>
<Title order={2} align="center">Welcome to Firegex 🔥</Title>
<Space h="xl" />
<Title order={2} align="center">Before you use the firewall, insert a password 🔒</Title>
<Title order={2} align="center">Before you use the firewall, insert the password 🔒</Title>
<Space h="xl" />
<form onSubmit={form.onSubmit(submitRequest)} style={{width:"80%"}}>
<TextInput

View File

@@ -5,7 +5,7 @@ import { GeneralStats, Service, ServiceAddForm, ServerResponse, RegexFilter, not
var Buffer = require('buffer').Buffer
const DEBUG = true
const DEBUG = false
const custom_url = DEBUG?"http://127.0.0.1:8080":""

43
start.py Executable file
View File

@@ -0,0 +1,43 @@
import argparse, sys, platform
parser = argparse.ArgumentParser()
parser.add_argument('port', type=int, help='Port where open the web service of the firewall')
args = parser.parse_args()
with open("docker-compose.yml","wt") as compose:
if "linux" in sys.platform and not 'microsoft-standard' in platform.uname().release: #Check if not is a wsl also
compose.write(f"""
version: '3.9'
services:
firewall:
restart: unless-stopped
build: .
network_mode: "host"
environment:
- NGINX_PORT={args.port}
volumes:
- /execute/db
""")
print("Done! You can start firegex with docker-compose up -d --build")
else:
print("-----------------------------------")
print("You are not in a linux machine, due to docker limitation on other platform, the firewall will not work in this machine. You will only see the interface of firegex.")
print("-----------------------------------")
compose.write(f"""
version: '3.9'
services:
firewall:
restart: unless-stopped
build: .
ports:
- {args.port}:{args.port}
environment:
- NGINX_PORT={args.port}
volumes:
- /execute/db
""")
print("Done! You can start firegex with docker-compose up -d --build")