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
a69da7ba
Commit
a69da7ba
authored
Oct 25, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add captcha validation (realperson lib)
parent
532ced09
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
10 deletions
+44
-10
comex_merci_pour_les_infos.py.cgi
cgi-bin/comex_merci_pour_les_infos.py.cgi
+44
-10
No files found.
cgi-bin/comex_merci_pour_les_infos.py.cgi
View file @
a69da7ba
...
@@ -12,13 +12,40 @@ __status__ = "Test"
...
@@ -12,13 +12,40 @@ __status__ = "Test"
from
cgi
import
FieldStorage
from
cgi
import
FieldStorage
from
traceback
import
format_tb
from
traceback
import
format_tb
from
ctypes
import
c_int
# debug
# debug
import
cgitb
import
cgitb
cgitb
.
enable
()
cgitb
.
enable
()
########### SUBS ###########
def
re_hash
(
userinput
,
salt
=
""
):
"""
Build the captcha's verification hash server side
(my rewrite of keith-wood.name/realPerson.html python's version)
"""
hashk
=
5381
value
=
userinput
.
upper
()
+
salt
for
i
,
char
in
enumerate
(
value
):
hashk
=
c_int
(
((
hashk
<<
5
)
+
hashk
+
ord
(
char
))
&
0xFFFFFFFF
)
.
value
# bitwise masks 0xFFFFFFFF to go back to int32 each time
# c_int( previous ).value to go from unsigned ints to c signed ints each time
# debug iterations
# print(i, hashk, '<br/>')
return
hashk
########### MAIN ###########
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# any response must have this
print
(
"Content-type: text/html"
)
print
()
# blank line <=> end of headers
# reception: the cgi library gets vars from html form within received http POST
# reception: the cgi library gets vars from html form within received http POST
this_data
=
FieldStorage
()
this_data
=
FieldStorage
()
...
@@ -39,21 +66,31 @@ if __name__ == "__main__":
...
@@ -39,21 +66,31 @@ if __name__ == "__main__":
keywordsss
=
this_data
[
'keywords'
]
.
value
# single string but ','-separated
keywordsss
=
this_data
[
'keywords'
]
.
value
# single string but ','-separated
# keywordzzz = this_data.getlist(keywords) # array
# keywordzzz = this_data.getlist(keywords) # array
#
todo
#
--------- todo ------>8--------------
# institution = this_data[].value
# institution = this_data[].value
# optional
# optional
# picture = form["user_picture"]
# picture = form["user_picture"]
# if picture.file & picture.filename:
# if picture.file & picture.filename:
# picture_bytes = picture.value
# picture_bytes = picture.value
# --------------------->8---------------
# for captcha validation -----------------------------------------------
form_accepted
=
False
captcha_userinput
=
this_data
[
'my-captcha'
]
.
value
captcha_verifhash
=
int
(
this_data
[
'my-captchaHash'
]
.
value
)
captcha_userhash
=
re_hash
(
captcha_userinput
)
form_accepted
=
(
captcha_userhash
==
captcha_verifhash
)
# ----------------------------------------------------------------------
# response
print
(
"Content-type: text/html"
)
print
()
# blank line <=> end of headers
# debug data keys
# print([k for k in this_data])
# show received values
print
(
"<TITLE>CGI script output</TITLE>"
)
print
(
"<TITLE>CGI script output</TITLE>"
)
print
([
k
for
k
in
this_data
])
#
print
(
"<p style='font-family:Calibri, sans-serif; font-size:80
%
'"
)
print
(
'<br>first_name:'
,
first_name
)
print
(
'<br>first_name:'
,
first_name
)
print
(
'<br>midle_name:'
,
middle_name
)
print
(
'<br>midle_name:'
,
middle_name
)
print
(
'<br>last_name:'
,
last_name
)
print
(
'<br>last_name:'
,
last_name
)
...
@@ -62,19 +99,16 @@ if __name__ == "__main__":
...
@@ -62,19 +99,16 @@ if __name__ == "__main__":
print
(
'<br>country:'
,
country
)
print
(
'<br>country:'
,
country
)
print
(
'<br>jobtitle:'
,
jobtitle
)
print
(
'<br>jobtitle:'
,
jobtitle
)
print
(
'<br>keywords:'
,
keywordsss
)
print
(
'<br>keywords:'
,
keywordsss
)
print
(
'<br>captcha is correct ?:'
,
form_accepted
)
# print('instituton:',institution)
# print('instituton:',institution)
except
KeyError
as
kerrr
:
except
KeyError
as
kerrr
:
print
(
"Content-type: text/html"
)
print
()
# blank line <=> end of headers
print
(
"<h3>Your form was empty</h3"
)
print
(
"<h3>Your form was empty</h3"
)
print
(
"<p style='font-family:monospace; font-size:80
%
'"
)
print
(
"<p style='font-family:monospace; font-size:80
%
'"
)
print
(
"<br/>"
.
join
(
format_tb
(
kerrr
.
__traceback__
)))
print
(
"<br/>"
.
join
(
format_tb
(
kerrr
.
__traceback__
)))
print
(
"</p>"
)
print
(
"</p>"
)
except
Exception
as
errr
:
except
Exception
as
errr
:
print
(
"Content-type: text/html"
)
print
()
# blank line <=> end of headers
print
(
"<h3>There was an error:</h3"
)
print
(
"<h3>There was an error:</h3"
)
print
(
"<p style='font-family:monospace; font-size:80
%
'"
)
print
(
"<p style='font-family:monospace; font-size:80
%
'"
)
print
(
"<br/>"
.
join
(
format_tb
(
errr
.
__traceback__
)))
print
(
"<br/>"
.
join
(
format_tb
(
errr
.
__traceback__
)))
...
...
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