Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
ffbs-website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ffbs
ffbs-website
Commits
be5b901c
Commit
be5b901c
authored
6 years ago
by
chrissi^
Browse files
Options
Downloads
Patches
Plain Diff
gci: Activate Contact with CAPTCHA
Signed-off-by:
Chris Fiege
<
chris@tinyhost.de
>
parent
ae6e1495
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cgi/contact
+31
-10
31 additions, 10 deletions
cgi/contact
cgi/contact_cp
+0
-62
0 additions, 62 deletions
cgi/contact_cp
with
31 additions
and
72 deletions
cgi/contact
+
31
−
10
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
"
...
...
This diff is collapsed.
Click to expand it.
cgi/contact_cp
deleted
100755 → 0
+
0
−
62
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
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment