mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-06 03:45:26 +00:00
Added the ability to upload a pcap file for analysis
This commit is contained in:
parent
932254f3f3
commit
fa51a2b4e8
10 changed files with 295 additions and 93 deletions
35
scripts/lua/analyze_pcap.lua
Normal file
35
scripts/lua/analyze_pcap.lua
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
--
|
||||
-- (C) 2013-21 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
require "lua_utils"
|
||||
local ts_utils = require("ts_utils")
|
||||
local info = ntop.getInfo()
|
||||
local page_utils = require("page_utils")
|
||||
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
local info = ntop.getInfo()
|
||||
page_utils.set_active_menu_entry(page_utils.menu_entries.about, { product=info.product })
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
|
||||
|
||||
if(_POST.uploaded_file ~= nil) then
|
||||
local iface_id = ntop.registerPcapInterface(_POST.uploaded_file)
|
||||
|
||||
if(iface_id > 0) then
|
||||
print [[
|
||||
<form method='POST' action="]] print(ntop.getHttpPrefix()) print [[/lua/flows_stats.lua?ifid=]] print(toint(iface_id)) print[[">
|
||||
<input hidden name='switch_interface' value='1' />
|
||||
<input hidden name='csrf' value=']] print(ntop.getRandomCSRFValue()) print[[' />
|
||||
<input type="submit" value="]] print(i18n("switch_new_pcap_interface")) print [[">
|
||||
</form>
|
||||
]]
|
||||
else
|
||||
print(i18n("switch_new_pcap_interface_error"))
|
||||
ntop.unlink(_POST.uploaded_file)
|
||||
end
|
||||
end
|
||||
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|
||||
|
|
@ -696,6 +696,10 @@ if not info.oem and auth.has_capability(auth.capabilities.developer) then
|
|||
{
|
||||
section = page_utils.menu_sections.dev,
|
||||
entries = {
|
||||
{
|
||||
entry = page_utils.menu_entries.analyze_pcap,
|
||||
url = '/lua/upload_pcap.lua',
|
||||
},
|
||||
{
|
||||
entry = page_utils.menu_entries.checks_dev,
|
||||
url = '/lua/checks_overview.lua',
|
||||
|
|
|
|||
|
|
@ -42,6 +42,11 @@ local function validateChoiceByKeys(defaults, v)
|
|||
end
|
||||
end
|
||||
|
||||
-- Placeholder for pcap file validation
|
||||
local function validatePcap(defaults, v)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Searches into the value of the table
|
||||
-- Optional key can be used to access fields of the array element
|
||||
local function validateChoice(defaults, v, key)
|
||||
|
|
@ -199,6 +204,14 @@ local function validateLuaScriptPath(p)
|
|||
end
|
||||
http_lint.validateLuaScriptPath = validateLuaScriptPath
|
||||
|
||||
local function validateUploadedFile(p)
|
||||
local os_utils = require("os_utils")
|
||||
local dirs = ntop.getDirs()
|
||||
|
||||
return(starts(p, dirs.workingdir .. os_utils.getPathDivider() .. "tmp" .. os_utils.getPathDivider() .. "upload"))
|
||||
end
|
||||
http_lint.validateLuaScriptPath = validateLuaScriptPath
|
||||
|
||||
local function validateUnchecked(p)
|
||||
-- This function does not perform any validation, so only the C side validation takes place.
|
||||
-- In particular, single quotes are allowed so they must be handled explicitly by the programmer in
|
||||
|
|
@ -2237,6 +2250,10 @@ local known_parameters = {
|
|||
["payload"] = { jsonCleanup, validateJSON },
|
||||
["JSON"] = { jsonCleanup, validateJSON },
|
||||
|
||||
-- POST pcap
|
||||
["pcap"] = validatePcap,
|
||||
["uploaded_file"] = validateUploadedFile,
|
||||
|
||||
-- See https://github.com/ntop/ntopng/issues/4275
|
||||
["csrf"] = validateSingleWord,
|
||||
|
||||
|
|
@ -2246,7 +2263,7 @@ local known_parameters = {
|
|||
["order"] = validateSortOrder,
|
||||
["length"] = validateNumber,
|
||||
["draw"] = validateNumber,
|
||||
["visible_columns"] = validateEmptyOr(validateListOfTypeInline(validateSingleWord))
|
||||
["visible_columns"] = validateEmptyOr(validateListOfTypeInline(validateSingleWord))
|
||||
}
|
||||
|
||||
-- A special parameter is formed by a prefix, followed by a variable suffix
|
||||
|
|
|
|||
|
|
@ -175,6 +175,7 @@ page_utils.menu_entries = {
|
|||
-- Developer
|
||||
directories = {key = "directories", i18n_title = "about.directories", section = "dev", help_link = "https://www.ntop.org/guides/ntopng/scripts/distributing_scripts.html"},
|
||||
checks_dev = {key = "checks_dev", i18n_title = "about.checks", section = "dev", help_link = "https://www.ntop.org/guides/ntopng/scripts/checks.html"},
|
||||
analyze_pcap = {key = "analyze_pcap", i18n_title = "about.analyze_pcap", section = "dev", help_link = "https://www.ntop.org/guides/ntopng/advanced_features/index.html"},
|
||||
alert_definitions = {key = "alert_definitions", i18n_title = "about.alert_defines", section = "dev", help_link = "https://www.ntop.org/guides/ntopng/scripts/alert_definitions.html"},
|
||||
api = {key = "api", i18n_title = "lua_c_api", section = "dev"},
|
||||
|
||||
|
|
|
|||
35
scripts/lua/upload_pcap.lua
Normal file
35
scripts/lua/upload_pcap.lua
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
--
|
||||
-- (C) 2013-21 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
require "lua_utils"
|
||||
local ts_utils = require("ts_utils")
|
||||
local info = ntop.getInfo()
|
||||
local page_utils = require("page_utils")
|
||||
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
local info = ntop.getInfo()
|
||||
page_utils.set_active_menu_entry(page_utils.menu_entries.about, { product=info.product })
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
|
||||
|
||||
-- accept=".pcap"
|
||||
|
||||
if isAdministrator() then
|
||||
print("<H3>"..i18n("analyze_pcap").."</H3>")
|
||||
|
||||
print [[
|
||||
<table class="table table-bordered table-striped">
|
||||
<tr><td>
|
||||
<form action="]] print(ntop.getHttpPrefix()) print [[/lua/analyze_pcap.lua" method=POST enctype="multipart/form-data">
|
||||
<input type="file" id="pcap" name="pcap">
|
||||
<input type="submit" value="]] print(i18n("upload_pcap")) print [[">
|
||||
</form>
|
||||
</td></tr>
|
||||
</table>
|
||||
]]
|
||||
end
|
||||
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|
||||
Loading…
Add table
Add a link
Reference in a new issue