taxonomie + add tags + tags display

This commit is contained in:
Terrtia 2018-05-23 16:58:56 +02:00
parent b9eb3ed9ba
commit f5cae0d99c
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
13 changed files with 803 additions and 62 deletions

View file

@ -18,6 +18,8 @@ sys.path.append('./modules/')
import Paste import Paste
from Date import Date from Date import Date
from pytaxonomies import Taxonomies
# Import config # Import config
import Flask_config import Flask_config
@ -82,6 +84,7 @@ for module_name, txt in list(to_add_to_header_dico.items()):
to_add_to_header = [] to_add_to_header = []
for module_name, txt in to_add_to_header_dico.items(): for module_name, txt in to_add_to_header_dico.items():
to_add_to_header.append(txt) to_add_to_header.append(txt)
print(to_add_to_header)
modified_header = modified_header.replace('<!--insert here-->', '\n'.join(to_add_to_header)) modified_header = modified_header.replace('<!--insert here-->', '\n'.join(to_add_to_header))
@ -113,6 +116,19 @@ def searchbox():
return render_template("searchbox.html") return render_template("searchbox.html")
# ========== INITIAL taxonomies ============
r_serv_tags = redis.StrictRedis(
host=cfg.get("ARDB_Tags", "host"),
port=cfg.getint("ARDB_Tags", "port"),
db=cfg.getint("ARDB_Tags", "db"),
decode_responses=True)
# add default ail taxonomies
r_serv_tags.sadd('active_taxonomies', 'infoleak')
# add default tags
taxonomies = Taxonomies()
for tag in taxonomies.get('infoleak').machinetags():
r_serv_tags.sadd('active_tag_infoleak', tag)
# ============ MAIN ============ # ============ MAIN ============
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -11,6 +11,8 @@ import json
import Paste import Paste
from pytaxonomies import Taxonomies
# ============ VARIABLES ============ # ============ VARIABLES ============
import Flask_config import Flask_config
@ -39,26 +41,62 @@ def get_all_tags():
all_tags = r_serv_tags.smembers('list_tags') all_tags = r_serv_tags.smembers('list_tags')
list_tags = [] list_tags = []
id = 0
for tag in all_tags: for tag in all_tags:
list_tags.append( tag ) list_tags.append( tag )
id += 1
return jsonify(list_tags) return jsonify(list_tags)
@Tags.route("/Tags/get_all_tags_taxonomies")
def get_all_tags_taxonomies():
taxonomies = Taxonomies()
list_taxonomies = list(taxonomies.keys())
active_taxonomie = r_serv_tags.smembers('active_taxonomies')
list_tags = []
for taxonomie in active_taxonomie:
#l_tags = taxonomies.get(taxonomie).machinetags()
l_tags = r_serv_tags.smembers('active_tag_' + taxonomie)
for tag in l_tags:
list_tags.append( tag )
return jsonify(list_tags)
@Tags.route("/Tags/get_tags_taxonomie")
def get_tags_taxonomie():
taxonomie = request.args.get('taxonomie')
taxonomies = Taxonomies()
list_taxonomies = list(taxonomies.keys())
active_taxonomie = r_serv_tags.smembers('active_taxonomies')
#verify input
if taxonomie in list_taxonomies:
if taxonomie in active_taxonomie:
list_tags = []
#l_tags = taxonomies.get(taxonomie).machinetags()
l_tags = r_serv_tags.smembers('active_tag_' + taxonomie)
for tag in l_tags:
list_tags.append( tag )
return jsonify(list_tags)
else:
return 'this taxinomie is disable'
else:
return 'INCORRECT INPUT'
@Tags.route("/Tags/get_tagged_paste") @Tags.route("/Tags/get_tagged_paste")
def get_tagged_paste(): def get_tagged_paste():
tags = request.args.get('ltags')[1:-1] tags = request.args.get('ltags')
tags = tags.replace('\\','')
list_tags = tags.split(',') list_tags = tags.split(',')
tmp_list_tags = []
# remove " char
for tag in list_tags:
tmp_list_tags.append(tag[1:-1])
list_tags = tmp_list_tags
# TODO verify input # TODO verify input
@ -106,8 +144,11 @@ def get_tagged_paste():
paste_date.append(curr_date) paste_date.append(curr_date)
paste_linenum.append(paste.get_lines_info()[0]) paste_linenum.append(paste.get_lines_info()[0])
p_tags = r_serv_metadata.smembers('tag:'+path) p_tags = r_serv_metadata.smembers('tag:'+path)
complete_tags = []
l_tags = [] l_tags = []
for tag in p_tags: for tag in p_tags:
complete_tag = tag
tag = tag.split('=') tag = tag.split('=')
if len(tag) > 1: if len(tag) > 1:
if tag[1] != '': if tag[1] != '':
@ -119,7 +160,7 @@ def get_tagged_paste():
else: else:
tag = tag[0] tag = tag[0]
l_tags.append(tag) l_tags.append( (tag,complete_tag) )
paste_tags.append(l_tags) paste_tags.append(l_tags)
@ -131,6 +172,7 @@ def get_tagged_paste():
return render_template("tagged.html", return render_template("tagged.html",
year=currentSelectYear, year=currentSelectYear,
all_path=all_path, all_path=all_path,
tags=tags,
paste_tags=paste_tags, paste_tags=paste_tags,
bootstrap_label=bootstrap_label, bootstrap_label=bootstrap_label,
content=all_content, content=all_content,
@ -139,12 +181,6 @@ def get_tagged_paste():
char_to_display=max_preview_modal, char_to_display=max_preview_modal,
finished=finished) finished=finished)
return 'OK'
@Tags.route("/Tags/res")
def get_tagged_paste_res():
return render_template("res.html")
@Tags.route("/Tags/remove_tag") @Tags.route("/Tags/remove_tag")
def remove_tag(): def remove_tag():
@ -183,6 +219,255 @@ def confirm_tag():
return 'incompatible tag' return 'incompatible tag'
@Tags.route("/Tags/addTags")
def addTags():
tags = request.args.get('tags')
path = request.args.get('path')
list_tag = tags.split(',')
taxonomies = Taxonomies()
active_taxonomies = r_serv_tags.smembers('active_taxonomies')
if not path:
return 'INCORRECT INPUT'
for tag in list_tag:
# verify input
tax = tag.split(':')[0]
if tax in active_taxonomies:
if tag in r_serv_tags.smembers('active_tag_' + tax):
#add tag
r_serv_metadata.sadd('tag:'+path, tag)
r_serv_tags.sadd(tag, path)
#add new tag in list of all used tags
r_serv_tags.sadd('list_tags', tag)
else:
return 'INCORRECT INPUT'
else:
return 'INCORRECT INPUT'
return redirect(url_for('showsavedpastes.showsavedpaste', paste=path))
@Tags.route("/Tags/thumbs_up_paste")
def thumbs_up_paste():
#TODO verify input
path = request.args.get('paste')
'''positive_t = 'infoleak:confirmed="true-positive"'
positive_f = 'infoleak:confirmed="false-positive"'
negative_t = 'infoleak:confirmed="true-negative"'
list_tags = r_serv_metadata.smembers('tag:'+path)
if(list_tags > 0):
if positive_f in list_tags:
r_serv_metadata.srem('tag:'+path, positive_f)
r_serv_metadata.sadd('tag:'+path, positive_t)
r_serv_tags.srem(positive_f, path)
r_serv_tags.sadd(positive_t, path)
#add new tag in list of all used tags
r_serv_tags.sadd('list_tags', positive_t)
return redirect(url_for('showsavedpastes.showsavedpaste', paste=path))
if positive_t in list_tags:
return redirect(url_for('showsavedpastes.showsavedpaste', paste=path))
else:
r_serv_metadata.sadd('tag:'+path, negative_t)
r_serv_tags.sadd(negative_t, path)
#add new tag in list of all used tags
r_serv_tags.sadd('list_tags', negative_t)'''
return redirect(url_for('showsavedpastes.showsavedpaste', paste=path))
@Tags.route("/Tags/thumbs_down_paste")
def thumbs_down_paste():
#TODO verify input
path = request.args.get('paste')
'''list_tags = r_serv_metadata.smembers('tag:'+path)'''
return redirect(url_for('showsavedpastes.showsavedpaste', paste=path))
@Tags.route("/Tags/taxonomies")
def taxonomies():
active_taxonomies = r_serv_tags.smembers('active_taxonomies')
taxonomies = Taxonomies()
list_taxonomies = list(taxonomies.keys())
id = []
name = []
description = []
version = []
enabled = []
n_tags = []
for taxonomie in list_taxonomies:
id.append(taxonomie)
name.append(taxonomies.get(taxonomie).name)
description.append(taxonomies.get(taxonomie).description)
version.append(taxonomies.get(taxonomie).version)
if taxonomie in active_taxonomies:
enabled.append(True)
else:
enabled.append(False)
n = str(r_serv_tags.scard('active_tag_' + taxonomie))
n_tags.append(n + '/' + str(len(taxonomies.get(taxonomie).machinetags())) )
return render_template("taxonomies.html",
id=id,
all_name = name,
description = description,
version = version,
enabled = enabled,
n_tags=n_tags)
#return 'O'
@Tags.route("/Tags/edit_taxonomie")
def edit_taxonomie():
taxonomies = Taxonomies()
list_taxonomies = list(taxonomies.keys())
id = request.args.get('taxonomie')
#verify input
if id in list(taxonomies.keys()):
active_tag = r_serv_tags.smembers('active_tag_' + id)
list_tag = taxonomies.get(id).machinetags()
list_tag_desc = taxonomies.get(id).machinetags_expanded()
active_taxonomies = r_serv_tags.smembers('active_taxonomies')
if id in active_taxonomies:
active = True
else:
active = False
name = taxonomies.get(id).name
description = taxonomies.get(id).description
version = taxonomies.get(id).version
status = []
for tag in list_tag:
if tag in active_tag:
status.append(True)
else:
status.append(False)
return render_template("edit_taxonomie.html",
id=id,
name=name,
description = description,
version = version,
active=active,
all_tags = list_tag,
list_tag_desc=list_tag_desc,
status = status)
else:
return 'INVALID TAXONOMIE'
@Tags.route("/Tags/test")
def test():
return 'test',
@Tags.route("/Tags/disable_taxonomie")
def disable_taxonomie():
taxonomies = Taxonomies()
list_taxonomies = list(taxonomies.keys())
id = request.args.get('taxonomie')
if id in list_taxonomies:
r_serv_tags.srem('active_taxonomies', id)
for tag in taxonomies.get(id).machinetags():
r_serv_tags.srem('active_tag_' + id, tag)
return redirect(url_for('Tags.taxonomies'))
else:
return "INCORRECT INPUT"
@Tags.route("/Tags/active_taxonomie")
def active_taxonomie():
taxonomies = Taxonomies()
list_taxonomies = list(taxonomies.keys())
id = request.args.get('taxonomie')
# verify input
if id in list_taxonomies:
r_serv_tags.sadd('active_taxonomies', id)
for tag in taxonomies.get(id).machinetags():
r_serv_tags.sadd('active_tag_' + id, tag)
return redirect(url_for('Tags.taxonomies'))
else:
return "INCORRECT INPUT"
@Tags.route("/Tags/edit_taxonomie_tag")
def edit_taxonomie_tag():
taxonomies = Taxonomies()
list_taxonomies = list(taxonomies.keys())
arg1 = request.args.getlist('tag_enabled')
arg2 = request.args.getlist('tag_disabled')
id = request.args.get('taxonomie')
#verify input
if id in list_taxonomies:
list_tag = taxonomies.get(id).machinetags()
#check tags validity
if ( all(elem in list_tag for elem in arg1) or (len(arg1) == 0) ) and ( all(elem in list_tag for elem in arg2) or (len(arg2) == 0) ):
active_tag = r_serv_tags.smembers('active_tag_' + id)
diff = list(set(arg1) ^ set(list_tag))
#remove tags
for tag in diff:
r_serv_tags.srem('active_tag_' + id, tag)
#all tags unchecked
if len(arg1) == 0 and len(arg2) == 0:
r_serv_tags.srem('active_taxonomies', id)
#add new tags
for tag in arg2:
r_serv_tags.sadd('active_taxonomies', id)
r_serv_tags.sadd('active_tag_' + id, tag)
return redirect(url_for('Tags.taxonomies'))
else:
return "INCORRECT INPUT"
else:
return "INCORRECT INPUT"
# ========= REGISTRATION ========= # ========= REGISTRATION =========
app.register_blueprint(Tags) app.register_blueprint(Tags)

View file

@ -34,28 +34,32 @@
<!-- /.col-lg-12 --> <!-- /.col-lg-12 -->
</div> </div>
<!-- /.row --> <!-- /.row -->
<form action="/Tags/get_tagged_paste">
<div class="form-group input-group" > <div class="form-group input-group" >
<input id="ltags" style="width:100%;" type="text" name="ltags"> <input id="ltags" style="width:100%;" type="text" name="ltags" autocomplete="off">
<div class="input-group-btn"> <div class="input-group-btn">
<button type="submit" class="btn btn-search btn-primary btn-tags"> <button class="btn btn-search btn-primary btn-tags" onclick="searchTags()">
<span class="glyphicon glyphicon-search"></span> <span class="glyphicon glyphicon-search"></span>
<span class="label-icon">Search</span> <span class="label-icon">Search</span>
</button> </button>
</div> </div>
</div> </div>
</form>
<button type="button" class="btn btn-primary" style="margin-bottom: 30px;" data-target="#filter-panel"> <button type="button" class="btn btn-primary" style="margin-bottom: 30px;" data-target="#filter-panel">
<span class="glyphicon glyphicon-cog "></span> Advanced Search <span class="glyphicon glyphicon-cog "></span> Advanced Search
</button> </button>
<div>
<a href="{{ url_for('Tags.taxonomies') }}"> [Taxonomies list] </a>
</div> </div>
</div>
<!-- /#page-wrapper --> <!-- /#page-wrapper -->
<script> <script>
var ltags
$(document).ready(function(){ $(document).ready(function(){
$.getJSON('/Tags/get_all_tags', $.getJSON('/Tags/get_all_tags',
@ -63,7 +67,7 @@
//console.log(data) //console.log(data)
//for(var i=0;i<data.length;i++) jsonData.push({id:i,name:data[i]}); //for(var i=0;i<data.length;i++) jsonData.push({id:i,name:data[i]});
var ltags = $('#ltags').tagSuggest({ ltags = $('#ltags').tagSuggest({
data: data, data: data,
sortOrder: 'name', sortOrder: 'name',
maxDropHeight: 200, maxDropHeight: 200,
@ -72,6 +76,13 @@
}); });
}); });
</script> </script>
<script>
function searchTags() {
var data = ltags.getValue();
console.log(data);
window.location.replace("{{ url_for('Tags.get_tagged_paste') }}?ltags=" + data);
}
</script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script> <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
</body> </body>

View file

@ -0,0 +1,171 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analysis Information Leak framework Dashboard</title>
<!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
<link href="/static//css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<!-- JS -->
<script type="text/javascript" src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script>
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="/static//js/bootstrap.min.js"></script>
<script src="/static//js/jquery.dataTables.min.js"></script>
<script src="/static//js/dataTables.bootstrap.js"></script>
<style>
.tooltip-inner {
text-align: left;
height: 200%;
width: 200%;
max-width: 500px;
max-height: 500px;
font-size: 13px;
}
xmp {
white-space:pre-wrap;
word-wrap:break-word;
}
.test thead{
background: #d91f2d;
color: #fff;
}
</style>
</head>
<body>
{% include 'navbar.html' %}
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<a href="/Tags/taxonomies" class="btn btn-light pull-left">
<i class="fa fa-arrow-left fa"></i> List Taxonomies
</a>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="panel panel-primary">
<div class="panel-heading">{{ name }}
{% if active %}
<span class="label label-success pull-right"> Enabled</span>
{% endif %}
{% if not active %}
<span class="label label-danger pull-right"> Disabled</span>
{% endif %}
</div>
<div class="panel-body">
{{ description }}
<br><br>
Version: {{ version }}
{% if active %}
<a href="{{ url_for('Tags.disable_taxonomie') }}?taxonomie={{ id }}" class="btn btn-danger pull-right">
<i class="fa fa-times fa"></i> Disable Taxonomie
</a>
{% endif %}
{% if not active %}
<a href="{{ url_for('Tags.active_taxonomie') }}?taxonomie={{ id }}" class="btn btn-success pull-right">
<i class="fa fa-check-square-o fa"></i> Enable Taxonomie
</a>
{% endif %}
</div>
</div>
<form action="/Tags/edit_taxonomie_tag" id="checkboxForm">
<input type="hidden" value="{{ id }}" name="taxonomie" />
<table class="test table table-striped table-bordered table-hover table-responsive " id="myTable_">
<thead>
<tr>
<th></th>
<th style="max-width: 800px;">Tag</th>
<th style="max-width: 800px;">Description</th>
<th>Enabled</th>
</tr>
</thead>
<tbody>
{% for tag in all_tags %}
<tr>
<td>
{% if status[loop.index0] %}
<div style="display:none;">Enabled</div>
<input type="checkbox" value="{{ tag }}" id="{{ tag }}" name="tag_enabled" checked>
{% endif %}
{% if not status[loop.index0] %}
<div style="display:none;">Disabled</div>
<input type="checkbox" value="{{ tag }}" id="{{ tag }}" name="tag_disabled" >
{% endif %}
</td>
<td>{{ tag }}</td>
<td>{{ list_tag_desc[loop.index0] }}</td>
<td style="text-align: center;">
{% if status[loop.index0] %}
<div style="display:none;">Enabled</div>
<div style="color:Green; display:inline-block"><i class="fa fa-check-circle fa-2x"></i></div>
{% endif %}
{% if not status[loop.index0] %}
<div style="display:none;">Disabled</div>
<div style="color:Red; display:inline-block"><i class="fa fa-times-circle fa-2x"></i></div>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="input-group-btn">
<button class="btn btn-primary btn-lg">
<i class="fa fa-check-square-o fa"></i>
Update Tags
</button>
</div>
</form>
</div>
<!-- /#page-wrapper -->
</body>
<script>
$(document).ready(function(){
/*$('[data-toggle="tooltip"]').tooltip();
$("[data-toggle='modal']").off('click.openmodal').on("click.openmodal", function (event) {
//get_html_and_update_modal(event);
get_html_and_update_modal(event, $(this));
});
search_table = $('#myTable_').DataTable({ "order": [[ 2, "desc" ]] });*/
$('#myTable_').DataTable(
{
"aLengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]],
"iDisplayLength": 10,
//"order": [[ 1, "asc" ]]
}
);
});
</script>
<script>
function submitActiveTags(){
document.getElementById("checkboxForm").submit();
}
</script>
</html>

View file

@ -70,19 +70,17 @@
<!-- /.col-lg-12 --> <!-- /.col-lg-12 -->
</div> </div>
<!-- /.row --> <!-- /.row -->
<form action="/Tags/get_tagged_paste">
<div class="form-group input-group" > <div class="form-group input-group" >
<input id="ltags" style="width:100%;" type="text" name="ltags"> <input id="ltags" style="width:100%;" type="text" name="ltags" autocomplete="off">
<div class="input-group-btn"> <div class="input-group-btn">
<button type="submit" class="btn btn-search btn-primary btn-tags"> <button class="btn btn-search btn-primary btn-tags" onclick="searchTags()">
<span class="glyphicon glyphicon-search"></span> <span class="glyphicon glyphicon-search"></span>
<span class="label-icon">Search</span> <span class="label-icon">Search</span>
</button> </button>
</div> </div>
</div> </div>
</form>
<button type="button" class="btn btn-primary" style="margin-bottom: 30px;" data-target="#filter-panel"> <button type="button" class="btn btn-primary" style="margin-bottom: 30px;" data-target="#filter-panel">
<span class="glyphicon glyphicon-cog "></span> Advanced Search <span class="glyphicon glyphicon-cog "></span> Advanced Search
@ -106,7 +104,9 @@
<td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}">{{ path }}</a> <td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}">{{ path }}</a>
<div> <div>
{% for tag in paste_tags[loop.index0] %} {% for tag in paste_tags[loop.index0] %}
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }} pull-left">{{ tag }}</span> <a href="{{ url_for('Tags.get_tagged_paste') }}?ltags={{ tag[1] }}">
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }} pull-left">{{ tag[0] }}</span>
</a>
{% endfor %} {% endfor %}
</div> </div>
</td> </td>
@ -129,24 +129,27 @@
<img id="loading_gif_browse" src="/static//image/loading.gif" heigt="20" width="20" style="margin: 2px;"></div> <img id="loading_gif_browse" src="/static//image/loading.gif" heigt="20" width="20" style="margin: 2px;"></div>
</br> </br>
<a href="{{ url_for('Tags.taxonomies') }}"> [Taxonomies list] </a>
</div> </div>
</body> </body>
<script> <script>
var search_table; var search_table;
var ltags;
var last_clicked_paste; var last_clicked_paste;
var can_change_modal_content = true; var can_change_modal_content = true;
$("#myTable_").attr('data-numElem', "{{ all_path|length }}"); $("#myTable_").attr('data-numElem', "{{ all_path|length }}");
$(document).ready(function(){ $(document).ready(function(){
search_table = $('#myTable_').DataTable({ "order": [[ 2, "desc" ]] });
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
$("[data-toggle='modal']").off('click.openmodal').on("click.openmodal", function (event) { $("[data-toggle='modal']").off('click.openmodal').on("click.openmodal", function (event) {
//get_html_and_update_modal(event); //get_html_and_update_modal(event);
get_html_and_update_modal(event, $(this)); get_html_and_update_modal(event, $(this));
}); });
search_table = $('#myTable_').DataTable({ "order": [[ 2, "desc" ]] });
$("#load_more_json_button1").hide(); $("#load_more_json_button1").hide();
$("#load_more_json_button2").hide(); $("#load_more_json_button2").hide();
@ -162,25 +165,31 @@ $(document).ready(function(){
$.getJSON('/Tags/get_all_tags', $.getJSON('/Tags/get_all_tags',
function(data) { function(data) {
//console.log(data)
//for(var i=0;i<data.length;i++) jsonData.push({id:i,name:data[i]});
//var slct_tags = String({{ original_tag }})
var ltags = $('#ltags').tagSuggest({ ltags = $('#ltags').tagSuggest({
data: data, data: data,
value: '["infoleak:automatic-detection=\"bitcoin-address\"","infoleak:automatic-detection=\"aws-key\""]', //value: ["infoleak:automatic-detection=\"bitcoin-address\"","infoleak:automatic-detection=\"aws-key\""],
sortOrder: 'name', sortOrder: 'name',
maxDropHeight: 200, maxDropHeight: 200,
name: 'ltags' name: 'ltags',
});
}); });
//ltags.setValue(["{{ tags }}"]);
ltags.setValue(["infoleak:automatic-detection='bitcoin-address'","infoleak:automatic-detection='aws-key'"]);
});
}); });
</script> </script>
<script>
function searchTags() {
var data = ltags.getValue();
window.location.replace("{{ url_for('Tags.get_tagged_paste') }}?ltags=" + data);
}
</script>
<!-- Dynamically update the modal --> <!-- Dynamically update the modal -->
<script type="text/javascript"> <script>
// static data // static data
var alert_message = '<div class="alert alert-info alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><strong>No more data.</strong> Full paste displayed.</div>'; var alert_message = '<div class="alert alert-info alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><strong>No more data.</strong> Full paste displayed.</div>';
var complete_paste = null; var complete_paste = null;

View file

@ -0,0 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analysis Information Leak framework Dashboard</title>
<!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
<link href="/static//css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<!-- JS -->
<script type="text/javascript" src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script>
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="/static//js/bootstrap.min.js"></script>
<script src="/static//js/jquery.dataTables.min.js"></script>
<script src="/static//js/dataTables.bootstrap.js"></script>
<style>
.tooltip-inner {
text-align: left;
height: 200%;
width: 200%;
max-width: 500px;
max-height: 500px;
font-size: 13px;
}
xmp {
white-space:pre-wrap;
word-wrap:break-word;
}
.test thead{
background: #d91f2d;
color: #fff;
}
</style>
</head>
<body>
{% include 'navbar.html' %}
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Taxonomies</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<table class="test table table-striped table-bordered table-hover table-responsive " id="myTable_">
<thead>
<tr>
<th>Name</th>
<th style="max-width: 800px;">Description</th>
<th>Version</th>
<th>Enabled</th>
<th>Active Tags</th>
</tr>
</thead>
<tbody>
{% for name in all_name %}
<tr>
<td>{{ name }}</td>
<td>{{ description[loop.index0] }}</td>
<td>{{ version[loop.index0] }}</td>
<td style="text-align: center;">
{% if enabled[loop.index0] %}
<div style="display:none;">Enabled</div>
<div style="color:Green; display:inline-block"><i class="fa fa-check-circle fa-2x"></i></div>
{% endif %}
{% if not enabled[loop.index0] %}
<div style="display:none;">Disabled</div>
<div style="color:Red; display:inline-block"><i class="fa fa-times-circle fa-2x"></i></div>
{% endif %}
</td>
<td style="text-align: center;">
<div style="display:none;">{{ n_tags[loop.index0] }}</div>
<a class="btn btn-primary" href="{{ url_for('Tags.edit_taxonomie') }}?taxonomie={{ id[loop.index0] }}">Active Tags <span class="badge">{{ n_tags[loop.index0] }}</span></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- /#page-wrapper -->
</body>
<script>
$(document).ready(function(){
/*$('[data-toggle="tooltip"]').tooltip();
$("[data-toggle='modal']").off('click.openmodal').on("click.openmodal", function (event) {
//get_html_and_update_modal(event);
get_html_and_update_modal(event, $(this));
});
search_table = $('#myTable_').DataTable({ "order": [[ 2, "desc" ]] });*/
$('#myTable_').DataTable(
{
"aLengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]],
"iDisplayLength": 15,
//"order": [[ 1, "asc" ]]
}
);
});
</script>
</html>

View file

@ -76,6 +76,7 @@ def event_stream_getImportantPasteByModule(module_name, year):
p_tags = r_serv_metadata.smembers('tag:'+path) p_tags = r_serv_metadata.smembers('tag:'+path)
l_tags = [] l_tags = []
for tag in p_tags: for tag in p_tags:
complete_tag = tag.replace('"', '&quot;')
tag = tag.split('=') tag = tag.split('=')
if len(tag) > 1: if len(tag) > 1:
if tag[1] != '': if tag[1] != '':
@ -87,7 +88,7 @@ def event_stream_getImportantPasteByModule(module_name, year):
else: else:
tag = tag[0] tag = tag[0]
l_tags.append(tag) l_tags.append( (tag, complete_tag) )
data = {} data = {}
data["module"] = module_name data["module"] = module_name
@ -149,6 +150,7 @@ def importantPasteByModule():
p_tags = r_serv_metadata.smembers('tag:'+path) p_tags = r_serv_metadata.smembers('tag:'+path)
l_tags = [] l_tags = []
for tag in p_tags: for tag in p_tags:
complete_tag = tag
tag = tag.split('=') tag = tag.split('=')
if len(tag) > 1: if len(tag) > 1:
if tag[1] != '': if tag[1] != '':
@ -160,7 +162,7 @@ def importantPasteByModule():
else: else:
tag = tag[0] tag = tag[0]
l_tags.append(tag) l_tags.append( (tag, complete_tag) )
paste_tags.append(l_tags) paste_tags.append(l_tags)

View file

@ -15,7 +15,9 @@
<td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}">{{ path }}</a> <td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}">{{ path }}</a>
<div> <div>
{% for tag in paste_tags[loop.index0] %} {% for tag in paste_tags[loop.index0] %}
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }} pull-left">{{ tag }}</span> <a href="{{ url_for('Tags.get_tagged_paste') }}?ltags={{ tag[1] }}">
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }} pull-left">{{ tag[0] }}</span>
</a>
{% endfor %} {% endfor %}
</div> </div>
</td> </td>
@ -97,7 +99,9 @@ function add_entries_X(to_add) {
elem_added++; elem_added++;
var tag = "" var tag = ""
for(j=0; j<feed.l_tags.length; j++) { for(j=0; j<feed.l_tags.length; j++) {
tag = tag + "<span class=\"label label-" + feed.bootstrap_label[j % 6] + " pull-left\">" + feed.l_tags[j] + "</span>" console.log(feed.l_tags[j][1])
tag = tag + "<a href=\"{{ url_for('Tags.get_tagged_paste') }}?ltags=" + feed.l_tags[j][1] + "\">"
+ "<span class=\"label label-" + feed.bootstrap_label[j % 6] + " pull-left\">" + feed.l_tags[j][0] + "</span>" + "</a>";
} }
search_table.row.add( [ search_table.row.add( [
feed.index, feed.index,

View file

@ -121,6 +121,7 @@ def search():
# Search full line # Search full line
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT) schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
print(selected_index)
ix = index.open_dir(selected_index) ix = index.open_dir(selected_index)
with ix.searcher() as searcher: with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse(" ".join(q)) query = QueryParser("content", ix.schema).parse(" ".join(q))
@ -139,6 +140,7 @@ def search():
p_tags = r_serv_metadata.smembers('tag:'+path) p_tags = r_serv_metadata.smembers('tag:'+path)
l_tags = [] l_tags = []
for tag in p_tags: for tag in p_tags:
complete_tag = tag
tag = tag.split('=') tag = tag.split('=')
if len(tag) > 1: if len(tag) > 1:
if tag[1] != '': if tag[1] != '':
@ -150,7 +152,7 @@ def search():
else: else:
tag = tag[0] tag = tag[0]
l_tags.append(tag) l_tags.append( (tag, complete_tag) )
paste_tags.append(l_tags) paste_tags.append(l_tags)
results = searcher.search(query) results = searcher.search(query)

View file

@ -100,7 +100,9 @@
<td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}">{{ path }}</a> <td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}">{{ path }}</a>
<div> <div>
{% for tag in paste_tags[loop.index0] %} {% for tag in paste_tags[loop.index0] %}
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }} pull-left">{{ tag }}</span> <a href="{{ url_for('Tags.get_tagged_paste') }}?ltags={{ tag[1] }}">
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }} pull-left">{{ tag[0] }}</span>
</a>
{% endfor %} {% endfor %}
</div> </div>
</td> </td>

View file

@ -19,6 +19,7 @@ app = Flask_config.app
cfg = Flask_config.cfg cfg = Flask_config.cfg
r_serv_pasteName = Flask_config.r_serv_pasteName r_serv_pasteName = Flask_config.r_serv_pasteName
r_serv_metadata = Flask_config.r_serv_metadata r_serv_metadata = Flask_config.r_serv_metadata
r_serv_tags = Flask_config.r_serv_tags
max_preview_char = Flask_config.max_preview_char max_preview_char = Flask_config.max_preview_char
max_preview_modal = Flask_config.max_preview_modal max_preview_modal = Flask_config.max_preview_modal
DiffMaxLineLength = Flask_config.DiffMaxLineLength DiffMaxLineLength = Flask_config.DiffMaxLineLength
@ -96,6 +97,7 @@ def showpaste(content_range):
if content_range != 0: if content_range != 0:
p_content = p_content[0:content_range] p_content = p_content[0:content_range]
#tag color
bootstrap_label = [] bootstrap_label = []
bootstrap_label.append('primary') bootstrap_label.append('primary')
bootstrap_label.append('success') bootstrap_label.append('success')
@ -104,9 +106,20 @@ def showpaste(content_range):
bootstrap_label.append('info') bootstrap_label.append('info')
bootstrap_label.append('dark') bootstrap_label.append('dark')
list_tags = r_serv_metadata.smembers('tag:'+requested_path) #active taxonomies
active_taxonomies = r_serv_tags.smembers('active_taxonomies')
return render_template("show_saved_paste.html", date=p_date, bootstrap_label=bootstrap_label, list_tags=list_tags, source=p_source, encoding=p_encoding, language=p_language, size=p_size, mime=p_mime, lineinfo=p_lineinfo, content=p_content, initsize=len(p_content), duplicate_list = p_duplicate_list, simil_list = p_simil_list, hashtype_list = p_hashtype_list, date_list=p_date_list) l_tags = r_serv_metadata.smembers('tag:'+requested_path)
list_tags = []
for tag in l_tags:
if(tag[9:28] == 'automatic-detection'):
list_tags.append( (tag, True) )
else:
list_tags.append( (tag, False) )
return render_template("show_saved_paste.html", date=p_date, bootstrap_label=bootstrap_label, active_taxonomies=active_taxonomies, list_tags=list_tags, source=p_source, encoding=p_encoding, language=p_language, size=p_size, mime=p_mime, lineinfo=p_lineinfo, content=p_content, initsize=len(p_content), duplicate_list = p_duplicate_list, simil_list = p_simil_list, hashtype_list = p_hashtype_list, date_list=p_date_list)
# ============ ROUTES ============ # ============ ROUTES ============

View file

@ -9,6 +9,8 @@
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.css') }}" rel="stylesheet" type="text/css" /> <link href="{{ url_for('static', filename='css/dataTables.bootstrap.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ url_for('static', filename='css/tags.css') }}" rel="stylesheet" type="text/css" />
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script> <script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script> <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js') }}"></script> <script src="{{ url_for('static', filename='js/jquery.dataTables.min.js') }}"></script>
@ -16,6 +18,17 @@
<script src="{{ url_for('static', filename='js/jquery.flot.js') }}"></script> <script src="{{ url_for('static', filename='js/jquery.flot.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.flot.time.js') }}"></script> <script src="{{ url_for('static', filename='js/jquery.flot.time.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.flot.stack.js') }}"></script> <script src="{{ url_for('static', filename='js/jquery.flot.stack.js') }}"></script>
<script src="{{ url_for('static', filename='js/tags.js') }}"></script>
<style>
.scrollable-menu {
height: auto;
max-height: 200px;
overflow-x: hidden;
width:100%;
}
</style>
</head> </head>
<body> <body>
<div class="panel panel-default"> <div class="panel panel-default">
@ -23,8 +36,53 @@
<h1 class="page-header" >Paste: {{ request.args.get('paste') }}</h1> <h1 class="page-header" >Paste: {{ request.args.get('paste') }}</h1>
<h2 class="page-header" > <h2 class="page-header" >
<div> <div>
<div id="mymodal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div id="mymodalcontent" class="modal-content">
<div class="modal-header" style="border-bottom: 4px solid #cccccc; background-color: #cccccc; color: #ffffff;">
<p class="heading">Edit this tag</p>
</div>
<div class="modal-body">
<div class="form-group input-group" >
<input id="ltags" style="width:850%;" type="text" name="ltags">
</div>
<div class="btn-group btn-block">
<button type="button" class="btn btn-primary dropdown-toggle btn-block" data-toggle="dropdown">Taxonomie Selection
<i class="fa fa-chevron-down"></i>
</button>
<ul class="dropdown-menu scrollable-menu" role="menu">
<li><a href="#" id="all-tags">All Tags <i class="fa fa-tags"></i></a></li>
<li role="separator" class="divider"></li>
{% for taxo in active_taxonomies %}
<li><a href="#" id="{{ taxo }}-id{{ loop.index0 }}">{{ taxo }}</a></li>
{% endfor %}
</ul>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary btn-tags" onclick="addTags()">
<span class="glyphicon glyphicon-plus"></span>
<span class="label-icon">Add Tags</span>
</button>
<button type="button" class="btn btn-default" data-dismiss="modal" >Close</button>
</div>
</div>
</div>
</div>
{% for tag in list_tags %} {% for tag in list_tags %}
<span class="btn btn-{{ bootstrap_label[loop.index0 % 6] }} btn-lg pull-left" data-toggle="modal" data-target="#myModal_{{ loop.index0 }}">{{ tag }}</span> <span class="btn btn-{{ bootstrap_label[loop.index0 % 6] }} btn-lg pull-left" data-toggle="modal" data-target="#myModal_{{ loop.index0 }}">{{ tag[0] }}</span>
<!-- Modal edit this tag --> <!-- Modal edit this tag -->
<div class="modal fade" id="myModal_{{ loop.index0 }}" role="dialog"> <div class="modal fade" id="myModal_{{ loop.index0 }}" role="dialog">
@ -36,13 +94,15 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }}" >{{ tag }}</span> <span class="label label-{{ bootstrap_label[loop.index0 % 6] }}" >{{ tag[0] }}</span>
</div> </div>
<div class="modal-footer center"> <div class="modal-footer center">
<a href="{{ url_for('Tags.confirm_tag') }}?paste={{ request.args.get('paste') }}&tag={{ tag }}" class="btn btn-primary"> {% if tag[1] %}
<a href="{{ url_for('Tags.confirm_tag') }}?paste={{ request.args.get('paste') }}&tag={{ tag[0] }}" class="btn btn-primary">
<span class="glyphicon glyphicon-ok "></span> Confirm this Tag <span class="glyphicon glyphicon-ok "></span> Confirm this Tag
</a> </a>
<a href="{{ url_for('Tags.remove_tag') }}?paste={{ request.args.get('paste') }}&tag={{ tag }}" class="btn btn-danger"> {% endif %}
<a href="{{ url_for('Tags.remove_tag') }}?paste={{ request.args.get('paste') }}&tag={{ tag[0] }}" class="btn btn-danger">
<span class="glyphicon glyphicon-trash "></span> Delete this Tag <span class="glyphicon glyphicon-trash "></span> Delete this Tag
</a> </a>
</div> </div>
@ -52,9 +112,9 @@
</div> </div>
{% endfor %} {% endfor %}
<button type="button" class="btn btn-light btn-lg" data-toggle="tooltip" title="Add Tag"> <button type="button" class="btn btn-light btn-lg" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('Tags.taxonomies') }}">
<span class="glyphicon glyphicon-plus "></span> <span class="glyphicon glyphicon-plus "></span>
</span> </button>
</div> </div>
</h2> </h2>
@ -85,12 +145,12 @@
</tbody> </tbody>
</table> </table>
<button type="button" class="btn btn-success btn-lg" data-toggle="tooltip" title="Good Detection"> <a href="{{ url_for('Tags.thumbs_up_paste') }}?paste={{ request.args.get('paste') }}" class="btn btn-success btn-lg" data-toggle="tooltip" title="Good Detection">
<span class="glyphicon glyphicon-thumbs-up "></span> <span class="glyphicon glyphicon-thumbs-up "></span>
</span> </a>
<button type="button" class="btn btn-danger btn-lg" data-toggle="tooltip" title="Bad Detection"> <a href="{{ url_for('Tags.thumbs_down_paste') }}?paste={{ request.args.get('paste') }}" class="btn btn-danger btn-lg" data-toggle="tooltip" title="Bad Detection">
<span class="glyphicon glyphicon-thumbs-down "></span> <span class="glyphicon glyphicon-thumbs-down "></span>
</span> </a>
</div> </div>
<div class="panel-body" id="panel-body"> <div class="panel-body" id="panel-body">
{% if duplicate_list|length == 0 %} {% if duplicate_list|length == 0 %}
@ -128,7 +188,54 @@
</div> </div>
</body> </body>
<script> <script>
var ltags
$(document).ready(function(){
$.getJSON('/Tags/get_all_tags_taxonomies',
function(data) {
ltags = $('#ltags').tagSuggest({
data: data,
//sortOrder: 'name',
maxDropHeight: 200,
name: 'ltags'
});
});
$('#tableDup').DataTable(); $('#tableDup').DataTable();
});
</script> </script>
<script>
jQuery("#all-tags").click(function(e){
//change input tags list /Tags/get_tags_taxonomie?taxonomie=infoleak
$.getJSON('/Tags/get_all_tags_taxonomies',
function(data) {
ltags.setData(data)
});
});
</script>
<script>
function addTags() {
var data = ltags.getValue()
var path = '{{ request.args.get('paste') }}'
window.location.replace("{{ url_for('Tags.addTags') }}?tags=" + data + "&path=" + path);
}
</script>
<script>
{% for taxo in active_taxonomies %}
jQuery("#{{ taxo }}-id{{ loop.index0 }}").click(function(e){
$.getJSON('/Tags/get_tags_taxonomie?taxonomie={{ taxo }}',
function(data) {
ltags.setData(data)
});
});
{% endfor %}
</script>
</html> </html>

View file

@ -1489,17 +1489,17 @@
})(jQuery); })(jQuery);
$(document).ready(function() { /*$(document).ready(function() {
var jsonData = []; var jsonData = [];
var fruits = 'Apple,Orange,Banana,Strawberry'.split(','); var fruits = 'Apple,Orange,Banana,Strawberry'.split(',');
//Default values //Default values
/*for(var i=0;i<fruits.length;i++) jsonData.push({id:i,name:fruits[i]}); for(var i=0;i<fruits.length;i++) jsonData.push({id:i,name:fruits[i]});
var ms1 = $('#ms1').tagSuggest({ var ms1 = $('#ms1').tagSuggest({
data: jsonData, data: jsonData,
sortOrder: 'name', sortOrder: 'name',
maxDropHeight: 200, maxDropHeight: 200,
name: 'ms1' name: 'ms1'
});*/ });
$.getJSON('/Tags/get_all_tags', $.getJSON('/Tags/get_all_tags',
function(data) { function(data) {
@ -1513,4 +1513,4 @@
name: 'ms0' name: 'ms0'
}); });
}); });
}); });*/