updated to universal drop/drive node

This commit is contained in:
MachinePainting
2026-01-29 03:37:37 -08:00
committed by GitHub
parent 47235efd22
commit 2d993e2ad6
7 changed files with 1149 additions and 0 deletions
+237
View File
@@ -0,0 +1,237 @@
#!/usr/bin/env python3
"""
ComfyUI Encryption Scripts - Cross-Platform Decryption
Works with both DropSend and DriveSend nodes
Compatible with macOS, Windows, and Linux
============================================================
LOCAL USE ONLY - Run this on your local machine to decrypt
.enc files downloaded/synced from Dropbox or Google Drive.
Do not run on cloud instances (RunPod, etc.)
============================================================
Key retrieval methods (checked in order):
- COMFYUI_ENCRYPTION_KEY environment variable
- comfyui_encryption_key environment variable
- DROPSEND_ENCRYPTION_KEY environment variable
- DRIVESEND_ENCRYPTION_KEY environment variable
- macOS Keychain (ComfyUI_Encryption_Key, DropSend_Encryption_Key, or DriveSend_Encryption_Key)
- Linux Secret Service (ComfyUI, DropSend, or DriveSend)
- Manual input
"""
import os
import sys
import platform
import shutil
try:
from cryptography.fernet import Fernet
except ImportError:
print("Error: cryptography library not installed.")
print("Run: pip install cryptography")
sys.exit(1)
def get_key_from_macos_keychain():
"""Try to retrieve the key from macOS Keychain."""
try:
import subprocess
# Try multiple keychain item names for compatibility
for service, account in [
('ComfyUI_Encryption_Key', 'ComfyUI'),
('DropSend_Encryption_Key', 'DropSend'),
('DriveSend_Encryption_Key', 'DriveSend')
]:
result = subprocess.run(
['security', 'find-generic-password', '-s', service, '-a', account, '-w'],
capture_output=True, text=True
)
if result.returncode == 0 and result.stdout.strip():
return result.stdout.strip()
except Exception:
pass
return None
def get_key_from_linux_secret_service():
"""Try to retrieve the key from Linux Secret Service."""
try:
import subprocess
# Try multiple service names for compatibility
for service, username in [
('ComfyUI', 'ComfyUI'),
('DropSend', 'DropSend'),
('DriveSend', 'DriveSend')
]:
result = subprocess.run(
['secret-tool', 'lookup', 'service', service, 'username', username],
capture_output=True, text=True
)
if result.returncode == 0 and result.stdout.strip():
return result.stdout.strip()
except Exception:
pass
return None
def get_encryption_key():
"""Get encryption key from environment, platform credential store, or user input."""
system = platform.system()
# Try multiple environment variable names for compatibility
key = (os.environ.get('COMFYUI_ENCRYPTION_KEY') or
os.environ.get('comfyui_encryption_key') or
os.environ.get('DROPSEND_ENCRYPTION_KEY') or
os.environ.get('DRIVESEND_ENCRYPTION_KEY'))
if key:
print("Using key from environment variable.")
return key
# Try platform-specific credential storage
if system == 'Darwin': # macOS
key = get_key_from_macos_keychain()
if key:
print("Using key from macOS Keychain.")
return key
elif system == 'Linux':
key = get_key_from_linux_secret_service()
if key:
print("Using key from Secret Service.")
return key
# Prompt user
print("")
print("Encryption key not found automatically.")
print("")
print("To set up automatic key retrieval:")
if system == 'Darwin':
print(" - Store in Keychain: Keychain Access > File > New Password Item")
print(" Item Name: ComfyUI_Encryption_Key, Account: ComfyUI")
elif system == 'Windows':
print(" - Set environment variable COMFYUI_ENCRYPTION_KEY")
print(" (Win+R > sysdm.cpl > Advanced > Environment Variables)")
elif system == 'Linux':
print(" - Set environment variable: export COMFYUI_ENCRYPTION_KEY=\"your_key\"")
print(" - Or use secret-tool: echo -n \"key\" | secret-tool store --label=\"ComfyUI\" service ComfyUI username ComfyUI")
print("")
key = input("Enter your encryption key: ").strip()
if not key:
print("Error: No key provided.")
sys.exit(1)
return key
def decrypt_file(encrypted_path, output_path, fernet):
"""Decrypt a single file."""
try:
with open(encrypted_path, 'rb') as enc_file:
encrypted_data = enc_file.read()
decrypted_data = fernet.decrypt(encrypted_data)
with open(output_path, 'wb') as dec_file:
dec_file.write(decrypted_data)
return True
except Exception as e:
print(f" X Error decrypting {os.path.basename(encrypted_path)}: {e}")
return False
def main():
system = platform.system()
print(f"=== ComfyUI File Decryption ({system}) ===")
print("")
print("Decrypts .enc files to restore original images/videos.")
print("Works with both DropSend and DriveSend nodes.")
print("")
# Get folder path
folder = input("Enter the folder path containing .enc files: ").strip()
folder = folder.strip('"\'')
folder = folder.replace('\\ ', ' ')
if not folder or not os.path.isdir(folder):
print(f"Error: '{folder}' is not a valid directory.")
sys.exit(1)
print(f"Processing folder: {folder}")
print("")
# Recursive option
recursive_input = input("Decrypt files recursively (including subfolders)? (Y/N): ").strip().upper()
recursive = recursive_input == 'Y'
# Get encryption key
print("")
key = get_encryption_key()
try:
fernet = Fernet(key.encode())
except Exception as e:
print(f"Error: Invalid encryption key format: {e}")
sys.exit(1)
print("")
print("Scanning for .enc files...")
# Find all .enc files
enc_files = []
if recursive:
for root, _, files in os.walk(folder):
for file in files:
if file.endswith('.enc'):
enc_files.append(os.path.join(root, file))
else:
for file in os.listdir(folder):
if file.endswith('.enc'):
enc_files.append(os.path.join(folder, file))
if not enc_files:
print("No .enc files found in the specified location.")
sys.exit(0)
print(f"Found {len(enc_files)} .enc file(s) to decrypt.")
print("")
success_count = 0
error_count = 0
for enc_path in enc_files:
out_path = enc_path[:-4] # Remove .enc
if decrypt_file(enc_path, out_path, fernet):
print(f" + Decrypted: {os.path.basename(out_path)}")
success_count += 1
else:
error_count += 1
print("")
print(f"Decryption complete: {success_count} successful, {error_count} failed")
print("")
# Offer to move .enc files
move_input = input("Move all .enc files to a separate folder? (Y/N): ").strip().upper()
if move_input == 'Y':
enc_folder = os.path.join(folder, "_encrypted_originals")
os.makedirs(enc_folder, exist_ok=True)
moved_count = 0
for enc_path in enc_files:
if os.path.exists(enc_path):
dest = os.path.join(enc_folder, os.path.basename(enc_path))
shutil.move(enc_path, dest)
moved_count += 1
print(f"Moved {moved_count} .enc file(s) to: {enc_folder}")
else:
print("Leaving .enc files in place.")
print("")
print("Done!")
if __name__ == "__main__":
main()
+162
View File
@@ -0,0 +1,162 @@
#!/bin/bash
# ComfyUI Encryption Scripts - Decryption (Linux)
# Works with both DropSend and DriveSend nodes
# Decrypts .enc files using a key from environment variable or Secret Service
echo "=== ComfyUI File Decryption (Linux) ==="
echo ""
echo "Enter the folder path containing .enc files:"
read -r FOLDER
FOLDER=$(echo "$FOLDER" | sed "s/^['\"]//;s/['\"]$//")
if [ -z "$FOLDER" ] || [ ! -d "$FOLDER" ]; then
echo "Error: '$FOLDER' is not a valid directory."
exit 1
fi
echo "Processing folder: $FOLDER"
echo ""
echo "Would you like to decrypt files recursively (including subfolders)? (Y/N)"
read -r RECURSIVE_RESPONSE
if [[ "$RECURSIVE_RESPONSE" == "Y" || "$RECURSIVE_RESPONSE" == "y" ]]; then
RECURSIVE="true"
else
RECURSIVE="false"
fi
echo ""
echo "Retrieving encryption key..."
# Try multiple environment variable names for compatibility
KEY="${COMFYUI_ENCRYPTION_KEY:-}"
[ -z "$KEY" ] && KEY="${comfyui_encryption_key:-}"
[ -z "$KEY" ] && KEY="${DROPSEND_ENCRYPTION_KEY:-}"
[ -z "$KEY" ] && KEY="${DRIVESEND_ENCRYPTION_KEY:-}"
# Try Secret Service with multiple names
if [ -z "$KEY" ] && command -v secret-tool &> /dev/null; then
KEY=$(secret-tool lookup service ComfyUI username ComfyUI 2>/dev/null)
[ -z "$KEY" ] && KEY=$(secret-tool lookup service DropSend username DropSend 2>/dev/null)
[ -z "$KEY" ] && KEY=$(secret-tool lookup service DriveSend username DriveSend 2>/dev/null)
if [ -n "$KEY" ]; then
echo "Using key from Secret Service."
fi
fi
if [ -z "$KEY" ]; then
echo ""
echo "Encryption key not found in environment or Secret Service."
echo ""
echo "To set up automatic key retrieval, either:"
echo " 1. Set environment variable: export COMFYUI_ENCRYPTION_KEY=\"your_key\""
echo " 2. Store with secret-tool: echo -n \"your_key\" | secret-tool store --label=\"ComfyUI\" service ComfyUI username ComfyUI"
echo ""
echo -n "Enter your encryption key: "
read -r KEY
if [ -z "$KEY" ]; then
echo "Error: No key provided."
exit 1
fi
else
echo "Key retrieved successfully."
fi
echo ""
python3 - <<EOF
import os
import sys
from cryptography.fernet import Fernet
def decrypt_file(encrypted_path, output_path, key):
try:
fernet = Fernet(key.encode())
with open(encrypted_path, 'rb') as enc_file:
encrypted_data = enc_file.read()
decrypted_data = fernet.decrypt(encrypted_data)
with open(output_path, 'wb') as dec_file:
dec_file.write(decrypted_data)
print(f" ✓ Decrypted: {os.path.basename(output_path)}")
return True
except Exception as e:
print(f" ✗ Error decrypting {os.path.basename(encrypted_path)}: {e}")
return False
folder = "$FOLDER"
key = "$KEY"
recursive = "$RECURSIVE" == "true"
enc_files = []
success_count = 0
error_count = 0
print("Scanning for .enc files...")
if recursive:
for root, _, files in os.walk(folder):
for file in files:
if file.endswith('.enc'):
enc_files.append(os.path.join(root, file))
else:
for file in os.listdir(folder):
if file.endswith('.enc'):
enc_files.append(os.path.join(folder, file))
if not enc_files:
print("No .enc files found.")
sys.exit(0)
print(f"Found {len(enc_files)} .enc file(s) to decrypt.")
print("")
for enc_path in enc_files:
out_path = enc_path[:-4]
if decrypt_file(enc_path, out_path, key):
success_count += 1
else:
error_count += 1
print("")
print(f"Decryption complete: {success_count} successful, {error_count} failed")
EOF
if [ $? -ne 0 ]; then
echo "Error: Decryption process encountered an error."
exit 1
fi
echo ""
echo "Would you like to move all .enc files to a separate folder? (Y/N)"
read -r MOVE_RESPONSE
if [[ "$MOVE_RESPONSE" == "Y" || "$MOVE_RESPONSE" == "y" ]]; then
ENC_FOLDER="$FOLDER/_encrypted_originals"
mkdir -p "$ENC_FOLDER"
MOVED_COUNT=0
if [ "$RECURSIVE" = "true" ]; then
while IFS= read -r -d '' file; do
if [ -f "$file" ]; then
mv "$file" "$ENC_FOLDER/$(basename "$file")"
((MOVED_COUNT++))
fi
done < <(find "$FOLDER" -type f -name "*.enc" -print0)
else
for file in "$FOLDER"/*.enc; do
if [ -f "$file" ]; then
mv "$file" "$ENC_FOLDER/$(basename "$file")"
((MOVED_COUNT++))
fi
done
fi
echo "Moved $MOVED_COUNT .enc file(s) to: $ENC_FOLDER"
else
echo "Leaving .enc files in place."
fi
echo ""
echo "Done!"
+147
View File
@@ -0,0 +1,147 @@
#!/bin/bash
# ComfyUI Encryption Scripts - Encryption (Linux)
# Works with both DropSend and DriveSend nodes
# Encrypts image/video files using a key from environment variable or Secret Service
#
# NOTE: This script is for LOCAL USE ONLY
echo "=== ComfyUI File Encryption (Linux) ==="
echo ""
echo "NOTE: This script is for LOCAL USE ONLY."
echo "The ComfyUI nodes handle encryption automatically during upload."
echo ""
echo "Enter the folder path containing files to encrypt:"
read -r FOLDER
FOLDER=$(echo "$FOLDER" | sed "s/^['\"]//;s/['\"]$//")
if [ -z "$FOLDER" ] || [ ! -d "$FOLDER" ]; then
echo "Error: '$FOLDER' is not a valid directory."
exit 1
fi
echo "Processing folder: $FOLDER"
echo ""
echo "Would you like to encrypt files recursively (including subfolders)? (Y/N)"
read -r RECURSIVE_RESPONSE
if [[ "$RECURSIVE_RESPONSE" == "Y" || "$RECURSIVE_RESPONSE" == "y" ]]; then
RECURSIVE="true"
else
RECURSIVE="false"
fi
echo ""
echo "Retrieving encryption key..."
# Try multiple environment variable names for compatibility
KEY="${COMFYUI_ENCRYPTION_KEY:-}"
[ -z "$KEY" ] && KEY="${comfyui_encryption_key:-}"
[ -z "$KEY" ] && KEY="${DROPSEND_ENCRYPTION_KEY:-}"
[ -z "$KEY" ] && KEY="${DRIVESEND_ENCRYPTION_KEY:-}"
# Try Secret Service with multiple names
if [ -z "$KEY" ] && command -v secret-tool &> /dev/null; then
KEY=$(secret-tool lookup service ComfyUI username ComfyUI 2>/dev/null)
[ -z "$KEY" ] && KEY=$(secret-tool lookup service DropSend username DropSend 2>/dev/null)
[ -z "$KEY" ] && KEY=$(secret-tool lookup service DriveSend username DriveSend 2>/dev/null)
if [ -n "$KEY" ]; then
echo "Using key from Secret Service."
fi
fi
if [ -z "$KEY" ]; then
echo ""
echo "Encryption key not found."
echo -n "Enter your encryption key: "
read -r KEY
if [ -z "$KEY" ]; then
echo "Error: No key provided."
exit 1
fi
else
echo "Key retrieved successfully."
fi
echo ""
python3 - <<EOF
import os
import sys
from cryptography.fernet import Fernet
SUPPORTED_EXTENSIONS = ('.png', '.jpg', '.jpeg', '.webp', '.gif', '.mp4', '.avi', '.mov')
def encrypt_file(input_path, output_path, key):
try:
fernet = Fernet(key.encode())
with open(input_path, 'rb') as in_file:
data = in_file.read()
encrypted_data = fernet.encrypt(data)
with open(output_path, 'wb') as out_file:
out_file.write(encrypted_data)
return True
except Exception as e:
print(f" ✗ Error encrypting {os.path.basename(input_path)}: {e}")
return False
folder = "$FOLDER"
key = "$KEY"
recursive = "$RECURSIVE" == "true"
files_to_encrypt = []
success_count = 0
error_count = 0
print("Scanning for supported files...")
print(f"Supported formats: {', '.join(SUPPORTED_EXTENSIONS)}")
print("")
if recursive:
for root, _, files in os.walk(folder):
for file in files:
if file.lower().endswith(SUPPORTED_EXTENSIONS):
files_to_encrypt.append(os.path.join(root, file))
else:
for file in os.listdir(folder):
if file.lower().endswith(SUPPORTED_EXTENSIONS):
files_to_encrypt.append(os.path.join(folder, file))
if not files_to_encrypt:
print("No supported files found.")
sys.exit(0)
print(f"Found {len(files_to_encrypt)} file(s) to encrypt.")
print("")
for file_path in files_to_encrypt:
temp_enc_path = file_path + '.tmp.enc'
final_enc_path = file_path + '.enc'
try:
if encrypt_file(file_path, temp_enc_path, key):
os.remove(file_path)
os.rename(temp_enc_path, final_enc_path)
print(f" ✓ Encrypted: {os.path.basename(file_path)}")
success_count += 1
else:
error_count += 1
if os.path.exists(temp_enc_path):
os.remove(temp_enc_path)
except Exception as e:
print(f" ✗ Error: {e}")
error_count += 1
print("")
print(f"Encryption complete: {success_count} successful, {error_count} failed")
EOF
if [ $? -ne 0 ]; then
echo "Error: Encryption process encountered an error."
exit 1
fi
echo ""
echo "Done!"
+163
View File
@@ -0,0 +1,163 @@
#!/bin/bash
# ComfyUI Encryption Scripts - Decryption (macOS)
# Works with both DropSend and DriveSend nodes
# Decrypts .enc files using a key stored in macOS Keychain
echo "=== ComfyUI File Decryption (macOS) ==="
echo ""
echo "Drag in the folder of files to decrypt, or type the path:"
# Read folder path (supports drag-and-drop)
read -r FOLDER
# Remove any surrounding quotes and trailing backslash from drag-and-drop
FOLDER=$(echo "$FOLDER" | sed "s/^['\"]//;s/['\"]$//;s/\\\\$//" | xargs)
# Validate folder path
if [ -z "$FOLDER" ] || [ ! -d "$FOLDER" ]; then
echo "Error: '$FOLDER' is not a valid directory."
exit 1
fi
echo "Processing folder: $FOLDER"
echo ""
# Prompt for recursive option
echo "Would you like to decrypt files recursively (including subfolders)? (Y/N)"
read -r RECURSIVE_RESPONSE
if [[ "$RECURSIVE_RESPONSE" == "Y" || "$RECURSIVE_RESPONSE" == "y" ]]; then
RECURSIVE="true"
else
RECURSIVE="false"
fi
# Retrieve key from Keychain (try multiple names for compatibility)
echo ""
echo "Retrieving key from Keychain..."
KEY=$(security find-generic-password -s "ComfyUI_Encryption_Key" -a "ComfyUI" -w 2>/dev/null)
if [ -z "$KEY" ]; then
# Fallback to legacy DropSend naming
KEY=$(security find-generic-password -s "DropSend_Encryption_Key" -a "DropSend" -w 2>/dev/null)
fi
if [ -z "$KEY" ]; then
# Fallback to legacy DriveSend naming
KEY=$(security find-generic-password -s "DriveSend_Encryption_Key" -a "DriveSend" -w 2>/dev/null)
fi
if [ -z "$KEY" ]; then
echo ""
echo "Error: Failed to retrieve key from Keychain."
echo ""
echo "To store your encryption key in Keychain:"
echo " 1. Open Keychain Access (search in Spotlight)"
echo " 2. Click File > New Password Item"
echo " 3. Set Keychain Item Name: ComfyUI_Encryption_Key"
echo " 4. Set Account Name: ComfyUI"
echo " 5. Set Password: [your encryption key]"
echo " 6. Click Add"
echo ""
exit 1
fi
echo "Key retrieved successfully."
echo ""
# Python script to decrypt all .enc files
python3 - <<EOF
import os
import sys
from cryptography.fernet import Fernet
def decrypt_file(encrypted_path, output_path, key):
try:
fernet = Fernet(key.encode())
with open(encrypted_path, 'rb') as enc_file:
encrypted_data = enc_file.read()
decrypted_data = fernet.decrypt(encrypted_data)
with open(output_path, 'wb') as dec_file:
dec_file.write(decrypted_data)
print(f" ✓ Decrypted: {os.path.basename(output_path)}")
return True
except Exception as e:
print(f" ✗ Error decrypting {os.path.basename(encrypted_path)}: {e}")
return False
# Process .enc files
folder = "$FOLDER"
key = "$KEY"
recursive = "$RECURSIVE" == "true"
enc_files = []
success_count = 0
error_count = 0
print("Scanning for .enc files...")
if recursive:
for root, _, files in os.walk(folder):
for file in files:
if file.endswith('.enc'):
enc_files.append(os.path.join(root, file))
else:
for file in os.listdir(folder):
if file.endswith('.enc'):
enc_files.append(os.path.join(folder, file))
if not enc_files:
print("No .enc files found in the specified location.")
sys.exit(0)
print(f"Found {len(enc_files)} .enc file(s) to decrypt.")
print("")
for enc_path in enc_files:
# Remove .enc extension to restore original filename
out_path = enc_path[:-4] # Remove .enc
if decrypt_file(enc_path, out_path, key):
success_count += 1
else:
error_count += 1
print("")
print(f"Decryption complete: {success_count} successful, {error_count} failed")
EOF
# Check if decryption was successful
if [ $? -ne 0 ]; then
echo "Error: Decryption process encountered an error."
exit 1
fi
echo ""
# Prompt to move .enc files
echo "Would you like to move all .enc files to a separate folder? (Y/N)"
read -r MOVE_RESPONSE
if [[ "$MOVE_RESPONSE" == "Y" || "$MOVE_RESPONSE" == "y" ]]; then
ENC_FOLDER="$FOLDER/_encrypted_originals"
mkdir -p "$ENC_FOLDER"
MOVED_COUNT=0
if [ "$RECURSIVE" = "true" ]; then
while IFS= read -r -d '' file; do
if [ -f "$file" ]; then
mv "$file" "$ENC_FOLDER/$(basename "$file")"
((MOVED_COUNT++))
fi
done < <(find "$FOLDER" -type f -name "*.enc" -print0)
else
for file in "$FOLDER"/*.enc; do
if [ -f "$file" ]; then
mv "$file" "$ENC_FOLDER/$(basename "$file")"
((MOVED_COUNT++))
fi
done
fi
echo "Moved $MOVED_COUNT .enc file(s) to: $ENC_FOLDER"
else
echo "Leaving .enc files in place."
fi
echo ""
echo "Done!"
+152
View File
@@ -0,0 +1,152 @@
#!/bin/bash
# ComfyUI Encryption Scripts - Encryption (macOS)
# Works with both DropSend and DriveSend nodes
# Encrypts image/video files using a key stored in macOS Keychain
#
# NOTE: This script is for LOCAL USE ONLY - for encrypting files on your local machine
# outside of ComfyUI. The nodes handle encryption automatically during upload.
echo "=== ComfyUI File Encryption (macOS) ==="
echo ""
echo "NOTE: This script is for LOCAL USE ONLY."
echo "The ComfyUI nodes handle encryption automatically during upload."
echo ""
echo "Drag in the folder of files to encrypt, or type the path:"
# Read folder path (supports drag-and-drop)
read -r FOLDER
# Remove any surrounding quotes and trailing backslash from drag-and-drop
FOLDER=$(echo "$FOLDER" | sed "s/^['\"]//;s/['\"]$//;s/\\\\$//" | xargs)
# Validate folder path
if [ -z "$FOLDER" ] || [ ! -d "$FOLDER" ]; then
echo "Error: '$FOLDER' is not a valid directory."
exit 1
fi
echo "Processing folder: $FOLDER"
echo ""
# Prompt for recursive option
echo "Would you like to encrypt files recursively (including subfolders)? (Y/N)"
read -r RECURSIVE_RESPONSE
if [[ "$RECURSIVE_RESPONSE" == "Y" || "$RECURSIVE_RESPONSE" == "y" ]]; then
RECURSIVE="true"
else
RECURSIVE="false"
fi
# Retrieve key from Keychain (try multiple names for compatibility)
echo ""
echo "Retrieving key from Keychain..."
KEY=$(security find-generic-password -s "ComfyUI_Encryption_Key" -a "ComfyUI" -w 2>/dev/null)
if [ -z "$KEY" ]; then
KEY=$(security find-generic-password -s "DropSend_Encryption_Key" -a "DropSend" -w 2>/dev/null)
fi
if [ -z "$KEY" ]; then
KEY=$(security find-generic-password -s "DriveSend_Encryption_Key" -a "DriveSend" -w 2>/dev/null)
fi
if [ -z "$KEY" ]; then
echo ""
echo "Error: Failed to retrieve key from Keychain."
echo ""
echo "To store your encryption key in Keychain:"
echo " 1. Open Keychain Access (search in Spotlight)"
echo " 2. Click File > New Password Item"
echo " 3. Set Keychain Item Name: ComfyUI_Encryption_Key"
echo " 4. Set Account Name: ComfyUI"
echo " 5. Set Password: [your encryption key]"
echo " 6. Click Add"
echo ""
exit 1
fi
echo "Key retrieved successfully."
echo ""
# Python script to encrypt supported files
python3 - <<EOF
import os
import sys
from cryptography.fernet import Fernet
# Supported file extensions
SUPPORTED_EXTENSIONS = ('.png', '.jpg', '.jpeg', '.webp', '.gif', '.mp4', '.avi', '.mov')
def encrypt_file(input_path, output_path, key):
try:
fernet = Fernet(key.encode())
with open(input_path, 'rb') as in_file:
data = in_file.read()
encrypted_data = fernet.encrypt(data)
with open(output_path, 'wb') as out_file:
out_file.write(encrypted_data)
return True
except Exception as e:
print(f" ✗ Error encrypting {os.path.basename(input_path)}: {e}")
return False
# Process files
folder = "$FOLDER"
key = "$KEY"
recursive = "$RECURSIVE" == "true"
files_to_encrypt = []
success_count = 0
error_count = 0
print("Scanning for supported files...")
print(f"Supported formats: {', '.join(SUPPORTED_EXTENSIONS)}")
print("")
if recursive:
for root, _, files in os.walk(folder):
for file in files:
if file.lower().endswith(SUPPORTED_EXTENSIONS):
files_to_encrypt.append(os.path.join(root, file))
else:
for file in os.listdir(folder):
if file.lower().endswith(SUPPORTED_EXTENSIONS):
files_to_encrypt.append(os.path.join(folder, file))
if not files_to_encrypt:
print("No supported files found in the specified location.")
sys.exit(0)
print(f"Found {len(files_to_encrypt)} file(s) to encrypt.")
print("")
for file_path in files_to_encrypt:
# Create temp file first, then rename
temp_enc_path = file_path + '.tmp.enc'
final_enc_path = file_path + '.enc'
try:
if encrypt_file(file_path, temp_enc_path, key):
os.remove(file_path) # Delete original
os.rename(temp_enc_path, final_enc_path) # Rename to final
print(f" ✓ Encrypted: {os.path.basename(file_path)} → {os.path.basename(final_enc_path)}")
success_count += 1
else:
error_count += 1
if os.path.exists(temp_enc_path):
os.remove(temp_enc_path)
except Exception as e:
print(f" ✗ Error processing {os.path.basename(file_path)}: {e}")
error_count += 1
if os.path.exists(temp_enc_path):
os.remove(temp_enc_path)
print("")
print(f"Encryption complete: {success_count} successful, {error_count} failed")
EOF
# Check if encryption was successful
if [ $? -ne 0 ]; then
echo "Error: Encryption process encountered an error."
exit 1
fi
echo ""
echo "Done!"
+156
View File
@@ -0,0 +1,156 @@
#!/usr/bin/env python3
"""
ComfyUI Encryption Scripts - Decryption (Windows)
Works with both DropSend and DriveSend nodes
Decrypts .enc files using a key from environment variable or manual input
"""
import os
import sys
import shutil
try:
from cryptography.fernet import Fernet
except ImportError:
print("Error: cryptography library not installed.")
print("Run: pip install cryptography")
sys.exit(1)
def get_encryption_key():
"""Get encryption key from environment variable or user input."""
# Try multiple environment variable names for compatibility
key = (os.environ.get('COMFYUI_ENCRYPTION_KEY') or
os.environ.get('comfyui_encryption_key') or
os.environ.get('DROPSEND_ENCRYPTION_KEY') or
os.environ.get('DRIVESEND_ENCRYPTION_KEY'))
if key:
print("Using key from environment variable.")
return key
# Prompt user
print("")
print("Encryption key not found in environment.")
print("")
print("To set up automatic key retrieval:")
print(" 1. Press Win + R, type 'sysdm.cpl', press Enter")
print(" 2. Go to Advanced tab > Environment Variables")
print(" 3. Under User variables, click New")
print(" 4. Variable name: COMFYUI_ENCRYPTION_KEY")
print(" 5. Variable value: [your encryption key]")
print(" 6. Click OK and restart any open terminals")
print("")
key = input("Enter your encryption key: ").strip()
if not key:
print("Error: No key provided.")
sys.exit(1)
return key
def decrypt_file(encrypted_path, output_path, fernet):
"""Decrypt a single file."""
try:
with open(encrypted_path, 'rb') as enc_file:
encrypted_data = enc_file.read()
decrypted_data = fernet.decrypt(encrypted_data)
with open(output_path, 'wb') as dec_file:
dec_file.write(decrypted_data)
return True
except Exception as e:
print(f" X Error decrypting {os.path.basename(encrypted_path)}: {e}")
return False
def main():
print("=== ComfyUI File Decryption (Windows) ===")
print("")
# Get folder path
folder = input("Enter the folder path containing .enc files: ").strip()
folder = folder.strip('"\'')
if not folder or not os.path.isdir(folder):
print(f"Error: '{folder}' is not a valid directory.")
sys.exit(1)
print(f"Processing folder: {folder}")
print("")
# Recursive option
recursive_input = input("Decrypt files recursively (including subfolders)? (Y/N): ").strip().upper()
recursive = recursive_input == 'Y'
# Get encryption key
print("")
key = get_encryption_key()
try:
fernet = Fernet(key.encode())
except Exception as e:
print(f"Error: Invalid encryption key format: {e}")
sys.exit(1)
print("")
print("Scanning for .enc files...")
# Find all .enc files
enc_files = []
if recursive:
for root, _, files in os.walk(folder):
for file in files:
if file.endswith('.enc'):
enc_files.append(os.path.join(root, file))
else:
for file in os.listdir(folder):
if file.endswith('.enc'):
enc_files.append(os.path.join(folder, file))
if not enc_files:
print("No .enc files found in the specified location.")
sys.exit(0)
print(f"Found {len(enc_files)} .enc file(s) to decrypt.")
print("")
success_count = 0
error_count = 0
for enc_path in enc_files:
out_path = enc_path[:-4] # Remove .enc
if decrypt_file(enc_path, out_path, fernet):
print(f" + Decrypted: {os.path.basename(out_path)}")
success_count += 1
else:
error_count += 1
print("")
print(f"Decryption complete: {success_count} successful, {error_count} failed")
print("")
# Offer to move .enc files
move_input = input("Move all .enc files to a separate folder? (Y/N): ").strip().upper()
if move_input == 'Y':
enc_folder = os.path.join(folder, "_encrypted_originals")
os.makedirs(enc_folder, exist_ok=True)
moved_count = 0
for enc_path in enc_files:
if os.path.exists(enc_path):
dest = os.path.join(enc_folder, os.path.basename(enc_path))
shutil.move(enc_path, dest)
moved_count += 1
print(f"Moved {moved_count} .enc file(s) to: {enc_folder}")
else:
print("Leaving .enc files in place.")
print("")
print("Done!")
if __name__ == "__main__":
main()
+132
View File
@@ -0,0 +1,132 @@
#!/usr/bin/env python3
"""
ComfyUI Encryption Scripts - Encryption (Windows)
Works with both DropSend and DriveSend nodes
Encrypts image/video files using a key from environment variable or manual input
NOTE: This script is for LOCAL USE ONLY - for encrypting files on your local machine
outside of ComfyUI. The nodes handle encryption automatically during upload.
"""
import os
import sys
try:
from cryptography.fernet import Fernet
except ImportError:
print("Error: cryptography library not installed.")
print("Run: pip install cryptography")
sys.exit(1)
SUPPORTED_EXTENSIONS = ('.png', '.jpg', '.jpeg', '.webp', '.gif', '.mp4', '.avi', '.mov')
def get_encryption_key():
"""Get encryption key from environment variable or user input."""
key = (os.environ.get('COMFYUI_ENCRYPTION_KEY') or
os.environ.get('comfyui_encryption_key') or
os.environ.get('DROPSEND_ENCRYPTION_KEY') or
os.environ.get('DRIVESEND_ENCRYPTION_KEY'))
if key:
print("Using key from environment variable.")
return key
print("")
print("Encryption key not found in environment.")
print("")
key = input("Enter your encryption key: ").strip()
if not key:
print("Error: No key provided.")
sys.exit(1)
return key
def encrypt_file(input_path, output_path, fernet):
"""Encrypt a single file."""
try:
with open(input_path, 'rb') as in_file:
data = in_file.read()
encrypted_data = fernet.encrypt(data)
with open(output_path, 'wb') as out_file:
out_file.write(encrypted_data)
return True
except Exception as e:
print(f" X Error encrypting {os.path.basename(input_path)}: {e}")
return False
def main():
print("=== ComfyUI File Encryption (Windows) ===")
print("")
print("NOTE: This script is for LOCAL USE ONLY.")
print("The ComfyUI nodes handle encryption automatically during upload.")
print("")
folder = input("Enter the folder path containing files to encrypt: ").strip().strip('"\'')
if not folder or not os.path.isdir(folder):
print(f"Error: '{folder}' is not a valid directory.")
sys.exit(1)
recursive_input = input("Encrypt files recursively? (Y/N): ").strip().upper()
recursive = recursive_input == 'Y'
key = get_encryption_key()
try:
fernet = Fernet(key.encode())
except Exception as e:
print(f"Error: Invalid encryption key format: {e}")
sys.exit(1)
print("")
print(f"Supported formats: {', '.join(SUPPORTED_EXTENSIONS)}")
files_to_encrypt = []
if recursive:
for root, _, files in os.walk(folder):
for file in files:
if file.lower().endswith(SUPPORTED_EXTENSIONS):
files_to_encrypt.append(os.path.join(root, file))
else:
for file in os.listdir(folder):
if file.lower().endswith(SUPPORTED_EXTENSIONS):
files_to_encrypt.append(os.path.join(folder, file))
if not files_to_encrypt:
print("No supported files found.")
sys.exit(0)
print(f"Found {len(files_to_encrypt)} file(s) to encrypt.")
print("")
success_count = 0
error_count = 0
for file_path in files_to_encrypt:
temp_enc_path = file_path + '.tmp.enc'
final_enc_path = file_path + '.enc'
try:
if encrypt_file(file_path, temp_enc_path, fernet):
os.remove(file_path)
os.rename(temp_enc_path, final_enc_path)
print(f" + Encrypted: {os.path.basename(file_path)}")
success_count += 1
else:
error_count += 1
if os.path.exists(temp_enc_path):
os.remove(temp_enc_path)
except Exception as e:
print(f" X Error: {e}")
error_count += 1
print(f"\nEncryption complete: {success_count} successful, {error_count} failed")
if __name__ == "__main__":
main()