SHA256
updated for better encryption handling.
This commit is contained in:
+9
-7
@@ -162,7 +162,9 @@ def encrypt(filepath, password):
|
||||
os.remove(filepath)
|
||||
|
||||
# Update password database with encryption AND protection (same password)
|
||||
file_key = get_file_key(enc_filepath)
|
||||
# Normalize file_key to relative path (without CONTENT_DIR prefix)
|
||||
display_path = enc_filepath.replace(CONTENT_DIR + '/', '')
|
||||
file_key = get_file_key(display_path)
|
||||
passwords = load_passwords()
|
||||
|
||||
passwords[file_key] = {
|
||||
@@ -175,7 +177,6 @@ def encrypt(filepath, password):
|
||||
|
||||
save_passwords(passwords)
|
||||
|
||||
display_path = enc_filepath.replace(CONTENT_DIR + '/', '')
|
||||
print(f"✓ Encrypted & protected: {filepath} → {display_path}")
|
||||
return True
|
||||
|
||||
@@ -282,7 +283,9 @@ def unprotect(filepath):
|
||||
if not filepath.startswith(CONTENT_DIR):
|
||||
filepath = os.path.join(CONTENT_DIR, filepath)
|
||||
|
||||
file_key = get_file_key(filepath)
|
||||
# Normalize file_key to relative path (without CONTENT_DIR prefix)
|
||||
display_path = filepath.replace(CONTENT_DIR + '/', '')
|
||||
file_key = get_file_key(display_path)
|
||||
passwords = load_passwords()
|
||||
|
||||
if file_key not in passwords:
|
||||
@@ -298,7 +301,6 @@ def unprotect(filepath):
|
||||
del passwords[file_key]['created_at']
|
||||
|
||||
if save_passwords(passwords):
|
||||
display_path = filepath.replace(CONTENT_DIR + '/', '')
|
||||
print(f"✓ Unprotected: {display_path} (file stays encrypted, viewable in browser)")
|
||||
return True
|
||||
else:
|
||||
@@ -381,14 +383,14 @@ def status(filepath):
|
||||
if not filepath.startswith(CONTENT_DIR):
|
||||
filepath = os.path.join(CONTENT_DIR, filepath)
|
||||
|
||||
file_key = get_file_key(filepath)
|
||||
# Normalize file_key to relative path (without CONTENT_DIR prefix)
|
||||
display_path = filepath.replace(CONTENT_DIR + '/', '')
|
||||
file_key = get_file_key(display_path)
|
||||
passwords = load_passwords()
|
||||
|
||||
is_encrypted = filepath.endswith('.enc')
|
||||
is_protected = file_key in passwords and passwords[file_key].get('protected', False)
|
||||
|
||||
display_path = filepath.replace(CONTENT_DIR + '/', '')
|
||||
|
||||
print(f"\nFile: {display_path}")
|
||||
print(f"Encrypted: {'Yes' if is_encrypted else 'No'}")
|
||||
print(f"Protected: {'Yes' if is_protected else 'No'}")
|
||||
|
||||
Reference in New Issue
Block a user