summaryrefslogtreecommitdiff
path: root/fbin.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-07-29 17:09:03 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-07-29 17:09:03 +0200
commit0e936a1e55d0168b8d4af5e396bc8a22c7d260e2 (patch)
tree1215aa6e389fbcaac2320b29fd53d2db23c28a30 /fbin.py
parent5aa1666cbe5482af7b79d0ee635423500b2fdc88 (diff)
Added support for configurable virtual root.
Diffstat (limited to 'fbin.py')
-rwxr-xr-xfbin.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/fbin.py b/fbin.py
index b7450f1..bae6434 100755
--- a/fbin.py
+++ b/fbin.py
@@ -154,7 +154,7 @@ class Application(object):
form = cgi.FieldStorage(fp = environ['wsgi.input'], environ = environ)
if environ['REQUEST_METHOD'] != 'POST' or not 'file' in form or not 'filename' in form:
start_response('200 OK', [('Content-Type', 'text/html')])
- return str(templates.upload(searchList = {'user': user}))
+ return str(templates.upload(searchList = {'root': settings.virtual_root, 'user': user}))
filename = form.getvalue('filename')
@@ -185,6 +185,7 @@ class Application(object):
else:
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.uploaded(searchList = {
+ 'root': settings.virtual_root,
'user': user,
'hash': hash,
'filename': filename,
@@ -200,6 +201,7 @@ class Application(object):
if environ['REQUEST_METHOD'] != 'POST' or not 'username' in form or not 'password' in form:
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.login(searchList = {
+ 'root': settings.virtual_root,
'user': user,
'error': None,
}))
@@ -212,6 +214,7 @@ class Application(object):
if user == None:
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.login(searchList = {
+ 'root': settings.virtual_root,
'user': user,
'error': 'Login failed',
}))
@@ -225,7 +228,10 @@ class Application(object):
c['uid']['expires'] = expires
c['identifier']['expires'] = expires
- start_response('302 Found', [('Location', '/u'), ('Set-Cookie', c['uid'].OutputString()), ('Set-Cookie', c['identifier'].OutputString())])
+ start_response('302 Found', [
+ ('Location', settings.virtual_root + 'u'),
+ ('Set-Cookie', c['uid'].OutputString()),
+ ('Set-Cookie', c['identifier'].OutputString())])
return []
def register(self, environ, start_response, path):
@@ -235,6 +241,7 @@ class Application(object):
if environ['REQUEST_METHOD'] != 'POST' or not 'username' in form or not 'password' in form or not 'password2' in form:
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.register(searchList = {
+ 'root': settings.virtual_root,
'user': user,
'error': None,
}))
@@ -245,6 +252,7 @@ class Application(object):
if password != password2:
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.register(searchList = {
+ 'root': settings.virtual_root,
'user': user,
'error': 'Passwords doesn\'t match',
}))
@@ -253,11 +261,12 @@ class Application(object):
if not user:
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.register(searchList = {
+ 'root': settings.virtual_root,
'user': None,
'error': 'Username already taken.',
}))
- start_response('302 Found', [('Location', '/l')])
+ start_response('302 Found', [('Location', settings.virtual_root + 'l')])
return []
def logout(self, environ, start_response, path):
@@ -267,7 +276,10 @@ class Application(object):
c['uid']['expires'] = expires
c['identifier'] = ''
c['identifier']['expires'] = expires
- start_response('302 Found', [('Set-Cookie', c['uid'].OutputString()), ('Set-Cookie', c['identifier'].OutputString()), ('Location', '/')])
+ start_response('302 Found', [
+ ('Set-Cookie', c['uid'].OutputString()),
+ ('Set-Cookie', c['identifier'].OutputString()),
+ ('Location', settings.virtual_root)])
return []
def static(self, environ, start_response, path):
@@ -285,6 +297,7 @@ class Application(object):
user = self.validate_cookie(c)
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.help(searchList = {
+ 'root': settings.virtual_root,
'user': user,
'scheme': environ['wsgi.url_scheme'],
'host': environ['HTTP_HOST'],
@@ -299,6 +312,7 @@ class Application(object):
files = self.get_files(user)
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.my(searchList = {
+ 'root': settings.virtual_root,
'user': user,
'files': files,
}))
@@ -312,6 +326,7 @@ class Application(object):
files = [f for f in self.get_files(user) if f.is_image()]
start_response('200 OK', [('Content-Type', 'text/html')])
return str(templates.images(searchList = {
+ 'root': settings.virtual_root,
'user': user,
'files': files,
}))
@@ -346,16 +361,21 @@ class Application(object):
def __call__(self, environ, start_response):
path = environ['PATH_INFO'].split('/')[1:]
- module = path[0]
+ module = path[0] if len(path) else ''
if len(module) and module in 'fulshmitor':
return getattr(self, module)(environ, start_response, path)
else:
- start_response('302 Found', [('Location', '/u')])
+ start_response('302 Found', [('Location', settings.virtual_root + 'u')])
return []
if __name__ == '__main__':
- from wsgiref.simple_server import make_server, WSGIServer
- # enable IPv6
- WSGIServer.address_family |= 10
- http = make_server('', 8000, Application())
- http.serve_forever()
+ import sys
+ if len(sys.argv) == 3:
+ from flup.server.fcgi import WSGIServer
+ WSGIServer(Application(), bindAddress = (sys.argv[1], int(sys.argv[2]))).run()
+ else:
+ from wsgiref.simple_server import make_server, WSGIServer
+ # enable IPv6
+ WSGIServer.address_family |= 10
+ http = make_server('', 8000, Application())
+ http.serve_forever()