Skip to content

Commit

Permalink
Updated for network configuration page
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Sep 4, 2024
1 parent dfc2526 commit 342ead9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
21 changes: 14 additions & 7 deletions scripts/locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,6 @@ local lang = {
},
},
["checks"] = {
["network_configuration"] = "Network Configuration",
["categories"] = "Categories",
["category"] = "Category",
["category_active_monitoring"] = "Active Monitoring",
Expand Down Expand Up @@ -1682,6 +1681,7 @@ local lang = {
["factory_reset_all_checks"] = "Factory Reset All Checks",
["factory_reset_all_message"] = "Do you want to reset the checks configuration to the default?",
["long_lived_flows_descr"] = "> %{duration}",
["network_configuration"] = "Network Configuration",
["network_discovery_alert_description"] = "Periodic Network Discovery executed",
["network_discovery_description"] = "Trigger an alert when a Network Discovery is detected",
["network_discovery_title"] = "Network Discovery",
Expand Down Expand Up @@ -2851,12 +2851,6 @@ local lang = {
["visual_explorer"] = "Visual Explorer",
},
["flow_checks"] = {
["dns_servers_title"] = "DNS Servers List",
["ntp_servers_title"] = "NTP Servers List",
["smtp_servers_title"] = "SMTP Servers List",
["dhcp_servers_title"] = "DHCP Servers List",
["save_configuration"] = "Save Configuration",
["gateway"] = "Gateway",
["allowed_server_names_description"] = "Comma separated values of allowed server IPs. Example: 173.194.76.109,my.example.com",
["allowed_servers_description"] = "Comma separated values of allowed server IPs. Example: 173.194.76.109,52.97.232.242",
["allowed_servers_title"] = "Allowed Servers",
Expand All @@ -2875,8 +2869,11 @@ local lang = {
["callback_function_num_flows"] = "Flows",
["callback_function_throughput"] = "Processing Speed",
["callback_latest_run"] = "Latest Run",
["dhcp_servers_title"] = "DHCP Servers List",
["dns_esclusion_list"] = "Excluded Domains",
["dns_esclusion_list_example"] = "A list of domains to exclude from invalid queries, separated by commas",
["dns_servers_title"] = "DNS Servers List",
["gateway"] = "Gateway",
["idle"] = "Idle",
["iec104_command_description"] = "Trigger an alert when a command to/from command or measure to/from command IEC transition is detected",
["iec104_command_title"] = "IEC Invalid Command Transition",
Expand Down Expand Up @@ -2918,9 +2915,12 @@ local lang = {
["note_flow_staus_changed"] = "\"Status Changed\" callbacks are executed every time there is a status change in the flow. For example when connection issues such as retransmissions are seen.",
["note_scripts_list"] = "A full list of available %{product} scripts can be found in the <a href=\"%{url}\">scripts</a> page.",
["notes"] = "NOTES",
["ntp_servers_title"] = "NTP Servers List",
["periodic_update"] = "Periodic Update",
["rare_destination_description"] = "Rare/unusual destination (hostname) detected.",
["rare_destination_title"] = "Rare Destination",
["save_configuration"] = "Save Configuration",
["smtp_servers_title"] = "SMTP Servers List",
["status_changed"] = "Status Changed",
["status_zero_tcp_window_description"] = "Reported TCP Zero Window",
["status_zero_tcp_window_description_c2s"] = "Reported client TCP zero window",
Expand Down Expand Up @@ -6174,6 +6174,13 @@ local lang = {
["trigger_alerts_for_network"] = "Trigger alerts for Network %{network}",
["trigger_network_alerts"] = "Trigger Network Alerts",
},
["network_configuration"] = {
["dhcp_servers_title"] = "DHCP Servers",
["dns_servers_title"] = "DNS Servers",
["gateway_servers_title"] = "Network Gateways",
["ntp_servers_title"] = "NTP Servers",
["smtp_servers_title"] = "SMTP Servers",
},
["network_details"] = {
["network"] = "Network",
["network_alias"] = "Network Alias",
Expand Down
15 changes: 10 additions & 5 deletions scripts/lua/rest/v2/get/network/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ local ifid = tonumber(_GET["ifid"])

local res = {}

-- Get data from redis: expected format, array of objects with keys:
res = {{key= "unexpected_dhcp", value_description="192.168.2.85, 192.168.2.45" or "", is_enabled=true or false}}


if isEmptyString(ifid) then
rest_utils.answer(rest_utils.consts.err.invalid_interface)
return
end

rest_utils.answer(rest_utils.consts.success.ok, res)
-- Get data from redis: expected format, array of objects with keys:
res = {
{key= "dns_list", value_description=ntop.getCache("ntopng.prefs.nw_config_dns_list") or "" },
{key= "ntp_list", value_description=ntop.getCache("ntopng.prefs.nw_config_ntp_list") or "" },
{key= "dhcp_list", value_description=ntop.getCache("ntopng.prefs.nw_config_dhcp_list") or "" },
{key= "smtp_list", value_description=ntop.getCache("ntopng.prefs.nw_config_smtp_list") or "" },
{key= "gateway_list", value_description=ntop.getCache("ntopng.prefs.nw_config_gateway_list") or "" },
}

rest_utils.answer(rest_utils.consts.success.ok, res)
26 changes: 5 additions & 21 deletions scripts/lua/rest/v2/set/network/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,11 @@ local post_data = _POST["payload"]

local res = {}

local config = _POST["config"]
tprint(_POST)
local payload = _POST["payload"]
local data = json.decode(payload)

local data = json.decode(config)

-- data is:
--[[
asset_key = [ "gateway", "unexpected_dhcp", "unexpected_dns", "unexpected_ntp", "unexpected_smtp"]
{ "csrf":..., "config": [ {"asset_key": asset_key, "item": [ip1, ip2, ip3...]}, {"asset_key": asset_key_1, "item": [ip1, ip2, ip3...]}]}
]]

-- local script_key = post_data["asset_key"] -- asset_key
-- local redis_key = "ntopng.prefs." .. script_key .. "_ip_list"

-- for each element in respone: ntop.getCache(redis_key)

if isEmptyString(ifid) then
rest_utils.answer(rest_utils.consts.err.invalid_interface)
return
for k,v in pairs(data.config) do
ntop.setCache("ntopng.prefs.nw_config_".. v.key, v.value)
end


rest_utils.answer(rest_utils.consts.success.ok, res)
rest_utils.answer(rest_utils.consts.success.ok, res)

0 comments on commit 342ead9

Please sign in to comment.