diff --git a/code/flees-manager.py b/code/flees-manager.py index d3e39a6..3a63198 100755 --- a/code/flees-manager.py +++ b/code/flees-manager.py @@ -87,6 +87,12 @@ def list_folders(shares,config): def add_share(shares, config, opts): + # check for share name exists already + for share in shares: + if share['name'] == opts.name: + print("Share with name '%s' already exists"%( opts.name, )) + sys.exit(1) + share = { 'name': opts.name, 'path': opts.path, @@ -114,6 +120,7 @@ def add_share(shares, config, opts): 'expire': opts.expire }) + print(json.dumps(share, indent = 2, sort_keys = True)) if opts.write: shares.append(share) shares_file = os.path.join(config['__root_path__'], opts.shares_file) @@ -127,9 +134,33 @@ def add_share(shares, config, opts): json.dump(shares, fp, indent = 2, sort_keys = True) print("Wrote file %s"%(shares_file,)) print("Add share: %s"%( opts.name, )) + check_login(share, config) else: print("Share not saved anywhere. Save with -w") - print(json.dumps(share, indent = 2, sort_keys = True)) + + + +def check_login(share, config): + import requests + print("Login link") + URL = None + if 'tokens' in share: + if len(share['tokens'])>0: + token = share['tokens'][0] + URL = "%s/list/%s/%s"%( + config['public_url'], + share['name'], + token + ) + if URL == None: + URL = "%s/list/%s"%( + config['public_url'], + share['name'] + ) + print(URL) + req = requests.get(URL) + if (req.status_code != 200): + print("Login did not appear to work") def modify_share(shares, config, opts): @@ -233,6 +264,9 @@ def remove_share(shares,config,opts): for share_ in share: print("Removing share: %s"%( name, )) print(json.dumps(share_, indent = 2, sort_keys = True)) + if len(share) == 0: + print("No such share") + sys.exit(1) if opts.write: shares = [share for share in shares if share['name'] != name] diff --git a/code/manager-requirements.txt b/code/manager-requirements.txt index 03234cb..46f457c 100644 --- a/code/manager-requirements.txt +++ b/code/manager-requirements.txt @@ -1,2 +1,3 @@ tabulate -pycrypto +#pycrypto +requests diff --git a/code/utils/crypt.py b/code/utils/crypt.py index ecd8f25..3d86c1c 100644 --- a/code/utils/crypt.py +++ b/code/utils/crypt.py @@ -1,34 +1,34 @@ import random import string import base64 -from Crypto.Cipher import AES +#~ from Crypto.Cipher import AES import hashlib -class Crypto: - def __init__(self, secret): - self.secret = add_pad(secret[0:16]) - self.cipher = AES.new(self.secret, AES.MODE_ECB) +#~ class Crypto: + #~ def __init__(self, secret): + #~ self.secret = add_pad(secret[0:16]) + #~ self.cipher = AES.new(self.secret, AES.MODE_ECB) - def encrypt(self, msg): + #~ def encrypt(self, msg): - return base64.urlsafe_b64encode( - self.cipher.encrypt( - add_pad( - msg - ) - ) - ).decode("utf-8") + #~ return base64.urlsafe_b64encode( + #~ self.cipher.encrypt( + #~ add_pad( + #~ msg + #~ ) + #~ ) + #~ ).decode("utf-8") - def decrypt(self, enc): + #~ def decrypt(self, enc): - return remove_pad( - self.cipher.decrypt( - base64.urlsafe_b64decode( - enc - ) - ).decode("utf-8") - ) + #~ return remove_pad( + #~ self.cipher.decrypt( + #~ base64.urlsafe_b64decode( + #~ enc + #~ ) + #~ ).decode("utf-8") + #~ ) def add_pad(string): diff --git a/data/shares.json.example b/data/shares.json.example index 4d8508c..0085122 100644 --- a/data/shares.json.example +++ b/data/shares.json.example @@ -1,8 +1,6 @@ [ { "name": "test", - "pass_hash": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", - "pass_plain": "password", "path": "files", "public": false, "upload": true