diff --git a/cgi/contact b/cgi/contact index 118aea8753a50669cda2d097dee1067ca29b3c40..23dbb4a11956b02d669f3472cd9af027d1bcaee3 100755 --- a/cgi/contact +++ b/cgi/contact @@ -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" diff --git a/cgi/contact_cp b/cgi/contact_cp deleted file mode 100755 index 23dbb4a11956b02d669f3472cd9af027d1bcaee3..0000000000000000000000000000000000000000 --- a/cgi/contact_cp +++ /dev/null @@ -1,62 +0,0 @@ -#!/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" - -