some checkups for manager

This commit is contained in:
Ville Rantanen
2018-03-02 12:04:48 +02:00
parent 06d42ee956
commit 01cfd02679
4 changed files with 58 additions and 25 deletions

View File

@@ -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]

View File

@@ -1,2 +1,3 @@
tabulate
pycrypto
#pycrypto
requests

View File

@@ -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):