mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
Fix AddressSelector component
This commit is contained in:
parent
e020220d15
commit
4857ea4193
2 changed files with 46 additions and 41 deletions
|
|
@ -255,31 +255,45 @@ function system_setup_ui_utils.printPageBody(sys_config, print_page_body_callbac
|
|||
end
|
||||
|
||||
|
||||
function system_setup_ui_utils.printPrivateAddressSelector(label, comment, ip_key, netmask_key, value, showEnabled, extra)
|
||||
function system_setup_ui_utils.printPrivateAddressSelector(label, comment, ip_key, netmask_key, value, netmask_value, showEnabled, extra)
|
||||
local field_id = ip_key .. "__id"
|
||||
local networks_presets = {
|
||||
{prefix="192.168", netmask="255.255.255.0"},
|
||||
{prefix="192.168", netmask="255.255.0.0"},
|
||||
{prefix="172.16", netmask="255.255.0.0"},
|
||||
{prefix="10.0", netmask="255.255.0.0"},
|
||||
}
|
||||
extra = extra or {}
|
||||
local initial_preset = ""
|
||||
local initial_quad3 = ""
|
||||
local initial_quad4 = ""
|
||||
local netmask_value = "255.255.255.0"
|
||||
|
||||
if value ~= nil then
|
||||
local parts = string.split(value, "%.")
|
||||
local prefix = table.concat({parts[1], parts[2]}, ".")
|
||||
if isEmptyString(netmask_value) then
|
||||
netmask_value = "255.255.255.0"
|
||||
end
|
||||
local netmask_parts = string.split(netmask_value, "%.")
|
||||
|
||||
local value_parts = { "", "", "", ""}
|
||||
if not isEmptyString(value) then
|
||||
value_parts = string.split(value, "%.")
|
||||
|
||||
local prefix = table.concat({value_parts[1], value_parts[2]}, ".")
|
||||
|
||||
for _, preset in pairs(networks_presets) do
|
||||
if preset.prefix == prefix then
|
||||
initial_preset = preset.prefix
|
||||
initial_quad3 = parts[3]
|
||||
initial_quad4 = parts[4]
|
||||
netmask_value = preset.netmask
|
||||
netmask_parts = string.split(netmask_value, "%.")
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if isEmptyString(initial_preset) then
|
||||
local masked_parts = {}
|
||||
for _, xxx in ipairs(netmask_parts) do
|
||||
if xxx == '255' then
|
||||
masked_parts[_] = value_parts[_]
|
||||
end
|
||||
end
|
||||
initial_preset = table.concat(masked_parts, ".")
|
||||
end
|
||||
end
|
||||
|
||||
if ((showEnabled == nil) or (showEnabled == true)) then
|
||||
|
|
@ -289,25 +303,14 @@ function system_setup_ui_utils.printPrivateAddressSelector(label, comment, ip_ke
|
|||
end
|
||||
|
||||
print('<tr id="'..field_id..'" style="display: '..showEnabled..';"><td width=50%><strong>'..label..'</strong><p><small>'..comment..'</small></td>')
|
||||
print [[
|
||||
print [[
|
||||
<td align=right>
|
||||
<table class="form-group mb-3" style="margin-bottom: 0; min-width:22em;">
|
||||
<tr class='border-0'>
|
||||
]]
|
||||
|
||||
print[[
|
||||
<td class="local-ip-selector border-0 text-end" style="vertical-align:top; padding-left: 2em;">]]
|
||||
|
||||
-- Find initial netmask
|
||||
for _, preset in pairs(networks_presets) do
|
||||
if preset.prefix == initial_preset then
|
||||
netmask_value = preset.netmask
|
||||
end
|
||||
end
|
||||
|
||||
if extra.net_select ~= false then
|
||||
print[[<select name="]] print(field_id) print[[_net" class="form-select d-inline-block" style="width: 9.6rem">]]
|
||||
|
||||
for _, preset in pairs(networks_presets) do
|
||||
print[[<option value="]] print(preset.prefix) print[["]]
|
||||
if preset.prefix == initial_preset then
|
||||
|
|
@ -320,27 +323,26 @@ function system_setup_ui_utils.printPrivateAddressSelector(label, comment, ip_ke
|
|||
print[[</select> .]]
|
||||
else
|
||||
print[[<input type="hidden" name="]] print(field_id) print[[_net" value="]] print(initial_preset) print[[">]]
|
||||
print([[<span>]] .. initial_preset .. [[</span>]])
|
||||
print(ternary(extra.quad3_select == false, ".", " . "))
|
||||
|
||||
for _, xxx in ipairs(netmask_parts) do
|
||||
if xxx == '255' then
|
||||
print[[<input class="form-control d-inline-block" style="width: 4.8rem" type="number" min="0" max="255" name="]] print(field_id) print[[_quad_]] print(tostring(_)) print[[" value="]] print(value_parts[_]) print[[" disabled /> . ]]
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local input_type = "number"
|
||||
if extra.quad3_select == false then
|
||||
input_type = "hidden"
|
||||
print(initial_quad3)
|
||||
for _, xxx in ipairs(netmask_parts) do
|
||||
if xxx ~= '255' then
|
||||
print[[<input class="form-control d-inline-block" style="width: 4.8rem" type="number" min="0" max="255" name="]] print(field_id) print[[_quad_]] print(tostring(_)) print[[" value="]] print(value_parts[_]) print[[" />]]
|
||||
if _ ~= 4 then
|
||||
print[[ . ]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print[[<input class="form-control d-inline-block" style="width: 4.8rem" type="]] print(input_type) print[[" min="0" max="255" name="]] print(field_id) print[[_quad_3" value="]] print(initial_quad3) print[[" />]]
|
||||
print(ternary(extra.quad4_select == false, ".", " . "))
|
||||
print[[<input type="hidden" name="]] print(ip_key) print[[">]]
|
||||
|
||||
local input_type = "number"
|
||||
if extra.quad4_select == false then
|
||||
input_type = "hidden"
|
||||
print(initial_quad4)
|
||||
end
|
||||
|
||||
print[[<input class="form-control d-inline-block" style="width: 4.8rem" type="]] print(input_type) print[[" min="1" max="254" name="]] print(field_id) print[[_quad_4" value="]] print(initial_quad4) print[[" />
|
||||
<input type="hidden" name="]] print(ip_key) print[[">]]
|
||||
if netmask_key ~= nil then
|
||||
print[[<input type="hidden" name="]] print(netmask_key) print[[" value="]] print(netmask_value) print[[">]]
|
||||
end
|
||||
|
|
@ -369,11 +371,12 @@ function system_setup_ui_utils.printPrivateAddressSelector(label, comment, ip_ke
|
|||
return false;
|
||||
|
||||
var f_net = form.find('[name="]] print(field_id) print[[_net"]');
|
||||
var f_quad1 = form.find('[name="]] print(field_id) print[[_quad_1"]');
|
||||
var f_quad2 = form.find('[name="]] print(field_id) print[[_quad_2"]');
|
||||
var f_quad3 = form.find('[name="]] print(field_id) print[[_quad_3"]');
|
||||
var f_quad4 = form.find('[name="]] print(field_id) print[[_quad_4"]');
|
||||
var f_ip = form.find('[name="]] print(ip_key) print[["]');
|
||||
f_ip.val([f_net.val(), f_quad3.val(), f_quad4.val()].join("."));
|
||||
|
||||
f_ip.val([f_quad1.val(), f_quad2.val(), f_quad3.val(), f_quad4.val()].join("."));
|
||||
]]
|
||||
|
||||
if netmask_key ~= nil then
|
||||
|
|
@ -394,6 +397,8 @@ function system_setup_ui_utils.printPrivateAddressSelector(label, comment, ip_ke
|
|||
print[[
|
||||
// Clear the support fields
|
||||
f_net.removeAttr("name");
|
||||
f_quad1.removeAttr("name");
|
||||
f_quad2.removeAttr("name");
|
||||
f_quad3.removeAttr("name");
|
||||
f_quad4.removeAttr("name");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue