1 # -*- coding: utf-8 -*-
3 # Unix SMB/CIFS implementation.
4 # Copyright © Jelmer Vernooij <jelmer@samba.org> 2008
6 # Implementation of SWAT that uses WSGI
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 def render_placeholder(environ
, start_response
):
23 """Send the user a simple placeholder about missing SWAT."""
25 response_headers
= [('Content-type', 'text/html')]
26 start_response(status
, response_headers
)
28 yield "<!doctype html>\n"
30 yield " <title>The Samba web service</title>\n"
34 yield "<p>Welcome to this Samba web server.</p>\n"
35 yield "<p>This page is a simple placeholder. You probably want to install "
36 yield "SWAT. More information can be found "
37 yield "<a href='http://wiki.samba.org/index.php/SWAT2'>on the wiki</a>.</p>"
43 def __call__(environ
, start_response
):
44 """Handle a HTTP request."""
45 from wsgiref
.util
import application_uri
, shift_path_info
46 from urlparse
import urljoin
50 except ImportError, e
:
51 print "NO SWAT: %r" % e
56 orig_path
= environ
['PATH_INFO']
57 name
= shift_path_info(environ
)
61 start_response('301 Redirect',
62 [('Location', urljoin(application_uri(environ
), 'swat')),])
65 return render_placeholder(environ
, start_response
)
66 elif have_swat
and name
== "swat":
67 return swat
.__call
__(environ
, start_response
)
69 status
= '404 Not found'
70 response_headers
= [('Content-type', 'text/html')]
71 start_response(status
, response_headers
)
72 return ["The path %s (%s) was not found" % (orig_path
, name
)]
75 if __name__
== '__main__':
76 from wsgiref
import simple_server
77 httpd
= simple_server
.make_server('localhost', 8090, __call__
)
78 print "Serving HTTP on port 8090..."