def search(request): context = {} context["Section"] = "Search" context["hashfile_list"] = Hashfile.objects.order_by('name') if request.method == 'POST': search_info = {} if len(request.POST["search_pattern"]) != 0: search_info["pattern"] = request.POST["search_pattern"] if "all_hashfiles" in request.POST: search_info["all_hashfiles"] = True else: search_info["hashfiles"] = request.POST.getlist("hashfile_search[]") if "ignore_uncracked" in request.POST: search_info["ignore_uncracked"] = True search_filename = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(12)) + ".csv" output_file = os.path.join(os.path.dirname(__file__), "..", "Files", "Searches", search_filename) search = Search( name=request.POST['search_name'], status="Starting", output_lines=None, output_file=output_file, json_search_info=json.dumps(search_info), ) search.save() run_search_task.delay(search.id) template = loader.get_template('Hashcat/search.html') return HttpResponse(template.render(context, request))
def api_search_action(request): if request.method == "POST": params = request.POST else: params = request.GET search = get_object_or_404(Search, id=params["search_id"]) if params["action"] == "remove": if os.path.exists(search.output_file): os.remove(search.output_file) search.delete() elif params["action"] == "reload": run_search_task.delay(search.id) return HttpResponse(json.dumps({"result": "success"}), content_type="application/json")