def cgi_main(config: SectionProxy) -> None: """Run REDbot as a CGI Script.""" def out(inbytes: bytes) -> None: try: sys.stdout.buffer.write(inbytes) sys.stdout.flush() except IOError: pass config['ui_uri'] = "%s://%s%s%s" % ('HTTPS' in os.environ and "https" or "http", os.environ.get('HTTP_HOST'), os.environ.get('SCRIPT_NAME'), os.environ.get('PATH_INFO', '')) method = os.environ.get('REQUEST_METHOD').encode(config['charset']) query_string = os.environ.get('QUERY_STRING', "").encode(config['charset']) def response_start(code: bytes, phrase: bytes, res_hdrs: RawHeaderListType) -> None: out_v = [b"Status: %s %s" % (code, phrase)] for name, value in res_hdrs: out_v.append(b"%s: %s" % (name, value)) out_v.append(b"") out_v.append(b"") out(b"\n".join(out_v)) freak_ceiling = 20000 def response_body(chunk: bytes) -> None: rest = None if len(chunk) > freak_ceiling: rest = chunk[freak_ceiling:] chunk = chunk[:freak_ceiling] out(chunk) if rest: response_body(rest) def response_done(trailers: RawHeaderListType) -> None: thor.schedule(0, thor.stop) try: RedWebUi(config, method.decode(config['charset']), query_string, response_start, response_body, response_done) thor.run() except Exception: except_handler_factory(config, qs=query_string.decode(config['charset']))()
def cgi_main(): """Run REDbot as a CGI Script.""" def out(inbytes): try: sys.stdout.buffer.write(inbytes) sys.stdout.flush() except IOError: pass ui_uri = "%s://%s%s%s" % ('HTTPS' in os.environ and "https" or "http", os.environ.get('HTTP_HOST'), os.environ.get('SCRIPT_NAME'), os.environ.get('PATH_INFO', '')) method = os.environ.get('REQUEST_METHOD').encode(Config.charset) query_string = os.environ.get('QUERY_STRING', "").encode(Config.charset) def response_start(code, phrase, res_hdrs): out_v = [b"Status: %s %s" % (code, phrase)] for k, v in res_hdrs: out_v.append(b"%s: %s" % (k, v)) out_v.append(b"") out_v.append(b"") out(b"\n".join(out_v)) freak_ceiling = 20000 def response_body(chunk): rest = None if len(chunk) > freak_ceiling: rest = chunk[freak_ceiling:] chunk = chunk[:freak_ceiling] out(chunk) if rest: response_body(rest) def response_done(trailers): thor.schedule(0, thor.stop) try: RedWebUi(Config, ui_uri, method, query_string, response_start, response_body, response_done) thor.run() except: except_handler_factory(Config, qs=query_string)()
def cgi_main(config: SectionProxy) -> None: """Run REDbot as a CGI Script.""" def out(inbytes: bytes) -> None: try: sys.stdout.buffer.write(inbytes) sys.stdout.flush() except IOError: pass config['ui_uri'] = "%s://%s%s%s" % ( 'HTTPS' in os.environ and "https" or "http", os.environ.get('HTTP_HOST'), os.environ.get('SCRIPT_NAME'), os.environ.get('PATH_INFO', '')) method = os.environ.get('REQUEST_METHOD').encode(config['charset']) query_string = os.environ.get('QUERY_STRING', "").encode(config['charset']) def response_start(code: bytes, phrase: bytes, res_hdrs: RawHeaderListType) -> None: out_v = [b"Status: %s %s" % (code, phrase)] for name, value in res_hdrs: out_v.append(b"%s: %s" % (name, value)) out_v.append(b"") out_v.append(b"") out(b"\n".join(out_v)) freak_ceiling = 20000 def response_body(chunk: bytes) -> None: rest = None if len(chunk) > freak_ceiling: rest = chunk[freak_ceiling:] chunk = chunk[:freak_ceiling] out(chunk) if rest: response_body(rest) def response_done(trailers: RawHeaderListType) -> None: thor.schedule(0, thor.stop) try: RedWebUi(config, method.decode(config['charset']), query_string, response_start, response_body, response_done) thor.run() except Exception: except_handler_factory(config, qs=query_string.decode(config['charset']))()
def cgi_main(): """Run REDbot as a CGI Script.""" def out(inbytes): try: sys.stdout.buffer.write(inbytes) sys.stdout.flush() except IOError: pass ui_uri = "%s://%s%s%s" % ( 'HTTPS' in os.environ and "https" or "http", os.environ.get('HTTP_HOST'), os.environ.get('SCRIPT_NAME'), os.environ.get('PATH_INFO', '')) method = os.environ.get('REQUEST_METHOD').encode(Config.charset) query_string = os.environ.get('QUERY_STRING', "").encode(Config.charset) def response_start(code, phrase, res_hdrs): out_v = [b"Status: %s %s" % (code, phrase)] for k, v in res_hdrs: out_v.append(b"%s: %s" % (k, v)) out_v.append(b"") out_v.append(b"") out(b"\n".join(out_v)) freak_ceiling = 20000 def response_body(chunk): rest = None if len(chunk) > freak_ceiling: rest = chunk[freak_ceiling:] chunk = chunk[:freak_ceiling] out(chunk) if rest: response_body(rest) def response_done(trailers): thor.schedule(0, thor.stop) try: RedWebUi(Config, ui_uri, method, query_string, response_start, response_body, response_done) thor.run() except: except_handler_factory(Config, qs=query_string)()
def mod_python_handler(r): """Run REDbot as a mod_python handler.""" from mod_python import apache status_lookup = { 100: apache.HTTP_CONTINUE, 101: apache.HTTP_SWITCHING_PROTOCOLS, 102: apache.HTTP_PROCESSING, 200: apache.HTTP_OK, 201: apache.HTTP_CREATED, 202: apache.HTTP_ACCEPTED, 203: apache.HTTP_NON_AUTHORITATIVE, 204: apache.HTTP_NO_CONTENT, 205: apache.HTTP_RESET_CONTENT, 206: apache.HTTP_PARTIAL_CONTENT, 207: apache.HTTP_MULTI_STATUS, 300: apache.HTTP_MULTIPLE_CHOICES, 301: apache.HTTP_MOVED_PERMANENTLY, 302: apache.HTTP_MOVED_TEMPORARILY, 303: apache.HTTP_SEE_OTHER, 304: apache.HTTP_NOT_MODIFIED, 305: apache.HTTP_USE_PROXY, 307: apache.HTTP_TEMPORARY_REDIRECT, 308: apache.HTTP_PERMANENT_REDIRECT, 400: apache.HTTP_BAD_REQUEST, 401: apache.HTTP_UNAUTHORIZED, 402: apache.HTTP_PAYMENT_REQUIRED, 403: apache.HTTP_FORBIDDEN, 404: apache.HTTP_NOT_FOUND, 405: apache.HTTP_METHOD_NOT_ALLOWED, 406: apache.HTTP_NOT_ACCEPTABLE, 407: apache.HTTP_PROXY_AUTHENTICATION_REQUIRED, 408: apache.HTTP_REQUEST_TIME_OUT, 409: apache.HTTP_CONFLICT, 410: apache.HTTP_GONE, 411: apache.HTTP_LENGTH_REQUIRED, 412: apache.HTTP_PRECONDITION_FAILED, 413: apache.HTTP_REQUEST_ENTITY_TOO_LARGE, 414: apache.HTTP_REQUEST_URI_TOO_LARGE, 415: apache.HTTP_UNSUPPORTED_MEDIA_TYPE, 416: apache.HTTP_RANGE_NOT_SATISFIABLE, 417: apache.HTTP_EXPECTATION_FAILED, 422: apache.HTTP_UNPROCESSABLE_ENTITY, 423: apache.HTTP_LOCKED, 424: apache.HTTP_FAILED_DEPENDENCY, 426: apache.HTTP_UPGRADE_REQUIRED, 500: apache.HTTP_INTERNAL_SERVER_ERROR, 501: apache.HTTP_NOT_IMPLEMENTED, 502: apache.HTTP_BAD_GATEWAY, 503: apache.HTTP_SERVICE_UNAVAILABLE, 504: apache.HTTP_GATEWAY_TIME_OUT, 505: apache.HTTP_VERSION_NOT_SUPPORTED, 506: apache.HTTP_VARIANT_ALSO_VARIES, 507: apache.HTTP_INSUFFICIENT_STORAGE, 510: apache.HTTP_NOT_EXTENDED} r.content_type = "text/html" def response_start(code, phrase, hdrs): r.status = status_lookup.get(int(code), apache.HTTP_INTERNAL_SERVER_ERROR) for hdr in hdrs: r.headers_out[hdr[0]] = hdr[1] def response_done(trailers): thor.schedule(0, thor.stop) try: RedWebUi(Config, r.unparsed_uri, r.method, r.args or "", response_start, r.write, response_done) thor.run() except: except_handler_factory(Config, r.write, qs=r.args)() return apache.OK
def mod_python_handler(r): """Run REDbot as a mod_python handler.""" from mod_python import apache status_lookup = { 100: apache.HTTP_CONTINUE, 101: apache.HTTP_SWITCHING_PROTOCOLS, 102: apache.HTTP_PROCESSING, 200: apache.HTTP_OK, 201: apache.HTTP_CREATED, 202: apache.HTTP_ACCEPTED, 203: apache.HTTP_NON_AUTHORITATIVE, 204: apache.HTTP_NO_CONTENT, 205: apache.HTTP_RESET_CONTENT, 206: apache.HTTP_PARTIAL_CONTENT, 207: apache.HTTP_MULTI_STATUS, 300: apache.HTTP_MULTIPLE_CHOICES, 301: apache.HTTP_MOVED_PERMANENTLY, 302: apache.HTTP_MOVED_TEMPORARILY, 303: apache.HTTP_SEE_OTHER, 304: apache.HTTP_NOT_MODIFIED, 305: apache.HTTP_USE_PROXY, 307: apache.HTTP_TEMPORARY_REDIRECT, 308: apache.HTTP_PERMANENT_REDIRECT, 400: apache.HTTP_BAD_REQUEST, 401: apache.HTTP_UNAUTHORIZED, 402: apache.HTTP_PAYMENT_REQUIRED, 403: apache.HTTP_FORBIDDEN, 404: apache.HTTP_NOT_FOUND, 405: apache.HTTP_METHOD_NOT_ALLOWED, 406: apache.HTTP_NOT_ACCEPTABLE, 407: apache.HTTP_PROXY_AUTHENTICATION_REQUIRED, 408: apache.HTTP_REQUEST_TIME_OUT, 409: apache.HTTP_CONFLICT, 410: apache.HTTP_GONE, 411: apache.HTTP_LENGTH_REQUIRED, 412: apache.HTTP_PRECONDITION_FAILED, 413: apache.HTTP_REQUEST_ENTITY_TOO_LARGE, 414: apache.HTTP_REQUEST_URI_TOO_LARGE, 415: apache.HTTP_UNSUPPORTED_MEDIA_TYPE, 416: apache.HTTP_RANGE_NOT_SATISFIABLE, 417: apache.HTTP_EXPECTATION_FAILED, 422: apache.HTTP_UNPROCESSABLE_ENTITY, 423: apache.HTTP_LOCKED, 424: apache.HTTP_FAILED_DEPENDENCY, 426: apache.HTTP_UPGRADE_REQUIRED, 500: apache.HTTP_INTERNAL_SERVER_ERROR, 501: apache.HTTP_NOT_IMPLEMENTED, 502: apache.HTTP_BAD_GATEWAY, 503: apache.HTTP_SERVICE_UNAVAILABLE, 504: apache.HTTP_GATEWAY_TIME_OUT, 505: apache.HTTP_VERSION_NOT_SUPPORTED, 506: apache.HTTP_VARIANT_ALSO_VARIES, 507: apache.HTTP_INSUFFICIENT_STORAGE, 510: apache.HTTP_NOT_EXTENDED } r.content_type = "text/html" def response_start(code, phrase, hdrs): r.status = status_lookup.get(int(code), apache.HTTP_INTERNAL_SERVER_ERROR) for hdr in hdrs: r.headers_out[hdr[0]] = hdr[1] def response_done(trailers): thor.schedule(0, thor.stop) try: RedWebUi(Config, r.unparsed_uri, r.method, r.args or "", response_start, r.write, response_done) thor.run() except: except_handler_factory(Config, r.write, qs=r.args)() return apache.OK