1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
--
-- (C) 2014-22 - ntop.org
--
local live_traffic_utils = {}
function live_traffic_utils.printLiveTrafficForm(ifid, host_info)
local has_vlan = (host_info and (tonumber(host_info["vlan"]) or 0) > 0)
if has_vlan then
local template = require "template_utils"
print(
template.gen("modal_confirm_dialog.html", {
dialog = {
id = "live_traffic_download_modal",
action = "live_traffic_download_submit()",
title = i18n("live_traffic.modal_vlan_tagged_with_bpf_title"),
message = i18n("live_traffic.modal_vlan_tagged_with_bpf_confirmation",
{vlan = host_info["vlan"]}),
confirm = i18n("live_traffic.modal_vlan_tagged_with_bpf_continue")
}
})
)
end
print[[
<form id="live-capture-form" class="form-inline" action="]] print(ntop.getHttpPrefix().."/lua/rest/v2/get/pcap/live_traffic.lua") print [[" method="GET">
<input type=hidden id="live-capture-ifid" name=ifid value="]] print(ifid.."") print [[">]]
if host_info then
print[[<input type=hidden id="live-capture-host" name=host value="]] print(hostinfo2hostkey(host_info)) print [[">]]
end
print[[
<div class="input-group mb-1">
<select class="btn border bg-white" id="duration" name=duration>
<option value=10>10 sec</option>
<option value=30>30 sec</option>
<option value=60 selected>1 min</option>
<option value=300>5 min</option>
<option value=600>10 min</option>
</select>
<label for="bpf_filter" class="sr-only">]] print(i18n("db_explorer.filter_bpf")) print[[</label>
<input type="text" class="form-control" id="live-capture-bpf-filter" name="bpf_filter" placeholder="]] print(i18n("db_explorer.filter_bpf")) print[["></input>
<button type="submit" class="btn btn-secondary" onclick="return live_capture_download_show_modal();">]] print(i18n("download_x", {what="pcap"})) print[[</button>
</div>
</form>
<script type='text/javascript'>
var live_capture_download_show_modal = function() {
let input = $('#live-capture-bpf-filter');
let valid = bpfValidator(input, true);
if (!valid) {
input.css('border-color', 'red');
return false; /* Invalif filter */
} else {
input.css('border-color', '');
}
]]
if not has_vlan then
print[[
/* resume submit */
return true;
};
]]
else
print[[
if($('#live-capture-bpf-filter').val() == '' ||
$('#live-capture-bpf-filter').val().includes('vlan')) {
/* Resume submit, nothing to show (the user didn't specify any BPF or VLAN is specified) */
return true;
}
$('#live_traffic_download_modal').modal('show');
/* Abort submit */
return false;
};
var live_traffic_download_submit = function() {
/* Now it's time to do the actual submit... */
$('#live_traffic_download_modal').modal('hide');
$('#live-capture-form').submit();
};
]]
end
print[[
</script>
]]
end
return live_traffic_utils
|