summaryrefslogtreecommitdiffstats
path: root/lite-server.py
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2010-08-25 13:06:15 -0400
committerAdam Young <ayoung@redhat.com>2010-08-25 13:06:15 -0400
commit005cc2d365de0e2c23b0a906c74d2b9536a94c47 (patch)
treed5650242f8c437dc4f80da6833763b011af42c55 /lite-server.py
parentead85f2866b65343ea4fcf5ff4db8d16bfb15119 (diff)
downloadfreeipa-005cc2d365de0e2c23b0a906c74d2b9536a94c47.zip
freeipa-005cc2d365de0e2c23b0a906c74d2b9536a94c47.tar.gz
freeipa-005cc2d365de0e2c23b0a906c74d2b9536a94c47.tar.xz
Add webUI application to lite-server.
Diffstat (limited to 'lite-server.py')
-rwxr-xr-xlite-server.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/lite-server.py b/lite-server.py
index de45c29..2a83dae 100755
--- a/lite-server.py
+++ b/lite-server.py
@@ -31,7 +31,7 @@ Unfortunately, SSL support is broken under Python 2.6 with paste 1.7.2, see:
http://trac.pythonpaste.org/pythonpaste/ticket/314
"""
-from os import path
+from os import path, getcwd
import optparse
from paste import httpserver
import paste.gzipper
@@ -50,6 +50,46 @@ class KRBCheater(object):
return self.app(environ, start_response)
+class WebUIApp(object):
+ INDEX_FILE = 'index.xhtml'
+ EXTENSION_TO_MIME_MAP = {
+ 'xhtml': 'text/html',
+ 'html': 'text/html',
+ 'js': 'text/javascript',
+ 'inc': 'text/html',
+ 'css': 'text/css',
+ 'png': 'image/png',
+ 'json': 'text/javascript',
+ }
+
+ def __init__(self):
+ self.url = '/ipa/ui'
+
+ def __call__(self, environ, start_response):
+ path_info = environ['PATH_INFO'].lstrip('/')
+ if path_info == '':
+ path_info = self.INDEX_FILE
+ requested_file = path.join(getcwd(), 'install/static/', path_info)
+ extension = requested_file.rsplit('.', 1)[-1]
+
+ if extension not in self.EXTENSION_TO_MIME_MAP:
+ start_response('404 Not Found', [('Content-Type', 'text/plain')])
+ return ['NOT FOUND']
+ mime_type = self.EXTENSION_TO_MIME_MAP[extension]
+
+ f = None
+ try:
+ f = open(requested_file, 'r')
+ start_response('200 OK', [('Content-Type', mime_type)])
+ return [f.read()]
+ except IOError:
+ start_response('404 Not Found', [('Content-Type', 'text/plain')])
+ return ['NOT FOUND']
+ finally:
+ if f is not None:
+ f.close()
+
+
if __name__ == '__main__':
parser = optparse.OptionParser()
@@ -83,6 +123,7 @@ if __name__ == '__main__':
urlmap = URLMap()
apps = [
('IPA', KRBCheater(api.Backend.session)),
+ ('webUI', KRBCheater(WebUIApp())),
]
for (name, app) in apps:
urlmap[app.url] = app