def getChild(self, path, request): # NOQA: N802 child = static.File.getChild(self, path, request) if request.uri.endswith(b'css'): return EncodingResourceWrapper(child, [server.GzipEncoderFactory()]) else: return child
def getChild(self, path, request): # NOQA: N802 if hasattr(request, 'lookup_path'): request.lookup_path = os.path.join(request.lookup_path, path) else: request.lookup_path = path if request.uri.endswith(b'css'): return EncodingResourceWrapper(self, [server.GzipEncoderFactory()]) else: return self
def __init__(self): set_proc_title('globaleaks') self.state = State self.arw = resource.EncodingResourceWrapper(APIResourceWrapper(), [server.GzipEncoderFactory()]) if Settings.nodaemon: self.api_factory = Site(self.arw, logFormatter=logFormatter) else: self.api_factory = Site(self.arw, logPath=Settings.accesslogfile, logFormatter=logFormatter) self.api_factory.displayTracebacks = False
def test_interfaces(self): """ L{server.GzipEncoderFactory} implements the L{iweb._IRequestEncoderFactory} and its C{encoderForRequest} returns an instance of L{server._GzipEncoder} which implements L{iweb._IRequestEncoder}. """ request = server.Request(self.channel, False) request.gotLength(0) request.requestHeaders.setRawHeaders(b"Accept-Encoding", [b"gzip,deflate"]) factory = server.GzipEncoderFactory() self.assertTrue(verifyObject(iweb._IRequestEncoderFactory, factory)) encoder = factory.encoderForRequest(request) self.assertTrue(verifyObject(iweb._IRequestEncoder, encoder))
def setUp(self): self.channel = DummyChannel() staticResource = Data(b"Some data", b"text/plain") wrapped = resource.EncodingResourceWrapper( staticResource, [server.GzipEncoderFactory()]) self.channel.site.resource.putChild(b"foo", wrapped)
precalculate_daily_resampling() if PRECALCULATE_HEATMAP_DATA: precalculate_heat_map_data() if USING_SSL: sslContext = ssl.DefaultOpenSSLContextFactory( '/cert/privkey.pem', '/cert/cacert.pem', ) root = File("web") root.putChild( 'rms', resource.EncodingResourceWrapper(DataResource(), [server.GzipEncoderFactory()])) root.putChild( 'monitors', resource.EncodingResourceWrapper(MonitorsResource(), [server.GzipEncoderFactory()])) root.putChild( 'heatmap', resource.EncodingResourceWrapper(AnnualHeatMapResource(), [server.GzipEncoderFactory()])) root.putChild( 'waveforms', resource.EncodingResourceWrapper(WaveformResource(), [server.GzipEncoderFactory()])) root.putChild( 'harmonics', resource.EncodingResourceWrapper(HarmonicsResource(),
def makeService(config): ini = RawConfigParser() ini.read(config['config']) configPath = FilePath(config['config']).parent() rproxyConf = dict(ini.items("rproxy")) hostsConf = dict(ini.items("hosts")) hosts = {} for k, v in hostsConf.items(): k = k.lower() hostname, part = k.rsplit("_", 1) if hostname not in hosts: hosts[hostname] = {} hosts[hostname][part] = v if not hosts: raise ValueError("No hosts configured.") for i in hosts: if "port" not in hosts[i]: raise ValueError("All hosts need a port.") if "host" not in hosts[i]: print("%s does not have a host, making localhost" % (i, )) hosts[i]["host"] = "localhost" if "onlysecure" not in hosts[i]: print("%s does not have an onlysecure setting, making False" % (i, )) hosts[i]["onlysecure"] = False if "wwwtoo" not in hosts[i]: print("%s does not have an wwwtoo setting, making True" % (i, )) hosts[i]["wwwtoo"] = "True" if "proxysecure" not in hosts[i]: print("%s does not have an proxysecure setting, making False" % (i, )) hosts[i]["proxysecure"] = False if "sendhsts" not in hosts[i]: print( "%s does not have an sendhsts setting, making the value of onlysecure" % (i, )) hosts[i]["sendhsts"] = hosts[i]["onlysecure"] hosts[i][ "onlysecure"] = True if hosts[i]["onlysecure"] == "True" else False hosts[i]["proxysecure"] = True if hosts[i][ "proxysecure"] == "True" else False hosts[i][ "sendhsts"] = True if hosts[i]["sendhsts"] == "True" else False hosts[i]["wwwtoo"] = True if hosts[i]["wwwtoo"] == "True" else False if hosts[i]["onlysecure"] and not hosts[i]["proxysecure"]: if not hosts[i].get("iamokwithalocalnetworkattackerpwningmyusers", "False") == "True": raise ValueError( "%s has onlysecure==True, but proxysecure==False. This will mean TLS protected requests will not be TLS-protected between the proxy and the proxied server. If this is okay (e.g., if it's going over localhost), set %s_iamokwithalocalnetworkattackerpwningmyusers=True in your config." % (i, i)) if hosts[i]["proxysecure"] and not hosts[i]["onlysecure"]: if not hosts[i].get( "iamokwithlyingtomyproxiedserverthatheuserisoverhttps", "False") == "True": raise ValueError( "%s has onlysecure==False, but proxysecure==True. This means that the connection may not be TLS protected between the user and this proxy, only the proxy and the proxied server. This can trick your proxied server into thinking the user is being served over HTTPS. If this is okay (I can't imagine why it is), set %s_iamokwithlyingtomyproxiedserverthatheuserisoverhttps=True in your config." % (i, i)) from twisted.internet import reactor from twisted.web.client import HTTPConnectionPool pool = HTTPConnectionPool(reactor) anonymous = False resource = EncodingResourceWrapper( RProxyResource(hosts, rproxyConf.get("clacks"), pool, reactor, {}, False), [server.GzipEncoderFactory()]) site = server.Site(resource) multiService = service.MultiService() certificates = rproxyConf.get("certificates", None) if certificates: try: configPath.child(certificates).makedirs() except: pass certificates = configPath.child(certificates).path for i in rproxyConf.get("https_ports").split(","): print("Starting HTTPS on port " + i) multiService.addService( strports.service('le:' + certificates + ':tcp:' + i, site)) for host in hosts.keys(): with open(FilePath(certificates).child(host + ".pem").path, 'a'): # Open it so that txacme can find it pass if hosts[host]["wwwtoo"]: with open( FilePath(certificates).child("www." + host + ".pem").path, 'a'): # Open it so that txacme can find it pass for i in rproxyConf.get("http_ports", "").split(","): print("Starting HTTP on port " + i) multiService.addService(strports.service('tcp:' + i, site)) return multiService
def get_site(*args, **kwargs): encoders = [server.GzipEncoderFactory()] wrapped = resource.EncodingResourceWrapper( get_root_resource(qs=kwargs['qs']), encoders) site = server.Site(wrapped) return site
def __init__(self): resource.Resource.__init__(self) self.putChild(b'css', LookupResource('Css', rpath('css'))) if os.path.isfile(rpath('js', 'gettext.js')): self.putChild( b'gettext.js', EncodingResourceWrapper(GetText(), [server.GzipEncoderFactory()]), ) else: log.warning( 'Cannot find "gettext.js" translation file!' ' Text will only be available in English.' ) self.putChild(b'gettext.js', MockGetText()) self.putChild(b'flag', Flag()) self.putChild(b'icons', LookupResource('Icons', rpath('icons'))) self.putChild(b'images', LookupResource('Images', rpath('images'))) self.putChild( b'ui_images', LookupResource( 'UI_Images', common.resource_filename('deluge.ui.data', 'pixmaps') ), ) js = ScriptResource() # configure the dev scripts js.add_script( 'ext-base-debug.js', rpath('js', 'extjs', 'ext-base-debug.js'), 'dev' ) js.add_script( 'ext-all-debug.js', rpath('js', 'extjs', 'ext-all-debug.js'), 'dev' ) js.add_script_folder( 'ext-extensions', rpath('js', 'extjs', 'ext-extensions'), 'dev' ) js.add_script_folder('deluge-all', rpath('js', 'deluge-all'), 'dev') # configure the debug scripts js.add_script( 'ext-base-debug.js', rpath('js', 'extjs', 'ext-base-debug.js'), 'debug' ) js.add_script( 'ext-all-debug.js', rpath('js', 'extjs', 'ext-all-debug.js'), 'debug' ) js.add_script( 'ext-extensions-debug.js', rpath('js', 'extjs', 'ext-extensions-debug.js'), 'debug', ) js.add_script( 'deluge-all-debug.js', rpath('js', 'deluge-all-debug.js'), 'debug' ) # configure the normal scripts js.add_script('ext-base.js', rpath('js', 'extjs', 'ext-base.js')) js.add_script('ext-all.js', rpath('js', 'extjs', 'ext-all.js')) js.add_script('ext-extensions.js', rpath('js', 'extjs', 'ext-extensions.js')) js.add_script('deluge-all.js', rpath('js', 'deluge-all.js')) self.js = js self.putChild(b'js', js) self.putChild( b'json', EncodingResourceWrapper(JSON(), [server.GzipEncoderFactory()]) ) self.putChild( b'upload', EncodingResourceWrapper(Upload(), [server.GzipEncoderFactory()]) ) self.putChild(b'render', Render()) self.putChild(b'themes', Themes(rpath('themes'))) self.putChild(b'tracker', Tracker()) theme = component.get('DelugeWeb').config['theme'] if not os.path.isfile(rpath('themes', 'css', 'xtheme-%s.css' % theme)): theme = CONFIG_DEFAULTS.get('theme') self.__stylesheets.insert(1, 'themes/css/xtheme-%s.css' % theme)
def getChild(self, path, request): # NOQA: N802 if hasattr(request, 'lookup_path'): request.lookup_path += b'/' + path else: request.lookup_path = path return EncodingResourceWrapper(self, [server.GzipEncoderFactory()])
def getChild(self, path, request): # NOQA: N802 request.render_file = path return EncodingResourceWrapper(self, [server.GzipEncoderFactory()])
def makeService(config): ini = ConfigParser.RawConfigParser() ini.read(config['config']) configPath = FilePath(config['config']).parent() rproxyConf = dict(ini.items("rproxy")) hostsConf = dict(ini.items("hosts")) hosts = {} for k, v in hostsConf.items(): k = k.lower() hostname, part = k.rsplit("_", 1) if hostname not in hosts: hosts[hostname] = {} hosts[hostname][part] = v if not hosts: raise ValueError("No hosts configured.") for i in hosts: if "port" not in hosts[i]: raise ValueError("All hosts need a port.") if "host" not in hosts[i]: print("%s does not have a host, making localhost" % (i, )) hosts[i]["host"] = "localhost" if "wwwtoo" not in hosts[i]: print("%s does not have an wwwtoo setting, making True" % (i, )) hosts[i]["wwwtoo"] = "True" if "proxysecure" not in hosts[i]: print("%s does not have an proxysecure setting, making False" % (i, )) hosts[i]["proxysecure"] = False hosts[i]["wwwtoo"] = True if hosts[i]["wwwtoo"] == "True" else False hosts[i]["proxysecure"] = True if hosts[i][ "proxysecure"] == "True" else False hosts[i]["sendhsts"] = True if hosts[i].get( "sendhsts") == "True" else False from twisted.internet import reactor pool = HTTPConnectionPool(reactor) resource = EncodingResourceWrapper( RProxyResource(hosts, rproxyConf.get("clacks"), pool, reactor, {}, False), [server.GzipEncoderFactory()]) responder = HTTP01Responder() site = server.Site(EnsureHTTPS(resource, responder.resource), ) multiService = service.MultiService() certificates = rproxyConf.get("certificates", None) if certificates: try: configPath.child(certificates).makedirs() except: pass certificates = configPath.child(certificates).path for i in rproxyConf.get("https_ports").split(","): print("Starting HTTPS on port " + i) multiService.addService( strports.service('txsni:' + certificates + ':tcp:' + i, site)) for host in hosts.keys(): with open(FilePath(certificates).child(host + ".pem").path, 'w'): # Open it so that txacme can find it pass if hosts[host]["wwwtoo"]: with open( FilePath(certificates).child("www." + host + ".pem").path, 'w'): # Open it so that txacme can find it pass for i in rproxyConf.get("http_ports", "").split(","): print("Starting HTTP on port " + i) multiService.addService(strports.service('tcp:' + i, site)) issuingService = AcmeIssuingService( cert_store=DirectoryStore(FilePath(certificates)), client_creator=(lambda: Client.from_url( reactor=reactor, url=LETSENCRYPT_DIRECTORY, key=load_or_create_client_key(FilePath(certificates)), alg=RS256, )), clock=reactor, responders=[responder], ) issuingService.setServiceParent(multiService) return multiService