Skip to content

Commit

Permalink
updated CLI apps
Browse files Browse the repository at this point in the history
  • Loading branch information
lunamidori5 committed Nov 15, 2024
1 parent 63d09da commit f6bb415
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
36 changes: 18 additions & 18 deletions Webserver/Programs/Downloader/helper_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
if random_id == None:
random_id = str(random.randint(999999, 99999999999999))

def get_api_key():
home_dir = os.path.expanduser("~")
folder_path = os.path.join(home_dir, ".midoriai")
os.makedirs(folder_path, exist_ok=True)
api_key_file = os.path.join(folder_path, "MIDORI_AI_API_KEY_TEMP")
home_dir = os.path.expanduser("~")
folder_path = os.path.join(home_dir, ".midoriai")
os.makedirs(folder_path, exist_ok=True)
api_key_file = os.path.join(folder_path, "MIDORI_AI_API_KEY_TEMP")
username_file = os.path.join(folder_path, "MIDORI_AI_USERNAME")

username = "unknown_user"

if os.path.exists(username_file):
with open(username_file, 'r') as f:
username = f.read()

def get_api_key():
api_key = None
attempt_count = 0

Expand Down Expand Up @@ -75,8 +82,7 @@ def is_api_key_loaded():
#return False

async def download_files(FILES):
log(f"Attempting to download files from {FILES}")
headers = {"Discord-ID": random_id, "key": get_api_key()}
headers = {"Discord-ID": random_id, "username": f"{str(username)}", "key": get_api_key()}
async with ClientSession() as session:
async with session.get(FILES, headers=headers) as response:
if response.status == 200:
Expand All @@ -86,7 +92,6 @@ async def download_files(FILES):
raise RuntimeError(f"Failed to download files: {response.status}")

async def download_keys(KEY):
log(f"Attempting to download keys from {KEY}")
headers = {"Discord-ID": random_id, "key": get_api_key()}
async with ClientSession() as session:
async with session.get(KEY, headers=headers) as response:
Expand All @@ -97,7 +102,7 @@ async def download_keys(KEY):


def acquire_files_with_streaming(FILES):
response = requests.get(FILES, headers={"Discord-ID": random_id, "key": get_api_key()}, stream=True, timeout=55)
response = requests.get(FILES, headers={"Discord-ID": random_id, "username": f"{str(username)}", "key": get_api_key()}, stream=True, timeout=55)

if response.status_code == 200:
total_size = int(response.headers.get("Content-Length", 0))
Expand Down Expand Up @@ -136,7 +141,6 @@ async def main():
else:
os.remove(filename)

# Download the key file
key_url = f"{base_url}{key_filename}"
encrypted_file_url = f"{base_url}ai/{filename}"
backup_file_url = f"{base_url}{filename}"
Expand All @@ -149,8 +153,7 @@ async def main():

if not is_api_key_loaded():
trys = 16

# Download commands and keys

while trys < 18:
try:
if trys > 15:
Expand All @@ -166,14 +169,11 @@ async def main():
encrypted_commands = await download_files(encrypted_file_url)
else:
encrypted_commands = acquire_files_with_streaming(encrypted_file_url)

log("Encrypted file downloaded successfully")

keys = await download_keys(key_url)
time.sleep(1)

# Decrypt commands
log("Decrypting file")
fernet = Fernet(keys.encode()) # Create Fernet object with the key
fernet = Fernet(keys.encode())
decrypted_commands = fernet.decrypt(encrypted_commands)

if args.output:
Expand All @@ -182,7 +182,7 @@ async def main():
with open(filename, "wb") as f:
f.write(decrypted_commands)

log(f"File decrypted successfully: {filename}")
log(f"File downloaded and decrypted successfully: {filename}")

break
except Exception as e:
Expand Down
6 changes: 3 additions & 3 deletions Webserver/Programs/File_manager/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ def decrypt_user_data(encrypted_data, username, salt):
decrypted_data = cipher.decrypt(encrypted_data).decode()
return decrypted_data



def upload_to_midori_ai():
print("Please enter a token to encrypt your data before sending it to Midori AI")
print("Midori AI will not get this token, please record this token in a safe place")
pre_salt = getpass.getpass("Token: ")
salt = str(pre_salt).encode()
filename_to_upload = "userfile"

def download_from_midori_ai():
print("Please enter a token to decrypt your data after downloading it from Midori AI")
pre_salt = getpass.getpass("Token: ")
salt = str(pre_salt).encode()
filename_to_download = "userfile"

def main(args):
item = str(args.item).lower()
Expand All @@ -157,7 +157,7 @@ def main(args):
if upload and download:
raise Exception("You cannot upload/download at the same time.")

midori_ai_programs = ["midori-ai-downloader", "midori-ai-uploader"]
midori_ai_programs = ["midori-ai-downloader", "midori-ai-uploader", "midori-ai-login"]

for program in midori_ai_programs:
if check_programs(program):
Expand Down

0 comments on commit f6bb415

Please sign in to comment.