Docker container changes

This commit is contained in:
DomySh
2022-06-12 18:50:57 +02:00
parent 3139cbf288
commit e5e6ca6098
12 changed files with 54 additions and 296 deletions

2
.gitignore vendored
View File

@@ -21,4 +21,4 @@
**/npm-debug.log* **/npm-debug.log*
**/yarn-debug.log* **/yarn-debug.log*
**/yarn-error.log* **/yarn-error.log*

View File

@@ -1,128 +0,0 @@
/api/general-stats
{
"services":1,
"closed":1,
"regex":1
}
#Processo di trasformazione del nome del servizio = primary_key
serv_id = serv_id.strip().replace(" ","-")
serv_id = "".join([c for c in serv_id if c in (strings.uppercase+strings.lowercase+strings.digits+"-")])
serv_id = serv_id.lower()
/api/services
[
{
"id":"serv_id",
"name":"text",
"status":"stop"/"wait"/"active"/"pause",
"public_port":1234,
"internal_port":44444,
"n_packets":1,
"n_regex":1,
}
]
/api/service/<serv>
{
"id":"serv_id",
"name":"text",
"status":"stop"/"wait"/"active"/"pause",
"public_port":1234,
"internal_port":44444,
"n_packets":1,
"n_regex":1,
}
/api/service/<serv>/stop
{
"status":"ok"
}
/api/service/<serv>/start
{
"status":"ok"
}
/api/service/<serv>/delete
{
"status":"ok"
}
/api/service/<serv>/terminate
{
"status":"ok"
}
/api/service/<serv>/regen-port
{
"status":"ok"
}
/api/service/<serv>/regexes
[
{
"id":5787,
"service_id":"serv_id",
"regex":"base64"
"is_blacklist":true,
"mode":"C","S","B" // C->S S->C BOTH
}
]
/api/regex/<regex_id>
{
"id":5787,
"service_id":"serv_id",
"regex":"base64"
"is_blacklist":true,
"mode":"C","S","B" // C->S S->C BOTH
}
/api/regex/<regex_id>/delete
{
"status":"ok"
}
/api/regexes/add POST
client
{
"service_id":"serv_id",
"regex":"base64",
"is_blacklist":true/false,
"mode":"C","S","B" // C->S S->C BOTH
}
server
{
"status":"ok"
}
/api/services/add POST
client
{
"name":"text",
"port":5362
}
server
{
"status":"ok"
}

View File

@@ -9,8 +9,8 @@ ADD ./requirements.txt /execute/requirements.txt
RUN pip install --no-cache-dir -r /execute/requirements.txt RUN pip install --no-cache-dir -r /execute/requirements.txt
COPY . /execute/ COPY . /execute/
COPY ./nginx.conf /etc/nginx/nginx.conf COPY ./config/nginx.conf /etc/nginx/nginx.conf
COPY ./supervisord.conf /etc/supervisor/supervisord.conf COPY ./config/supervisord.conf /etc/supervisor/supervisord.conf
RUN usermod -a -G root nobody RUN usermod -a -G root nobody
RUN chown -R nobody:root /execute && \ RUN chown -R nobody:root /execute && \

View File

@@ -1,4 +0,0 @@
venv
firegex.db
firegex.db-journal
__pycache__

View File

@@ -1,127 +0,0 @@
/api/general-stats
{
"services":1,
"closed":1,
"regex":1
}
#Processo di trasformazione del nome del servizio = primary_key
serv_id = serv_id.strip().replace(" ","-")
serv_id = "".join([c for c in serv_id if c in (strings.uppercase+strings.lowercase+strings.digits+"-")])
serv_id = serv_id.lower()
/api/services
[
{
"id": "serv_id",
"name":"text",
"status":"text",
"public_port":1234,
"internal_port":44444,
"n_pacchetti":1,
"n_regex":1,
}
]
/api/service/<serv>
{
"id":"serv_id",
"name":"text",
"status":"stop"/"wait"/"active"/"pause",
"public_port":1234,
"internal_port":44444,
"n_packets":1,
"n_regex":1,
}
/api/service/<serv>/stop
{
"status":"ok"
}
/api/service/<serv>/start
{
"status":"ok"
}
/api/service/<serv>/delete
{
"status":"ok"
}
/api/service/<serv>/terminate
{
"status":"ok"
}
/api/service/<serv>/regen-port
{
"status":"ok"
}
/api/service/<serv>/regexes
[
{
"id": "5787",
"service_id": "serv_id",
"regex":"base64",
"is_blacklist":true,
"mode":"C","S","B" // C->S S->C BOTH
}
]
/api/regex/<regex_id>
{
"id": 5787
"service_id":"serv_id",
"regex":"base64"
"is_blacklist":true,
"mode":"C","S","B" // C->S S->C BOTH
}
/api/regex/<regex_id>/delete
{
"status":"ok"
}
/api/regexes/add POST
client
{
"service_id":"serv_id",
"regex":"base64",
"is_blacklist":true/false,
"mode":"C","S","B" // C->S S->C BOTH
}
server
{
"status":"ok"
}
/api/services/add POST
client
{
"name":"text",
"port":5362
}
server
{
"status":"ok"
}

View File

@@ -1,7 +0,0 @@
click==8.1.3
colorama==0.4.4
Flask==2.1.2
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
Werkzeug==2.1.2

View File

@@ -30,33 +30,15 @@ class SQLite():
''', (t,)) ''', (t,))
if len(self.cur.fetchall()) == 0: if len(self.cur.fetchall()) == 0:
self.cur.execute('''CREATE TABLE main.?(?);''', (t, ''.join([(c + ' ' + tables[t][c] + ', ') for c in tables[t]])[:-2])) self.cur.execute(f'CREATE TABLE main.{t}({"".join([(c + " " + tables[t][c] + ", ") for c in tables[t]])[:-2]});')
def query(self, query, values = ()): def query(self, query, values = ()):
self.cur.execute(query, values) self.cur.execute(query, values)
return self.cur.fetchall() return self.cur.fetchall()
# DB init
db = SQLite('firegex') db = SQLite('firegex')
db.connect() db.connect()
db.check_integrity({
'regexes': {
'regex': 'TEXT NOT NULL',
'mode': 'CHAR(1)',
'service_id': 'TEXT NOT NULL',
'is_blacklist': 'CHAR(50) NOT NULL',
'blocked_packets': 'INTEGER DEFAULT 0',
'regex_id': 'INTEGER NOT NULL'
},
'services': {
'status': 'CHAR(50)',
'service_id': 'TEXT NOT NULL',
'internal_port': 'INT NOT NULL',
'public_port': 'INT NOT NULL'
}
})
app = Flask(__name__) app = Flask(__name__)
@app.route('/api/general-stats') @app.route('/api/general-stats')
@@ -255,4 +237,27 @@ def post_services_add():
'status': 'ok' 'status': 'ok'
} }
return res return res
if __name__ == "__main__":
import subprocess
# DB init
db.check_integrity({
'regexes': {
'regex': 'TEXT NOT NULL',
'mode': 'CHAR(1)',
'service_id': 'TEXT NOT NULL',
'is_blacklist': 'CHAR(50) NOT NULL',
'blocked_packets': 'INTEGER DEFAULT 0',
'regex_id': 'INTEGER NOT NULL'
},
'services': {
'status': 'CHAR(50)',
'service_id': 'TEXT NOT NULL',
'internal_port': 'INT NOT NULL',
'public_port': 'INT NOT NULL'
}
})
#uwsgi
subprocess.run(["uwsgi","--http","127.0.0.1:8080","--master","--module","app:app"])

View File

@@ -1,7 +1,7 @@
worker_processes 5; ## Default: 1 worker_processes 5; ## Default: 1
pid /var/run/nginx.pid; pid /var/run/nginx.pid;
user nobody nobody; user nobody nogroup;
events { events {
worker_connections 1024; worker_connections 1024;
@@ -15,12 +15,12 @@ http{
location / { location / {
include proxy_params; include proxy_params;
proxy_pass http://frontend:5000/; proxy_pass http://frontend:3000/;
} }
location /api/ { location /api/ {
include proxy_params; include proxy_params;
proxy_pass http://127.0.0.1:8080/; proxy_pass http://127.0.0.1:8080;
} }
} }

View File

@@ -9,6 +9,7 @@ nodaemon = true
command=/usr/sbin/nginx -g "daemon off;" command=/usr/sbin/nginx -g "daemon off;"
autostart=true autostart=true
autorestart=true autorestart=true
user = root
startretries=5 startretries=5
numprocs=1 numprocs=1
startsecs=0 startsecs=0
@@ -18,9 +19,10 @@ stderr_logfile_maxbytes=10MB
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log
stdout_logfile_maxbytes=10MB stdout_logfile_maxbytes=10MB
[program:uwsgi_backend] [program:backend]
directory=/execute directory=/execute
command=uwsgi --http 127.0.0.1:8080 --master --module app:app user = nobody
command=python3 app.py
stdout_logfile="syslog" stdout_logfile="syslog"
stderr_logfile="syslog" stderr_logfile="syslog"
startsecs=10 startsecs=10

View File

@@ -1,2 +1,8 @@
flask click==8.1.3
colorama==0.4.4
Flask==2.1.2
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
Werkzeug==2.1.2
uwsgi uwsgi

View File

@@ -0,0 +1,11 @@
version: '3.9'
services:
frontend:
restart: unless-stopped
build: frontend
backend:
restart: unless-stopped
build: backend
ports:
- 80:80