File: misc.lua

package info (click to toggle)
ntopng 5.2.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 121,832 kB
  • sloc: javascript: 143,431; cpp: 71,175; ansic: 11,108; sh: 4,687; makefile: 911; python: 587; sql: 512; pascal: 234; perl: 118; ruby: 52; exp: 4
file content (119 lines) | stat: -rw-r--r-- 4,031 bytes parent folder | download
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
--
-- (C) 2013-22 - ntop.org
--

local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path

local template = require "template_utils"
local system_setup_ui_utils = require "system_setup_ui_utils"
require "lua_utils"
require "prefs_utils"
prefsSkipRedis(true)

local is_nedge = ntop.isnEdge()
local is_appliance = ntop.isAppliance()

if not (is_nedge or is_appliance) or not isAdministrator() then
   return
end

local sys_config
if is_nedge then
   package.path = dirs.installdir .. "/pro/scripts/lua/nedge/modules/system_config/?.lua;" .. package.path
   sys_config = require("nf_config"):create(true)
else -- ntop.isAppliance()
   package.path = dirs.installdir .. "/scripts/lua/modules/system_config/?.lua;" .. package.path
   sys_config = require("appliance_config"):create(true)
end

local info = ntop.getInfo(false)

system_setup_ui_utils.process_apply_discard_config(sys_config)

if table.len(_POST) > 0 then
  if (_POST["factory_reset"] ~= nil) then
    sys_config:prepareFactoryReset()
  elseif (_POST["data_reset"] ~= nil) then
    sys_config:prepareDataReset()
  else
    local changed = false

    if (_POST["lan_recovery_ip"] ~= nil) and (_POST["lan_recovery_netmask"] ~= nil) then
      local lan_recovery = sys_config:getLanRecoveryIpConfig()
      lan_recovery.ip = _POST["lan_recovery_ip"]
      lan_recovery.netmask = _POST["lan_recovery_netmask"]
      sys_config:setLanRecoveryIpConfig(lan_recovery)
      changed = true
    end

    if changed then
      sys_config:save()
    end
  end
end

local function print_page_body()
  printPageSection(i18n("prefs.network_interfaces"))
  local lan_recovery = sys_config:getLanRecoveryIpConfig()
  local descr = i18n("nedge.lan_recovery_ip_descr", {product=info["product"]}) .. "<br><b>" .. i18n("nedge.lan_recovery_warning") .. "</b>"
  system_setup_ui_utils.printPrivateAddressSelector(i18n("nedge.lan_recovery_ip"), descr, "lan_recovery_ip", "lan_recovery_netmask", lan_recovery.ip, true)

  print('<tr><th colspan=2 style="text-align:right;">')
  if is_nedge then
    print('<button class="btn btn-danger disable-on-dirty" type="button" onclick="$(\'#factoryResetDialog\').modal(\'show\');" style="width:200px; float:left;">'..i18n("nedge.factory_reset")..'</button>')
    print('<button class="btn btn-danger disable-on-dirty" type="button" onclick="$(\'#dataResetDialog\').modal(\'show\');" style="width:200px; float:left; margin-left:10px;"> '..i18n("nedge.data_reset")..'</button>')
  end
  print('<button type="submit" class="btn btn-primary" style="width:115px" disabled="disabled">'..i18n("save")..'</button>')
  print('</th></tr>')
end

if not system_setup_ui_utils.print_page_before() then
  return
end

if is_nedge then

  print(
   template.gen("modal_confirm_dialog.html", {
		   dialog={
		      id      = "factoryResetDialog",
		      action  = "$('#factoryResetForm').submit()",
		      title   = i18n("nedge.factory_reset"),
		      message = i18n("nedge.factory_reset_msg"),
		      confirm = i18n("nedge.reset_and_reboot"),
		      confirm_button = "btn-danger",
		   }
   })
  )

  print(
   template.gen("modal_confirm_dialog.html", {
		   dialog = {
		      id      = "dataResetDialog",
		      action  = "$('#dataResetForm').submit()",
		      title   = i18n("nedge.data_reset"),
		      message = i18n("nedge.data_reset_msg", {product = ntop.getInfo()["product"]}),
		      confirm = i18n("nedge.reset_and_restart_self"),
		      confirm_button = "btn-danger",
		   }
   })
  )

  print[[
  <form id="factoryResetForm" method="POST">
    <input name="csrf" value="]] print(ntop.getRandomCSRFValue()) print[[" type="hidden" />
    <input name="factory_reset" value="" type="hidden" />
  </form>
  ]]

  print[[
  <form id="dataResetForm" method="POST">
    <input name="csrf" value="]] print(ntop.getRandomCSRFValue()) print[[" type="hidden" />
    <input name="data_reset" value="" type="hidden" />
  </form>
  ]]

end

system_setup_ui_utils.print_page_after(print_page_body, sys_config, {})