Commit 08349bcc authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

skey management + create app corresp modifs

parent cf0176b6
from app.helpers.misc import with_psql
@with_psql
def create(cur, name, appkey, username, desc):
def create(cur, name, appkey, username, desc, secure, secure_key):
query = """
INSERT INTO
applications
VALUES
(%s, %s, %s, %s)
(%s, %s, %s, %s, %s, %s)
"""
cur.execute(query, (name, appkey, username, desc))
cur.execute(query, (name, appkey, username, desc, secure, secure_key))
return (True,)
......@@ -54,17 +54,18 @@ def get_list(cur, username):
return (True, cur.fetchall())
@with_psql
def update(cur, appkey, name, desc):
def update(cur, appkey, name, desc, secure):
query = """
UPDATE
applications
SET
name = %s,
description = %s,
secure = %s
WHERE
app_key = %s
"""
cur.execute(query, (name, desc, appkey))
cur.execute(query, (name, desc, secure, appkey))
return (True,)
......@@ -77,3 +78,16 @@ def get_count(cur):
cur.execute(query, ())
return (True, cur.fetchone())
@with_psql
def get_count_by_user(cur, username):
query = """
SELECT COUNT(*) FROM
applications
WHERE
username = %s
"""
cur.execute(query, (username,))
return (True, cur.fetchone())
......@@ -10,6 +10,12 @@ def rand_str(length):
else:
return hexlify(os.urandom(length//2 + 1))
def gen_skey_b64(nbytes):
return binascii.b2a_base64(os.urandom(nbytes)).decode('utf-8')
def skey_b64_to_hex(b64_skey):
return hexlify(binascii.a2b_base64(b64_skey))
def prep_id_range(devlist):
r = list(range(1,255))
......
......@@ -144,7 +144,13 @@ def app_():
return render_template('public/new-app.html', feedback=error)
else:
appkey = misc.rand_str(app.config['APPKEY_LENGTH']).decode('utf-8')
res = ad.create(request.form['appname'], appkey, session['name'], request.form['appdesc'])
secure_key = misc.gen_skey_b64(16)
secure = False
if request.form.getlist('secure') and request.form.getlist('secure')[0] == 'true':
secure = True
res = ad.create(request.form['appname'], appkey, session['name'], request.form['appdesc'], secure, secure_key)
if not res[0]:
return render_template('public/new-app.html', feedback=res[1])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment