def search_post(): """Handle form submit.""" try: post_data = flask.request.form['domains'] except KeyError: app.logger.info( 'Missing "domains" key from POST: {}'.format(flask.request.form) ) return flask.redirect('/error/2') if post_data is None or post_data.strip() == '': app.logger.info( 'No data in "domains" key in POST' ) return flask.redirect('/error/2') # We currently don't support Unicode in searches. try: post_data.decode('ascii') except UnicodeEncodeError: app.logger.info( 'Unicode search requested' ) return flask.redirect('/error/3') search_domains = tools.parse_post_data(post_data) valid_domains = sorted(list(set(filter(None, map(tools.parse_domain, search_domains))))) if len(valid_domains) == 0: app.logger.info( 'No valid domains in POST {}'.format(flask.request.form) ) suggestion = tools.suggest_domain(search_domains) if suggestion is not None: encoded_suggestion = binascii.hexlify(suggestion) return flask.redirect( '/error/0?suggestion={}'.format(encoded_suggestion) ) return flask.redirect('/error/0') # Attempt to create a <= 200 character GET parameter from the domains so # we can redirect to that (allows bookmarking). As in '/api/analysis/ip' # we use hex to hide the domains from firewalls that already block some of # them. path = ','.join(map(binascii.hexlify, search_domains)) if len(path) <= 200: return flask.redirect('/search/{}'.format(path)) # If there's a ton of domains, just to the report. return html_render(search_domains)
def search(search_domain, fmt=None): """Handle redirect from form submit.""" domain = tools.parse_post_data(search_domain) if domain is None: return handle_invalid_domain(search_domain) if fmt is None: return html_render(domain) elif fmt == 'json': return json_render(domain) elif fmt == 'csv': return csv_render(domain) else: flask.abort(400, 'Unknown export format: {}'.format(fmt))
def search(search_domain, fmt=None): """Handle redirect from form submit.""" # We currently don't support Unicode in searches. try: search_domain.decode('ascii') except UnicodeEncodeError: app.logger.info('Unicode search requested') return flask.redirect('/error/3') domain = tools.parse_post_data(search_domain) if domain is None: return handle_invalid_domain(search_domain) if fmt is None: return html_render(domain) elif fmt == 'json': return json_render(domain) elif fmt == 'csv': return csv_render(domain) else: flask.abort(400, 'Unknown export format: {}'.format(fmt))