Automatic choice of production and dev mode

This commit is contained in:
DomySh
2022-06-15 09:11:27 +02:00
parent 3ec0879608
commit 8eb3403a79
6 changed files with 53 additions and 56 deletions

View File

@@ -14,7 +14,7 @@ firewall = ProxyManager(db)
app = Flask(__name__) 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(): def is_loggined():
if DEBUG: return True 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);") 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) app.run(host="0.0.0.0", port=8080 ,debug=True)
else: else:
subprocess.run(["uwsgi","--socket","./uwsgi.sock","--master","--module","app:app", "--enable-threads"]) subprocess.run(["uwsgi","--socket","./uwsgi.sock","--master","--module","app:app", "--enable-threads"])

View File

@@ -9,7 +9,7 @@ nodaemon = true
directory=/execute directory=/execute
user = nobody user = nobody
group = root group = root
command=python3 app.py command=python3 app.py UWSGI
startsecs=10 startsecs=10
stopsignal=QUIT stopsignal=QUIT
stopasgroup=true stopasgroup=true

View File

@@ -5,15 +5,13 @@ import { GeneralStats, Service, ServiceAddForm, ServerResponse, RegexFilter, not
var Buffer = require('buffer').Buffer var Buffer = require('buffer').Buffer
const DEBUG = false const custom_url = (!process.env.NODE_ENV || process.env.NODE_ENV === 'development')?"http://127.0.0.1:8080":""
const custom_url = DEBUG?"http://127.0.0.1:8080":""
export async function getapi(path:string):Promise<any>{ export async function getapi(path:string):Promise<any>{
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
fetch(`${custom_url}/api/${path}`,{credentials: "same-origin"}) fetch(`${custom_url}/api/${path}`,{credentials: "same-origin"})
.then(res => { .then(res => {
if(res.status == 401) window.location.reload() if(res.status === 401) window.location.reload()
if(!res.ok) reject(res.statusText) if(!res.ok) reject(res.statusText)
res.json().then( res => resolve(res) ).catch( err => reject(err)) res.json().then( res => resolve(res) ).catch( err => reject(err))
}) })
@@ -34,7 +32,7 @@ export async function postapi(path:string,data:any):Promise<any>{
}, },
body: JSON.stringify(data) body: JSON.stringify(data)
}).then(res => { }).then(res => {
if(res.status == 401) window.location.reload() if(res.status === 401) window.location.reload()
if(!res.ok) reject(res.statusText) if(!res.ok) reject(res.statusText)
res.json().then( res => resolve(res) ).catch( err => reject(err)) res.json().then( res => resolve(res) ).catch( err => reject(err))
}) })

View File

@@ -37,7 +37,7 @@ function HomePage() {
<LoadingOverlay visible={loader} /> <LoadingOverlay visible={loader} />
{services.length > 0?services.map( srv => <ServiceRow service={srv} key={srv.id} onClick={()=>{ {services.length > 0?services.map( srv => <ServiceRow service={srv} key={srv.id} onClick={()=>{
navigator("/"+srv.id) navigator("/"+srv.id)
}} />):<><Space h="xl"/> <Title className='center-flex' align='center' order={3}>No services found! Add one clicking the "+" button above</Title> }} />):<><Space h="xl"/> <Title className='center-flex' align='center' order={3}>No services found! Add one clicking the "+" buttons</Title>
<Space h="xl" /> <Space h="xl" /> <Space h="xl" /> <Space h="xl" />
<div className='center-flex'> <div className='center-flex'>
<Tooltip label="Add a new service" transition="pop" transitionDuration={200} openDelay={500} zIndex={0} transitionTimingFunction="ease" color="blue"> <Tooltip label="Add a new service" transition="pop" transitionDuration={200} openDelay={500} zIndex={0} transitionTimingFunction="ease" color="blue">

View File

@@ -96,7 +96,7 @@ function ServiceDetails() {
{regexesList.length === 0?<> {regexesList.length === 0?<>
<Space h="xl" /> <Space h="xl" />
<Title className='center-flex' align='center' order={3}>No regex found for this service! Add one by clicking the "+" button</Title> <Title className='center-flex' align='center' order={3}>No regex found for this service! Add one by clicking the "+" buttons</Title>
<Space h="xl" /> <Space h="xl" /> <Space h="xl" /> <Space h="xl" />
<div className='center-flex'> <div className='center-flex'>
<Tooltip label="Add a new regex" zIndex={0} transition="pop" transitionDuration={200} openDelay={500} transitionTimingFunction="ease" color="blue"> <Tooltip label="Add a new regex" zIndex={0} transition="pop" transitionDuration={200} openDelay={500} transitionTimingFunction="ease" color="blue">

View File

@@ -1,45 +1,45 @@
#! /bin/python3 #!/usr/bin/env python3
import argparse, sys, platform import argparse, sys, platform
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('port', type=int, help='Port where open the web service of the firewall') parser.add_argument('port', type=int, help='Port where open the web service of the firewall')
args = parser.parse_args() args = parser.parse_args()
with open("docker-compose.yml","wt") as compose: 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 if "linux" in sys.platform and not 'microsoft-standard' in platform.uname().release: #Check if not is a wsl also
compose.write(f""" compose.write(f"""
version: '3.9' version: '3.9'
services: services:
firewall: firewall:
restart: unless-stopped restart: unless-stopped
build: . build: .
network_mode: "host" network_mode: "host"
environment: environment:
- NGINX_PORT={args.port} - NGINX_PORT={args.port}
volumes: volumes:
- /execute/db - /execute/db
""") """)
print("Done! You can start firegex with docker-compose up -d --build") print("Done! You can start firegex with docker-compose up -d --build")
else: else:
print("-----------------------------------") 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("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("-----------------------------------") print("-----------------------------------")
compose.write(f""" compose.write(f"""
version: '3.9' version: '3.9'
services: services:
firewall: firewall:
restart: unless-stopped restart: unless-stopped
build: . build: .
ports: ports:
- {args.port}:{args.port} - {args.port}:{args.port}
environment: environment:
- NGINX_PORT={args.port} - NGINX_PORT={args.port}
volumes: volumes:
- /execute/db - /execute/db
""") """)
print("Done! You can start firegex with docker-compose up -d --build") print("Done! You can start firegex with docker-compose up -d --build")