Skip to content

Commit

Permalink
[+] 添加在搜索结果页导出搜索结果的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
neargle committed Oct 20, 2017
1 parent dda9656 commit 5023674
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
31 changes: 30 additions & 1 deletion views/View.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def Main():
query = querylogic(result)
cursor = Mongo.coll['Info'].find(query).sort('time', -1).limit(page_size).skip((page - 1) * page_size)
return render_template('main.html', item=cursor, plugin=plugin, itemcount=cursor.count(),
plugin_type=plugin_type)
plugin_type=plugin_type, query=q)
else: # 自定义,无任何结果,用户手工添加
return render_template('main.html', item=[], plugin=plugin, itemcount=0, plugin_type=plugin_type)

Expand Down Expand Up @@ -278,6 +278,35 @@ def DownloadXls():
return response


# 搜索结果报表下载接口
@app.route('/searchxls', methods=['get'])
@logincheck
@anticsrf
def search_result_xls():
query = request.args.get('query', '')
if query:
result = query.strip().split(';')
filter_ = querylogic(result)
cursor = Mongo.coll['Info'].find(filter_).sort('time', -1)
title_tup = ('IP', '端口号', '主机名', '服务类型')
xls = [title_tup, ]
for info in cursor:
item = (
info.get('ip'), info.get('port'),
info.get('hostname'), info.get('server')
)
xls.append(item)
file = write_data(xls, 'search_result')
resp = make_response(file.getvalue())
resp.headers["Content-Disposition"] = "attachment; filename=search_result.xls;"
resp.headers["Content-Type"] = "application/x-xls"
resp.headers["X-Content-Type-Options"] = "nosniff"
return resp
else:
redirect(url_for('NotFound'))



# 插件列表页
@app.route('/plugin')
@logincheck
Expand Down
5 changes: 5 additions & 0 deletions views/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<div class="row" style="margin-bottom: 20px">
<div class="col-sm-12">
<div class="btn-group pull-right m-t-15">
{% if itemcount %}
<a href="{{ url_for('search_result_xls') }}?query={{ query }}" type="button" class="btn btn-tag waves-effect waves-light"
style="margin-right: 5px;color:white">下载搜索结果
</a>
{% endif %}
<button type="button" class="btn btn-tag waves-effect waves-light"
data-toggle="modal" data-target="#add-new-item" style="margin-right: 5px;color:white">新增目标
</button>
Expand Down

0 comments on commit 5023674

Please sign in to comment.