Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffbs-website
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ffbs
ffbs-website
Commits
be5b901c
Commit
be5b901c
authored
Jan 03, 2019
by
chrissi^
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gci: Activate Contact with CAPTCHA
Signed-off-by:
Chris Fiege
<
chris@tinyhost.de
>
parent
ae6e1495
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
72 deletions
+31
-72
cgi/contact
cgi/contact
+31
-10
cgi/contact_cp
cgi/contact_cp
+0
-62
No files found.
cgi/contact
View file @
be5b901c
...
...
@@ -6,6 +6,7 @@ import cgitb
import
re
import
smtplib
import
uuid
import
datetime
from
email.mime.text
import
MIMEText
from
subprocess
import
Popen
,
PIPE
cgitb
.
enable
()
...
...
@@ -25,16 +26,36 @@ try:
if
not
re
.
match
(
EMAIL_REGEX
,
email
):
raise
ValueError
()
message
=
form
[
'message'
].
value
msg
=
MIMEText
(
message
,
'plain'
,
'utf-8'
)
msg
[
'From'
]
=
"kontakt@freifunk-bs.de"
msg
[
'To'
]
=
CONTACT_EMAIL_TO
msg
[
'Subject'
]
=
'Kontaktanfrage von %s'
%
email
msg
[
'Reply-To'
]
=
','
.
join
([
email
,
CONTACT_EMAIL_TO
])
uuid
=
str
(
uuid
.
uuid4
())
#get a random uuid
msg
[
'Message-ID'
]
=
'<'
+
uuid
+
'@freifunk-bs.de>'
p
=
Popen
([
"/usr/sbin/sendmail"
,
"-t"
,
"-oi"
,
"-FKontaktformular"
],
stdin
=
PIPE
)
p
.
communicate
(
msg
.
as_string
())
print
template
%
"Ihre Nachricht wurde entgegengenommen"
captcha
=
form
[
'captcha'
].
value
captcha
=
captcha
.
replace
(
"'"
,
""
)
captcha
=
captcha
.
replace
(
'"'
,
""
)
captcha
=
captcha
.
strip
()
today
=
str
(
datetime
.
datetime
.
now
().
day
)
if
today
==
captcha
:
msg
=
MIMEText
(
message
,
'plain'
,
'utf-8'
)
msg
[
'From'
]
=
"kontakt@freifunk-bs.de"
msg
[
'To'
]
=
CONTACT_EMAIL_TO
msg
[
'Subject'
]
=
'Kontaktanfrage von %s'
%
email
msg
[
'Reply-To'
]
=
','
.
join
([
email
,
CONTACT_EMAIL_TO
])
uuid
=
str
(
uuid
.
uuid4
())
#get a random uuid
msg
[
'Message-ID'
]
=
'<'
+
uuid
+
'@freifunk-bs.de>'
p
=
Popen
([
"/usr/sbin/sendmail"
,
"-t"
,
"-oi"
,
"-FKontaktformular"
],
stdin
=
PIPE
)
p
.
communicate
(
msg
.
as_string
())
print
template
%
"Ihre Nachricht wurde entgegengenommen"
else
:
msg
=
MIMEText
(
message
,
'plain'
,
'utf-8'
)
msg
[
'From'
]
=
"kontakt@freifunk-bs.de"
msg
[
'To'
]
=
CONTACT_EMAIL_TO
msg
[
'Subject'
]
=
'[CAPTCHA]Kontaktanfrage von %s'
%
email
msg
[
'Reply-To'
]
=
','
.
join
([
email
,
CONTACT_EMAIL_TO
])
uuid
=
str
(
uuid
.
uuid4
())
#get a random uuid
msg
[
'Message-ID'
]
=
'<'
+
uuid
+
'@freifunk-bs.de>'
msg
[
'X-FFBS-CAPTCHA'
]
=
"Failed: User tried: {}; I expected: {}"
.
format
(
captcha
,
today
)
p
=
Popen
([
"/usr/sbin/sendmail"
,
"-t"
,
"-oi"
,
"-FKontaktformular"
],
stdin
=
PIPE
)
p
.
communicate
(
msg
.
as_string
())
print
template
%
"Der Spamschutz wurde nicht erfolgreich ausgefüllt. Bitte versuchen Sie es erneut."
except
Exception
as
e
:
print
template
%
"Die Anfrage ist ungültig"
...
...
cgi/contact_cp
deleted
100755 → 0
View file @
ae6e1495
#!/usr/bin/env python2
# coding=utf-8
import
cgi
import
cgitb
import
re
import
smtplib
import
uuid
import
datetime
from
email.mime.text
import
MIMEText
from
subprocess
import
Popen
,
PIPE
cgitb
.
enable
()
CONTACT_EMAIL_TO
=
'kontakt@freifunk-bs.de'
EMAIL_REGEX
=
r
"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
print
"Content-Type: text/html"
print
""
template
=
"""<meta charset="utf-8">
\n
%s<br>
\n
<a href="/kontakt.html">zurück</a>"""
form
=
cgi
.
FieldStorage
()
try
:
email
=
form
[
'email'
].
value
if
not
re
.
match
(
EMAIL_REGEX
,
email
):
raise
ValueError
()
message
=
form
[
'message'
].
value
captcha
=
form
[
'captcha'
].
value
captcha
=
captcha
.
replace
(
"'"
,
""
)
captcha
=
captcha
.
replace
(
'"'
,
""
)
captcha
=
captcha
.
strip
()
today
=
str
(
datetime
.
datetime
.
now
().
day
)
if
today
==
captcha
:
msg
=
MIMEText
(
message
,
'plain'
,
'utf-8'
)
msg
[
'From'
]
=
"kontakt@freifunk-bs.de"
msg
[
'To'
]
=
CONTACT_EMAIL_TO
msg
[
'Subject'
]
=
'Kontaktanfrage von %s'
%
email
msg
[
'Reply-To'
]
=
','
.
join
([
email
,
CONTACT_EMAIL_TO
])
uuid
=
str
(
uuid
.
uuid4
())
#get a random uuid
msg
[
'Message-ID'
]
=
'<'
+
uuid
+
'@freifunk-bs.de>'
p
=
Popen
([
"/usr/sbin/sendmail"
,
"-t"
,
"-oi"
,
"-FKontaktformular"
],
stdin
=
PIPE
)
p
.
communicate
(
msg
.
as_string
())
print
template
%
"Ihre Nachricht wurde entgegengenommen"
else
:
msg
=
MIMEText
(
message
,
'plain'
,
'utf-8'
)
msg
[
'From'
]
=
"kontakt@freifunk-bs.de"
msg
[
'To'
]
=
CONTACT_EMAIL_TO
msg
[
'Subject'
]
=
'[CAPTCHA]Kontaktanfrage von %s'
%
email
msg
[
'Reply-To'
]
=
','
.
join
([
email
,
CONTACT_EMAIL_TO
])
uuid
=
str
(
uuid
.
uuid4
())
#get a random uuid
msg
[
'Message-ID'
]
=
'<'
+
uuid
+
'@freifunk-bs.de>'
msg
[
'X-FFBS-CAPTCHA'
]
=
"Failed: User tried: {}; I expected: {}"
.
format
(
captcha
,
today
)
p
=
Popen
([
"/usr/sbin/sendmail"
,
"-t"
,
"-oi"
,
"-FKontaktformular"
],
stdin
=
PIPE
)
p
.
communicate
(
msg
.
as_string
())
print
template
%
"Der Spamschutz wurde nicht erfolgreich ausgefüllt. Bitte versuchen Sie es erneut."
except
Exception
as
e
:
print
template
%
"Die Anfrage ist ungültig"
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