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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
|
--
-- (C) 2013-22 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
local if_stats = interface.getStats()
if (if_stats.has_seen_pods or if_stats.has_seen_containers) then
-- Use a different flows page
dofile(dirs.installdir .. "/scripts/lua/inc/ebpf_flows_stats.lua")
return
end
require "lua_utils"
local graph_utils = require "graph_utils"
require "flow_utils"
local page_utils = require("page_utils")
local tcp_flow_state_utils = require("tcp_flow_state_utils")
local have_nedge = ntop.isnEdge()
sendHTTPContentTypeHeader('text/html')
page_utils.set_active_menu_entry(ternary(have_nedge, page_utils.menu_entries.nedge_flows, page_utils.menu_entries.flows))
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
-- nDPI application and category
local application = _GET["application"]
local category = _GET["category"]
local hosts = _GET["hosts"]
local host = _GET["host"]
local vhost = _GET["vhost"]
local flowhosts_type = _GET["flowhosts_type"]
local ipversion = _GET["version"]
local l4proto = _GET["l4proto"]
local vlan = _GET["vlan"]
local port = _GET["port"]
local icmp_type = _GET["icmp_type"]
local icmp_code = _GET["icmp_cod"]
local dscp_filter = _GET["dscp"]
local host_pool = _GET["host_pool_id"]
local traffic_profile = _GET["traffic_profile"]
-- remote exporters address and interfaces
local deviceIP = _GET["deviceIP"]
local inIfIdx = _GET["inIfIdx"]
local outIfIdx = _GET["outIfIdx"]
local traffic_type = _GET["traffic_type"]
local alert_type = _GET["alert_type"]
local alert_type_severity = _GET["alert_type_severity"]
local tcp_state = _GET["tcp_flow_state"]
local port = _GET["port"]
local network_id = _GET["network"]
local client_asn = _GET["client_asn"]
local server_asn = _GET["server_asn"]
local prefs = ntop.getPrefs()
local ifstats = interface.getStats()
local duration_or_last_seen = prefs.flow_table_time
local begin_epoch_set = (ntop.getPref("ntopng.prefs.first_seen_set") == "1")
local flows_filter = getFlowsFilter()
flows_filter.statusFilter = nil -- remove the filter, otherwise no menu entries will be shown
local flowstats = interface.getActiveFlowsStats(host, flows_filter)
local base_url = ntop.getHttpPrefix() .. "/lua/flows_stats.lua"
local page_params = { ifid = interface.getId() }
if (page == "flows" or page == nil) then
local active_msg = getFlowsTableTitle()
page_utils.print_page_title(active_msg)
if(category ~= nil) then
page_params["category"] = category
end
if(application ~= nil) then
page_params["application"] = application
end
if(host ~= nil) then
page_params["host"] = host
end
if(port ~= nil) then
page_params["port"] = port
end
if(vhost ~= nil) then
page_params["vhost"] = vhost
end
if(hosts ~= nil) then
page_params["hosts"] = hosts
end
if(port ~= nil) then
page_params["port"] = port
end
if(ipversion ~= nil) then
page_params["version"] = ipversion
end
if(l4proto ~= nil) then
page_params["l4proto"] = l4proto
end
if(deviceIP ~= nil) then
page_params["deviceIP"] = deviceIP
end
if(inIfIdx ~= nil) then
page_params["inIfIdx"] = inIfIdx
end
if(outIfIdx ~= nil) then
page_params["outIfIdx"] = outIfIdx
end
if(vlan ~= nil) then
page_params["vlan"] = vlan
end
if(traffic_type ~= nil) then
page_params["traffic_type"] = traffic_type
end
if(alert_type ~= nil) then
page_params["alert_type"] = alert_type
end
if(alert_type_severity ~= nil) then
page_params["alert_type_severity"] = alert_type_severity
end
if(tcp_state ~= nil) then
page_params["tcp_flow_state"] = tcp_state
end
if(network_id ~= nil) then
page_params["network"] = network_id
end
if(flowhosts_type ~= nil) then
page_params["flowhosts_type"] = flowhosts_type
end
if((icmp_type ~= nil) and (icmp_code ~= nil)) then
page_params["icmp_type"] = icmp_type
page_params["icmp_cod"] = icmp_code
end
if(dscp_filter ~= nil) then
page_params["dscp"] = dscp_filter
end
if(host_pool ~= nil) then
page_params["host_pool_id"] = host_pool
end
if(traffic_profile ~= nil) then
page_params["traffic_profile"] = traffic_profile
end
if (table.len(page_params) > 0) and (not isEmptyString(page_params["application"])) then
print [[
<div class="col-12 p-1">
<div class="info-stats">
<ul class="nav-side" style="list-style-type: none;">
<li class="nav-item">
<div class="up">
<i class="fas fa-arrow-up" data-original-title="" title=""></i>
<span id="upload-filter-traffic-chart" class="line">0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</span>
<span class='d-inline-block text-end' style='width: 13ch'>
<span id="upload-filter-traffic-value">0 kbit/s</span> |
</span>
<span id="filtered-flows-tot-bytes">]] print(i18n("flows_page.tot_bytes")) print[[</span>
<span id="filtered-flows-tot-bytes-value">0 B</span>
</div>
</li>
<li class="nav-item">
<div class="down">
<i class="fas fa-arrow-down" data-original-title="" title=""></i>
<span id="download-filter-traffic-chart" class="line">0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</span>
<span class='d-inline-block text-end' style='width: 13ch'>
<span id="download-filter-traffic-value">0 kbit/s</span> |
</span>
<span id="filtered-flows-tot-throughput">]] print(i18n("flows_page.tot_throughput")) print[[</span>
<span id="filtered-flows-tot-throughput-value">0 kbit/s</span>
</div>
</li>
</ul>
</div>
</div>
]]
end
print [[
<div id="table-flows"></div>
<script>
var url_update = "]]
print(getPageUrl(ntop.getHttpPrefix().."/lua/get_flows_data.lua", page_params))
print ('";')
print [[
var table = $("#table-flows").datatable({
url: url_update ,
tableCallback: function(test_tmp) {
]] initFlowsRefreshRows() print[[
},
]]
preference = tablePreferences("rows_number",_GET["perPage"])
if (preference ~= "") then print ('perPage: '..preference.. ",\n") end
print(" title: \"")
print [[",
showFilter: true,
showPagination: true,
]]
-- Automatic default sorted. NB: the column must be exists.
print ('sort: [ ["' .. getDefaultTableSort("flows") ..'","' .. getDefaultTableSortOrder("flows").. '"] ],\n')
print ('buttons: [')
printActiveFlowsDropdown(base_url, page_params, ifstats, flowstats)
print(" ],\n")
print[[
columns: [
{
title: "",
field: "key",
hidden: true,
}, {
title: "",
field: "hash_id",
hidden: true,
}, {
title: "",
field: "column_key",
css: {
textAlign: 'center'
}
}, {
title: "]] print(i18n("application")) print[[",
field: "column_ndpi",
sortable: true,
css: {
textAlign: 'center',
whiteSpace: 'nowrap'
}
}, {
title: "]] print(i18n("protocol")) print[[",
field: "column_proto_l4",
sortable: true,
css: {
textAlign: 'center'
}
},
]]
if(ifstats.vlan) then
print [[
{
title: "]] print(i18n("vlan")) print[[",
field: "column_vlan",
sortable: true,
css: {
textAlign: 'center'
}
},
]]
end
end
print[[
{
title: "]] print(i18n("client")) print[[",
field: "column_client",
sortable: true,
css: {
whiteSpace: 'nowrap'
}
}, {
title: "]] print(i18n("server")) print[[",
field: "column_server",
sortable: true,
css: {
whiteSpace: 'nowrap'
}
},
]]
if begin_epoch_set == true then
print[[
{
title: "]] print(i18n("first_seen")) print[[",
field: "column_first_seen",
sortable: true,
css: {
whiteSpace: 'nowrap',
textAlign: 'center',
}
},
]]
end
if duration_or_last_seen == false then
print[[
{
title: "]] print(i18n("duration")) print[[",
field: "column_duration",
sortable: true,
css: {
whiteSpace: 'nowrap',
textAlign: 'center',
}
},
]]
else
print[[
{
title: "]] print(i18n("last_seen")) print[[",
field: "column_last_seen",
sortable: true,
css: {
whiteSpace: 'nowrap',
textAlign: 'center'
}
},
]]
end
print[[{
title: "]] print(i18n("score")) print[[",
field: "column_score",
hidden: ]] print(ternary(isScoreEnabled(), "false", "true")) print[[,
sortable: true,
css: {
textAlign: 'center'
}
}, {
title: "]] print(i18n("breakdown")) print[[",
field: "column_breakdown",
sortable: false,
css: {
textAlign: 'center'
}
}, {
title: "]] print(i18n("flows_page.actual_throughput")) print[[",
field: "column_thpt",
sortable: true,
css: {
textAlign: 'right',
whiteSpace: 'nowrap'
}
}, {
title: "]] print(i18n("flows_page.total_bytes")) print[[",
field: "column_bytes",
sortable: true,
css: {
textAlign: 'right',
whiteSpace: 'nowrap'
}
}, {
title: "]] print(i18n("info")) print[[",
field: "column_info",
sortable: false,
css: {
textAlign: 'left',
whiteSpace: 'nowrap'
}
}
]
});
]]
if(have_nedge) then
printBlockFlowJs()
end
print[[
</script>
]]
if (table.len(page_params) > 0) and (not isEmptyString(page_params["application"])) then
print([[
<script type='text/javascript'>
let old_totBytesSent = 0;
let old_totBytesRcvd = 0;
let refresh_rate = 5; /* seconds */
$(document).ready(function() {
const downloadChart = $("#download-filter-traffic-chart").peity("line", { width: 64, fill: "lightgreen" });
const uploadChart = $("#upload-filter-traffic-chart").peity("line", { width: 64 });
function pushNewValue(chart, newValue) {
const values = chart.text().split(",");
values.shift();
values.push(newValue);
chart
.text(values.join(","))
.change()
}
function updateChart() {
const request = $.get("]] .. getPageUrl(ntop.getHttpPrefix() .. "/lua/rest/v2/get/flow/traffic_stats.lua", page_params) .. "&ifid=" .. interface.getId() .. [[");
request.then((data) => {
let throughput_bps_sent = (8 * (data.rsp.totBytesSent - old_totBytesSent)) / refresh_rate;
let throughput_bps_rcvd = (8 * (data.rsp.totBytesRcvd - old_totBytesRcvd)) / refresh_rate;
let tot_throughput = (8 * data.rsp.totThpt);
if (tot_throughput < 0) tot_throughput = 0;
if (throughput_bps_sent < 0) throughput_bps_sent = 0;
if (throughput_bps_rcvd < 0) throughput_bps_rcvd = 0;
if ((old_totBytesSent > 0) || (old_totBytesRcvd > 0)) {
/* Second iteration or later */
pushNewValue(downloadChart, -throughput_bps_rcvd);
pushNewValue(uploadChart, throughput_bps_sent);
$('#download-filter-traffic-value').html(NtopUtils.bitsToSize(throughput_bps_rcvd, 1000));
$('#upload-filter-traffic-value').html(NtopUtils.bitsToSize(throughput_bps_sent, 1000));
}
/* Keep the old value for computing the differnce at the next round */
old_totBytesSent = data.rsp.totBytesSent;
old_totBytesRcvd = data.rsp.totBytesRcvd;
$('#filtered-flows-tot-bytes-value').html(NtopUtils.bytesToSize(old_totBytesSent + old_totBytesRcvd));
$('#filtered-flows-tot-throughput-value').html(NtopUtils.bitsToSize(tot_throughput, 1000));
})
}
setInterval(() => { updateChart() }, refresh_rate*1000);
updateChart();
})
</script>
]])
end
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|