manager to show paswd

This commit is contained in:
2018-01-26 15:00:33 +02:00
parent 19ba46535b
commit 928e953f34

View File

@@ -2,6 +2,7 @@
import argparse,json,sys,os
from shutil import copyfile
from tabulate import tabulate
import hashlib
def get_folder_size(path):
@@ -26,12 +27,17 @@ def file_size_human(num):
return "%3.1f %s" % (num, x)
num /= 1024.0
def list_shares(shares):
def list_shares(shares,opts):
table = []
table.append(('Name', 'Path','Public','Password','Upload','Overwrite','Direct','Expire'))
for share in shares:
public = get_or_no('public',share, False)
password = 'pass_hash' in share or 'pass_plain' in share
if opts.show_password:
if 'pass_plain' in share:
password = hashlib.sha1(share['pass_plain'].encode('utf-8')).hexdigest()
if 'pass_hash' in share:
password = share['pass_hash']
upload = get_or_no('upload',share, False)
overwrite = get_or_no('overwrite',share, True)
direct = get_or_no('direct_links',share, False) if password else False
@@ -74,7 +80,8 @@ def list_folders(shares,config):
))
print(tabulate(table, headers = "firstrow"))
def remove_share(name,shares,config):
def remove_share(shares,config,opts):
name = opts.name
share = [share for share in shares if share['name'] == name]
for share_ in share:
print("Removing share: %s"%( name, ))
@@ -97,6 +104,8 @@ parser.add_argument('-c','--config', action="store", dest="config", default = "d
subparsers = parser.add_subparsers(help='sub-command help', dest='subparser_name')
parser_list = subparsers.add_parser('list', help = "List shares")
parser_list.add_argument('-P', action="store_true", dest="show_password", default = False,
help = "Display hashed passwords")
parser_folders = subparsers.add_parser('folders', help = "List folders and share names")
@@ -119,11 +128,11 @@ else:
sys.exit(1)
if opts.subparser_name == 'list':
list_shares(shares)
list_shares(shares,opts)
elif opts.subparser_name == 'folders':
list_folders(shares,config)
elif opts.subparser_name == 'remove':
remove_share(opts.name,shares,config)
remove_share(shares,config,opts)