Browse Source

Add cgi-bin & data folder & content; move static content into subfolder meissner-wohnen

T. Meissner 1 month ago
parent
commit
860943a4a7

+ 194
- 0
cgi-bin/meissner-wohnen.py View File

@@ -0,0 +1,194 @@
1
+#!/usr/bin/python
2
+# -*- coding: utf-8 -*-
3
+
4
+
5
+import cgi
6
+import cgitb
7
+import os
8
+from email.mime.text import MIMEText
9
+from subprocess import call
10
+from datetime import datetime
11
+from fnmatch import fnmatch
12
+from string import Template
13
+
14
+
15
+def escapeTags(text):
16
+    text = text.replace('<', '')
17
+    text = text.replace('>', '')
18
+    return text
19
+
20
+
21
+def checkEntries(buchung):
22
+
23
+    mailstring = '*@*'
24
+    datestring = '[0-9][0-9].[0-9][0-9].[0-9][0-9][0-9][0-9]'
25
+    entries = {'name': False, 'sender': False, 'dates': False}
26
+
27
+    if len(buchung['name']) > 0:
28
+        entries['name'] = True
29
+
30
+    if fnmatch(buchung['sender'], mailstring):
31
+        entries['sender'] = True
32
+
33
+    try:
34
+        if (fnmatch(buchung['begin'], datestring) and fnmatch(buchung['end'], datestring) and
35
+            datetime.strptime(buchung['begin'], '%d.%m.%Y') >= datetime.now() and
36
+            datetime.strptime(buchung['end'], '%d.%m.%Y') > datetime.strptime(buchung['begin'], '%d.%m.%Y')):
37
+            entries['dates'] = True
38
+    except ValueError:
39
+        pass
40
+
41
+    return entries
42
+
43
+
44
+class Mail:
45
+
46
+    def __init__(self, buchung, receiver, reply=False):
47
+        self.buchung = buchung
48
+        self.buchung['receiver'] = receiver
49
+        self.reply = reply
50
+
51
+    def genMailFile(self):
52
+        # write email to file
53
+        try:
54
+            self.filename = "../data/email_" + datetime.now().strftime('%d-%m-%Y_%H-%M-%S-%f') + ".txt"
55
+            fp = open(self.filename, 'wb')
56
+            fp.write(self.msg.as_string())
57
+            fp.close()
58
+        except IOError:
59
+            http = HttpResponse(url)
60
+            http.sendError()
61
+            exit()
62
+
63
+    def sendMail(self):
64
+        # send mail on strato powerweb
65
+        call(["mail", self.buchung['receiver']], stdin=open(self.filename))
66
+
67
+    def genMail(self):
68
+        # replace evil html tags
69
+        self.buchung['msg'] = escapeTags(self.buchung['msg'])
70
+        # gen mail text
71
+        if self.reply is True:
72
+            self.text = ("Buchungsanfrage:\n\nName: " + self.buchung['name'] +
73
+                "\nEmail: " + self.buchung['receiver'] + "\nTelefon: " + self.buchung['tel'] +
74
+                "\nAnreise: " + self.buchung['begin'] + "\nAbreise: " + self.buchung['end'] +
75
+                "\nPersonen: " + self.buchung['persons'] + "\n\nNachricht:\n" + self.buchung['msg'])
76
+        else:
77
+            self.text = ("Buchungsanfrage:\n\nName: " + self.buchung['name'] +
78
+                "\nEmail: " + self.buchung['sender'] + "\nTelefon: " + self.buchung['tel'] +
79
+                "\nAnreise: " + self.buchung['begin'] + "\nAbreise: " + self.buchung['end'] +
80
+                "\nPersonen: " + self.buchung['persons'] + "\n\nNachricht:\n" + self.buchung['msg'])
81
+        # gen mail
82
+        self.msg = MIMEText(self.text, 'plain', 'utf-8')
83
+        self.msg['Subject'] = 'Buchungsanfrage von %s' % self.buchung['name']
84
+        self.msg['From'] = self.buchung['sender']
85
+        self.msg['To'] = self.buchung['receiver']
86
+
87
+
88
+class HttpResponse:
89
+
90
+    def __init__(self, url='https://www.meissner-wohnen.de'):
91
+        self.url = url
92
+
93
+    def sendRedirect(self):
94
+        # redirect to buchung.html
95
+        print 'Status: 301'
96
+        print 'Location: https://www.meissner-wohnen.de/%s' % self.url
97
+        print ''
98
+
99
+    def sendError(self):
100
+        print "Content-type: text/html\n"
101
+        print "<p>Uuups, da ist ein Fehler aufgetreten. Bitte zur <a href='https://www.meissner-wohnen.de'>Startseite</a> zurückkehren</p>"
102
+
103
+
104
+def main():
105
+    #cgitb.enable()
106
+
107
+    # some values
108
+    buchung         = {}
109
+    blub            = ["name", "sender", "tel", "begin", "end", "persons", "msg", "reply"]
110
+    template_values = {'name_warning': '', 'email_warning': '', 'date_warning': '', 'name': '', 'email': '', 'tel': '', 'msg': '', 'kopie': ''}
111
+    url             = 'buchung'
112
+    receiver        = 'kontakt@meissner-wohnen.de'
113
+
114
+    # get cgi object
115
+    form = cgi.FieldStorage()
116
+
117
+    # bot detection
118
+    if form.getvalue('email'):
119
+        # logging
120
+        now = datetime.now().strftime('%d.%m.%Y %H:%M:%S')
121
+        f = open("../data/meissner_wohnen.log", "ab")
122
+        f.write(now + " : " + cgi.escape(os.environ["REMOTE_ADDR"]) + " : bot detected\n")
123
+        f.close()
124
+        # gen and send http response
125
+        http = HttpResponse(url + '.html')
126
+        http.sendRedirect()
127
+        exit()
128
+
129
+    # get form values if exist
130
+    for index in range(0, 8):
131
+        if form.getvalue(str(index)):
132
+            buchung[blub[index]] = form.getvalue(str(index))
133
+        else:
134
+            buchung[blub[index]] = ""
135
+
136
+    # check for valid entries
137
+    test = checkEntries(buchung)
138
+
139
+    # generate mails if entries are valid
140
+    if (test['name'] and test['sender'] and test['dates']):
141
+
142
+        msg = Mail(buchung, receiver)
143
+        msg.genMail()
144
+        msg.genMailFile()
145
+        msg.sendMail()
146
+
147
+        if buchung['reply'] == 'true':
148
+            receiver, buchung['sender'] = buchung['sender'], 'kontakt@meissner-wohnen.de'
149
+            msg = Mail(buchung, receiver, True)
150
+            msg.genMail()
151
+            msg.genMailFile()
152
+            msg.sendMail()
153
+
154
+        url = url + '_erfolgreich.html'
155
+
156
+    # generate error site from template if entries are invalid
157
+    else:
158
+
159
+        if not test['name']:
160
+            template_values['name_warning'] = 'warning'
161
+        if not test['sender']:
162
+            template_values['email_warning'] = 'warning'
163
+        if not test['dates']:
164
+            template_values['date_warning'] = 'warning'
165
+
166
+        url = url + '_fehler.html'
167
+
168
+        # read html template
169
+        try:
170
+            f = open("../data/buchung.template", "rb")
171
+            html_template = Template(f.read())
172
+            f.close()
173
+        except IOError:
174
+            http = HttpResponse(url)
175
+            http.sendError()
176
+            exit()
177
+
178
+        # write templated html file
179
+        try:
180
+            f = open('../meissner-wohnen/%s' % url, "wb")
181
+            f.write(html_template.safe_substitute(template_values))
182
+            f.close()
183
+        except IOError:
184
+            http = HttpResponse(url)
185
+            http.sendError()
186
+            exit()
187
+
188
+    # gen and send http response
189
+    http = HttpResponse(url)
190
+    http.sendRedirect()
191
+
192
+
193
+if __name__ == '__main__':
194
+    main()

+ 141
- 0
data/buchung.template View File

@@ -0,0 +1,141 @@
1
+<!DOCTYPE html>
2
+<html>
3
+
4
+<head>
5
+    <title>Willkommen bei Ferienwohnung Mei&szlig;ner - Preise und Buchungsanfrage</title>
6
+    <meta charset="utf-8">
7
+    <meta name="keywords" content="Ferienwohnung, Mei&szlig;ner, Weixdorf, Dresden, &Uuml;bernachten">
8
+    <meta name="description" content="Willkommen bei Ferienwohnung Mei&szlig;ner. Unsere Preise. Au&szlig;erdem k&ouml;nnen Sie eine unverbindliche Buchungsanfrage stellen">
9
+    <meta name="author" content="Torsten Mei&szlig;ner">
10
+    <link rel="stylesheet" href="css/style.css">
11
+</head>
12
+
13
+<body>
14
+
15
+    <div id="wrapper">
16
+
17
+        <div id="header">
18
+            <img src="images/header.jpg" alt="Kirchteich Weixdorf" width="944" height="200">
19
+            <h1>Ferienwohnung Mei&szlig;ner</h1>
20
+        </div>
21
+
22
+        <div id="nav">
23
+            <ul>
24
+                <li><a class="nav-left" href="index.html">Startseite</a></li>
25
+                <li><a href="wohnung.html">Wohnung</a></li>
26
+                <li><a class="active" href="buchung.html">Preis/Anfrage</a></li>
27
+                <li><a href="kontakt.html">Lage/Kontakt</a></li>
28
+                <li><a class="nav-right" href="extras.html">Ausfl&uuml;ge</a></li>
29
+            </ul>
30
+        </div>
31
+
32
+        <div id="content">
33
+            <div id="content-left">
34
+                <h2>Buchungsanfrage</h2>
35
+                <form id="buchung" action="https:www.meissner-wohnen.de/cgi-bin/meissner-wohnen.py" method="post">
36
+                    <fieldset>
37
+                        <legend>Kontaktformular</legend>
38
+                        <ul>
39
+                            <li>
40
+                                <label for="buchung-name" class="$name_warning">Name</label>
41
+                                <input class="textinput" id="buchung-name" name="0" type="text" placeholder="$name" required>
42
+                            </li>
43
+                            <li>
44
+                                <label for="buchung-email" class="$email_warning">Email</label>
45
+                                <input class="textinput" id="buchung-email" name="1" type="email" placeholder="$email" required>
46
+                            </li>
47
+                            <li>
48
+                                <label for="buchung-tel">Telefon</label>
49
+                                <input class="textinput" id="buchung-tel" name="2" type="tel" placeholder="$tel">
50
+                            </li>
51
+                            <li>
52
+                                <label>Personen</label>
53
+                                <ul id="buchung-personen">
54
+                                    <li><label><input type="radio" name="5" value="1" checked>1</label></li>
55
+                                    <li><label><input type="radio" name="5" value="2">2</label></li>
56
+                                    <li><label><input type="radio" name="5" value="3">3</label></li>
57
+                                </ul>
58
+                            </li>
59
+                            <li>
60
+                                <label for="buchung-anreise" class="$date_warning">Von</label>
61
+                                <input class="textinput date" id="buchung-anreise" name="3" type="text" placeholder="TT.MM.JJJJ" required>
62
+                                <label for="buchung-anreise" class="$date_warning">bis</label>
63
+                                <input class="textinput date" id="buchung-abreise" name="4" type="text" placeholder="TT.MM.JJJJ" required>
64
+                            </li>
65
+                            <li>
66
+                                <label for="buchung-nachricht">Nachricht</label>
67
+                                <textarea class="textinput" id="buchung-nachricht" name="6" rows="3" placeholder="$msg"></textarea>
68
+                            </li>
69
+                            <li id="kopie">
70
+                                <label for="buchung-kopie">Kopie erhalten</label>
71
+                                <input type="checkbox" id="buchung-kopie" name="7" value="true" $kopie>
72
+                            </li>
73
+                            <li>
74
+                                <p>Ihre Daten werden verschl&uuml;sselt<br />&uuml;bertragen.</p>
75
+                            </li>
76
+                            <li class="buttons last">
77
+                                <input type="reset" id="buchung-reset" value="Zur&uuml;cksetzen">
78
+                                <input type="submit" id="buchung-absenden" value="Absenden">
79
+                            </li>
80
+                            <li class="hidden">
81
+                                <label for="email">Email</label>
82
+                                <input id="email" name="email" type="text">
83
+                            </li>
84
+                        </ul>
85
+                    </fieldset>
86
+                </form>
87
+                <h3>Per Email</h3>
88
+                <p>
89
+                    Senden Sie eine Email mit Ihrer Buchungsanfrage an unsere Kontaktadresse
90
+                    <a href="mailto:kontakt@meissner-wohnen.de">kontakt@meissner-wohnen.de</a>.
91
+                    Bitte vergessen Sie nicht den Zeitraum und die Zahl der Personen anzugeben.
92
+                </p>
93
+            </div>
94
+            <div id="content-right">
95
+                <h2>Preise</h2>
96
+                <h3>&Uuml;bernachtung</h3>
97
+                <table>
98
+                    <tr>
99
+                        <th>Personen</th>
100
+                        <th>Preis/Nacht</th>
101
+                    </tr>
102
+                    <tr>
103
+                        <td>1-2</td>
104
+                        <td>38€</td>
105
+                    </tr>
106
+                    <tr>
107
+                        <td></td>
108
+                        <td>36€ ab 5 N&auml;chte</td>
109
+                    </tr>
110
+                    <tr>
111
+                        <td></td>
112
+                        <td>34€ ab 14 N&auml;chte</td>
113
+                    </tr>
114
+                    <tr>
115
+                        <td>Dritte Person</td>
116
+                        <td>7€ Zuschlag</td>
117
+                    </tr>
118
+                </table>
119
+                <h3>weitere Leistungen</h3>
120
+                <table>
121
+                    <tr>
122
+                        <td>Endreinigung</td>
123
+                        <td>inkl.</td>
124
+                    </tr>
125
+                </table>
126
+                <h3>
127
+                    <a href="http://www.travanto.de/ferienwohnungen/dresden/1000693/ferienwohnung-meissner.php" title="Ferienwohnung Mei&szlig;ner in Dresden" target="_blank">Profil bei Travanto (mit Belegungsplan)</a>
128
+	         </h3>
129
+            </div>
130
+        </div>
131
+
132
+        <div id="footer">
133
+            <div id="footer-left">&copy; 2020 Ferienwohnung Mei&szlig;ner</div>
134
+            <div id="footer-right"><a href="index.html">Startseite</a><a href="kontakt.html">Kontakt</a><a href="impressum.html">Impressum/Datenschutz</a></div>
135
+        </div>
136
+
137
+    </div>
138
+
139
+</body>
140
+
141
+</html>

buchung.html → meissner-wohnen/buchung.html View File


buchung_erfolgreich.html → meissner-wohnen/buchung_erfolgreich.html View File


buchung_fehler.html → meissner-wohnen/buchung_fehler.html View File


css/style.css → meissner-wohnen/css/style.css View File


datenschutz.html → meissner-wohnen/datenschutz.html View File


extras.html → meissner-wohnen/extras.html View File


images/header.jpg → meissner-wohnen/images/header.jpg View File


images/transparent.png → meissner-wohnen/images/transparent.png View File


images/willkommen.jpg → meissner-wohnen/images/willkommen.jpg View File


images/willkommen_links.jpg → meissner-wohnen/images/willkommen_links.jpg View File


images/willkommen_rechts.jpg → meissner-wohnen/images/willkommen_rechts.jpg View File


images/wohnung1.jpg → meissner-wohnen/images/wohnung1.jpg View File


images/wohnung2.jpg → meissner-wohnen/images/wohnung2.jpg View File


images/wohnung3.jpg → meissner-wohnen/images/wohnung3.jpg View File


images/wohnung4.jpg → meissner-wohnen/images/wohnung4.jpg View File


images/wohnung5.jpg → meissner-wohnen/images/wohnung5.jpg View File


images/wohnung6.jpg → meissner-wohnen/images/wohnung6.jpg View File


images/wohnung7.jpg → meissner-wohnen/images/wohnung7.jpg View File


images/wohnung8.jpg → meissner-wohnen/images/wohnung8.jpg View File


impressum.html → meissner-wohnen/impressum.html View File


index.html → meissner-wohnen/index.html View File


js/meissner-wohnen.js → meissner-wohnen/js/meissner-wohnen.js View File


kontakt.html → meissner-wohnen/kontakt.html View File


wohnung.html → meissner-wohnen/wohnung.html View File