2024-11-12 10:26:56 +00:00
|
|
|
#!/bin/python3
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
import json
|
|
|
|
import requests
|
2024-11-17 19:37:41 +00:00
|
|
|
import argparse
|
2024-11-12 10:26:56 +00:00
|
|
|
|
|
|
|
# Identity attributes
|
|
|
|
# {'username' : '', 'full_name' : '', 'email' : '', public_key : '' }
|
|
|
|
|
|
|
|
logging.basicConfig(format='%(levelname)s\t- %(message)s')
|
|
|
|
logger = logging.getLogger()
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
state = {}
|
|
|
|
|
|
|
|
#get file
|
2024-11-17 19:37:41 +00:00
|
|
|
#file handle - file(optonal)
|
2024-11-12 10:26:56 +00:00
|
|
|
def getFile(args):
|
2024-11-17 19:37:41 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
2024-11-12 10:26:56 +00:00
|
|
|
|
2024-11-17 19:37:41 +00:00
|
|
|
parser.add_argument('filehandle', nargs='?', default=None)
|
|
|
|
parser.add_argument('file', nargs='?', default=None)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
if not args.filehandle:
|
2024-11-12 10:26:56 +00:00
|
|
|
logger.error("Need a file handle.")
|
|
|
|
sys.exit(-1)
|
2024-11-17 19:37:41 +00:00
|
|
|
else:
|
|
|
|
if not os.path.isfile(args.filehandle):
|
|
|
|
logger.error("File '" + args.filehandle + "' not found" )
|
2024-11-12 10:26:56 +00:00
|
|
|
|
2024-11-17 19:37:41 +00:00
|
|
|
try:
|
|
|
|
file = requests.get(f'http://{state['REP_ADDRESS']}/file'), params = {"file_handle" : args.filehandle}
|
|
|
|
file.raise_for_status()
|
|
|
|
except requests.exceptions.RequestException as errex:
|
|
|
|
logger.error("Failed to obtain response from server.")
|
|
|
|
sys.exit(1)
|
2024-11-12 10:26:56 +00:00
|
|
|
|
2024-11-17 19:37:41 +00:00
|
|
|
file = json.loads(file)
|
2024-11-12 10:26:56 +00:00
|
|
|
|
|
|
|
# decrypt file
|
|
|
|
content = '' #decrypt(file.encode('utf-8'))
|
|
|
|
|
2024-11-17 19:37:41 +00:00
|
|
|
if not args.file:
|
2024-11-12 10:26:56 +00:00
|
|
|
sys.stdout.write(content)
|
|
|
|
else:
|
2024-11-17 19:37:41 +00:00
|
|
|
with open(args.file, "wb") as f:
|
2024-11-12 10:26:56 +00:00
|
|
|
f.write(content)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
getFile(sys.argv[1:])
|