From 147ef3667e1db97142583c350b8d0d3d2b0a76eb Mon Sep 17 00:00:00 2001 From: jgaunt Date: Wed, 27 Nov 2019 11:39:03 -0500 Subject: [PATCH] Update 'freenas_network_unlock.py' --- freenas_network_unlock.py | 60 +++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/freenas_network_unlock.py b/freenas_network_unlock.py index dbfdd23..2c2cc84 100644 --- a/freenas_network_unlock.py +++ b/freenas_network_unlock.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import requests, platform, subprocess, config, logging, simplejson as json, argparse +import requests, platform, subprocess, config, logging, simplejson as json, argparse, from subprocess import call # You must initialize logging, otherwise you'll not see debug output. logging.basicConfig(level=logging.INFO,format='%(asctime)s - [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S') @@ -35,31 +35,37 @@ def request(resource, method='GET', data=None): #if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Unlock FreeNAS Pools') - group = parser.add_mutually_exclusive_group() - group.add_argument('-s', '--server', action='store_true', help='server (Usually runs on another system where passwords are stored)') - group.add_argument('-c', '--client', action='store_true', help='client (Usually runs on the FreeNAS server)') - parser.add_argument('-ip', '--host', type=str, help='Hostname/IP of the host running the unlock script (Required for client)') - parser.add_argument('-f', '--filePath', type=str, help='Absolute path to the script on the host (Required for client)') - args = parser.parse_args() - if args.client and (args.host is None or args.filePath is None): - parser.error("--client requires --host and --filePath.") +# parser = argparse.ArgumentParser(description='Unlock FreeNAS Pools') +# group = parser.add_mutually_exclusive_group() +# group.add_argument('-s', '--server', action='store_true', help='server (Usually runs on another system where passwords are stored)') +# group.add_argument('-c', '--client', action='store_true', help='client (Usually runs on the FreeNAS server)') +# parser.add_argument('-ip', '--host', type=str, help='Hostname/IP of the host running the unlock script (Required for client)') +# parser.add_argument('-f', '--filePath', type=str, help='Absolute path to the script on the host (Required for client)') +# args = parser.parse_args() +# if args.client and (args.host is None or args.filePath is None): +# parser.error("--client requires --host and --filePath.") + + +#POOLS = request('storage/volume/', 'GET') +#for pool in POOLS['response']: +# if pool['is_decrypted'] == False: +# logging.info('Pool {} is locked'.format(pool['name'])) +# response = request('storage/volume/{}/unlock/'.format(pool['name']), 'POST', {'passphrase': '{}'.format(config.ENCRYPTION_PASSPHRASES[pool['name']])}) +# if response['ok']: +# logging.info('Pool {} was unlocked successfully'.format(pool['name'])) +# else: +# logging.error('Pool {} was NOT unlocked successfully'.format(pool['name'])) +# else: +# logging.debug('Pool {} is already unlocked'.format(pool['name'])) + + + +# Create a small ramdrive to store our recovery keys temporarily +rc = call("mkdir /mnt/ramfs", shell=True) +rc = call("mdmfs -s 1m md /mnt/ramfs", shell=True) + +# Send our unlock/mount script to the pi and execute it on the pi using ssh +rc = call("ssh root@ 'bash -s'", shell=True) + -if args.server or True: - POOLS = request('storage/volume/', 'GET') - for pool in POOLS['response']: - if pool['is_decrypted'] == False: - logging.info('Pool {} is locked'.format(pool['name'])) - response = request('storage/volume/{}/unlock/'.format(pool['name']), 'POST', {'passphrase': '{}'.format(config.ENCRYPTION_PASSPHRASES[pool['name']])}) - if response['ok']: - logging.info('Pool {} was unlocked successfully'.format(pool['name'])) - else: - logging.error('Pool {} was NOT unlocked successfully'.format(pool['name'])) - else: - logging.debug('Pool {} is already unlocked'.format(pool['name'])) -elif args.client and False: - host = args.host - filePath = args.filePath -else: - print(parser.print_help()) \ No newline at end of file