-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_encrypted_transfer.py
More file actions
154 lines (130 loc) · 6.73 KB
/
local_encrypted_transfer.py
File metadata and controls
154 lines (130 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Copyright (c) Local Encrypted Transfer by Loxy0dev
from flask import Flask, request, render_template_string, send_from_directory, send_file
import os, socket, colorama, sys, ctypes, json
credits = {
"tool_name" : "Local Encrypted Transfer",
"tool_version" : "1.0",
"developer" : "loxy0dev",
"github" : "github.com/loxy0devlp/Local-Encrypted-Transfer",
"gunslol" : "guns.lol/loxy0dev"
}
color = colorama.Fore
white = color.WHITE
reset = color.RESET
green = color.GREEN
blue = color.BLUE
red = color.RED
ERROR = f"{red}[{white}x{red}]"
INPUT = f"{blue}[{white}>{blue}]"
INFO = f"{blue}[{white}!{blue}]"
ADD = f"{blue}[{white}+{blue}]"
try: os_name = "Windows" if sys.platform.startswith("win") else "Linux" if sys.platform.startswith("linux") else "Unknown"
except: os_name = "Unknown"
banner = rf"""
.____ .__ ___________ _____
| | ____ ____ _____ | | \__ ___/___________ ____ _______/ ____\___________
| | / _ \_/ ___\\__ \ | | | | \_ __ \__ \ / \ / ___/\ __\/ __ \_ __ \
| |__( <_> ) \___ / __ \| |__ | | | | \// __ \| | \\___ \ | | \ ___/| | \/
|________\____/ \_____>______/____/ |____| |__| (______/___|__/______> |__| \_____>__|
{white + credits['github']}
"""
path_tool = os.path.dirname(os.path.abspath(__file__))
path_folder_storage = os.path.join(path_tool, "Storage")
path_folder_structure = os.path.join(path_tool, "Structure")
path_folder_config = os.path.join(path_tool, "Config")
path_file_config = os.path.join(path_folder_config, "Config.json")
path_file_logs = os.path.join(path_folder_config, "Logs.json")
path_file_css = os.path.join(path_folder_structure, "Css.css")
path_file_javascript = os.path.join(path_folder_structure, "Javascript.js")
path_file_html = os.path.join(path_folder_structure, "Html.html")
with open(path_file_config, "r", encoding="utf-8") as file: data_config = json.load(file)
with open(path_file_css, "r", encoding="utf-8") as file: content_css = file.read()
with open(path_file_javascript, "r", encoding="utf-8") as file: content_javascript = file.read()
with open(path_file_html, "r", encoding="utf-8") as file: content_html = file.read().replace("/*%CSS%*/", content_css).replace("/*%JAVASCRIPT%*/", content_javascript).replace("/*%TITLE1%*/", f"{credits["tool_name"]} v{credits["tool_version"]} (by {credits["developer"]})").replace("/*%TITLE2%*/", credits["tool_name"]).replace(r"/*%GITHUB%*/", credits["github"]).replace(r"/*%DEVELOPER%*/", credits["developer"])
HOST = data_config["host"]
PORT = data_config["port"]
def Title():
if os_name == "Windows": ctypes.windll.kernel32.SetConsoleTitleW(f"{credits["tool_name"]} v{credits["tool_version"]} (by {credits["developer"]})")
elif os_name == "Linux": sys.stdout.write(f"\x1b]2;{credits["tool_name"]} v{credits["tool_version"]} (by {credits["developer"]})\x07")
def CreateFolderAndFile():
os.makedirs(path_folder_storage, exist_ok=True)
if not os.path.exists(path_file_logs):
with open(path_file_logs, "w", encoding="utf-8") as file: json.dump({}, file)
def GetLocalIp():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
except: ip = "127.0.0.1"
finally: s.close()
return ip
def LoadFilesJson():
if os.path.exists(path_file_logs):
try:
with open(path_file_logs, "r", encoding="utf-8") as file:
data = json.load(file)
if isinstance(data, dict): return data
except json.JSONDecodeError: pass
return {}
def SaveFilesJson(data):
with open(path_file_logs, "w", encoding="utf-8") as file: json.dump(data, file, indent=2)
def Start():
colorama.init()
Title()
CreateFolderAndFile()
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def Index():
os.makedirs(path_folder_storage, exist_ok=True)
files_data = LoadFilesJson()
if request.method == "POST":
uploaded_file = request.files.get("file")
if uploaded_file and uploaded_file.filename:
path = os.path.join(path_folder_storage, uploaded_file.filename)
uploaded_file.save(path)
print(f"{ADD} File received (encrypted): {white}{uploaded_file.filename}{reset}")
if uploaded_file.filename not in files_data:
next_number = max(files_data.values(), default=0) + 1
files_data[uploaded_file.filename] = next_number
SaveFilesJson(files_data)
else:
print(f"{ERROR} No file received in POST.{reset}")
sorted_files = sorted(files_data.items(), key=lambda x: x[1])
return render_template_string(content_html, files=sorted_files)
@app.route("/download/<filename>")
def Download(filename):
path = os.path.join(path_folder_storage, filename)
if not os.path.exists(path): return f"{ERROR} File not found", 404
return send_file(path, as_attachment=True)
@app.route("/delete/<filename>", methods=["POST"])
def DeleteFile(filename):
path = os.path.join(path_folder_storage, filename)
if os.path.exists(path):
try:
size = os.path.getsize(path)
with open(path, "r+b") as file: file.write(b"\x00" * size)
os.remove(path)
files_data = LoadFilesJson()
if filename in files_data:
del files_data[filename]
SaveFilesJson(files_data)
print(f"{ADD} File downloaded and successfully deleted: {white}{filename}{reset}")
return "OK", 200
except Exception as e:
print(f"{ERROR} Failed to delete {filename}: {white}{e}{reset}")
return "Error", 500
return "File not found", 404
@app.route("/favicon.ico")
def Favicon():
return send_from_directory(path_folder_structure, "Icone.ico", mimetype="image/vnd.microsoft.icon")
IP = GetLocalIp()
print(f"""{blue + banner + reset}
{blue}Access:{reset}
* Local : https://localhost:{PORT}
* Network : https://{IP}:{PORT}
{blue}Logs:{reset}""")
app.run(host=HOST, port=PORT, ssl_context="adhoc")
try: Start()
except Exception as e:
print(f"{ERROR} Error: {white}{e}")
input(f"{INPUT} Press enter -> {reset}")