add to pool shortcut for interface and local network (#4093)

This commit is contained in:
gabryon99 2020-10-16 18:02:22 +02:00
parent 4608c52596
commit d9bba4b4b2
4 changed files with 75 additions and 1 deletions

View file

@ -20,6 +20,9 @@ local format_utils = require "format_utils"
local top_talkers_utils = require "top_talkers_utils"
local internals_utils = require "internals_utils"
local page_utils = require("page_utils")
local ui_utils = require("ui_utils")
local interface_pools = require ("interface_pools")
require "lua_utils"
require "prefs_utils"
@ -31,6 +34,7 @@ local recording_utils = require "recording_utils"
local companion_interface_utils = require "companion_interface_utils"
local storage_utils = require "storage_utils"
local have_nedge = ntop.isnEdge()
if ntop.isPro() then
@ -1411,6 +1415,7 @@ elseif(page == "config") then
return
end
local interface_pools_instance = interface_pools:create()
local messages = {}
-- Flow dump check
@ -1434,6 +1439,13 @@ elseif(page == "config") then
end
end
if _SERVER["REQUEST_METHOD"] == "POST" then
-- bind interface to pool
if (_POST["pool"]) then
interface_pools_instance:bind_member(ifid, tonumber(_POST["pool"]))
end
end
if not table.empty(messages) then
printMessageBanners(messages)
print("<br>")
@ -1460,6 +1472,16 @@ elseif(page == "config") then
</td>
</tr>]]
-- Interface Pool
print([[
<tr>
<th>]].. i18n("pools.pool") ..[[</th>
<td>
]].. ui_utils.render_pools_dropdown(interface_pools_instance, ifid, "interface") ..[[
</td>
</tr>
]])
-- Interface speed
if not have_nedge then
print[[

View file

@ -17,7 +17,7 @@ end
function ui_utils.render_notes(notes_items)
if notes_items == nil then
traceError(TRACE_ERROR, TRACE_DEBUG, "The notes table is nil!")
traceError(TRACE_DEBUG, TRACE_CONSOLE, "The notes table is nil!")
return ""
end
@ -26,6 +26,30 @@ function ui_utils.render_notes(notes_items)
})
end
function ui_utils.render_pools_dropdown(pools_instance, member, key)
if (pools_instance == nil) then
traceError(TRACE_DEBUG, TRACE_CONSOLE, "The pools instance is nil!")
return ""
end
if (member == nil) then
traceError(TRACE_DEBUG, TRACE_CONSOLE, "The member is nil!")
return ""
end
local selected_pool = pools_instance:get_pool_by_member(member)
local selected_pool_id = selected_pool and selected_pool.pool_id or pools_instance.DEFAULT_POOL_ID
local all_pools = pools_instance:get_all_pools()
return template_utils.gen("pages/components/pool-select.template", {
pools = all_pools,
selected_pool_id = selected_pool_id,
key = key,
})
end
function ui_utils.create_navbar_title(title, subpage, title_link)
if isEmptyString(subpage) then return title end

View file

@ -15,6 +15,8 @@ local graph_utils = require "graph_utils"
local alert_utils = require "alert_utils"
local page_utils = require("page_utils")
local ts_utils = require("ts_utils")
local ui_utils = require("ui_utils")
local local_network_pools = require ("local_network_pools")
local network = _GET["network"]
local network_name = _GET["network_cidr"]
@ -110,6 +112,8 @@ elseif (page == "config") then
return
end
local local_network_pools_instance = local_network_pools:create()
print[[
<form id="network_config" class="form-inline" style="margin-bottom: 0px;" method="post">
<input id="csrf" name="csrf" type="hidden" value="]] print(ntop.getRandomCSRFValue()) print[["/>
@ -118,6 +122,10 @@ elseif (page == "config") then
if _SERVER["REQUEST_METHOD"] == "POST" then
setLocalNetworkAlias(network_name, _POST["custom_name"])
custom_name = getLocalNetworkAlias(network_name)
-- bind local network to pool
if (_POST["pool"]) then
local_network_pools_instance:bind_member(network_name, tonumber(_POST["pool"]))
end
end
print [[<tr>
@ -127,6 +135,16 @@ elseif (page == "config") then
</td>
</tr>]]
-- Local Network Pool
print([[
<tr>
<th>]].. i18n("pools.pool") ..[[</th>
<td>
]].. ui_utils.render_pools_dropdown(local_network_pools_instance, network_name,"local_network") ..[[
</td>
</tr>
]])
print[[
</table>
<button class="btn btn-primary" style="float:right; margin-right:1em; margin-left: auto" disabled="disabled" type="submit">]] print(i18n("save_settings")) print[[</button><br><br>