def post(self): if GLSettings.memory_copy.hostname == '': raise errors.ValidationError('hostname is not set') net_agent = GLSettings.get_agent() t = ('http', GLSettings.memory_copy.hostname, 'robots.txt', None, None) url = bytes(urlparse.urlunsplit(t)) try: resp = yield net_agent.request('GET', url) body = yield readBody(resp) server_h = resp.headers.getRawHeaders('Server', [None])[-1].lower() if not body.startswith('User-agent: *') or server_h != 'globaleaks': raise EnvironmentError('Response unexpected') except (EnvironmentError, ConnectError) as e: log.err(e) raise errors.ExternalResourceError()
def verify_hostname(self, req_args, *args, **kwargs): net_agent = self.state.get_agent() url = urlunsplit(('http', req_args['value'], 'robots.txt', None, None)).encode() try: resp = yield net_agent.request(b'GET', url) body = yield readBody(resp) server_h = resp.headers.getRawHeaders(b'Server', [None])[-1].lower() if not body.startswith(b'User-agent: *') or server_h != b'globaleaks': raise EnvironmentError('Response unexpected') except Exception as e: # Convert networking failures into a generic response if is_common_net_error(self.state.tenant_cache[self.request.tid], e): raise errors.ExternalResourceError() raise e