Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
eaffc178
Commit
eaffc178
authored
Apr 14, 2020
by
Vladislav Rykov
Browse files
dev conf added, need test
parent
896de2fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
dao/pend/__init__.pyc
0 → 100644
View file @
eaffc178
File added
dao/pend/pend.py
0 → 100644
View file @
eaffc178
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
,)
dao/pend/pend.pyc
0 → 100644
View file @
eaffc178
File added
server.py
View file @
eaffc178
...
...
@@ -5,6 +5,9 @@ import misc
import
dao.user.user
as
ud
import
dao.application.application
as
ad
import
dao.device.device
as
dd
import
dao.pend.pend
as
pend
import
binascii
APP_KEY_LEN
=
8
...
...
@@ -180,21 +183,26 @@ def dev_conf():
if
request
.
method
==
'GET'
:
return
render_template
(
'dev-conf.html'
,
devname
=
session
[
'devname'
])
else
:
argslen
=
len
(
request
.
form
[
'arg'
])
+
1
args
=
bytearray
(
argslen
+
2
)
args
[
0
]
=
int
(
request
.
form
[
'confid'
])
args
[
1
]
=
argslen
bstr
=
request
.
form
[
'arg'
]
.
encode
(
'utf-8'
)
bstr
=
bytes
(
request
.
form
[
'arg'
])
i
=
0
while
i
<
argslen
:
print
(
args
[
2
+
i
])
while
i
<
argslen
-
1
:
args
[
2
+
i
]
=
bstr
[
i
]
i
+=
1
print
(
'msg = '
,
args
)
print
(
type
(
request
.
form
[
'arg'
].
encode
(
'utf-8'
)))
print
(
request
.
form
[
'arg'
].
encode
(
'utf-8'
))
base64_args
=
binascii
.
b2a_base64
(
args
).
decode
(
'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'
]))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment