diff --git a/.gitignore b/.gitignore index 3fb825f..e5a403b 100755 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ **/npm-debug.log* **/yarn-debug.log* -**/yarn-error.log* \ No newline at end of file +**/yarn-error.log* diff --git a/api-model.txt b/api-model.txt deleted file mode 100755 index 4548814..0000000 --- a/api-model.txt +++ /dev/null @@ -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/ - -{ - "id":"serv_id", - "name":"text", - "status":"stop"/"wait"/"active"/"pause", - "public_port":1234, - "internal_port":44444, - "n_packets":1, - "n_regex":1, -} - -/api/service//stop - -{ - "status":"ok" -} - -/api/service//start - -{ - "status":"ok" -} - -/api/service//delete - -{ - "status":"ok" -} - -/api/service//terminate - -{ - "status":"ok" -} - -/api/service//regen-port - -{ - "status":"ok" -} - -/api/service//regexes - -[ - { - "id":5787, - "service_id":"serv_id", - "regex":"base64" - "is_blacklist":true, - "mode":"C","S","B" // C->S S->C BOTH - } -] - - -/api/regex/ -{ - "id":5787, - "service_id":"serv_id", - "regex":"base64" - "is_blacklist":true, - "mode":"C","S","B" // C->S S->C BOTH -} - -/api/regex//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" -} diff --git a/backend/Dockerfile b/backend/Dockerfile index 3429b6f..219446a 100755 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -9,8 +9,8 @@ ADD ./requirements.txt /execute/requirements.txt RUN pip install --no-cache-dir -r /execute/requirements.txt COPY . /execute/ -COPY ./nginx.conf /etc/nginx/nginx.conf -COPY ./supervisord.conf /etc/supervisor/supervisord.conf +COPY ./config/nginx.conf /etc/nginx/nginx.conf +COPY ./config/supervisord.conf /etc/supervisor/supervisord.conf RUN usermod -a -G root nobody RUN chown -R nobody:root /execute && \ diff --git a/backend/Firegex-API/.gitignore b/backend/Firegex-API/.gitignore deleted file mode 100644 index afbb464..0000000 --- a/backend/Firegex-API/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -venv -firegex.db -firegex.db-journal -__pycache__ \ No newline at end of file diff --git a/backend/Firegex-API/api-model.txt b/backend/Firegex-API/api-model.txt deleted file mode 100644 index 201d5b8..0000000 --- a/backend/Firegex-API/api-model.txt +++ /dev/null @@ -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/ -{ - "id":"serv_id", - "name":"text", - "status":"stop"/"wait"/"active"/"pause", - "public_port":1234, - "internal_port":44444, - "n_packets":1, - "n_regex":1, -} - -/api/service//stop - -{ - "status":"ok" -} - -/api/service//start - -{ - "status":"ok" -} - -/api/service//delete - -{ - "status":"ok" -} - -/api/service//terminate - -{ - "status":"ok" -} - -/api/service//regen-port - -{ - "status":"ok" -} - -/api/service//regexes - -[ - { - "id": "5787", - "service_id": "serv_id", - "regex":"base64", - "is_blacklist":true, - "mode":"C","S","B" // C->S S->C BOTH - } -] - - -/api/regex/ -{ - "id": 5787 - "service_id":"serv_id", - "regex":"base64" - "is_blacklist":true, - "mode":"C","S","B" // C->S S->C BOTH -} - -/api/regex//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" -} diff --git a/backend/Firegex-API/requirements.txt b/backend/Firegex-API/requirements.txt deleted file mode 100644 index 83d53d7..0000000 --- a/backend/Firegex-API/requirements.txt +++ /dev/null @@ -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 diff --git a/backend/Firegex-API/README.md b/backend/README.md similarity index 100% rename from backend/Firegex-API/README.md rename to backend/README.md diff --git a/backend/Firegex-API/app.py b/backend/app.py similarity index 87% rename from backend/Firegex-API/app.py rename to backend/app.py index cb5e9a9..1393116 100644 --- a/backend/Firegex-API/app.py +++ b/backend/app.py @@ -30,33 +30,15 @@ class SQLite(): ''', (t,)) 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 = ()): self.cur.execute(query, values) return self.cur.fetchall() -# DB init + db = SQLite('firegex') 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.route('/api/general-stats') @@ -255,4 +237,27 @@ def post_services_add(): 'status': 'ok' } - return res \ No newline at end of file + 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"]) + diff --git a/backend/nginx.conf b/backend/config/nginx.conf similarity index 68% rename from backend/nginx.conf rename to backend/config/nginx.conf index 8b165f5..500d8f4 100755 --- a/backend/nginx.conf +++ b/backend/config/nginx.conf @@ -1,7 +1,7 @@ worker_processes 5; ## Default: 1 pid /var/run/nginx.pid; -user nobody nobody; +user nobody nogroup; events { worker_connections 1024; @@ -15,12 +15,12 @@ http{ location / { include proxy_params; - proxy_pass http://frontend:5000/; + proxy_pass http://frontend:3000/; } location /api/ { include proxy_params; - proxy_pass http://127.0.0.1:8080/; + proxy_pass http://127.0.0.1:8080; } } diff --git a/backend/supervisord.conf b/backend/config/supervisord.conf similarity index 84% rename from backend/supervisord.conf rename to backend/config/supervisord.conf index ade914c..005f708 100755 --- a/backend/supervisord.conf +++ b/backend/config/supervisord.conf @@ -9,6 +9,7 @@ nodaemon = true command=/usr/sbin/nginx -g "daemon off;" autostart=true autorestart=true +user = root startretries=5 numprocs=1 startsecs=0 @@ -18,9 +19,10 @@ stderr_logfile_maxbytes=10MB stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log stdout_logfile_maxbytes=10MB -[program:uwsgi_backend] +[program:backend] directory=/execute -command=uwsgi --http 127.0.0.1:8080 --master --module app:app +user = nobody +command=python3 app.py stdout_logfile="syslog" stderr_logfile="syslog" startsecs=10 diff --git a/backend/requirements.txt b/backend/requirements.txt index c4c9d86..7f5756b 100755 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -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 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e69de29..c42cddd 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.9' + +services: + frontend: + restart: unless-stopped + build: frontend + backend: + restart: unless-stopped + build: backend + ports: + - 80:80 \ No newline at end of file