def index(req): server = sapi.ModPythonServer(req) cfg = viewvc.load_config(CONF_PATHNAME, server) try: viewvc.main(server, cfg) finally: server.close()
def run_viewvc(self): """Run ViewVC to field a single request.""" ### Much of this is adapter from Python's standard library ### module CGIHTTPServer. # Is this request even aimed at ViewVC? If not, complain. if not self.is_viewvc(): raise NotViewVCLocationException() # If htpasswd authentication is enabled, try to authenticate the user. self.username = None if options.htpasswd_file: authn = self.headers.get('authorization') if not authn: raise AuthenticationException() try: kind, data = authn.split(' ', 1) if kind == 'Basic': data = base64.b64decode(data) username, password = data.split(':', 1) except: raise AuthenticationException() if not self.validate_password(options.htpasswd_file, username, password): raise AuthenticationException() self.username = username # Setup the environment in preparation of executing ViewVC's core code. env = os.environ scriptname = options.script_alias and '/' + options.script_alias or '' viewvc_url = self.server.url[:-1] + scriptname rest = self.path[len(scriptname):] i = rest.rfind('?') if i >= 0: rest, query = rest[:i], rest[i + 1:] else: query = '' # Since we're going to modify the env in the parent, provide empty # values to override previously set values for k in env.keys(): if k[:5] == 'HTTP_': del env[k] for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH', 'HTTP_USER_AGENT', 'HTTP_COOKIE'): if k in env: env[k] = "" # XXX Much of the following could be prepared ahead of time! env['SERVER_SOFTWARE'] = self.version_string() env['SERVER_NAME'] = self.server.server_name env['GATEWAY_INTERFACE'] = 'CGI/1.1' env['SERVER_PROTOCOL'] = self.protocol_version env['SERVER_PORT'] = str(self.server.server_port) env['REQUEST_METHOD'] = self.command uqrest = _unquote(rest) env['PATH_INFO'] = uqrest env['SCRIPT_NAME'] = scriptname if query: env['QUERY_STRING'] = query env['HTTP_HOST'] = self.server.address[0] host = self.address_string() if host != self.client_address[0]: env['REMOTE_HOST'] = host env['REMOTE_ADDR'] = self.client_address[0] if self.username: env['REMOTE_USER'] = self.username env['CONTENT_TYPE'] = self.headers.get_content_type() length = self.headers.get('content-length', None) if length: env['CONTENT_LENGTH'] = length accept = [] for line in self.headers.getallmatchingheaders('accept'): if line[:1] in string.whitespace: accept.append(line.strip()) else: accept = accept + line[7:].split(',') env['HTTP_ACCEPT'] = ','.join(accept) ua = self.headers.get('user-agent', None) if ua: env['HTTP_USER_AGENT'] = ua modified = self.headers.get('if-modified-since', None) if modified: env['HTTP_IF_MODIFIED_SINCE'] = modified etag = self.headers.get('if-none-match', None) if etag: env['HTTP_IF_NONE_MATCH'] = etag # AUTH_TYPE # REMOTE_IDENT # XXX Other HTTP_* headers try: try: viewvc.main(StandaloneServer(self), cfg) finally: if not self.wfile.closed: self.wfile.flush() except SystemExit as status: self.log_error("ViewVC exit status %s", str(status)) else: self.log_error("ViewVC exited ok")
def run_viewvc(self): """This is a quick and dirty cut'n'rape from Python's standard library module CGIHTTPServer.""" scriptname = '/' + options.script_alias assert string.find(self.path, scriptname) == 0 viewvc_url = self.server.url[:-1] + scriptname rest = self.path[len(scriptname):] i = string.rfind(rest, '?') if i >= 0: rest, query = rest[:i], rest[i+1:] else: query = '' # sys.stderr.write("Debug: '"+scriptname+"' '"+rest+"' '"+query+"'\n") env = os.environ # Since we're going to modify the env in the parent, provide empty # values to override previously set values for k in env.keys(): if k[:5] == 'HTTP_': del env[k] for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH', 'HTTP_USER_AGENT', 'HTTP_COOKIE'): if env.has_key(k): env[k] = "" # XXX Much of the following could be prepared ahead of time! env['SERVER_SOFTWARE'] = self.version_string() env['SERVER_NAME'] = self.server.server_name env['GATEWAY_INTERFACE'] = 'CGI/1.1' env['SERVER_PROTOCOL'] = self.protocol_version env['SERVER_PORT'] = str(self.server.server_port) env['REQUEST_METHOD'] = self.command uqrest = urllib.unquote(rest) env['PATH_INFO'] = uqrest env['SCRIPT_NAME'] = scriptname if query: env['QUERY_STRING'] = query env['HTTP_HOST'] = self.server.address[0] host = self.address_string() if host != self.client_address[0]: env['REMOTE_HOST'] = host env['REMOTE_ADDR'] = self.client_address[0] # AUTH_TYPE # REMOTE_USER # REMOTE_IDENT if self.headers.typeheader is None: env['CONTENT_TYPE'] = self.headers.type else: env['CONTENT_TYPE'] = self.headers.typeheader length = self.headers.getheader('content-length') if length: env['CONTENT_LENGTH'] = length accept = [] for line in self.headers.getallmatchingheaders('accept'): if line[:1] in string.whitespace: accept.append(string.strip(line)) else: accept = accept + string.split(line[7:], ',') env['HTTP_ACCEPT'] = string.joinfields(accept, ',') ua = self.headers.getheader('user-agent') if ua: env['HTTP_USER_AGENT'] = ua modified = self.headers.getheader('if-modified-since') if modified: env['HTTP_IF_MODIFIED_SINCE'] = modified etag = self.headers.getheader('if-none-match') if etag: env['HTTP_IF_NONE_MATCH'] = etag # XXX Other HTTP_* headers decoded_query = string.replace(query, '+', ' ') # Preserve state, because we execute script in current process: save_argv = sys.argv save_stdin = sys.stdin save_stdout = sys.stdout save_stderr = sys.stderr # For external tools like enscript we also need to redirect # the real stdout file descriptor. (On windows, reassigning the # sys.stdout variable is sufficient because pipe_cmds makes it # the standard output for child processes.) if sys.platform != "win32": save_realstdout = os.dup(1) try: try: sys.stdout = self.wfile if sys.platform != "win32": os.dup2(self.wfile.fileno(), 1) sys.stdin = self.rfile viewvc.main(StandaloneServer(self), cfg) finally: sys.argv = save_argv sys.stdin = save_stdin sys.stdout.flush() if sys.platform != "win32": os.dup2(save_realstdout, 1) os.close(save_realstdout) sys.stdout = save_stdout sys.stderr = save_stderr except SystemExit, status: self.log_error("ViewVC exit status %s", str(status))
def run_viewvc(self): """Run ViewVC to field a single request.""" ### Much of this is adapter from Python's standard library ### module CGIHTTPServer. # Is this request even aimed at ViewVC? If not, complain. if not self.is_viewvc(): raise NotViewVCLocationException() # If htpasswd authentication is enabled, try to authenticate the user. self.username = None if options.htpasswd_file: authn = self.headers.get('authorization') if not authn: raise AuthenticationException() try: kind, data = authn.split(' ', 1) if kind == 'Basic': data = base64.b64decode(data) username, password = data.split(':', 1) except: raise AuthenticationException() if not self.validate_password(options.htpasswd_file, username, password): raise AuthenticationException() self.username = username # Setup the environment in preparation of executing ViewVC's core code. env = os.environ scriptname = options.script_alias and '/' + options.script_alias or '' viewvc_url = self.server.url[:-1] + scriptname rest = self.path[len(scriptname):] i = rest.rfind('?') if i >= 0: rest, query = rest[:i], rest[i+1:] else: query = '' # Since we're going to modify the env in the parent, provide empty # values to override previously set values for k in env.keys(): if k[:5] == 'HTTP_': del env[k] for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH', 'HTTP_USER_AGENT', 'HTTP_COOKIE'): if env.has_key(k): env[k] = "" # XXX Much of the following could be prepared ahead of time! env['SERVER_SOFTWARE'] = self.version_string() env['SERVER_NAME'] = self.server.server_name env['GATEWAY_INTERFACE'] = 'CGI/1.1' env['SERVER_PROTOCOL'] = self.protocol_version env['SERVER_PORT'] = str(self.server.server_port) env['REQUEST_METHOD'] = self.command uqrest = urllib.unquote(rest) env['PATH_INFO'] = uqrest env['SCRIPT_NAME'] = scriptname if query: env['QUERY_STRING'] = query env['HTTP_HOST'] = self.server.address[0] host = self.address_string() if host != self.client_address[0]: env['REMOTE_HOST'] = host env['REMOTE_ADDR'] = self.client_address[0] if self.username: env['REMOTE_USER'] = self.username if self.headers.typeheader is None: env['CONTENT_TYPE'] = self.headers.type else: env['CONTENT_TYPE'] = self.headers.typeheader length = self.headers.getheader('content-length') if length: env['CONTENT_LENGTH'] = length accept = [] for line in self.headers.getallmatchingheaders('accept'): if line[:1] in string.whitespace: accept.append(line.strip()) else: accept = accept + line[7:].split(',') env['HTTP_ACCEPT'] = ','.join(accept) ua = self.headers.getheader('user-agent') if ua: env['HTTP_USER_AGENT'] = ua modified = self.headers.getheader('if-modified-since') if modified: env['HTTP_IF_MODIFIED_SINCE'] = modified etag = self.headers.getheader('if-none-match') if etag: env['HTTP_IF_NONE_MATCH'] = etag # AUTH_TYPE # REMOTE_IDENT # XXX Other HTTP_* headers # Preserve state, because we execute script in current process: save_argv = sys.argv save_stdin = sys.stdin save_stdout = sys.stdout save_stderr = sys.stderr # For external tools like enscript we also need to redirect # the real stdout file descriptor. # # FIXME: This code used to carry the following comment: # # (On windows, reassigning the sys.stdout variable is sufficient # because pipe_cmds makes it the standard output for child # processes.) # # But we no longer use pipe_cmds. So at the very least, the # comment is stale. Is the code okay, though? if sys.platform != "win32": save_realstdout = os.dup(1) try: try: sys.stdout = self.wfile if sys.platform != "win32": os.dup2(self.wfile.fileno(), 1) sys.stdin = self.rfile viewvc.main(StandaloneServer(self), cfg) finally: sys.argv = save_argv sys.stdin = save_stdin sys.stdout.flush() if sys.platform != "win32": os.dup2(save_realstdout, 1) os.close(save_realstdout) sys.stdout = save_stdout sys.stderr = save_stderr except SystemExit, status: self.log_error("ViewVC exit status %s", str(status))
def run_viewvc(self): """Run ViewVC to field a single request.""" ### Much of this is adapter from Python's standard library ### module CGIHTTPServer. # Is this request even aimed at ViewVC? If not, complain. if not self.is_viewvc(): raise NotViewVCLocationException() # If htpasswd authentication is enabled, try to authenticate the user. self.username = None if options.htpasswd_file: authn = self.headers.get('authorization') if not authn: raise AuthenticationException() try: kind, data = string.split(authn, ' ', 1) if kind == 'Basic': data = base64.b64decode(data) username, password = string.split(data, ':', 1) except: raise AuthenticationException() if not self.validate_password(options.htpasswd_file, username, password): raise AuthenticationException() self.username = username # Setup the environment in preparation of executing ViewVC's core code. env = os.environ scriptname = options.script_alias and '/' + options.script_alias or '' viewvc_url = self.server.url[:-1] + scriptname rest = self.path[len(scriptname):] i = string.rfind(rest, '?') if i >= 0: rest, query = rest[:i], rest[i+1:] else: query = '' # Since we're going to modify the env in the parent, provide empty # values to override previously set values for k in env.keys(): if k[:5] == 'HTTP_': del env[k] for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH', 'HTTP_USER_AGENT', 'HTTP_COOKIE'): if env.has_key(k): env[k] = "" # XXX Much of the following could be prepared ahead of time! env['SERVER_SOFTWARE'] = self.version_string() env['SERVER_NAME'] = self.server.server_name env['GATEWAY_INTERFACE'] = 'CGI/1.1' env['SERVER_PROTOCOL'] = self.protocol_version env['SERVER_PORT'] = str(self.server.server_port) env['REQUEST_METHOD'] = self.command uqrest = urllib.unquote(rest) env['PATH_INFO'] = uqrest env['SCRIPT_NAME'] = scriptname if query: env['QUERY_STRING'] = query env['HTTP_HOST'] = self.server.address[0] host = self.address_string() if host != self.client_address[0]: env['REMOTE_HOST'] = host env['REMOTE_ADDR'] = self.client_address[0] if self.username: env['REMOTE_USER'] = self.username if self.headers.typeheader is None: env['CONTENT_TYPE'] = self.headers.type else: env['CONTENT_TYPE'] = self.headers.typeheader length = self.headers.getheader('content-length') if length: env['CONTENT_LENGTH'] = length accept = [] for line in self.headers.getallmatchingheaders('accept'): if line[:1] in string.whitespace: accept.append(string.strip(line)) else: accept = accept + string.split(line[7:], ',') env['HTTP_ACCEPT'] = string.joinfields(accept, ',') ua = self.headers.getheader('user-agent') if ua: env['HTTP_USER_AGENT'] = ua modified = self.headers.getheader('if-modified-since') if modified: env['HTTP_IF_MODIFIED_SINCE'] = modified etag = self.headers.getheader('if-none-match') if etag: env['HTTP_IF_NONE_MATCH'] = etag # AUTH_TYPE # REMOTE_IDENT # XXX Other HTTP_* headers # Preserve state, because we execute script in current process: save_argv = sys.argv save_stdin = sys.stdin save_stdout = sys.stdout save_stderr = sys.stderr # For external tools like enscript we also need to redirect # the real stdout file descriptor. # # FIXME: This code used to carry the following comment: # # (On windows, reassigning the sys.stdout variable is sufficient # because pipe_cmds makes it the standard output for child # processes.) # # But we no longer use pipe_cmds. So at the very least, the # comment is stale. Is the code okay, though? if sys.platform != "win32": save_realstdout = os.dup(1) try: try: sys.stdout = self.wfile if sys.platform != "win32": os.dup2(self.wfile.fileno(), 1) sys.stdin = self.rfile viewvc.main(StandaloneServer(self), cfg) finally: sys.argv = save_argv sys.stdin = save_stdin sys.stdout.flush() if sys.platform != "win32": os.dup2(save_realstdout, 1) os.close(save_realstdout) sys.stdout = save_stdout sys.stderr = save_stderr except SystemExit, status: self.log_error("ViewVC exit status %s", str(status))
def application(environ, start_response): server = sapi.WsgiServer(environ, start_response) cfg = viewvc.load_config(CONF_PATHNAME, server) viewvc.main(server, cfg) return []
def run_viewvc(self): """This is a quick and dirty cut'n'rape from Python's standard library module CGIHTTPServer.""" scriptname = '/' + options.script_alias assert string.find(self.path, scriptname) == 0 viewvc_url = self.server.url[:-1] + scriptname rest = self.path[len(scriptname):] i = string.rfind(rest, '?') if i >= 0: rest, query = rest[:i], rest[i + 1:] else: query = '' # sys.stderr.write("Debug: '"+scriptname+"' '"+rest+"' '"+query+"'\n") env = os.environ # Since we're going to modify the env in the parent, provide empty # values to override previously set values for k in env.keys(): if k[:5] == 'HTTP_': del env[k] for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH', 'HTTP_USER_AGENT', 'HTTP_COOKIE'): if env.has_key(k): env[k] = "" # XXX Much of the following could be prepared ahead of time! env['SERVER_SOFTWARE'] = self.version_string() env['SERVER_NAME'] = self.server.server_name env['GATEWAY_INTERFACE'] = 'CGI/1.1' env['SERVER_PROTOCOL'] = self.protocol_version env['SERVER_PORT'] = str(self.server.server_port) env['REQUEST_METHOD'] = self.command uqrest = urllib.unquote(rest) env['PATH_INFO'] = uqrest env['SCRIPT_NAME'] = scriptname if query: env['QUERY_STRING'] = query env['HTTP_HOST'] = self.server.address[0] host = self.address_string() if host != self.client_address[0]: env['REMOTE_HOST'] = host env['REMOTE_ADDR'] = self.client_address[0] # AUTH_TYPE # REMOTE_USER # REMOTE_IDENT if self.headers.typeheader is None: env['CONTENT_TYPE'] = self.headers.type else: env['CONTENT_TYPE'] = self.headers.typeheader length = self.headers.getheader('content-length') if length: env['CONTENT_LENGTH'] = length accept = [] for line in self.headers.getallmatchingheaders('accept'): if line[:1] in string.whitespace: accept.append(string.strip(line)) else: accept = accept + string.split(line[7:], ',') env['HTTP_ACCEPT'] = string.joinfields(accept, ',') ua = self.headers.getheader('user-agent') if ua: env['HTTP_USER_AGENT'] = ua modified = self.headers.getheader('if-modified-since') if modified: env['HTTP_IF_MODIFIED_SINCE'] = modified etag = self.headers.getheader('if-none-match') if etag: env['HTTP_IF_NONE_MATCH'] = etag # XXX Other HTTP_* headers decoded_query = string.replace(query, '+', ' ') # Preserve state, because we execute script in current process: save_argv = sys.argv save_stdin = sys.stdin save_stdout = sys.stdout save_stderr = sys.stderr # For external tools like enscript we also need to redirect # the real stdout file descriptor. (On windows, reassigning the # sys.stdout variable is sufficient because pipe_cmds makes it # the standard output for child processes.) if sys.platform != "win32": save_realstdout = os.dup(1) try: try: sys.stdout = self.wfile if sys.platform != "win32": os.dup2(self.wfile.fileno(), 1) sys.stdin = self.rfile viewvc.main(StandaloneServer(self), cfg) finally: sys.argv = save_argv sys.stdin = save_stdin sys.stdout.flush() if sys.platform != "win32": os.dup2(save_realstdout, 1) os.close(save_realstdout) sys.stdout = save_stdout sys.stderr = save_stderr except SystemExit, status: self.log_error("ViewVC exit status %s", str(status))