def get_session_id(cls, communicator): if cls.debug: return 1 headers = parse_request_headers(communicator) cookies = request_headers_get_cookies(headers) if Config.ulteo_session_cookie in cookies: sess_id = cookies[Config.ulteo_session_cookie].strip('"') return sess_id
def __process__(self, context, post_processors): try: next_handler = self.options['bindings']['next_handler'] for condition in self.options['bindings']: if condition == 'next_handler': continue locals_dict = {'request_path': context.requested_path, 'request_headers': parse_request_headers(context.communicator),} exec('result = ' + self.options['bindings'][condition]['cond'], {}, locals_dict) if locals_dict['result']: next_handler = self.options['bindings'][condition]['next_handler'] break except KeyError, e: Logger.error('Key %s was not found. Correct your configuration file.' % e) return ''
def tunnel_request(self, context, post_processors): communicator, session, path = context.communicator, context.session, context.requested_path Logger.debug("------------------- tunneling request") target = self.config['target'] if target.scheme == 'https' and self.config.get( 'check_ssl_certificates', False): if not self.check_ssl_certs(): self.display_err_page(Config.invalid_cert_page, communicator) self.close_connection(None, communicator) return if 'ntlm_auth' in context.options: conn = CurlConnection(target.scheme, target.netloc, auth=context.options['ntlm_auth']) else: if target.scheme == 'https': conn = httplib.HTTPSConnection( target.netloc, timeout=Config.connection_timeout) else: conn = httplib.HTTPConnection( target.netloc, timeout=Config.connection_timeout) method = communicator.http.http_req_ptn.match( communicator.http.headers).group(1) req_headers = parse_request_headers(communicator) req_headers['Host'] = target.netloc # override accept-encoding headers, because we couldn't handle gzip'ed data if 'Accept-Encoding' in req_headers: req_headers['Accept-Encoding'] = 'deflate' Logger.debug("Requesting path: " + path) conn.request(method, path, communicator.http.body, req_headers) try: response = conn.getresponse() except (timeout, ssl.SSLError), exc: if isinstance(exc, ssl.SSLError) and not (exc.args and 'timed out' in exc.args[0]): #TODO: handling other exceptions; same as below Logger.error("Error getting requested site: %s" % exc) return self.display_err_page(Config.timeout_page, communicator) self.close_connection(conn, communicator) return
def __process__(self, context, post_processors): try: next_handler = self.options['bindings']['next_handler'] for condition in self.options['bindings']: if condition == 'next_handler': continue locals_dict = { 'request_path': context.requested_path, 'request_headers': parse_request_headers(context.communicator), } exec('result = ' + self.options['bindings'][condition]['cond'], {}, locals_dict) if locals_dict['result']: next_handler = self.options['bindings'][condition][ 'next_handler'] break except KeyError, e: Logger.error( 'Key %s was not found. Correct your configuration file.' % e) return ''
def pre_process(self, context): """ Get auth_cookies and cookies form session and inject to request headers. """ Logger.debug("CookieFilter pre_process") session = context.session headers = context.communicator.http.headers.split('\r\n')[:-1] cookies = '' if session.get('auth_cookies'): for cookie in session['auth_cookies'].values(): cookie_match = COOKIE_RE.search(cookie) cookies += cookie_match.group(1) + '=' + cookie_match.group( 2) + '; ' if session.get('cookies'): for name, value in session['cookies'].items(): cookies += name + '=' + value + '; ' if cookies: Logger.debug("Injecting following cookies: " + cookies) req_headers = parse_request_headers(context.communicator) if 'Cookie' in req_headers: req_cookies = request_headers_get_cookies(req_headers) modified = bool(cookies) for name, value in req_cookies.items(): if name in self.options['suppressed']: modified = True Logger.debug("Suppressing cookies: " + name) else: cookies += name + '=' + value + '; ' if modified: for header in headers: if header.startswith('Cookie: '): newheader = 'Cookie: ' + cookies headers[headers.index(header)] = newheader elif cookies: headers.append('Cookie: ' + cookies) context.communicator.http.headers = '\r\n'.join(headers)
def pre_process(self, context): """ Get auth_cookies and cookies form session and inject to request headers. """ Logger.debug("CookieFilter pre_process") session = context.session headers = context.communicator.http.headers.split('\r\n')[:-1] cookies = '' if session.get('auth_cookies'): for cookie in session['auth_cookies'].values(): cookie_match = COOKIE_RE.search(cookie) cookies += cookie_match.group(1) + '=' + cookie_match.group(2) + '; ' if session.get('cookies'): for name, value in session['cookies'].items(): cookies += name + '=' + value + '; ' if cookies: Logger.debug("Injecting following cookies: " + cookies) req_headers = parse_request_headers(context.communicator) if 'Cookie' in req_headers: req_cookies = request_headers_get_cookies(req_headers) modified = bool(cookies) for name, value in req_cookies.items(): if name in self.options['suppressed']: modified = True Logger.debug("Suppressing cookies: " + name) else: cookies += name + '=' + value + '; ' if modified: for header in headers: if header.startswith('Cookie: '): newheader = 'Cookie: ' + cookies headers[headers.index(header)] = newheader elif cookies: headers.append('Cookie: ' + cookies) context.communicator.http.headers = '\r\n'.join(headers)
def tunnel_request(self, context, post_processors): communicator, session, path = context.communicator, context.session, context.requested_path Logger.debug("------------------- tunneling request") target = self.config['target'] if target.scheme == 'https' and self.config.get('check_ssl_certificates', False): if not self.check_ssl_certs(): self.display_err_page(Config.invalid_cert_page, communicator) self.close_connection(None, communicator) return if 'ntlm_auth' in context.options: conn = CurlConnection(target.scheme, target.netloc, auth=context.options['ntlm_auth']) else: if target.scheme == 'https': conn = httplib.HTTPSConnection(target.netloc, timeout=Config.connection_timeout) else: conn = httplib.HTTPConnection(target.netloc, timeout=Config.connection_timeout) method = communicator.http.http_req_ptn.match(communicator.http.headers).group(1) req_headers = parse_request_headers(communicator) req_headers['Host'] = target.netloc # override accept-encoding headers, because we couldn't handle gzip'ed data if 'Accept-Encoding' in req_headers: req_headers['Accept-Encoding'] = 'deflate' Logger.debug("Requesting path: " + path) conn.request(method, path, communicator.http.body, req_headers) try: response = conn.getresponse() except (timeout, ssl.SSLError), exc: if isinstance(exc, ssl.SSLError) and not (exc.args and 'timed out' in exc.args[0]): #TODO: handling other exceptions; same as below Logger.error("Error getting requested site: %s" % exc) return self.display_err_page(Config.timeout_page, communicator) self.close_connection(conn, communicator) return