Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
ac951090
Commit
ac951090
authored
8 years ago
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
saving to db: 1st version
parent
9a129163
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
comex_merci_pour_les_infos.py.cgi
cgi-bin/comex_merci_pour_les_infos.py.cgi
+39
-0
test_cgi_user.py.cgi
cgi-bin/test_cgi_user.py.cgi
+43
-0
registered.db
data/registered.db
+0
-0
No files found.
cgi-bin/comex_merci_pour_les_infos.py.cgi
View file @
ac951090
...
@@ -16,6 +16,7 @@ from ctypes import c_int
...
@@ -16,6 +16,7 @@ from ctypes import c_int
from
re
import
sub
from
re
import
sub
from
jinja2
import
Template
,
Environment
,
FileSystemLoader
from
jinja2
import
Template
,
Environment
,
FileSystemLoader
from
sys
import
stdout
# for direct buffer write of utf-8 bytes
from
sys
import
stdout
# for direct buffer write of utf-8 bytes
from
sqlite3
import
connect
# debug
# debug
import
cgitb
import
cgitb
...
@@ -61,6 +62,42 @@ def print_to_buffer(stringy):
...
@@ -61,6 +62,42 @@ def print_to_buffer(stringy):
"""
"""
stdout
.
buffer
.
write
((
stringy
+
'
\n
'
)
.
encode
(
'utf-8'
))
stdout
.
buffer
.
write
((
stringy
+
'
\n
'
)
.
encode
(
'utf-8'
))
def
sanitize
(
value_array
):
"""
simple and radical: leaves only alphanum and '.' '-' ':'
TODO allow more of the safe chars
"""
sanitized_array
=
[]
for
val
in
value_array
:
str_val
=
str
(
val
)
sanitized_array
.
append
(
sub
(
r'[^\w@\.-:]'
,
''
,
str_val
))
return
sanitized_array
def
save_to_db
(
records
):
"""
Expected columns:
FOR TESTS
- email
- initials
TODO
- first_name
- middle_name
- last_name
- jobtitle
- keywords
- institution
- institution city
- team/lab if applicable
- organization type
"""
safe_records
=
sanitize
(
records
)
c
=
connect
(
'../data/registered.db'
)
c
.
execute
(
'INSERT INTO test_table VALUES (?,?)'
,
safe_records
)
c
.
close
()
########### MAIN ###########
########### MAIN ###########
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
@@ -110,6 +147,8 @@ if __name__ == "__main__":
...
@@ -110,6 +147,8 @@ if __name__ == "__main__":
# debug data keys
# debug data keys
# print([k for k in this_data])
# print([k for k in this_data])
# sanitize & save to DB
save_to_db
([
email
,
initials
])
# show received values in template
# show received values in template
template_thanks
=
get_template
(
"thank_you.html"
)
template_thanks
=
get_template
(
"thank_you.html"
)
...
...
This diff is collapsed.
Click to expand it.
cgi-bin/test_cgi_user.py.cgi
0 → 100755
View file @
ac951090
#!/usr/bin/env python3
"""
Package: Registration page for comex app
simple script to test the cgi user (apache?)
=> to know what db permissions to set
(inspired by stackoverflow.com/a/25574419)
"""
__author__
=
"CNRS"
__copyright__
=
"Copyright 2016 ISCPIF-CNRS"
__version__
=
"1"
__email__
=
"romain.loth@iscpif.fr"
__status__
=
"Test"
from
os
import
getegid
from
getpass
import
getuser
from
sys
import
stdout
# debug
import
cgitb
cgitb
.
enable
()
def
print_to_buffer
(
stringy
):
"""
print() with utf-8 in a cgi doesn't work well because print is
connected to sys.stdout which has hardcoded encoding ASCII...
(but in reality html can of course have utf-8 bytes in cgi)
so to avoid print function we write to sys.stdout.buffer
(inspired by http://stackoverflow.com/questions/14860034)
"""
stdout
.
buffer
.
write
((
stringy
)
.
encode
(
'utf-8'
)
+
b
'
\n
'
)
########### MAIN ###########
if
__name__
==
"__main__"
:
# any response must have this
print_to_buffer
(
"Content-type: text/html"
)
print_to_buffer
(
''
)
# blank line <=> end of headers
print_to_buffer
(
"Env user id:
%
s <br/>"
%
getegid
()
)
print_to_buffer
(
"Real user:
%
s <br/>"
%
getuser
()
)
This diff is collapsed.
Click to expand it.
data/registered.db
0 → 100644
View file @
ac951090
File added
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
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