mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
using 'unknown' presets as default, added also 'unknown' to the editor
This commit is contained in:
parent
2ac9e5406c
commit
9f77e758f0
4 changed files with 197 additions and 32 deletions
168
scripts/lua/admin/get_device_protocols.lua
Normal file
168
scripts/lua/admin/get_device_protocols.lua
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
--
|
||||
-- (C) 2013-18 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/pro/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
||||
local presets_utils = require "presets_utils"
|
||||
local json = require("dkjson")
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
-- ################################################
|
||||
-- Table parameters
|
||||
local currentPage = _GET["currentPage"]
|
||||
local perPage = _GET["perPage"]
|
||||
local sortColumn = _GET["sortColumn"]
|
||||
local sortOrder = _GET["sortOrder"]
|
||||
|
||||
local device_type = _GET["device_type"]
|
||||
local policy_filter = _GET["policy_filter"]
|
||||
local proto_filter = _GET["l7proto"]
|
||||
|
||||
-- ################################################
|
||||
-- Sorting and Pagination
|
||||
|
||||
local sortPrefs = "nf_device_protocols"
|
||||
|
||||
if isEmptyString(sortColumn) or sortColumn == "column_" then
|
||||
sortColumn = getDefaultTableSort(sortPrefs)
|
||||
else
|
||||
if((sortColumn ~= "column_")
|
||||
and (sortColumn ~= "")) then
|
||||
tablePreferences("sort_"..sortPrefs, sortColumn)
|
||||
end
|
||||
end
|
||||
|
||||
if isEmptyString(_GET["sortColumn"]) then
|
||||
sortOrder = getDefaultTableSortOrder(sortPrefs, true)
|
||||
end
|
||||
|
||||
if((_GET["sortColumn"] ~= "column_")
|
||||
and (_GET["sortColumn"] ~= "")) then
|
||||
tablePreferences("sort_order_"..sortPrefs, sortOrder, true)
|
||||
end
|
||||
|
||||
if(currentPage == nil) then
|
||||
currentPage = 1
|
||||
else
|
||||
currentPage = tonumber(currentPage)
|
||||
end
|
||||
|
||||
if(perPage == nil) then
|
||||
perPage = 10
|
||||
else
|
||||
perPage = tonumber(perPage)
|
||||
tablePreferences("rows_number_policies", perPage)
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
interface.select(ifname)
|
||||
|
||||
local to_skip = (currentPage-1) * perPage
|
||||
|
||||
if(sortOrder == "desc") then sOrder = rev_insensitive else sOrder = asc_insensitive end
|
||||
|
||||
local device_policies = presets_utils.getDevicePolicies(device_type)
|
||||
|
||||
local function matchesPolicyFilter(item_name)
|
||||
if isEmptyString(policy_filter) then
|
||||
return true
|
||||
end
|
||||
|
||||
local policy = device_policies[item_name]
|
||||
if policy == nil then
|
||||
if policy_filter ~= presets_utils.DEFAULT_ACTION then -- != default
|
||||
return false
|
||||
end
|
||||
elseif policy_filter ~= policy.clientActionId and policy_filter ~= policy.serverActionId then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function matchesProtoFilter(item_id)
|
||||
if isEmptyString(proto_filter) then
|
||||
return true
|
||||
end
|
||||
|
||||
return proto_filter == item_id
|
||||
end
|
||||
|
||||
local items = {}
|
||||
local sorter = {}
|
||||
local num_items = 0
|
||||
|
||||
items = interface.getnDPIProtocols(nil, true)
|
||||
|
||||
for item_name, item_id in pairs(items) do
|
||||
if not matchesProtoFilter(item_id) or not matchesPolicyFilter(item_name) then
|
||||
goto continue
|
||||
end
|
||||
|
||||
items[item_name] = { name = item_name, id = item_id, conf = device_policies[item_name] }
|
||||
num_items = num_items + 1
|
||||
|
||||
if sortColumn == "column_" or sortColumn == "column_ndpi_application" then
|
||||
sorter[item_name] = item_name
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
|
||||
local res_formatted = {}
|
||||
local cur_num = 0
|
||||
for sorted_item, _ in pairsByValues(sorter, sOrder) do
|
||||
cur_num = cur_num + 1
|
||||
if cur_num <= to_skip then
|
||||
goto continue
|
||||
elseif cur_num > to_skip + perPage then
|
||||
break
|
||||
end
|
||||
|
||||
local record = {}
|
||||
|
||||
record["column_ndpi_application_id"] = tostring(items[sorted_item]["id"])
|
||||
record["column_ndpi_application"] = tostring(items[sorted_item]["name"])
|
||||
|
||||
local field_id = items[sorted_item]["id"]
|
||||
|
||||
local cr = ''
|
||||
local sr = ''
|
||||
local conf = items[sorted_item]["conf"]
|
||||
for _, action in ipairs(presets_utils.actions) do
|
||||
local checked = ''
|
||||
if ((conf == nil or conf.clientActionId == nil) and action.id == presets_utils.DEFAULT_ACTION) or
|
||||
((conf ~= nil and conf.clientActionId ~= nil) and conf.clientActionId == action.id) then
|
||||
checked = 'checked'
|
||||
end
|
||||
cr = cr..'<label class="radio-inline"><input type="radio" name="'..field_id..'_client_action" value="'..action.id..'" '..checked..'><span style="font-size: 16px;">'..action.icon..'</span></label>'
|
||||
|
||||
checked = ''
|
||||
if ((conf == nil or conf.serverActionId == nil) and action.id == presets_utils.DEFAULT_ACTION) or
|
||||
((conf ~= nil and conf.serverActionId ~= nil) and conf.serverActionId == action.id) then
|
||||
checked = 'checked'
|
||||
end
|
||||
sr = sr..'<label class="radio-inline"><input type="radio" name="'..field_id..'_server_action" value="'..action.id..'" '..checked..'><span style="font-size: 16px;">'..action.icon..'</span></label>'
|
||||
end
|
||||
|
||||
record["column_client_policy"] = cr
|
||||
record["column_server_policy"] = sr
|
||||
|
||||
res_formatted[#res_formatted + 1] = record
|
||||
::continue::
|
||||
end
|
||||
|
||||
local result = {}
|
||||
result["perPage"] = perPage
|
||||
result["currentPage"] = currentPage
|
||||
result["totalRows"] = num_items
|
||||
result["data"] = res_formatted
|
||||
result["sort"] = {{sortColumn, sortOrder}}
|
||||
|
||||
print(json.encode(result, nil))
|
||||
Loading…
Add table
Add a link
Reference in a new issue