some checkups for manager
This commit is contained in:
@@ -87,6 +87,12 @@ def list_folders(shares,config):
|
|||||||
|
|
||||||
def add_share(shares, config, opts):
|
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 = {
|
share = {
|
||||||
'name': opts.name,
|
'name': opts.name,
|
||||||
'path': opts.path,
|
'path': opts.path,
|
||||||
@@ -114,6 +120,7 @@ def add_share(shares, config, opts):
|
|||||||
'expire': opts.expire
|
'expire': opts.expire
|
||||||
})
|
})
|
||||||
|
|
||||||
|
print(json.dumps(share, indent = 2, sort_keys = True))
|
||||||
if opts.write:
|
if opts.write:
|
||||||
shares.append(share)
|
shares.append(share)
|
||||||
shares_file = os.path.join(config['__root_path__'], opts.shares_file)
|
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)
|
json.dump(shares, fp, indent = 2, sort_keys = True)
|
||||||
print("Wrote file %s"%(shares_file,))
|
print("Wrote file %s"%(shares_file,))
|
||||||
print("Add share: %s"%( opts.name, ))
|
print("Add share: %s"%( opts.name, ))
|
||||||
|
check_login(share, config)
|
||||||
else:
|
else:
|
||||||
print("Share not saved anywhere. Save with -w")
|
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):
|
def modify_share(shares, config, opts):
|
||||||
@@ -233,6 +264,9 @@ def remove_share(shares,config,opts):
|
|||||||
for share_ in share:
|
for share_ in share:
|
||||||
print("Removing share: %s"%( name, ))
|
print("Removing share: %s"%( name, ))
|
||||||
print(json.dumps(share_, indent = 2, sort_keys = True))
|
print(json.dumps(share_, indent = 2, sort_keys = True))
|
||||||
|
if len(share) == 0:
|
||||||
|
print("No such share")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if opts.write:
|
if opts.write:
|
||||||
shares = [share for share in shares if share['name'] != name]
|
shares = [share for share in shares if share['name'] != name]
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
tabulate
|
tabulate
|
||||||
pycrypto
|
#pycrypto
|
||||||
|
requests
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import base64
|
import base64
|
||||||
from Crypto.Cipher import AES
|
#~ from Crypto.Cipher import AES
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
class Crypto:
|
#~ class Crypto:
|
||||||
def __init__(self, secret):
|
#~ def __init__(self, secret):
|
||||||
self.secret = add_pad(secret[0:16])
|
#~ self.secret = add_pad(secret[0:16])
|
||||||
self.cipher = AES.new(self.secret, AES.MODE_ECB)
|
#~ self.cipher = AES.new(self.secret, AES.MODE_ECB)
|
||||||
|
|
||||||
def encrypt(self, msg):
|
#~ def encrypt(self, msg):
|
||||||
|
|
||||||
return base64.urlsafe_b64encode(
|
#~ return base64.urlsafe_b64encode(
|
||||||
self.cipher.encrypt(
|
#~ self.cipher.encrypt(
|
||||||
add_pad(
|
#~ add_pad(
|
||||||
msg
|
#~ msg
|
||||||
)
|
#~ )
|
||||||
)
|
#~ )
|
||||||
).decode("utf-8")
|
#~ ).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
def decrypt(self, enc):
|
#~ def decrypt(self, enc):
|
||||||
|
|
||||||
return remove_pad(
|
#~ return remove_pad(
|
||||||
self.cipher.decrypt(
|
#~ self.cipher.decrypt(
|
||||||
base64.urlsafe_b64decode(
|
#~ base64.urlsafe_b64decode(
|
||||||
enc
|
#~ enc
|
||||||
)
|
#~ )
|
||||||
).decode("utf-8")
|
#~ ).decode("utf-8")
|
||||||
)
|
#~ )
|
||||||
|
|
||||||
|
|
||||||
def add_pad(string):
|
def add_pad(string):
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"pass_hash": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
|
||||||
"pass_plain": "password",
|
|
||||||
"path": "files",
|
"path": "files",
|
||||||
"public": false,
|
"public": false,
|
||||||
"upload": true
|
"upload": true
|
||||||
|
|||||||
Reference in New Issue
Block a user