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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# own modules
import config, util
import sys, os, re, socket, web
from web import form
from Mailman.Utils import list_exists
urls = (
r'/', 'index',
r'/neu.*', 'new',
r'/new.*', 'new',
r'/help/spam.*', 'spam',
r'/help/unsubscribe\.([a-z]+).*', 'unsubscribe',
)
render = web.template.render('templates/', base='layout');
app = web.application(urls, globals(), autoreload=False)
create_form = form.Form(
form.Textbox('name',
form.notnull,
form.regexp(r'^[a-zA-Z0-9+.-]{2,}$', 'This name should least be two characters long ' +
'and may only consist of letters, digits, plus (+), minus (-), and underlines (_).'),
form.Validator('This name ends with a reserved suffix. Please choose another name.',
util.validate_listname),
form.Validator('A list with this name allready exists. Please choose another name.',
lambda name: list_exists(name) == False),
description = 'Name of your list'),
form.Textbox('email',
form.notnull,
form.regexp(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\b',
'This should be a valid email address.'),
form.regexp(r'.*fu-berlin\.de',
'E-mail address should end with fu-berlin.de'),
description = 'Your E-mail address'),
)
class index:
def GET(self):
running = not os.path.exists('./offline')
return render.index(running)
class spam:
def GET(self):
return render.spam()
class unsubscribe:
def GET(self, lang):
if (lang.startswith('de')):
return render.unsubscribe_de()
else:
return render.unsubscribe_en()
class new:
def validate(self, ip):
for regex in config.invalid_ips:
if re.match(regex, ip):
return False
for regex in config.valid_ips:
if re.match(regex, ip):
return True
return False
def get_user_information(self):
try:
host = socket.gethostbyaddr(web.ctx.ip)[0]
except:
host = web.ctx.ip
return {'ip': web.ctx.ip,
'host': host,
'valid': self.validate(web.ctx.ip)}
def GET(self):
form = create_form()
user = self.get_user_information()
return render.new(form, user)
def POST(self):
form = create_form()
user = self.get_user_information()
if not form.validates():
return render.new(form, user)
else:
listname = form.d.name.lower()
listadmin = form.d.email
(success, progress) = util.create_list(listname, listadmin)
util.notify_admins(listname, listadmin, success, progress)
if success and config.listadmins_list:
(is_member, message) = util.add_to_list(config.listadmins_list, listadmin)
progress += '\n' + message
return render.progress(listname, not success, progress)
if __name__ == "__main__":
if '--debug' in sys.argv:
sys.argv.remove('--debug')
else:
web.config.debug = False
if '--fastcgi' in sys.argv:
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
sys.argv.remove('--fastcgi')
app.run()
|