11 from config import config, init_conf
13 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
15 import request_handler
18 class MyHandler(BaseHTTPRequestHandler):
26 length = int(self.headers.getheader('content-length'))
27 ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
28 if ctype != 'application/x-www-form-urlencoded':
29 log.error("request_handler_server: [%s]: 401 Unauthorized" % self.client_address[0])
34 query = self.rfile.read(length)
36 filename = self.headers.getheader('x-filename')
38 if not request_handler.handle_request_main(query, filename = filename):
39 error = log.last_log();
40 log.error("request_handler_server: [%s]: handle_request_main(..., %s) failed" % (self.client_address[0], filename))
41 self.send_error(500, "%s: request failed. %s" % (filename, error))
45 self.send_response(200)
49 self.send_error(500, "%s: %s" % (filename, e))
51 log.error("request_handler_server: [%s]: exception: %s\n%s" % (self.client_address[0], e, traceback.format_exc()))
56 css_file = path.www_dir + "/style.css"
57 # skip if file exists and code is not newer
58 if os.path.exists(css_file) and os.stat(__file__).st_mtime < os.stat(css_file).st_mtime:
61 # css from www.pld-linux.org wiki theme, using css usage firebug plugin to cleanup
64 background-color: white;
66 font-family: Tahoma, Arial, Lucida Grande, sans-serif;
72 text-decoration: underline;
82 border: 1pt solid #FFE2AB;
83 font-family: courier, monospace;
85 white-space: pre-wrap;
86 word-wrap: break-word;
89 @media screen, projection {
91 background-color: #f3efe3;
99 background-color: white;
111 background-color: #ffffcc;
115 background-color: #cff1d0;
120 background-color: inherit;
126 html { line-height: 1.8em; }
127 body, b, a, p { font-size: 22pt; }
130 old_umask = os.umask(0022)
131 f = open(css_file, "w")
138 socket.setdefaulttimeout(30)
142 port = config.request_handler_server_port
145 server = HTTPServer((host, port), MyHandler)
147 log.notice("request_handler_server: can't start server on [%s:%d]: %s" % (host, port, e))
148 print >> sys.stderr, "ERROR: Can't start server on [%s:%d]: %s" % (host, port, e)
151 log.notice('request_handler_server: started on [%s:%d]...' % (host, port))
152 server.serve_forever()
153 except KeyboardInterrupt:
154 log.notice('request_handler_server: ^C received, shutting down server')
155 server.socket.close()
157 if __name__ == '__main__':