get client without auth

This commit is contained in:
2018-09-20 20:58:08 +03:00
parent 7834fb442d
commit 5c0a275a12
2 changed files with 61 additions and 18 deletions

View File

@@ -14,7 +14,7 @@ from utils.utils import *
from utils.crypt import *
__FLEES_VERSION__ = "20180919.0"
__FLEES_VERSION__ = "20180920.0"
app = Flask(__name__)
app.config.from_object(__name__)
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'])
def script_client(name = None, token = None):
(ok,share) = get_share(name, token = token)
if not ok:
notify({
"share": name,
"operation": "unauthorized_script_client"
})
return share
def script_client(name = "", token = ""):
notify({
'share': name,
'operation': 'script_client'
})
return render_template(
"client.py",
name = name,
@@ -566,6 +564,7 @@ def script_client(name = None, token = None):
rooturl = request.url_root
)
@app.route('/script/flip/<name>/<token>', methods=['GET'])
@app.route('/script/flip', methods=['GET'])
def script_flip(name = "", token = ""):

View File

@@ -72,6 +72,22 @@ class Completer(object):
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):
print("Download " + file['name'])
if not filename:
@@ -121,12 +137,17 @@ def edit_file(file):
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")
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):
print(" %s. %s"%( command, commands[command]['name']))
comp = Completer(choices = commands.keys())
@@ -134,14 +155,18 @@ def menu(opts):
print("\n[Empty to exit]")
choice = user_input("Number of action: ").strip()
if choice in commands:
commands[choice]['cmd'](opts)
value = commands[choice]['cmd'](opts)
if isinstance(value, dict):
opts = value
else:
sys.exit(0)
return opts
def menu_download(opts):
while True:
print_title("Download files")
files = json.loads(run_command("file/details", opts))
file_table = []
for f in files:
@@ -206,6 +231,25 @@ def menu_edit(opts):
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):
while True:
print_title("Upload")
@@ -301,7 +345,7 @@ def run_command(command, opts):
def run_loop(opts):
try:
while True:
menu(opts)
opts = menu(opts)
except KeyboardInterrupt:
print("")
return