Skip to content

Commit

Permalink
增加报表下载功能
Browse files Browse the repository at this point in the history
  • Loading branch information
boy-hack committed Aug 7, 2018
1 parent c4dc537 commit a314091
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -6,7 +6,7 @@ w11scan是一款分布式的WEB指纹识别系统(包括CMS识别、js框架

## 安装
软件本身安装非常简单,比较复杂的是一些框架、数据库的安装。
[安装](./docs/install.md)
- [安装](./docs/install.md)
- docker在筹划中...

## 使用的技术和思路
Expand All @@ -21,6 +21,7 @@ w11scan是一款分布式的WEB指纹识别系统(包括CMS识别、js框架
2. 优先使用命中率最高的指纹,其次,将指纹按照访问路径分类排序,再优先使用访问路径次数最多的指纹。
3. 一个指纹识别成功后,会停止识别该URL的其他指纹,开始下一个任务
4. 搜索功能支持多种语法,全文搜索(mongodb特性)
5. 支持将内容下载为报表

## show
Preview [https://x.hacking8.com/?tag=w11scan](https://x.hacking8.com/?tag=w11scan)
Expand Down
27 changes: 27 additions & 0 deletions app/Common.py
@@ -0,0 +1,27 @@
from io import BytesIO
import xlwt

# 将数据保存成excel
def write_data(data, tname):
file = xlwt.Workbook(encoding='utf-8')
table = file.add_sheet(tname, cell_overwrite_ok=True)
l = 0
for line in data:
c = 0
for _ in line:
table.write(l, c, line[c])
c += 1
l += 1
sio = BytesIO()
file.save(sio)
return sio


# excel业务逻辑处理
def CreateTable(cursor, id):
item = []
item.append(['任务状态', '域名', '网站标题', 'CMS识别结果', '其他信息'])
for i in cursor:
item.append(i)
file = write_data(item, id)
return file.getvalue()
36 changes: 35 additions & 1 deletion app/views.py
Expand Up @@ -9,6 +9,7 @@
import time
from cms.tasks import buildPayload
from urllib.parse import urlparse
from app.Common import CreateTable
import re

# Create your views here.
Expand Down Expand Up @@ -330,4 +331,37 @@ def detail(request,slug = ""):

data = db.coll["result"].find({"taskid":ObjectId(slug)})

return render(request, "task_detail.html", {"cursor":data,"tasks":tasks,"len":data.count()})
return render(request, "task_detail.html", {"cursor":data,"tasks":tasks,"len":data.count()})

def download(request,slug = ""):

if not request.session.get('is_login',None):
return redirect(login)

db = Conn.MongDB(database="w11scan_config")

tasks = db.coll["tasks"].find_one({"_id":ObjectId(slug)})
colname = tasks.get("name",None)
taskdate = tasks.get("time",None)
if taskdate is None:
return HttpResponse("faild,taskid invalid")
taskdate = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(taskdate))
data = db.coll["result"].find({"taskid":ObjectId(slug)})
# { "_id" : ObjectId("5b6696d78598849b135dd44e"), "url" : "http://okoko.cn", "status" : "finish", "taskid" : ObjectId("5b6696d78598849b135dd448"), "other" : { "web-servers" : [ "Tengine" ], "other" : [ "Langeuage:php", "Server:Tengine/1.4.2", "X-Powered-By:PHP/5.3.10" ] }, "title" : "okoko.cn-您正在访问的网站可以合作!" }
# ['任务状态', '域名', '网站标题', 'CMS识别结果', '其他信息']
show = []
for i in data:
cms = i.get("webdna","")
if cms != "":
cms = cms.get("cmsname","")
_ = [i.get("status",""),i.get("url",""),i.get("title",""),cms,repr(i.get("other",""))]
show.append(_)
siov = CreateTable(show,colname)

response = HttpResponse(siov, content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename={}.xls'.format(taskdate)
response.write(siov)

return response


1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -15,3 +15,4 @@ requests==2.19.1
six==1.11.0
urllib3==1.23
vine==1.1.4
xlwt==1.3.0
5 changes: 3 additions & 2 deletions templates/task_detail.html
@@ -1,4 +1,5 @@
{% extends "layout.html" %}
{% load appname_tags %}
{% load staticfiles %}
{% block css %}
<link href="{% static 'buss/css/task.css' %}" rel="stylesheet" type="text/css"/>
Expand All @@ -12,8 +13,8 @@
<div class="row">
<div class="col-sm-12">
<div class="btn-group pull-right m-t-15">
<a type="button" class="btn btn-tag dropdown-toggle waves-effect waves-light"
href="/downloadxls" style="color: white">下载
<a type="button" target="_blank" class="btn btn-tag dropdown-toggle waves-effect waves-light"
href="{% url 'download' tasks|mongo2id:'_id' %}" style="color: white">下载
</a>

</div>
Expand Down
3 changes: 2 additions & 1 deletion xun/urls.py
Expand Up @@ -33,5 +33,6 @@
path(r'logout',views.logout),
path(r'task_add',views.task_add),
path(r'task_del',views.task_del),
path(r'task/<str:slug>',views.detail,name="task_detail")
path(r'task/<str:slug>',views.detail,name="task_detail"),
path(r'download/<str:slug>',views.download,name="download")
]

0 comments on commit a314091

Please sign in to comment.