50 lines
1.9 KiB
Python
Executable File
50 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# cryptomator-utils: Python utilities for inspecting Cryptomator drives
|
|
# Copyright (C) 2024 Lee Yingtong Li (RunasSudo)
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
from lib_cryptomator_utils.cryptomator import directory_path_to_id, encrypt_filename, hash_directory_id, list_directory, load_vault_config
|
|
|
|
import os
|
|
import sys
|
|
|
|
def main():
|
|
if len(sys.argv) < 3:
|
|
print('Lists the contents of a given directory in a Cryptomator drive', file=sys.stderr)
|
|
print('', file=sys.stderr)
|
|
print('Usage: {} /path/to/vault.cryptomator /plaintext/path/within/drive'.format(sys.argv[0]), file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# Parse CLI arguments
|
|
vault_config_path = sys.argv[1]
|
|
target_directory = sys.argv[2]
|
|
|
|
vault_path = os.path.split(vault_config_path)[0]
|
|
|
|
# Load vault config (asks for password)
|
|
primary_master_key, hmac_master_key = load_vault_config(vault_config_path)
|
|
|
|
# Resolve the target directory
|
|
target_directory_parts = target_directory.strip('/').split('/')
|
|
directory_id = directory_path_to_id(vault_path, primary_master_key, hmac_master_key, '/'.join(target_directory_parts))
|
|
|
|
# Print directory listing
|
|
for filename in sorted(list_directory(vault_path, primary_master_key, hmac_master_key, directory_id)):
|
|
print(filename)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|