def csv_masks(request, hashfile_id):
hashfile = get_object_or_404(Hashfile, id=hashfile_id)
# didn't found the correct way in pure django...
res = Cracked.objects.raw("SELECT id, password_mask, COUNT(*) AS count FROM Hashcat_cracked USE INDEX (hashfileid_id_index) WHERE hashfile_id=%s GROUP BY password_mask ORDER BY count DESC", [hashfile.id])
fp = tempfile.SpooledTemporaryFile(mode='w')
csvfile = csv.writer(fp, quotechar='"', quoting=csv.QUOTE_ALL)
for item in res:
csvfile.writerow([item.count, item.password_mask])
fp.seek(0) # rewind the file handle
csvfile_data = fp.read()
for query in connection.queries[-1:]:
print(query["sql"])
print(query["time"])
response = HttpResponse(csvfile_data, content_type='application/force-download') # mimetype is replaced by content_type for django 1.7
response['Content-Disposition'] = 'attachment; filename=%s_masks.csv' % hashfile.name
return response
评论列表
文章目录