1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
--
-- (C) 2013-22 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local delete_data_utils = require "delete_data_utils"
local template_utils = require "template_utils"
local ui_utils = require "ui_utils"
local page_utils = require("page_utils")
local is_system_interface = page_utils.is_system_view()
local page
if (_GET['page']) then
page = _GET['page']
-- if the user tries to get the export/delete page in system interface
-- then send him to the system interface default page
-- Same thing for the non system interface pages
if ((page == 'export' or page == 'delete') and is_system_interface) then
page = 'system_interface_data'
elseif ((page == 'inactive_interfaces_data' or page == 'system_interface_data') and not is_system_interface) then
page = 'export'
end
else
page = ternary(is_system_interface, 'system_interface_data', 'export')
end
local info = ntop.getInfo()
sendHTTPContentTypeHeader('text/html')
page_utils.set_active_menu_entry(page_utils.menu_entries.manage_data)
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
-- import the modals if we are inside system interface pages
if is_system_interface then
dofile(dirs.installdir .. "/scripts/lua/inc/manage_data.lua")
else
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(_POST["ifid"])
print(
'<div class="alert alert-success alert-dismissable">' ..
i18n('delete_data.delete_active_interface_data_ok',
{ifname = ifname, product = ntop.getInfo().product}) ..
'<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>')
else -- we're deleting an host
local host_info = url2hostinfo(_POST)
local parts = split(host_info["host"], "/")
local res
if (#parts == 2) and (tonumber(parts[2]) ~= nil) then
res = delete_data_utils.delete_network(_POST["ifid"], parts[1],
parts[2],
host_info["vlan"] or 0)
else
res = delete_data_utils.delete_host(_POST["ifid"], host_info)
end
local err_msgs = {}
for what, what_res in pairs(res) do
if what_res["status"] ~= "OK" then
err_msgs[#err_msgs + 1] =
i18n(delete_data_utils.status_to_i18n(what_res["status"]))
end
end
if #err_msgs == 0 then
print(
'<div class="alert alert-success alert-dismissable">' ..
i18n('delete_data.delete_ok',
{host = hostinfo2hostkey(host_info)}) .. '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>')
else
print(
'<div class="alert alert-danger alert-dismissable">' ..
i18n('delete_data.delete_failed',
{host = hostinfo2hostkey(host_info)}) .. ' ' ..
table.concat(err_msgs, ' ') .. '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>')
end
end
end
end
local delete_active_interface_requested =
delete_data_utils.delete_active_interface_data_requested(ifname)
local inactive_interfaces = delete_data_utils.list_inactive_interfaces()
local num_inactive_interfaces = ternary(not ntop.isnEdge(), table.len(inactive_interfaces or {}), 0)
local delete_active_interface_requested_system = delete_data_utils.delete_active_interface_data_requested(getSystemInterfaceId())
page_utils.print_page_title(i18n("manage_data.manage_data"))
local is_system_interface = page_utils.is_system_view()
local is_admin = isAdministrator()
local menu = {
entries = {
{
key = 'export',
title = i18n("manage_data.export_tab"),
url = "?page=export",
hidden = is_system_interface
},
{
key = 'delete',
title = i18n("manage_data.delete_tab"),
url = "?page=delete",
hidden = not is_admin or is_system_interface,
},
{
key = 'system_interface_data',
title = i18n("manage_data.system_interface_data"),
url = "?page=system_interface_data",
hidden = not is_admin or not is_system_interface,
},
{
key = "inactive_interfaces_data",
url = "?page=inactive_interfaces_data",
title = i18n("manage_data.inactive_interfaces_data"),
hidden = not is_system_interface or not is_admin
}
},
current_page = page
}
local notes = {
export = {
{content = i18n('export_data.note_maximum_number')},
{content = i18n('export_data.note_active_hosts')}
},
delete = {
{content = i18n('delete_data.note_persistent_data')},
{content = i18n('manage_data.system_interface_note')},
{content = i18n('delete_data.node_nindex_flows'), hidden = not interfaceHasClickHouseSupport() }
}
}
print(template_utils.gen("pages/manage_data.template", {
menu = menu,
template_utils = template_utils,
ui_utils = ui_utils,
manage_data = {
page = page,
note = notes[page],
delete_active_interface_requested = delete_active_interface_requested,
num_inactive_interfaces = num_inactive_interfaces,
delete_active_interface_requested_system = delete_active_interface_requested_system
}
}))
if not delete_active_interface_requested then
print(template_utils.gen("modal_confirm_dialog.html", {
dialog = {
id = "delete_active_interface_data",
action = "delete_interfaces_data('delete_active_if_data')",
title = i18n("manage_data.delete_active_interface"),
message = i18n("delete_data.delete_active_interface_confirmation", {
ifname = "<span id='interface-name-to-delete'></span>",
product = ntop.getInfo().product
}),
confirm = i18n("delete"),
custom_alert_class = 'alert alert-danger',
confirm_button = "btn-danger"
}
}))
end
print(template_utils.gen("modal_confirm_dialog.html", {
dialog = {
id = "delete_data",
action = "delete_data()",
title = i18n("manage_data.delete"),
message = i18n("delete_data.delete_confirmation", {
host = '<span id="modal_host"></span><span id="modal_vlan"></span>'
}),
confirm = i18n("delete"),
confirm_button = "btn-danger"
}
}))
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|