chg: use json to submit hash

pull/237/head
Terrtia 2018-07-17 14:23:49 +02:00
parent 412b012ddf
commit d9c924c38d
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
5 changed files with 111 additions and 56 deletions

View File

@ -179,13 +179,18 @@ def base64Decoded_page():
if r_serv_metadata.hexists('metadata_hash:'+hash, 'vt_link'):
b64_vt = True
b64_vt_link = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_link')
b64_vt_report = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_report')
else:
b64_vt = False
b64_vt_link = ''
b64_vt_report = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_report')
# hash never refreshed
if b64_vt_report is None:
b64_vt_report = ''
sparklines_value = list_sparkline_values(date_range_sparkline, hash)
b64_metadata.append( (file_icon, estimated_type, hash, nb_seen_in_paste, size, first_seen, last_seen, b64_vt, b64_vt_link, sparklines_value) )
b64_metadata.append( (file_icon, estimated_type, hash, nb_seen_in_paste, size, first_seen, last_seen, b64_vt, b64_vt_link, b64_vt_report, sparklines_value) )
l_type = r_serv_metadata.smembers('hash_all_type')
@ -229,9 +234,21 @@ def showHash():
date_range_sparkline = get_date_range(num_day_type)
sparkline_values = list_sparkline_values(date_range_sparkline, hash)
print(sparkline_values)
if r_serv_metadata.hexists('metadata_hash:'+hash, 'vt_link'):
b64_vt = True
b64_vt_link = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_link')
b64_vt_report = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_report')
else:
b64_vt = False
b64_vt_link = ''
b64_vt_report = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_report')
# hash never refreshed
if b64_vt_report is None:
b64_vt_report = ''
return render_template('showHash.html', hash=hash, size=size, estimated_type=estimated_type, file_icon=file_icon,
return render_template('showHash.html', hash=hash, vt_enabled=vt_enabled, b64_vt=b64_vt, b64_vt_link=b64_vt_link,
b64_vt_report=b64_vt_report,
size=size, estimated_type=estimated_type, file_icon=file_icon,
first_seen=first_seen,
last_seen=last_seen, nb_seen_in_all_pastes=nb_seen_in_all_pastes, sparkline_values=sparkline_values)
@ -411,10 +428,9 @@ def base64_types():
date_to = 20180706
return render_template('base64_types.html', date_from=date_from, date_to=date_to)
@base64Decoded.route('/base64Decoded/send_file_to_vt', methods=['POST'])
def send_file_to_vt():
paste = request.form['paste']
hash = request.form['hash']
@base64Decoded.route('/base64Decoded/send_file_to_vt_js')
def send_file_to_vt_js():
hash = request.args.get('hash')
b64_path = r_serv_metadata.hget('metadata_hash:'+hash, 'saved_path')
b64_full_path = os.path.join(os.environ['AIL_HOME'], b64_path)
@ -427,11 +443,13 @@ def send_file_to_vt():
json_response = response.json()
print(json_response)
vt_b64_link = json_response['permalink'].split('analysis')[0] + 'analysis/'
r_serv_metadata.hset('metadata_hash:'+hash, 'vt_link', vt_b64_link)
b64_vt_report = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_report', '')
vt_link = json_response['permalink'].split('analysis')[0] + 'analysis/'
r_serv_metadata.hset('metadata_hash:'+hash, 'vt_link', vt_link)
vt_report = 'Please Refresh'
r_serv_metadata.hset('metadata_hash:'+hash, 'vt_report', vt_report)
return jsonify({'vt_link': vt_link, 'vt_report': vt_report})
return redirect(url_for('showsavedpastes.showsavedpaste', paste=paste))
@base64Decoded.route('/base64Decoded/update_vt_result')
def update_vt_result():

View File

@ -139,21 +139,21 @@
<td style="text-align:center;max-width:150px;">
{% if vt_enabled %}
{% if not b64[7] %}
<form action="/base64Decoded/send_file_to_vt" id="vt_submit" method='post'>
<input type="hidden" id="hash" name="hash" value="b64[2]">
<button class="btn btn-primary">
<i class="fa fa-paper-plane"></i> Send this file to VT
<darkbutton_{{ b64[2] }}>
<button id="submit_vt_{{ b64[2] }}" class="btn btn-primary" onclick="sendFileToVT('{{ b64[2] }}')">
<i class="fa fa-paper-plane"></i>&nbsp;Send this file to VT
</button>
</form>
</darkbutton_{{ b64[2] }}>
{% else %}
<a class="btn btn-default" target="_blank" href="{{ b64[8] }}"><i class="fa fa-link"> VT scan reports</i></a>
<a class="btn btn-primary" target="_blank" href="{{ b64[8] }}"><i class="fa fa-link"> VT Report</i></a>
{% endif %}
<button class="btn btn-default" onclick="updateVTReport('{{ b64[2] }}')">
<div id="report_vt_{{ b64[2] }}"><span class="glyphicon glyphicon-refresh"></span>&nbsp;{{ b64[8] }}</div>
</button>
<div id="report_vt_{{ b64[2] }}"><span class="glyphicon glyphicon-refresh"></span>&nbsp;{{ b64[9] }}</div>
</button>
{% else %}
Virus Total submission is disabled
{% endif %}
</td>
<td id="sparklines_{{ b64[2] }}" style="text-align:center;">
</td>
@ -240,6 +240,15 @@
});
}
function sendFileToVT(hash) {
//send file to vt
$.getJSON('/base64Decoded/send_file_to_vt_js?hash='+hash,
function(data) {
var content = '<a id="submit_vt_'+hash+'" class="btn btn-primary" target="_blank" href="'+ data['vt_link'] +'"><i class="fa fa-link"> '+ ' VT Report' +'</i></a>';
$('#submit_vt_'+hash).remove();
$('darkbutton_'+hash).append(content);
});
}
</script>
<script>
//var data = [6,3,3,2,5,3,9];
@ -280,7 +289,7 @@ function sparklines(id, points) {
</script>
<script>
{% for b64 in l_64 %}
sparklines("sparklines_{{ b64[2] }}", {{ b64[9] }})
sparklines("sparklines_{{ b64[2] }}", {{ b64[10] }})
{% endfor %}
</script>

View File

@ -131,10 +131,26 @@
<div class="col-md-1">
<div id="sparkline"></div>
</div>
</div>
</li></ul>
{% if vt_enabled %}
{% if not b64_vt %}
<darkbutton>
<button id="submit_vt_b" class="btn btn-primary" onclick="sendFileToVT('{{ hash }}')">
<i class="fa fa-paper-plane"></i>&nbsp;Send this file to VT
</button>
</darkbutton>
{% else %}
<a class="btn btn-primary" target="_blank" href="{{ b64_vt_link }}"><i class="fa fa-link"> VT Report</i></a>
{% endif %}
<button class="btn btn-default" onclick="updateVTReport('{{ hash }}')">
<div id="report_vt_b"><span class="glyphicon glyphicon-refresh"></span>&nbsp;{{ b64_vt_report }}</div>
</button>
{% else %}
Virus Total submission is disabled
{% endif %}
</div></div>
<div class="row">
@ -166,7 +182,7 @@
<div class="panel panel-default">
<div class="panel-heading">
<i id="flash-tld" class="glyphicon glyphicon-flash " flash-tld=""></i> Graph
<i id="flash-tld" class="glyphicon glyphicon-stats" flash-tld=""></i> Graph
</div>
<div class="panel-body ">
<div id="graph_line">
@ -196,12 +212,22 @@
});
</script>
<script>
function sendFileToVT(hash) {
//send file to vt
$.getJSON('/base64Decoded/send_file_to_vt_js?hash='+hash,
function(data) {
var content = '<a id="submit_vt_b" class="btn btn-primary" target="_blank" href="'+ data['vt_link'] +'"><i class="fa fa-link"> '+ ' VT Report' +'</i></a>';
$('#submit_vt_b').remove();
$('darkbutton').append(content);
});
}
function updateVTReport(hash) {
//updateReport
$.getJSON('/base64Decoded/update_vt_result?hash='+hash,
function(data) {
content = '<span class="glyphicon glyphicon-refresh"></span> ' +data['report_vt']
$( "#report_vt_"+hash ).html(content);
var content = '<span class="glyphicon glyphicon-refresh"></span> ' +data['report_vt'];
$( "#report_vt_b" ).html(content);
});
}
@ -448,8 +474,6 @@ function create_line_chart(id, url){
var margin = {top: 20, right: 55, bottom: 50, left: 40};
var x = d3.scaleTime().range([0, width]);
//var x = d3.scaleBand().rangeRound([0, width]);
//var x = d3.scaleLinear().rangeRound([0, width]);
var y = d3.scaleLinear().rangeRound([height, 0]);
var xAxis = d3.axisBottom(x);
@ -481,15 +505,9 @@ d3.json(url)
.then(function(data){
data.forEach(function(d) {
d.date_label = d.date;
d.date = parseTime(d.date);
//d.date = d['date']; // not usefull ?
d.value = +d.value;
/*d.mapping = varNames.map(function (name) {
return {
y1: y0 += +d[value],
label: d['date']
};
});*/
});
// fit the data
@ -515,7 +533,7 @@ d3.json(url)
svg_line.append("g")
.call(d3.axisLeft(y));
//add a dot at each data point to which hover behaviour can be attached
//add a dot circle
svg_line.selectAll('dot')
.data(data).enter()
.append('circle')
@ -525,8 +543,9 @@ d3.json(url)
.on('mouseover', function(d) {
div.transition().style('opacity', .9);
div.html('' + d.value + '<br/>' + d.date).style('left', (d3.event.pageX) + 'px')
.style('top', (d3.event.pageY) + 'px');
div.html('' + d.date_label+ '<br/>' + d.value).style('left', (d3.event.pageX) + 'px')
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on('mouseout', function(d)
{

View File

@ -156,11 +156,14 @@ def showpaste(content_range, requested_path):
if r_serv_metadata.hexists('metadata_hash:'+hash, 'vt_link'):
b64_vt = True
b64_vt_link = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_link')
print(b64_vt_report)
b64_vt_report = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_report')
else:
b64_vt = False
b64_vt_link = ''
b64_vt_report = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_report')
b64_vt_report = r_serv_metadata.hget('metadata_hash:'+hash, 'vt_report')
# hash never refreshed
if b64_vt_report is None:
b64_vt_report = ''
l_64.append( (file_icon, estimated_type, hash, saved_path, nb_in_file, b64_vt, b64_vt_link, b64_vt_report) )

View File

@ -398,21 +398,17 @@
<td style="text-align:center;">
{% if vt_enabled %}
{% if not b64[5] %}
<form action="/base64Decoded/send_file_to_vt" id="vt_submit" method='post'>
<input type="hidden" id="hash" name="hash" value="{{ b64[2] }}">
<input type="hidden" id="paste" name="paste" value="{{ request.args.get('paste') }}">
<button class="btn btn-primary">
<i class="fa fa-paper-plane"></i> Send this file to VT
<darkbutton_{{ b64[2] }}>
<button id="submit_vt_{{ b64[2] }}" class="btn btn-primary" onclick="sendFileToVT('{{ b64[2] }}')">
<i class="fa fa-paper-plane"></i>&nbsp;Send this file to VT
</button>
</form>
</darkbutton_{{ b64[2] }}>
{% else %}
<a class="btn btn-default" target="_blank" href="{{ b64[6] }}"><i class="fa fa-link"> VT scan reports</i></a>
<a class="btn btn-primary" target="_blank" href="{{ b64[6] }}"><i class="fa fa-link"> VT Report</i></a>
{% endif %}
<button class="btn btn-default" onclick="updateVTReport('{{ b64[2] }}')">
<div id="report_vt_{{ b64[2] }}"><span class="glyphicon glyphicon-refresh"></span>&nbsp;{{ b64[7] }}</div>
</button>
</button>
{% else %}
Virus Total submission is disabled
{% endif %}
@ -466,14 +462,24 @@
</script>
<script>
function updateVTReport(hash) {
//updateReport
$.getJSON('/base64Decoded/update_vt_result?hash='+hash,
function(data) {
content = '<span class="glyphicon glyphicon-refresh"></span> ' +data['report_vt']
$( "#report_vt_"+hash ).html(content);
});
}
function updateVTReport(hash) {
//updateReport
$.getJSON('/base64Decoded/update_vt_result?hash='+hash,
function(data) {
content = '<span class="glyphicon glyphicon-refresh"></span> ' +data['report_vt']
$( "#report_vt_"+hash ).html(content);
});
}
function sendFileToVT(hash) {
//send file to vt
$.getJSON('/base64Decoded/send_file_to_vt_js?hash='+hash,
function(data) {
var content = '<a id="submit_vt_'+hash+'" class="btn btn-primary" target="_blank" href="'+ data['vt_link'] +'"><i class="fa fa-link"> '+ ' VT Report' +'</i></a>';
$('#submit_vt_'+hash).remove();
$('darkbutton_'+hash).append(content);
});
}
</script>