-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.cgi
executable file
·46 lines (38 loc) · 1.18 KB
/
index.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
### Switch on the virtualenv
import os, os.path
this_dir = os.path.dirname(os.path.abspath(__file__))
virtualenv_path = os.path.join(this_dir,
'env')
activate_this = os.path.join(virtualenv_path, 'bin', 'activate_this.py')
assert os.path.exists(activate_this)
execfile(activate_this,
dict(__file__=activate_this))
### code for our trivial Flask app
from flask import Flask, request
import pprint
import smtplib
import email.mime.text
app = Flask(__name__)
ME = '[email protected]'
YOU = 'paulproteus@localhost'
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
as_string = pprint.pformat(dict(request.form))
msg = email.mime.text.MIMEText(as_string)
msg['Subject'] = 'Inbound IPN POST'
msg['From'] = ME
msg['To'] = YOU
s = smtplib.SMTP('localhost')
s.sendmail(ME,
[YOU],
msg.as_string())
s.quit()
return "Success."
else:
return "You probably want to POST."
### Actually enable Flask
from wsgiref.handlers import CGIHandler
if __name__ == '__main__':
CGIHandler().run(app)