mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-10 00:42:14 +00:00
Initial system interface data delete
This commit is contained in:
parent
8dfb66fe82
commit
0748ef191d
5 changed files with 70 additions and 25 deletions
|
|
@ -27,7 +27,7 @@ if _POST and table.len(_POST) > 0 and isAdministrator() then
|
|||
if _POST["delete_active_if_data"] then
|
||||
-- Data for the active interface can't be hot-deleted.
|
||||
-- a restart of ntopng is required so we just mark the deletion.
|
||||
delete_data_utils.request_delete_active_interface_data(ifname)
|
||||
delete_data_utils.request_delete_active_interface_data(_POST["ifid"])
|
||||
|
||||
print('<div class="alert alert-success alert-dismissable"><a href="" class="close" data-dismiss="alert" aria-label="close">×</a>'..i18n('delete_data.delete_active_interface_data_ok', {ifname = ifname, product = ntop.getInfo().product})..'</div>')
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ if not delete_active_interface_requested then
|
|||
action = "delete_interfaces_data('delete_active_if_data')",
|
||||
title = i18n("manage_data.delete_active_interface"),
|
||||
message = i18n("delete_data.delete_active_interface_confirmation",
|
||||
{ifname = ifname, product = ntop.getInfo().product}),
|
||||
{ifname = "<span id='interface-name-to-delete'></span>", product = ntop.getInfo().product}),
|
||||
confirm = i18n("delete"),
|
||||
confirm_button = "btn-danger",
|
||||
}
|
||||
|
|
@ -317,6 +317,12 @@ print [[
|
|||
|
||||
print[[<div>]]
|
||||
|
||||
print[[
|
||||
<form class="interface_data_form" method="POST">
|
||||
<button class="btn btn-default" type="submit" onclick="$('#interface-name-to-delete').html(']] print(i18n("system")) print[['); delete_system_iface = true; return delete_interfaces_data_show_modal('delete_active_interface_data');" style="float:right; margin-right:1em;"><i class="fa fa-trash" aria-hidden="true" data-original-title="" title="]] print(i18n("manage_data.delete_active_interface")) print[["></i> ]] print(i18n("manage_data.delete_system_interface_data")) print[[</button>
|
||||
</form>
|
||||
]]
|
||||
|
||||
if num_inactive_interfaces > 0 then
|
||||
print[[
|
||||
<form class="interface_data_form" id="form_delete_inactive_interfaces" method="POST">
|
||||
|
|
@ -327,8 +333,8 @@ end
|
|||
|
||||
if (not ntop.isnEdge()) and (not delete_active_interface_requested) then
|
||||
print[[
|
||||
<form class="interface_data_form" id="form_delete_inactive_interfaces" method="POST">
|
||||
<button class="btn btn-default" type="submit" onclick="return delete_interfaces_data_show_modal('delete_active_interface_data');" style="float:right; margin-right:1em;"><i class="fa fa-trash" aria-hidden="true" data-original-title="" title="]] print(i18n("manage_data.delete_active_interface")) print[["></i> ]] print(i18n("manage_data.delete_active_interface")) print[[</button>
|
||||
<form class="interface_data_form" method="POST">
|
||||
<button class="btn btn-default" type="submit" onclick="$('#interface-name-to-delete').html(']] print(ifname) print[['); delete_system_iface = false; return delete_interfaces_data_show_modal('delete_active_interface_data');" style="float:right; margin-right:1em;"><i class="fa fa-trash" aria-hidden="true" data-original-title="" title="]] print(i18n("manage_data.delete_active_interface")) print[["></i> ]] print(i18n("manage_data.delete_active_interface")) print[[</button>
|
||||
</form>
|
||||
]]
|
||||
end
|
||||
|
|
@ -338,6 +344,7 @@ print[[</div><br>]]
|
|||
print[[ <b>]] print(i18n('notes')) print[[</b>
|
||||
<ul>
|
||||
<li>]] print(i18n('delete_data.note_persistent_data')) print[[</li>
|
||||
<li>]] print(i18n('manage_data.system_interface_note')) print[[</li>
|
||||
</ul>
|
||||
</div>]]
|
||||
|
||||
|
|
@ -347,6 +354,8 @@ print("</div>") -- closes <div class="tab-content">
|
|||
|
||||
print[[<script type='text/javascript'>
|
||||
|
||||
var delete_system_iface = false;
|
||||
|
||||
var delete_data_show_modal = function() {
|
||||
$(".modal-body #modal_host").html(" " + $('#delete_host').val());
|
||||
if($('#delete_vlan').val() != "") {
|
||||
|
|
@ -387,6 +396,7 @@ var delete_interfaces_data = function(action) {
|
|||
var params = {[action] : ''};
|
||||
|
||||
params.page = 'delete';
|
||||
params.ifid = delete_system_iface ? ]] print(getSystemInterfaceId()) print[[ : ]] print(getInterfaceId(ifname)) print[[;
|
||||
|
||||
params.csrf = "]] print(ntop.getRandomCSRFValue()) print[[";
|
||||
|
||||
|
|
|
|||
|
|
@ -193,6 +193,35 @@ end
|
|||
|
||||
-- ################################################################
|
||||
|
||||
local function delete_keys_patterns(keys_patterns, preserve_prefs)
|
||||
for _, pattern in pairs(keys_patterns) do
|
||||
local matching_keys = ntop.getKeysCache(pattern)
|
||||
|
||||
for matching_key, _ in pairs(matching_keys or {}) do
|
||||
if((not preserve_prefs) or
|
||||
((not starts(matching_key, "ntopng.prefs.")) and
|
||||
(not starts(matching_key, "ntopng.user.")))) then
|
||||
if not dry_run then
|
||||
ntop.delCache(matching_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ################################################################
|
||||
|
||||
local function delete_system_interface_redis(preserve_prefs)
|
||||
local keys_patterns = {
|
||||
"ntopng.prefs.snmp_devices*",
|
||||
"ntopng.prefs.system_rtt_hosts*",
|
||||
}
|
||||
|
||||
delete_keys_patterns(keys_patterns, preserve_prefs)
|
||||
end
|
||||
|
||||
-- ################################################################
|
||||
|
||||
local function delete_interfaces_redis_keys(interfaces_list, preserve_prefs)
|
||||
local pref_prefix = "ntopng.prefs"
|
||||
local status = "OK"
|
||||
|
|
@ -234,18 +263,10 @@ local function delete_interfaces_redis_keys(interfaces_list, preserve_prefs)
|
|||
string.format("%s.%s_*", pref_prefix, if_name),
|
||||
}
|
||||
|
||||
for _, pattern in pairs(keys_patterns) do
|
||||
local matching_keys = ntop.getKeysCache(pattern)
|
||||
delete_keys_patterns(keys_patterns, preserve_prefs)
|
||||
|
||||
for matching_key, _ in pairs(matching_keys or {}) do
|
||||
if((not preserve_prefs) or
|
||||
((not starts(matching_key, "ntopng.prefs.")) and
|
||||
(not starts(matching_key, "ntopng.user.")))) then
|
||||
if not dry_run then
|
||||
ntop.delCache(matching_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
if(if_id == getSystemInterfaceId()) then
|
||||
delete_system_interface_redis(preserve_prefs)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -433,12 +454,9 @@ end
|
|||
|
||||
-- ################################################################
|
||||
|
||||
function delete_data_utils.request_delete_active_interface_data(if_name)
|
||||
local if_id = getInterfaceId(if_name)
|
||||
|
||||
if tonumber(if_id) >= 0 then
|
||||
ntop.setHashCache(ACTIVE_INTERFACES_DELETE_HASH, tostring(if_id), if_name)
|
||||
end
|
||||
function delete_data_utils.request_delete_active_interface_data(if_id)
|
||||
local if_name = getInterfaceName(if_name)
|
||||
ntop.setHashCache(ACTIVE_INTERFACES_DELETE_HASH, tostring(if_id), if_name)
|
||||
end
|
||||
|
||||
-- ################################################################
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ end
|
|||
-- ##############################################
|
||||
|
||||
function getInterfaceName(interface_id, windows_skip_description)
|
||||
if(interface_id == getSystemInterfaceId()) then
|
||||
return(getSystemInterfaceName())
|
||||
end
|
||||
|
||||
local ifnames = interface.getIfNames()
|
||||
local iface = ifnames[tostring(interface_id)]
|
||||
|
||||
|
|
@ -88,6 +92,10 @@ end
|
|||
-- ##############################################
|
||||
|
||||
function getInterfaceId(interface_name)
|
||||
if(interface_name == getSystemInterfaceName()) then
|
||||
return(getSystemInterfaceId())
|
||||
end
|
||||
|
||||
local ifnames = interface.getIfNames()
|
||||
|
||||
for if_id, if_name in pairs(ifnames) do
|
||||
|
|
|
|||
|
|
@ -248,3 +248,10 @@ function getSystemInterfaceId()
|
|||
-- This must be a string as it is passed in interface.select
|
||||
return "-1"
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function getSystemInterfaceName()
|
||||
-- NOTE: keep in sync with SYSTEM_INTERFACE_NAME in ntop_defines.h
|
||||
return "__system__"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue