summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-11-22 00:47:00 +0000
committerMatthieu Patou <mat@samba.org>2012-11-23 01:39:38 +0100
commit0d9bdcf834cbe9ec4e1354bc7e912f197bf72d7b (patch)
treeec840311bb8b0db3c6c0be29dbb4cc4416ac964b /source4/scripting
parentbfc6a9e21d2955d0662e4179448c7031806ad6d7 (diff)
downloadsamba-0d9bdcf834cbe9ec4e1354bc7e912f197bf72d7b.tar.gz
samba-0d9bdcf834cbe9ec4e1354bc7e912f197bf72d7b.tar.bz2
samba-0d9bdcf834cbe9ec4e1354bc7e912f197bf72d7b.zip
web_server: Load SWAT if it is available.
Reviewed-by: Matthieu Patou <mat@matws.net> Autobuild-User(master): Matthieu Patou <mat@samba.org> Autobuild-Date(master): Fri Nov 23 01:39:38 CET 2012 on sn-devel-104
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/python/samba/web_server/__init__.py34
1 files changed, 31 insertions, 3 deletions
diff --git a/source4/scripting/python/samba/web_server/__init__.py b/source4/scripting/python/samba/web_server/__init__.py
index ed3c7dee69..78ce953c61 100644
--- a/source4/scripting/python/samba/web_server/__init__.py
+++ b/source4/scripting/python/samba/web_server/__init__.py
@@ -19,9 +19,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
-
def render_placeholder(environ, start_response):
+ """Send the user a simple placeholder about missing SWAT."""
status = '200 OK'
response_headers = [('Content-type', 'text/html')]
start_response(status, response_headers)
@@ -41,7 +40,36 @@ def render_placeholder(environ, start_response):
yield "</html>\n"
-__call__ = render_placeholder
+def __call__(environ, start_response):
+ """Handle a HTTP request."""
+ from wsgiref.util import application_uri, shift_path_info
+ from urlparse import urljoin
+
+ try:
+ import swat
+ except ImportError, e:
+ print "NO SWAT: %r" % e
+ have_swat = False
+ else:
+ have_swat = True
+
+ orig_path = environ['PATH_INFO']
+ name = shift_path_info(environ)
+
+ if name == "":
+ if have_swat:
+ start_response('301 Redirect',
+ [('Location', urljoin(application_uri(environ), 'swat')),])
+ return []
+ else:
+ return render_placeholder(environ, start_response)
+ elif have_swat and name == "swat":
+ return swat.__call__(environ, start_response)
+ else:
+ status = '404 Not found'
+ response_headers = [('Content-type', 'text/html')]
+ start_response(status, response_headers)
+ return ["The path %s (%s) was not found" % (orig_path, name)]
if __name__ == '__main__':