From 018165cc9e48ba4f1fa39f64efccfa27b2630a5b Mon Sep 17 00:00:00 2001 From: Lorenzo Chesi Date: Tue, 4 Apr 2023 22:43:34 +0200 Subject: [PATCH] Dev (#97) * Aggiurnate FAQ * 1.9.3 --- config/app/api.py | 80 ++++++++++++++-------- config/start.c | 131 +++++++++++++++++++----------------- config/utility/functions.py | 2 +- 3 files changed, 122 insertions(+), 91 deletions(-) diff --git a/config/app/api.py b/config/app/api.py index 40a71c0..b6dc87c 100644 --- a/config/app/api.py +++ b/config/app/api.py @@ -21,7 +21,8 @@ def getTable(): response=json.dumps({ "error": False, "data": Table.data - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/table/add', methods=['POST']) @@ -45,7 +46,8 @@ def addData(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/table/remove', methods=['POST']) @@ -67,7 +69,8 @@ def removeData(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/table/edit', methods=['POST']) @@ -90,7 +93,8 @@ def editData(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/settings', methods=['GET']) @@ -101,7 +105,8 @@ def getSettings(): response=json.dumps({ "error": False, "data": Settings.data - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/settings', methods=['POST']) @@ -123,7 +128,8 @@ def updateSettings(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/log', methods=['GET']) @@ -141,7 +147,8 @@ def getLog(row:int=0): x for x in (open("log.log", 'r', encoding='utf-8').readlines()) ][ -(rows + row) :] # ][ -100 : - 1] - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/connections', methods=['GET']) @@ -161,7 +168,8 @@ def getConnections(): response=json.dumps({ "error": False, "data": connections - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/connections/toggle', methods=['POST']) @@ -178,7 +186,8 @@ def toggleConnection(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/connections/remove', methods=['POST']) @@ -195,7 +204,8 @@ def removeConnection(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/connections/add', methods=['POST']) @@ -214,7 +224,8 @@ def addConnection(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) # TAGS @@ -233,7 +244,8 @@ def getTags(): return Response( mimetype='application/json', status=200, - response=json.dumps({"error": str(error)}) + response=json.dumps({"error": str(error)}), + headers={"Access-Control-Allow-Origin": "*"} ) for tag in tags: @@ -248,7 +260,8 @@ def getTags(): response=json.dumps({ "error": False, "data": tags - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/tags/toggle', methods=['POST']) @@ -264,7 +277,8 @@ def toggleTag(): return Response( mimetype='application/json', status=200, - response=json.dumps({"error": str(error)}) + response=json.dumps({"error": str(error)}), + headers={"Access-Control-Allow-Origin": "*"} ) return Response( @@ -273,7 +287,8 @@ def toggleTag(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/tags/remove', methods=['POST']) @@ -291,7 +306,8 @@ def removeTag(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @app.route('/api/tags/add', methods=['POST']) @@ -306,7 +322,8 @@ def addTag(): return Response( mimetype='application/json', status=200, - response=json.dumps({"error": str(error)}) + response=json.dumps({"error": str(error)}), + headers={"Access-Control-Allow-Origin": "*"} ) return Response( @@ -315,7 +332,8 @@ def addTag(): response=json.dumps({ "error": False, "data": log - }) + }), + headers={"Access-Control-Allow-Origin": "*"} ) @@ -326,7 +344,7 @@ def ieTable(): return Response( json.dumps(Table.data, indent=4), mimetype="text/plain", - headers={"Content-disposition":"attachment; filename=table.json"} + headers={"Content-disposition":"attachment; filename=table.json", "Access-Control-Allow-Origin": "*"}, ) else: uploaded_file = request.files['file'] @@ -344,7 +362,9 @@ def ieTable(): status=200, response=json.dumps({ "error": False if check else f"Table invalida." - }) + }, + headers={"Access-Control-Allow-Origin": "*"} + ) ) @app.route('/ie/settings', methods=['GET', 'POST']) @@ -353,7 +373,7 @@ def ieSettings(): return Response( json.dumps(Settings.data, indent=4), mimetype="text/plain", - headers={"Content-disposition":"attachment; filename=settings.json"} + headers={"Content-disposition":"attachment; filename=settings.json", "Access-Control-Allow-Origin": "*"} ) else: uploaded_file = request.files['file'] @@ -371,7 +391,9 @@ def ieSettings(): status=200, response=json.dumps({ "error": False if check else f"Settings invalide." - }) + }, + headers={"Access-Control-Allow-Origin": "*"} + ) ) @app.route('/ie/log', methods=['GET']) @@ -383,7 +405,7 @@ def ieLog(): return Response( data, mimetype="text/plain", - headers={"Content-disposition":"attachment; filename=log.log"} + headers={"Content-disposition":"attachment; filename=log.log", "Access-Control-Allow-Origin": "*"} ) @app.route('/ie/connections', methods=['GET', 'POST']) @@ -392,7 +414,7 @@ def ieConnections(): return Response( json.dumps(Connections.data, indent=4), mimetype="text/plain", - headers={"Content-disposition":"attachment; filename=connections.json"} + headers={"Content-disposition":"attachment; filename=connections.json", "Access-Control-Allow-Origin": "*"} ) else: uploaded_file = request.files['file'] @@ -411,7 +433,9 @@ def ieConnections(): status=200, response=json.dumps({ "error": False if check else f"Connections invalide." - }) + }, + headers={"Access-Control-Allow-Origin": "*"} + ) ) @app.route('/ie/tags', methods=['GET', 'POST']) @@ -420,7 +444,7 @@ def ieTags(): return Response( json.dumps(Tags.data, indent=4), mimetype="text/plain", - headers={"Content-disposition":"attachment; filename=tags.json"} + headers={"Content-disposition":"attachment; filename=tags.json", "Access-Control-Allow-Origin": "*"} ) else: uploaded_file = request.files['file'] @@ -439,5 +463,7 @@ def ieTags(): status=200, response=json.dumps({ "error": False if check else f"Tag invalidi." - }) + }, + headers={"Access-Control-Allow-Origin": "*"} + ) ) \ No newline at end of file diff --git a/config/start.c b/config/start.c index f77ba51..7a5b655 100644 --- a/config/start.c +++ b/config/start.c @@ -8,14 +8,10 @@ #include #include -int main(int argc, char *argv[]) -{ - int status; /* Stato di uscita processo figlio */ - struct passwd* res; /* Risultato valore getpwnam */ - DIR* dir; /* Cartella */ - struct dirent* dir_inf; - - int dbg = 0; +int start(){ + char command[500]; /* Buffer per i comandi system */ + struct passwd* pwn; /* Risultato valore getpwnam */ + int res; /* Risposta System */ char* PUID = getenv("PUID"); if(!PUID) PUID = "1000"; @@ -23,67 +19,76 @@ int main(int argc, char *argv[]) if(!PGID) PGID = "1000"; char* USER_NAME = getenv("USER_NAME"); - if(fork()){ - wait(&status); - if(fork()){ - wait(&status); + sprintf(command, "usermod -o -u %s %s", PUID, USER_NAME); + res = system(command); + if(res) return res; + + sprintf(command, "groupmod -o -g %s %s", PGID, USER_NAME); + res = system(command); + if(res) return res; + + pwn = getpwnam(USER_NAME); + printf( + "\n\n-------------------------------------\n" + "GID/UID\n" + "-------------------------------------\n" + "User uid:\t%d\n" + "User gid:\t%d\n" + "-------------------------------------\n\n\n", + pwn->pw_uid, pwn->pw_gid + ); - res = getpwnam(USER_NAME); + strcpy(command, "touch /script/json/settings.json"); + res = system(command); + if(res) return res; - printf( - "\n\n-------------------------------------\n" - "GID/UID\n" - "-------------------------------------\n" - "User uid:\t%d\n" - "User gid:\t%d\n" - "-------------------------------------\n\n\n", - res->pw_uid, res->pw_gid - ); - if(fork()){ - wait(&status); - if(fork()){ - wait(&status); - if(fork()){ - wait(&status); - if(fork()){ - wait(&status); - if(fork()){ - wait(&status); - if(fork()){ - wait(&status); - if(fork()){ - wait(&status); + strcpy(command, "touch /script/json/table.json"); + res = system(command); + if(res) return res; - chdir("/script"); - setuid(atoi(PUID)); + sprintf(command, "chown %s:%s /script -R", USER_NAME, USER_NAME); + res = system(command); + if(res) return res; - return system("python3 -u /script/main.py"); - } else { - char* tmp; /* buffer */ - dir = opendir("/script/connections"); - if(!dir) exit(0); + strcpy(command, "chmod 777 /script -R"); + res = system(command); + if(res) return res; - while(1){ - dir_inf = readdir(dir); - if(!dir_inf) exit(0); + strcpy(command, "pip3 install --upgrade --no-cache-dir --disable-pip-version-check --quiet animeworld"); + res = system(command); + if(res) return res; - if((tmp = strrchr(dir_inf->d_name, '.'))){ - if(strcmp(".sh", tmp) == 0) break; - } - } - closedir(dir); + char* tmp; /* buffer */ + DIR* dir = opendir("/script/connections"); + if(dir){ + struct dirent* dir_inf; - execlp(NULL, "sed", "-i", "-e", "'s/\\r$//'", "/script/connections/*.sh", NULL); - } - } else execlp(NULL, "pip3", "install", "--upgrade", "--no-cache-dir", "--disable-pip-version-check", "--quiet", "animeworld", NULL); - } else execlp(NULL, "chmod", "777", "/script", "-R", NULL); - } else execlp(NULL, "chgrp", USER_NAME, "/script", "-R", NULL); - } else execlp(NULL, "chown", USER_NAME, "/script", "-R", NULL); - } else execlp(NULL, "touch", "/script/json/table.json", NULL); - } else execlp(NULL, "touch", "/script/json/settings.json", NULL); - } else execlp(NULL, "groupmod", "-o", "-g", PGID, USER_NAME, NULL); - } else execlp(NULL, "usermod", "-o", "-u", PUID, USER_NAME, NULL); + while(1){ + dir_inf = readdir(dir); + if(!dir_inf) break; - fprintf(stderr, "ERROR %d: %s", dbg, strerror(errno)); - exit(EXIT_FAILURE); + if((tmp = strrchr(dir_inf->d_name, '.'))){ + if(strcmp(".sh", tmp) == 0){ + system("sed -i -e 's/\\r$//' /script/connections/*.sh"); + break; + } + } + } + closedir(dir); + } + + chdir("/script"); + setuid(atoi(PUID)); + + return system("python3 -u /script/main.py"); +} + +int main(int argc, char *argv[]) +{ + int res = start(); + if(res){ + fprintf(stderr, "ERROR: %s", strerror(errno)); + exit(EXIT_FAILURE); + } + return 0; } \ No newline at end of file diff --git a/config/utility/functions.py b/config/utility/functions.py index 765a0e2..b9e7ad3 100644 --- a/config/utility/functions.py +++ b/config/utility/functions.py @@ -277,7 +277,7 @@ def downloadProgress(d): """ if int(datetime.timestamp(datetime.now()) - downloadProgress.step ) > 0 or d["percentage"] == 1: - socketio.emit("download_info", d, broadcast=True) + socketio.emit("download_info", d) downloadProgress.step = datetime.timestamp(datetime.now()) downloadProgress.step = datetime.timestamp(datetime.now())