diff --git a/include/Ntop.h b/include/Ntop.h index 4876bde157..f33ef6d65c 100644 --- a/include/Ntop.h +++ b/include/Ntop.h @@ -388,10 +388,11 @@ class Ntop { bool changeAllowedIfname(char *username, char *allowed_ifname) const; bool changeUserHostPool(const char * const username, const char * const host_pool_id) const; bool changeUserLanguage(const char * const username, const char * const language) const; + bool changeUserPermission(const char * const username, bool allow_pcap_download) const; bool existsUser(const char * const username) const; bool addUser(char *username, char *full_name, char *password, char *host_role, char *allowed_networks, char *allowed_ifname, char *host_pool_id, - char *language); + char *language, bool allow_pcap_download); bool addUserLifetime(const char * const username, u_int32_t lifetime_secs); /* Captive portal users may expire */ bool clearUserLifetime(const char * const username); bool isCaptivePortalUser(const char * const username); diff --git a/include/ntop_defines.h b/include/ntop_defines.h index 63ee359346..06ef414750 100644 --- a/include/ntop_defines.h +++ b/include/ntop_defines.h @@ -249,6 +249,7 @@ #define CONST_STR_USER_ALLOWED_IFNAME "ntopng.user.%s.allowed_ifname" #define CONST_STR_USER_HOST_POOL_ID "ntopng.user.%s.host_pool_id" #define CONST_STR_USER_LANGUAGE "ntopng.user.%s.language" +#define CONST_STR_USER_ALLOW_PCAP "ntopng.user.%s.allow_pcap" #define CONST_STR_USER_EXPIRE "ntopng.user.%s.expire" #define CONST_ALLOWED_NETS "allowed_nets" #define CONST_ALLOWED_IFNAME "allowed_ifname" diff --git a/scripts/locales/en.lua b/scripts/locales/en.lua index 712b6f59d3..61e6a0cd6c 100644 --- a/scripts/locales/en.lua +++ b/scripts/locales/en.lua @@ -416,6 +416,7 @@ local lang = { ["too_many_hosts_description"] = "Trigger an alert when the number of active hosts is too high", ["total_alerts"] = "Total Alerts", ["trailing_msg"] = "Time Window", + ["trailing_msg_compact"] = "Window", ["unresponsive_device"] = "Unresponsive Device", ["user_activity"] = "User Activity", ["user_scripts_calls_drops"] = "User Scripts Calls Dropped", @@ -2239,6 +2240,8 @@ local lang = { ["manage_users"] = { ["add_new_user"] = "Add New User", ["administrator"] = "Administrator", + ["allow_pcap_download"] = "Allow PCAP Download", + ["allow_pcap_download_descr"] = "Allow the user to download live traffic and PCAPs", ["allowed_interface"] = "Allowed Interface", ["allowed_networks"] = "Allowed Networks", ["allowed_networks_descr"] = "Comma separated list of networks this user can view. Example:", diff --git a/scripts/lua/admin/add_user.lua b/scripts/lua/admin/add_user.lua index 9607c0ea20..a22c6dda1c 100644 --- a/scripts/lua/admin/add_user.lua +++ b/scripts/lua/admin/add_user.lua @@ -9,17 +9,18 @@ require "lua_utils" sendHTTPContentTypeHeader('text/html') if(haveAdminPrivileges()) then - username = _POST["username"] - full_name = _POST["full_name"] - password = _POST["password"] - confirm_password = _POST["confirm_password"] - host_role = _POST["user_role"] - networks = _POST["allowed_networks"] - allowed_interface = _POST["allowed_interface"] - language = _POST["user_language"] - host_pool_id = _POST["host_pool_id"] - limited_lifetime = _POST["lifetime_limited"] - lifetime_secs = tonumber((_POST["lifetime_secs"] or -1)) + local username = _POST["username"] + local full_name = _POST["full_name"] + local password = _POST["password"] + local confirm_password = _POST["confirm_password"] + local host_role = _POST["user_role"] + local networks = _POST["allowed_networks"] + local allowed_interface = _POST["allowed_interface"] + local language = _POST["user_language"] + local allow_pcap_download = _POST["allow_pcap_download"] + local host_pool_id = _POST["host_pool_id"] + local limited_lifetime = _POST["lifetime_limited"] + local lifetime_secs = tonumber((_POST["lifetime_secs"] or -1)) if(username == nil or full_name == nil or password == nil or confirm_password == nil or host_role == nil or networks == nil or allowed_interface == nil) then print ("{ \"result\" : -1, \"message\" : \"Invalid parameters\" }") @@ -34,7 +35,12 @@ if(haveAdminPrivileges()) then local ret = false username = string.lower(username) - if(ntop.addUser(username, full_name, password, host_role, networks, getInterfaceName(allowed_interface), host_pool_id, language)) then + local allow_pcap_download_enabled = false + if _POST["allow_pcap_download"] and _POST["allow_pcap_download"] == "1" then + allow_pcap_download_enabled = true + end + + if(ntop.addUser(username, full_name, password, host_role, networks, getInterfaceName(allowed_interface), host_pool_id, language, allow_pcap_download_enabled)) then ret = true if limited_lifetime and not ntop.addUserLifetime(username, lifetime_secs) then diff --git a/scripts/lua/admin/change_user_prefs.lua b/scripts/lua/admin/change_user_prefs.lua index 5236201b8a..fcd02eea4a 100644 --- a/scripts/lua/admin/change_user_prefs.lua +++ b/scripts/lua/admin/change_user_prefs.lua @@ -12,6 +12,7 @@ local username = _POST["username"] local host_role = _POST["user_role"] local networks = _POST["allowed_networks"] local allowed_interface = _POST["allowed_interface"] +local allow_pcap_download = _POST["allow_pcap_download"] local language = _POST["user_language"] -- for captive portal users @@ -50,11 +51,13 @@ if(networks ~= nil) then end end -if(allowed_interface ~= nil) then - if(not ntop.changeAllowedIfname(username, getInterfaceName(allowed_interface))) then - print ("{ \"result\" : -1, \"message\" : \"Error in changing the allowed interface\" }") - return - end +local allow_pcap_download_enabled = false +if allow_pcap_download and allow_pcap_download == "1" then + allow_pcap_download_enabled = true; +end +if(not ntop.changeUserPermission(username, allow_pcap_download_enabled)) then + print ("{ \"result\" : -1, \"message\" : \"Error in changing user permission\" }") + return end if(language ~= nil) then diff --git a/scripts/lua/admin/get_user_info.lua b/scripts/lua/admin/get_user_info.lua index fde70d9842..bfcbac8ce7 100644 --- a/scripts/lua/admin/get_user_info.lua +++ b/scripts/lua/admin/get_user_info.lua @@ -48,6 +48,9 @@ if(haveAdminPrivileges()) then end end print(' "language": "'..value["language"]..'",\n') + if value["allow_pcap_download"] then + print(' "allow_pcap_download": true,\n') + end print(' "username": "'..key..'",\n') print(' "password": "'..value["password"]..'",\n') diff --git a/scripts/lua/inc/add_user_dialog.lua b/scripts/lua/inc/add_user_dialog.lua index 3441126588..d438fb88c1 100644 --- a/scripts/lua/inc/add_user_dialog.lua +++ b/scripts/lua/inc/add_user_dialog.lua @@ -66,7 +66,6 @@ print [[ -
-