Implements nEDGE timezone functions

This commit is contained in:
Simone Mainardi 2018-01-05 12:54:02 +01:00
parent 8ad7b4ce08
commit dcb9abc640
4 changed files with 482 additions and 0 deletions

View file

@ -386,6 +386,23 @@ local function validateUserLanguage(code)
return validateChoice(codes, code)
end
local function validateTimeZoneName(tz)
local tz_utils = require("tz_utils")
local timezones = tz_utils.ListTimeZones()
if timezones then
for _, t in ipairs(timezones) do
if tz == t then
return true
end
end
return false
end
-- never reached as timezones are listed in a text file
return false
end
-- #################################################################
local function validateHost(p)
@ -1044,6 +1061,7 @@ local known_parameters = {
["policy_name"] = validateRoutingPolicyName,
["delete_policy"] = validateRoutingPolicyName,
["policy_id"] = validateNumber,
["timezone_name"] = validateTimeZoneName,
["global_dns_preset"] = validateSingleWord,
["child_dns_preset"] = validateSingleWord,
["global_primary_dns"] = validateIPV4,
@ -1053,6 +1071,7 @@ local known_parameters = {
["lan_recovery_ip"] = validateIPV4,
["lan_recovery_netmask"] = validateIPV4,
["dhcp_server_enabled"] = validateBool,
["ntp_sync_enabled"] = validateBool,
["dhcp_first_ip"] = validateIPV4,
["dhcp_last_ip"] = validateIPV4,
["factory_reset"] = validateEmpty,

View file

@ -0,0 +1,33 @@
--
-- (C) 2014-17 - ntop.org
--
local dirs = ntop.getDirs()
local os_utils = require("os_utils")
local tz_utils = {}
function tz_utils.ListTimeZones()
local tz_file = os_utils.fixPath(dirs.httpdocsdir.."/other/TimeZones.txt")
local res = {}
if ntop.exists(tz_file) then
for line in io.lines(tz_file) do
res[#res + 1] = line
end
end
return res
end
function tz_utils.TimeZone()
-- currently not portable for WINDOWS
local f = io.open(os_utils.fixPath("/etc/timezone"), "r")
local tz
if f then
tz = f:read "*l"
f:close()
end
return tz
end
return tz_utils