def browse(): """ A simple browser that doesn't deal with queries at all """ page = int(request.args.get("page", 1)) includeHistory = request.args.get("includeHistory", False) results_per_page, search_offset = results_offset(page) searchIndex = "history" if includeHistory else "latest" count, hostdata = current_app.elastic.search(results_per_page, search_offset, searchIndex=searchIndex) totalHosts = current_app.elastic.total_hosts() if includeHistory: next_url, prev_url = build_pagination_urls( "main.browse", page, count, includeHistory=includeHistory) else: # By using the if/else we can avoid putting includeHistory=False into the url that gets constructed next_url, prev_url = build_pagination_urls("main.browse", page, count) return render_template( "main/browse.html", numresults=count, totalHosts=totalHosts, page=page, hosts=hostdata, next_url=next_url, prev_url=prev_url, )
def search(): """ Return search results for a given query """ query = request.args.get("query", "") if query == "": return redirect(url_for("main.browse")) page = int(request.args.get("page", 1)) format = request.args.get("format", "") scan_ids = request.args.get("includeScanIDs", "") includeHistory = request.args.get("includeHistory", False) results_per_page, search_offset = results_offset(page) searchIndex = "history" if includeHistory else "latest" count, context = current_app.elastic.search(results_per_page, search_offset, query=query, searchIndex=searchIndex) totalHosts = current_app.elastic.total_hosts() if includeHistory: next_url, prev_url = build_pagination_urls( "main.search", page, count, query=query, includeHistory=includeHistory) else: next_url, prev_url = build_pagination_urls("main.search", page, count, query=query) # what kind of output are we looking for? if format == "hostlist": hostlist = [] for host in context: if scan_ids: hostlist.append(str(host["ip"]) + "," + str(host["scan_id"])) else: hostlist.append(str(host["ip"])) return Response("\n".join(hostlist), mimetype="text/plain") elif format == "json": return jsonify(list(context)) else: return render_template( "main/search.html", query=query, numresults=count, totalHosts=totalHosts, page=page, hosts=context, next_url=next_url, prev_url=prev_url, )
def search(): ''' Return search results for a given query ''' query = request.args.get('query', '') page = int(request.args.get('page', 1)) format = request.args.get('format', '') scan_ids = request.args.get('includeScanIDs', '') includeHistory = request.args.get('includeHistory', False) results_per_page, search_offset = results_offset(page) searchIndex = "nmap_history" if includeHistory else "nmap" count, context = current_app.elastic.search(results_per_page, search_offset, query=query, searchIndex=searchIndex) totalHosts = current_app.elastic.total_hosts() if includeHistory: next_url, prev_url = build_pagination_urls( 'main.search', page, count, query=query, includeHistory=includeHistory) else: next_url, prev_url = build_pagination_urls('main.search', page, count, query=query) # what kind of output are we looking for? if format == 'hostlist': hostlist = [] for host in context: if scan_ids: hostlist.append(str(host['ip']) + ',' + str(host['scan_id'])) else: hostlist.append(str(host['ip'])) return Response('\n'.join(hostlist), mimetype='text/plain') elif format == 'json': return jsonify(list(context)) else: return render_template("main/search.html", query=query, numresults=count, totalHosts=totalHosts, page=page, hosts=context, next_url=next_url, prev_url=prev_url)
def screenshots(): page = int(request.args.get('page', 1)) results_per_page, search_offset = results_offset(page) total_hosts, total_screenshots, hosts = current_app.elastic.get_current_screenshots( results_per_page, search_offset) next_url, prev_url = build_pagination_urls('main.screenshots', page, total_hosts) return render_template("main/screenshots.html", total_hosts=total_hosts, total_screenshots=total_screenshots, hosts=hosts, next_url=next_url, prev_url=prev_url)