--
-- (C) 2017-26 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" ..
package.path
if (ntop.isPro and ntop.isPro()) then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" ..
package.path
local snmp_utils = require "snmp_utils"
shaper_utils = require "shaper_utils"
end
require "lua_utils"
local graph_utils = require "graph_utils"
local alert_utils = require "alert_utils"
local page_utils = require("page_utils")
local host_pools_nedge
if ntop.isnEdge and ntop.isnEdge() then host_pools_nedge = require "host_pools_nedge" end
local host_pools = require "host_pools"
-- Instantiate host pools
local host_pools_instance = host_pools:create()
local template = require "template_utils"
local have_nedge = ntop.isnEdge and ntop.isnEdge()
local pool_id = _GET["pool"]
local page = _GET["page"] or "historical"
if (not (ntop.isPro and ntop.isPro())) then return end
if ifname == "__system__" then
-- Someone jumped from the users to the quotas in the System interface, redirect to a Network interface (e.g. nf:0)
local available_interfaces = interface.getIfNames()
ifname = available_interfaces["0"]
end
interface.select(ifname)
local ifstats = interface.getStats()
local ifId = ifstats.id
local pool_name = host_pools_instance:get_pool_name(pool_id)
if ntop.isnEdge and ntop.isnEdge() then
if _POST["reset_quotas"] ~= nil then
host_pools_nedge.resetPoolsQuotas(tonumber(pool_id))
end
end
sendHTTPContentTypeHeader('text/html')
page_utils.print_header_and_set_active_menu_entry(
page_utils.menu_entries.host_pools)
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
if (pool_id == nil) then
print(
"
")
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
return
end
local base_url = ntop.getHttpPrefix() .. '/lua/pool_details.lua?pool=' ..
pool_id
local page_params = {}
page_params["ifid"] = ifId
page_params["pool"] = pool_id
page_params["page"] = page
local title =
i18n(ternary(have_nedge, "nedge.user", "pool_details.host_pool")) .. ": " ..
pool_name
page_utils.print_navbar(title, base_url, {
{
active = page == "historical" or not page,
page_name = "historical",
label = ""
}, {
hidden = not (ntop.isEnterpriseM and ntop.isEnterpriseM()) or not (ntop.isnEdge and ntop.isnEdge()) or not ifstats or
pool_id == host_pools_instance.DEFAULT_POOL_ID,
active = page == "quotas",
page_name = "quotas",
label = i18n("quotas")
}
})
local pools_stats = interface.getHostPoolsStats()
local pool_stats = pools_stats and pools_stats[tonumber(pool_id)]
if (ntop.isEnterpriseM and ntop.isEnterpriseM() or ntop.isnEdge and ntop.isnEdge()) and pool_id ~=
host_pools_instance.DEFAULT_POOL_ID and ifstats.inline and
(page == "quotas") and (pool_stats ~= nil) then
print(template.gen("modal_confirm_dialog.html", {
dialog = {
id = "reset_quotas_dialog",
action = "$('#reset_quotas_form').submit()",
title = i18n("host_pools.reset_quotas"),
message = i18n("host_pools.confirm_reset_pool_quotas",
{pool = pool_name}),
confirm = i18n("host_pools.reset_quotas")
}
}))
print [[]]
host_pools_nedge.printQuotas(pool_id, nil, page_params)
print [[
]]
if ntop.isnEdge and ntop.isnEdge() then
local username = host_pools_nedge.poolIdToUsername(pool_id)
print [[]]
end
print [[
]]
elseif page == "historical" then
local source_value_object = {
pool = tonumber(pool_id),
ifid = interface.getId()
}
graph_utils.drawNewGraphs(source_value_object)
end
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")