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: #e4f1cf;
114 background-color: #ffffcc;
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")
137 js_file = path.www_dir + "/script.js"
138 # skip if file exists and code is not newer
139 if os.path.exists(js_file) and os.stat(__file__).st_mtime < os.stat(js_file).st_mtime:
143 // update date stamps to reflect viewers timezone
144 function update_tz(t) {
146 collection = document.getElementsByTagName('span');
147 for (off in collection) {
148 el = collection[off];
150 dt = new Date(el.innerHTML).toString();
151 // strip timezone name, it is usually wrong when not initialized
152 // from TZ env, but reverse calculated from os data
153 dt = dt.replace(/\s+\(.+\)/, "");
155 dt = dt.replace(/GMT/, "");
160 window.onload = update_tz;
162 old_umask = os.umask(0022)
163 f = open(js_file, "w")
171 socket.setdefaulttimeout(30)
175 port = config.request_handler_server_port
178 server = HTTPServer((host, port), MyHandler)
180 log.notice("request_handler_server: can't start server on [%s:%d]: %s" % (host, port, e))
181 print >> sys.stderr, "ERROR: Can't start server on [%s:%d]: %s" % (host, port, e)
184 log.notice('request_handler_server: started on [%s:%d]...' % (host, port))
185 server.serve_forever()
186 except KeyboardInterrupt:
187 log.notice('request_handler_server: ^C received, shutting down server')
188 server.socket.close()
190 if __name__ == '__main__':