2 # Copyright 2008, Google Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 This is intended to be used for testing, and
35 only run from within the
36 googleclient/native_client
46 CGIHTTPServer
.cgi_directory
= [] # no CGIs!
49 # We only run from the native_client directory, so that not too much
50 # is exposed via this HTTP server. Everything in the directory is
51 # served, so there should never be anything potentially sensitive in
52 # the serving directory, especially if the machine might be a
53 # multi-user machine and not all users are trusted. We only serve via
54 # the loopback interface.
56 SAFE_DIR_COMPONENTS
= ['googleclient', 'native_client']
57 SAFE_DIR_SUFFIX
= apply(os
.path
.join
, SAFE_DIR_COMPONENTS
)
60 def SanityCheckDirectory():
61 if os
.getcwd().endswith(SAFE_DIR_SUFFIX
):
64 print >>sys
.stderr
, 'httpd.py should only be run from the'
65 print >>sys
.stderr
, SAFE_DIR_SUFFIX
66 print >>sys
.stderr
, 'directory for testing purposes.'
67 print >>sys
.stderr
, 'We are currently in %s' % os
.getcwd()
72 def Run(server_port
=5103,
73 server_class
=BaseHTTPServer
.HTTPServer
,
74 handler_class
=CGIHTTPServer
.CGIHTTPRequestHandler
):
75 # Using 'localhost' means that we only accept connections
76 # via the loop back interface.
77 server_address
= ('localhost', server_port
)
78 httpd
= server_class(server_address
, handler_class
)
83 if __name__
== '__main__':
84 SanityCheckDirectory()
86 Run(server_port
=int(sys
.argv
[1]))