get client without auth
This commit is contained in:
17
code/app.py
17
code/app.py
@@ -14,7 +14,7 @@ from utils.utils import *
|
|||||||
from utils.crypt import *
|
from utils.crypt import *
|
||||||
|
|
||||||
|
|
||||||
__FLEES_VERSION__ = "20180919.0"
|
__FLEES_VERSION__ = "20180920.0"
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(__name__)
|
app.config.from_object(__name__)
|
||||||
config_values = read_config(app)
|
config_values = read_config(app)
|
||||||
@@ -550,15 +550,13 @@ def download_zip(name, token = None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/script/client', methods=['GET'])
|
||||||
@app.route('/script/client/<name>/<token>', methods=['GET'])
|
@app.route('/script/client/<name>/<token>', methods=['GET'])
|
||||||
def script_client(name = None, token = None):
|
def script_client(name = "", token = ""):
|
||||||
(ok,share) = get_share(name, token = token)
|
notify({
|
||||||
if not ok:
|
'share': name,
|
||||||
notify({
|
'operation': 'script_client'
|
||||||
"share": name,
|
})
|
||||||
"operation": "unauthorized_script_client"
|
|
||||||
})
|
|
||||||
return share
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"client.py",
|
"client.py",
|
||||||
name = name,
|
name = name,
|
||||||
@@ -566,6 +564,7 @@ def script_client(name = None, token = None):
|
|||||||
rooturl = request.url_root
|
rooturl = request.url_root
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/script/flip/<name>/<token>', methods=['GET'])
|
@app.route('/script/flip/<name>/<token>', methods=['GET'])
|
||||||
@app.route('/script/flip', methods=['GET'])
|
@app.route('/script/flip', methods=['GET'])
|
||||||
def script_flip(name = "", token = ""):
|
def script_flip(name = "", token = ""):
|
||||||
|
|||||||
@@ -72,6 +72,22 @@ class Completer(object):
|
|||||||
return results[state]
|
return results[state]
|
||||||
|
|
||||||
|
|
||||||
|
def check_connection(opts):
|
||||||
|
p = Popen(
|
||||||
|
[
|
||||||
|
'curl','-s','-f',
|
||||||
|
'%s%s/%s/%s'%(opts.rooturl, "file/list", opts.share, opts.token)
|
||||||
|
],
|
||||||
|
stdout=PIPE,
|
||||||
|
stderr=PIPE
|
||||||
|
)
|
||||||
|
p.communicate()
|
||||||
|
rc = p.returncode
|
||||||
|
if rc != 0:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def download_file(file, opts, filename = False):
|
def download_file(file, opts, filename = False):
|
||||||
print("Download " + file['name'])
|
print("Download " + file['name'])
|
||||||
if not filename:
|
if not filename:
|
||||||
@@ -121,12 +137,17 @@ def edit_file(file):
|
|||||||
|
|
||||||
|
|
||||||
def menu(opts):
|
def menu(opts):
|
||||||
commands = {
|
|
||||||
'1': {'name': 'Download', 'cmd': menu_download},
|
|
||||||
'2': {'name': 'Upload', 'cmd': menu_upload},
|
|
||||||
'3': {'name': 'Edit', 'cmd': menu_edit},
|
|
||||||
}
|
|
||||||
print_title("Main menu")
|
print_title("Main menu")
|
||||||
|
commands = {
|
||||||
|
'4': {'name': 'Change login', 'cmd': menu_login}
|
||||||
|
}
|
||||||
|
if check_connection(opts):
|
||||||
|
commands['1'] = {'name': 'Download', 'cmd': menu_download}
|
||||||
|
commands['2'] = {'name': 'Upload', 'cmd': menu_upload}
|
||||||
|
commands['3'] = {'name': 'Edit', 'cmd': menu_edit}
|
||||||
|
else:
|
||||||
|
print(" Not a valid login")
|
||||||
|
|
||||||
for command in sorted(commands):
|
for command in sorted(commands):
|
||||||
print(" %s. %s"%( command, commands[command]['name']))
|
print(" %s. %s"%( command, commands[command]['name']))
|
||||||
comp = Completer(choices = commands.keys())
|
comp = Completer(choices = commands.keys())
|
||||||
@@ -134,20 +155,24 @@ def menu(opts):
|
|||||||
print("\n[Empty to exit]")
|
print("\n[Empty to exit]")
|
||||||
choice = user_input("Number of action: ").strip()
|
choice = user_input("Number of action: ").strip()
|
||||||
if choice in commands:
|
if choice in commands:
|
||||||
commands[choice]['cmd'](opts)
|
value = commands[choice]['cmd'](opts)
|
||||||
|
if isinstance(value, dict):
|
||||||
|
opts = value
|
||||||
else:
|
else:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
return opts
|
||||||
|
|
||||||
|
|
||||||
def menu_download(opts):
|
def menu_download(opts):
|
||||||
while True:
|
while True:
|
||||||
print_title("Download files")
|
print_title("Download files")
|
||||||
|
|
||||||
files = json.loads(run_command("file/details", opts))
|
files = json.loads(run_command("file/details", opts))
|
||||||
file_table = []
|
file_table = []
|
||||||
for f in files:
|
for f in files:
|
||||||
file_table.append((
|
file_table.append((
|
||||||
f['name'],
|
f['name'],
|
||||||
float(f['size'].replace(",","")),
|
float(f['size'].replace(",","")),
|
||||||
f['mtime']
|
f['mtime']
|
||||||
))
|
))
|
||||||
print(tabulate(file_table, headers = ("Name", "Size [Mb]", "Modified")))
|
print(tabulate(file_table, headers = ("Name", "Size [Mb]", "Modified")))
|
||||||
@@ -206,6 +231,25 @@ def menu_edit(opts):
|
|||||||
os.remove(tmp)
|
os.remove(tmp)
|
||||||
|
|
||||||
|
|
||||||
|
def menu_login(opts):
|
||||||
|
print_title("Login")
|
||||||
|
print("\n[Empty to keep previous value]")
|
||||||
|
|
||||||
|
|
||||||
|
choice = user_input('Host [%s]: '%( opts.rooturl, )).strip()
|
||||||
|
if choice != "":
|
||||||
|
opts.rooturl = choice
|
||||||
|
|
||||||
|
choice = user_input('Share name [%s]: '%( opts.share, )).strip()
|
||||||
|
if choice != "":
|
||||||
|
opts.share = choice
|
||||||
|
|
||||||
|
choice = user_input('Token [%s]: '%( opts.token, )).strip()
|
||||||
|
if choice != "":
|
||||||
|
opts.token = choice
|
||||||
|
|
||||||
|
return opts
|
||||||
|
|
||||||
def menu_upload(opts):
|
def menu_upload(opts):
|
||||||
while True:
|
while True:
|
||||||
print_title("Upload")
|
print_title("Upload")
|
||||||
@@ -301,7 +345,7 @@ def run_command(command, opts):
|
|||||||
def run_loop(opts):
|
def run_loop(opts):
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
menu(opts)
|
opts = menu(opts)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user