diff --git a/backend/app.py b/backend/app.py index c4bcad0..0681d81 100644 --- a/backend/app.py +++ b/backend/app.py @@ -14,7 +14,7 @@ firewall = ProxyManager(db) app = Flask(__name__) -DEBUG = len(sys.argv) > 1 and sys.argv[1] == "DEBUG" +DEBUG = not (len(sys.argv) > 1 and sys.argv[1] == "UWSGI") def is_loggined(): if DEBUG: return True @@ -354,8 +354,7 @@ if __name__ == '__main__': }, }) db.query("CREATE UNIQUE INDEX IF NOT EXISTS unique_regex_service ON regexes (regex,service_id,is_blacklist,mode);") - - if DEBUG: + if DEBUG: app.run(host="0.0.0.0", port=8080 ,debug=True) else: subprocess.run(["uwsgi","--socket","./uwsgi.sock","--master","--module","app:app", "--enable-threads"]) diff --git a/config/supervisord.conf b/config/supervisord.conf index 1dcc4ca..be3142e 100755 --- a/config/supervisord.conf +++ b/config/supervisord.conf @@ -9,7 +9,7 @@ nodaemon = true directory=/execute user = nobody group = root -command=python3 app.py +command=python3 app.py UWSGI startsecs=10 stopsignal=QUIT stopasgroup=true diff --git a/frontend/src/js/utils.tsx b/frontend/src/js/utils.tsx index e58361e..cc65d06 100755 --- a/frontend/src/js/utils.tsx +++ b/frontend/src/js/utils.tsx @@ -5,15 +5,13 @@ import { GeneralStats, Service, ServiceAddForm, ServerResponse, RegexFilter, not var Buffer = require('buffer').Buffer -const DEBUG = false - -const custom_url = DEBUG?"http://127.0.0.1:8080":"" +const custom_url = (!process.env.NODE_ENV || process.env.NODE_ENV === 'development')?"http://127.0.0.1:8080":"" export async function getapi(path:string):Promise{ return await new Promise((resolve, reject) => { fetch(`${custom_url}/api/${path}`,{credentials: "same-origin"}) .then(res => { - if(res.status == 401) window.location.reload() + if(res.status === 401) window.location.reload() if(!res.ok) reject(res.statusText) res.json().then( res => resolve(res) ).catch( err => reject(err)) }) @@ -34,7 +32,7 @@ export async function postapi(path:string,data:any):Promise{ }, body: JSON.stringify(data) }).then(res => { - if(res.status == 401) window.location.reload() + if(res.status === 401) window.location.reload() if(!res.ok) reject(res.statusText) res.json().then( res => resolve(res) ).catch( err => reject(err)) }) diff --git a/frontend/src/pages/HomePage.tsx b/frontend/src/pages/HomePage.tsx index 229c26f..410bf40 100755 --- a/frontend/src/pages/HomePage.tsx +++ b/frontend/src/pages/HomePage.tsx @@ -37,7 +37,7 @@ function HomePage() { {services.length > 0?services.map( srv => { navigator("/"+srv.id) - }} />):<> No services found! Add one clicking the "+" button above + }} />):<> No services found! Add one clicking the "+" buttons
diff --git a/frontend/src/pages/ServiceDetails.tsx b/frontend/src/pages/ServiceDetails.tsx index ace0cf8..bd24487 100755 --- a/frontend/src/pages/ServiceDetails.tsx +++ b/frontend/src/pages/ServiceDetails.tsx @@ -96,7 +96,7 @@ function ServiceDetails() { {regexesList.length === 0?<> - No regex found for this service! Add one by clicking the "+" button + No regex found for this service! Add one by clicking the "+" buttons
diff --git a/start.py b/start.py index 40b7ed0..a67656f 100755 --- a/start.py +++ b/start.py @@ -1,45 +1,45 @@ -#! /bin/python3 - -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") \ No newline at end of file +#!/usr/bin/env python3 + +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")