mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-28 23:19:33 +00:00
Implement remote assistance
- It enables a VPN via n2n - Remote assistance will be automatically disabled after 1 day - Optionally it's possible to give admin access to the support
This commit is contained in:
parent
578e1362da
commit
eac278a28d
19 changed files with 857 additions and 59 deletions
|
|
@ -5,8 +5,11 @@
|
|||
local dirs = ntop.getDirs()
|
||||
|
||||
local os_utils = {}
|
||||
local NTOPCTL_CMD = "sudo ntopctl"
|
||||
local NTOPNG_CONFIG_TOOL = "/usr/bin/ntopng-utils-manage-config"
|
||||
local is_windows = ntop.isWindows()
|
||||
|
||||
-- #################################
|
||||
-- ########################################################
|
||||
|
||||
function os_utils.getPathDivider()
|
||||
if(ntop.isWindows()) then
|
||||
|
|
@ -16,7 +19,7 @@ function os_utils.getPathDivider()
|
|||
end
|
||||
end
|
||||
|
||||
-- #################################
|
||||
-- ########################################################
|
||||
|
||||
-- Fix path format Unix <-> Windows
|
||||
function os_utils.fixPath(path)
|
||||
|
|
@ -29,7 +32,124 @@ function os_utils.fixPath(path)
|
|||
return(path)
|
||||
end
|
||||
|
||||
-- #################################
|
||||
-- ########################################################
|
||||
|
||||
--! @brief Execute a system command and return its output
|
||||
--! @return the pair (output, ret_code). output will be nil on error.
|
||||
--! @note error condition is determined from the command exit status
|
||||
--! @note redirect the stderr of the command if the command is expected to fail
|
||||
function os_utils.execWithOutput(c, ret_code_success)
|
||||
if is_windows then
|
||||
return nil
|
||||
end
|
||||
|
||||
local f = assert(io.popen(c, 'r'))
|
||||
ret_code_success = ret_code_success or 0
|
||||
|
||||
local s = assert(f:read('*a'))
|
||||
local rv = {f:close()}
|
||||
local retcode = rv[3]
|
||||
|
||||
if retcode ~= ret_code_success then
|
||||
return nil, retcode
|
||||
end
|
||||
|
||||
return s, retcode
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
local function ntopctl_cmd(service_name, ...)
|
||||
local cmd = {NTOPCTL_CMD, service_name, ...}
|
||||
return table.concat(cmd, " ") .. " 2>/dev/null"
|
||||
end
|
||||
|
||||
--! @brief Execute service control tool and get its output.
|
||||
--! @return Command output. See os_utils.execWithOutput for details.
|
||||
function os_utils.ntopctlCmd(service_name, ...)
|
||||
return os_utils.execWithOutput(ntopctl_cmd(service_name, ...))
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
--! @brief Check if a service is available into the system.
|
||||
--! @return true if service is available, false otherwise.
|
||||
function os_utils.hasService(service_name, ...)
|
||||
if not ntop.exists(NTOPNG_CONFIG_TOOL) then
|
||||
return false
|
||||
end
|
||||
|
||||
return(os_utils.execWithOutput(ntopctl_cmd(service_name, "has-service", ...)) == "yes")
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
--! @brief Enable a service
|
||||
--! @return true if service was enabled successfully, false otherwise
|
||||
function os_utils.enableService(service_name, ...)
|
||||
os_utils.execWithOutput(ntopctl_cmd(service_name, "enable", ...))
|
||||
return os_utils.isEnabled(service_name)
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
--! @brief Disable a service
|
||||
--! @return true if service was disabled successfully, false otherwise
|
||||
function os_utils.disableService(service_name, ...)
|
||||
os_utils.execWithOutput(ntopctl_cmd(service_name, "disable", ...))
|
||||
return not os_utils.isEnabled(service_name)
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
--! @brief Restart a service
|
||||
--! @note See os_utils.execWithOutput for return value
|
||||
function os_utils.restartService(service_name, ...)
|
||||
os_utils.execWithOutput(ntopctl_cmd(service_name, "restart", ...))
|
||||
return(os_utils.serviceStatus(service_name) == "active")
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
--! @brief Stop a service
|
||||
--! @note See os_utils.execWithOutput for return value
|
||||
function os_utils.stopService(service_name, ...)
|
||||
os_utils.execWithOutput(ntopctl_cmd(service_name, "stop", ...))
|
||||
return(os_utils.serviceStatus(service_name) == "inactive")
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
--! @brief Check the service status.
|
||||
--! @return active|inactive|error
|
||||
function os_utils.serviceStatus(service_name, ...)
|
||||
local rv = os_utils.execWithOutput(ntopctl_cmd(service_name, "is-active", ...))
|
||||
|
||||
if rv == "active\n" then
|
||||
return "active"
|
||||
elseif rv == "inactive\n" then
|
||||
return "inactive"
|
||||
else
|
||||
return "error"
|
||||
end
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
--! @brief Check if the service is active
|
||||
--! @return true if service is active, false otehrwise
|
||||
function os_utils.isActive(service_name, ...)
|
||||
return(os_utils.serviceStatus(service_name, ...) == "active")
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
function os_utils.isEnabled(service_name, ...)
|
||||
local rv = os_utils.execWithOutput(ntopctl_cmd(service_name, "is-enabled", ...))
|
||||
return(rv == "enabled")
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
return os_utils
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue