--
-- (C) 2018 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local remote_assistance = require("remote_assistance")
local template = require "template_utils"
local page_utils = require("page_utils")
if((not isAdministrator()) or (not remote_assistance.isAvailable())) then
return
end
local info = ntop.getInfo()
local tab = _GET["tab"] or "config"
if not table.empty(_POST) then
if tab == "config" then
local enabled = (_POST["toggle_remote_assistance"] == "1") and (_POST["accept_tos"] == "1")
if enabled then
local admin_access = _POST["allow_admin_access"]
local community = _POST["assistance_community"]
local key = _POST["assistance_key"]
if admin_access == "1" then
remote_assistance.enableTempAdminAccess(key)
else
remote_assistance.disableTempAdminAccess()
end
ntop.setPref("ntopng.prefs.remote_assistance.community", community)
ntop.setPref("ntopng.prefs.remote_assistance.key", key)
ntop.setPref("ntopng.prefs.remote_assistance.admin_access", admin_access or "0")
remote_assistance.createConfig(community, key)
remote_assistance.enableAndStart()
else
remote_assistance.disableTempAdminAccess()
remote_assistance.disableAndStop()
end
else -- tab == "status"
if _POST["action"] == "restart" then
remote_assistance.restart()
end
end
elseif _GET["action"] == "get_script" then
sendHTTPContentTypeHeader('text/x-shellscript', 'attachment; filename="n2n_assistance.sh"')
print("#!/bin/sh\n")
print(remote_assistance.getConnectionCommand())
return
end
sendHTTPContentTypeHeader('text/html')
page_utils.set_active_menu_entry(page_utils.menu_entries.remote_assistance)
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
print(template.gen("modal_confirm_dialog.html", {
dialog = {
id = "tos-accept-modal",
title = i18n("remote_assistance.enable_remote_assistance"),
custom_alert_class = "alert alert-danger",
message = i18n("remote_assistance.tos_notice", {button=i18n("remote_assistance.accept_and_enable")}),
confirm = i18n("remote_assistance.accept_and_enable"),
action = "acceptTos()",
}
}))
page_utils.print_page_title(i18n("remote_assistance.product_remote_assistance", {product=info.product}))
local assist_enabled = remote_assistance.isEnabled()
local admin_enabled = false
if assist_enabled then
if ntop.getPref("ntopng.prefs.remote_assistance.admin_access") == "1" then
admin_enabled = true
end
end
if ntop.isGuiAccessRestricted() and admin_enabled then
printMessageBanners({{
type = "warning",
text = i18n("remote_assistance.gui_access_restricted_info", {
url_acl = ntop.getHttpPrefix() .. "/lua/admin/prefs.lua?tab=misc",
cli_options = "-w -W",
}),
}})
print("
")
end
print [[