Merge branch 'MichaelDeciso-feature/2287-bis'

This commit is contained in:
Ad Schellevis 2018-12-22 17:04:39 +01:00
commit fb80a8c0ef

View File

@ -27,23 +27,66 @@ POSSIBILITY OF SUCH DAMAGE.
#}
<script>
'use strict';
$( document ).ready(function() {
var field_type_icons = {'pass': 'fa-play', 'block': 'fa-ban', 'in': 'fa-arrow-right', 'out': 'fa-arrow-left', 'rdr': 'fa-exchange' }
var interface_descriptions = {};
function fetch_log(){
let hostnameMap = {};
/**
* reverse lookup address fields (replace adres part for hostname if found)
*/
function reverse_lookup() {
let to_fetch = [];
$(".address").each(function(){
let address = $(this).data('address')
if (!hostnameMap.hasOwnProperty(address) && !to_fetch.includes(address)) {
to_fetch.push(address);
}
});
let update_grid = function() {
$(".address").each(function(){
if (hostnameMap.hasOwnProperty($(this).data('address'))) {
$(this).text($(this).text().replace(
$(this).data('address'),
hostnameMap[$(this).data('address')]
));
$(this).removeClass('address');
}
});
}
if (to_fetch.length > 0) {
ajaxGet('/api/diagnostics/dns/reverse_lookup', { 'address': to_fetch }, function(data, status) {
$.each(to_fetch, function(index, address) {
if (!data.hasOwnProperty(address) || data[address] === undefined) {
hostnameMap[address] = address;
} else {
hostnameMap[address] = data[address];
}
});
update_grid();
});
} else {
update_grid();
}
}
function fetch_log() {
var record_spec = [];
// read heading, contains field specs
$("#grid-log > thead > tr > th ").each(function(){
record_spec.push({'column-id': $(this).data('column-id'),
'type': $(this).data('type'),
'class': $(this).attr('class')
});
$("#grid-log > thead > tr > th ").each(function () {
record_spec.push({
'column-id': $(this).data('column-id'),
'type': $(this).data('type'),
'class': $(this).attr('class')
});
});
// read last digest (record hash) from top data row
var last_digest = $("#grid-log > tbody > tr:first > td:first").text();
// fetch new log lines and add on top of grid-log
ajaxGet('/api/diagnostics/firewall/log/', {'digest': last_digest, 'limit': $("#limit").val()}, function(data, status) {
if (data != undefined && data.length > 0) {
if (data !== undefined && data.length > 0) {
let record;
while ((record = data.pop()) != null) {
if (record['__digest__'] != last_digest) {
@ -70,7 +113,9 @@ POSSIBILITY OF SUCH DAMAGE.
break;
case 'address':
log_td.text(record[column_name]);
if (record[column_name+'port'] != undefined) {
log_td.addClass('address');
log_td.data('address', record[column_name]);
if (record[column_name+'port'] !== undefined) {
if (record['version'] == 6) {
log_td.text('['+log_td.text()+']:'+record[column_name+'port']);
} else {
@ -186,9 +231,13 @@ POSSIBILITY OF SUCH DAMAGE.
}]
});
});
// reverse lookup when selected
if ($('#dolookup').is(':checked')) {
reverse_lookup();
}
}
});
};
}
// live filter
$("#filter").keyup(function(){
@ -203,14 +252,14 @@ POSSIBILITY OF SUCH DAMAGE.
selected_tr.hide();
}
} catch(e) {
null; // ignore regexp errors
// ignore regexp errors
}
});
});
// reset log content on limit change, forces a reload
$("#limit").change(function(){
$("#grid-log > tbody").html("<tr/>");
$('#grid-log > tbody').html("<tr></tr>");
});
function poller() {
@ -227,7 +276,6 @@ POSSIBILITY OF SUCH DAMAGE.
// startup poller
poller();
});
</script>
<style>
@ -264,6 +312,11 @@ POSSIBILITY OF SUCH DAMAGE.
<input id="auto_refresh" type="checkbox" checked="checked">
<span class="fa fa-refresh"></span> {{ lang._('Auto refresh') }}
</label>
<br/>
<label>
<input id="dolookup" type="checkbox">
<span class="fa fa-search"></span> {{ lang._('Lookup hostnames') }}
</label>
</div>
<select id="limit" class="selectpicker pull-right" data-width="100" >
<option value="25" selected="selected">25</option>
@ -295,7 +348,7 @@ POSSIBILITY OF SUCH DAMAGE.
</tr>
</thead>
<tbody>
<tr/>
<tr></tr>
</tbody>
</table>
<br/>