summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2011-09-28 22:23:20 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2011-09-28 22:28:12 +0200
commita537ee33121b7f43966661c37e13682524820983 (patch)
treebdf3f0408e9686e3ce3ee532973f835a5ef607e8
parent94897110886c6af645260a39c70c244e7e69fce2 (diff)
downloadsites-a537ee33121b7f43966661c37e13682524820983.tar.gz
sites-a537ee33121b7f43966661c37e13682524820983.tar.bz2
sites-a537ee33121b7f43966661c37e13682524820983.zip
added config, externalized util
added external config file (usage from multiple own modules) externalized some functions to seperate module
-rw-r--r--config.py38
-rwxr-xr-xindex.py54
-rw-r--r--util.py12
3 files changed, 68 insertions, 36 deletions
diff --git a/config.py b/config.py
new file mode 100644
index 0000000..a35e3bd
--- /dev/null
+++ b/config.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+import socket, sys
+
+mailman_path = '/usr/lib/mailman'
+sys.path += [mailman_path]
+
+admin_emails = [
+ 'alex@animux.de',
+ #'mailman-newlists@lists.spline.de',
+ ]
+
+valid_ips = [
+ r'^160\.0?45\.',
+ r'^130\.133\.',
+ r'^87\.77\.',
+ r'^2001:6f8:1c3c:67f0:',
+ r'^127\.0\.',
+ ]
+
+invalid_ips = [
+ ]
+
+try:
+ invalid_ips.append(socket.gethostbyname('squid.fu-berlin.de'))
+except:
+ pass
+
+reserved_names = [
+ r'-admin$',
+ r'-join$',
+ r'-leave$',
+ r'-owner$',
+ r'-request$',
+ r'-bounces$',
+ ]
+
+listadmins_list = 'listadmins'
diff --git a/index.py b/index.py
index 38ee86b..b8d1167 100755
--- a/index.py
+++ b/index.py
@@ -1,28 +1,12 @@
#!/usr/bin/env python
+# -*- coding: utf-8 -*-
-import sys, os, re
-from web import template, form, application, ctx, wsgi, config
-from socket import gethostbyaddr, gethostbyname
+# own modules
+import config, util
-sys.path += ['/usr/lib/mailman']
-import Mailman.Utils
-
-valid_ips = [
- r'^160\.0?45\.',
- r'^130\.133\.',
- r'^87\.77\.',
- r'^2001:6f8:1c3c:67f0:',
- ]
-
-reserved_names = [
- r'-admin$',
- r'-join$',
- r'-leave$',
- r'-owner$',
- r'-request$',
- ]
-
-proxy = gethostbyname('squid.fu-berlin.de')
+import sys, os, re, time, socket, subprocess
+from web import template, form, application, ctx, wsgi, config, sendmail
+from Mailman.Utils import list_exists
urls = (
r'/', 'index',
@@ -35,26 +19,23 @@ urls = (
render = template.render('templates/', base='layout');
app = application(urls, globals(), autoreload=False)
-def validate_name(name):
- for regex in reserved_names:
- if re.search(regex, name):
- return False
- return True
-
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.',
- validate_name),
+ util.validate_listname),
form.Validator('A list with this name allready exists. Please choose another name.',
- lambda name: Mailman.Utils.list_exists(name) == False),
+ 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'),
+ 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'),
)
@@ -76,10 +57,11 @@ class unsubscribe:
class new:
def validate(self, ip):
- if ip == proxy:
- return False
+ for regex in config.invalid_ips:
+ if re.match(regex, ip):
+ return False
- for regex in valid_ips:
+ for regex in config.valid_ips:
if re.match(regex, ip):
return True
@@ -87,7 +69,7 @@ class new:
def get_user_information(self):
try:
- host = gethostbyaddr(ctx.ip)[0]
+ host = socket.gethostbyaddr(ctx.ip)[0]
except:
host = ctx.ip
diff --git a/util.py b/util.py
index 7051134..e375aa1 100644
--- a/util.py
+++ b/util.py
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
+import config
+
+import web
from random import Random
rng = Random()
@@ -17,6 +20,15 @@ def generate_char(i, alternate_hands):
else:
return rng.choice(righthand)
+
def generate_password(length = 8, alternate_hands = True):
return ''.join([generate_char(i, alternate_hands) for i in xrange(length)])
+
+def validate_listname(name):
+ for regex in config.reserved_names:
+ if re.search(regex, name):
+ return False
+ return True
+
+