Commit eaffc178 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

dev conf added, need test

parent 896de2fe
import psycopg2
# decorator implementation
def with_psql(f):
def _with_psql(*args, **kwargs):
conn = psycopg2.connect('dbname=gateway')
cur = conn.cursor()
try:
res = f(cur, *args, **kwargs)
except (Exception, psycopg2.DatabaseError) as error:
conn.rollback()
res = (False, error)
else:
conn.commit()
finally:
cur.close()
conn.close()
return res
return _with_psql
@with_psql
def create(cur, appkey, devid, msg):
query = """
INSERT INTO
pend_msgs
VALUES
(%s, %s, %s)
"""
cur.execute(query, (appkey, devid, msg))
return (True,)
...@@ -5,6 +5,9 @@ import misc ...@@ -5,6 +5,9 @@ import misc
import dao.user.user as ud import dao.user.user as ud
import dao.application.application as ad import dao.application.application as ad
import dao.device.device as dd import dao.device.device as dd
import dao.pend.pend as pend
import binascii
APP_KEY_LEN = 8 APP_KEY_LEN = 8
...@@ -180,21 +183,26 @@ def dev_conf(): ...@@ -180,21 +183,26 @@ def dev_conf():
if request.method == 'GET': if request.method == 'GET':
return render_template('dev-conf.html', devname=session['devname']) return render_template('dev-conf.html', devname=session['devname'])
else: else:
argslen = len(request.form['arg']) + 1 argslen = len(request.form['arg']) + 1
args = bytearray(argslen + 2) args = bytearray(argslen + 2)
args[0] = int(request.form['confid']) args[0] = int(request.form['confid'])
args[1] = argslen args[1] = argslen
bstr = request.form['arg'].encode('utf-8') bstr = bytes(request.form['arg'])
i = 0 i = 0
while i < argslen: while i < argslen - 1:
print(args[2+i])
args[2+i] = bstr[i] args[2+i] = bstr[i]
i += 1 i += 1
print('msg = ', args) base64_args = binascii.b2a_base64(args).decode('utf-8')
print(type(request.form['arg'].encode('utf-8')))
print(request.form['arg'].encode('utf-8')) pend.create(session['appkey'], session['devid'], base64_args)
#print('msg = ', args)
#print('base64 = ', base64_args)
#print(type(request.form['arg'].encode('utf-8')))
#print(request.form['arg'].encode('utf-8'))
return redirect(url_for('dev', id=session['devid'])) return redirect(url_for('dev', id=session['devid']))
......
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