Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/ntop/ntopng into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBiscosi committed Sep 4, 2024
2 parents 8aae18e + 342ead9 commit e8aaf91
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 45 deletions.
20 changes: 9 additions & 11 deletions http_src/vue/page-network-configuration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ const saveButtonClass = computed(() => {
});
const check_name = {
"dns_list": { "i18n_title": "flow_checks.dns_servers_title", "device_type": "DNS Server", "reques_param": "dns_list" },
"ntp_list": { "i18n_title": "flow_checks.ntp_servers_title", "device_type": "NTP Server", "reques_param": "ntp_list" },
"dhcp_list": { "i18n_title": "flow_checks.dhcp_servers_title", "device_type": "DHCP Server", "reques_param": "dhcp_list" },
"smtp_list": { "i18n_title": "flow_checks.smtp_servers_title", "device_type": "SMTP Server", "reques_param": "smtp_list" },
"gateway": { "i18n_title": "flow_checks.gateway", "device_type": "Gateway", "reques_param": "gateway" },
"dns_list": { "i18n_title": "network_configuration.dns_servers_title", "device_type": "DNS Server", "reques_param": "dns_list" },
"ntp_list": { "i18n_title": "network_configuration.ntp_servers_title", "device_type": "NTP Server", "reques_param": "ntp_list" },
"dhcp_list": { "i18n_title": "network_configuration.dhcp_servers_title", "device_type": "DHCP Server", "reques_param": "dhcp_list" },
"smtp_list": { "i18n_title": "network_configuration.smtp_servers_title", "device_type": "SMTP Server", "reques_param": "smtp_list" },
"gateway_list": { "i18n_title": "network_configuration.gateway_servers_title", "device_type": "Gateway", "reques_param": "gateway_list" },
}
Object.keys(check_name).forEach(key => {
Expand All @@ -74,7 +74,7 @@ const getConfig = async () => {
data.forEach(item => {
const key = Object.keys(check_name).find(k => k === item.key);
if (key && item.is_enabled === true) {
if (key) {
ipAddresses[key] = Array.isArray(item.value_description)
? item.value_description.join(', ')
: item.value_description;
Expand Down Expand Up @@ -119,18 +119,16 @@ const saveConfig = async () => {
try {
for (const key of modifiedInputs.value) {
const value = ipAddresses[key];
const ips = value.split(',').map(ip => ip.trim());
let requestData = {
asset_key: check_name[key].reques_param,
item: ips
key: check_name[key].reques_param,
value: value
};
data.config.push(requestData)
}
console.log(data)
// console.log(data)
//await ntopng_utility.http_post_request(set_config_url, data);
await ntopng_utility.http_request(set_config_url, { method: 'post', headers, body: JSON.stringify(data) })
Expand Down
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 e8aaf91

Please sign in to comment.