summaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2016-01-18 15:44:40 +0000
committerTed Trask <ttrask01@yahoo.com>2016-01-18 15:44:40 +0000
commit8a180f8a449ab86e1f7e22459e0512ee3ac613f1 (patch)
tree691c1db87b4350300c62a63db86ed5e8795c1b72 /config
parent4b73ef0dd480502dee2fff044667c04692b7d3a3 (diff)
downloadacf-provisioning-8a180f8a449ab86e1f7e22459e0512ee3ac613f1.tar.bz2
acf-provisioning-8a180f8a449ab86e1f7e22459e0512ee3ac613f1.tar.xz
Modify CyberData template to work with any init.cfg or none at all
Previously, init.cfg had to follow a specific format to work
Diffstat (limited to 'config')
-rw-r--r--config/templates/cyberdata-template.lua59
1 files changed, 44 insertions, 15 deletions
diff --git a/config/templates/cyberdata-template.lua b/config/templates/cyberdata-template.lua
index 515cceb..11206ba 100644
--- a/config/templates/cyberdata-template.lua
+++ b/config/templates/cyberdata-template.lua
@@ -6,32 +6,61 @@ local values = ...
xml = require("LuaXml")
-local init_cfg = xml.load("/var/www/provisioning/htdocs/CyberData/init.cfg")
+local InitFile = "/var/www/provisioning/htdocs/CyberData/init.cfg"
+
+local function findSection(xmlobj, name)
+ -- Cannot use xmlobj:find() because we don't want recursion
+ for i,s in ipairs(xmlobj) do
+ if s:tag() == name then
+ return s
+ end
+ end
+ return null
+end
+
+local function findOrAppendSection(xmlobj, name)
+ return findSection(xmlobj, name) or xmlobj:append(name)
+end
+
+local function setValue(xmlobj, name, value)
+ if value then
+ findOrAppendSection(xmlobj, name)[1] = value
+ end
+end
+
+-- Load the initial config
+local init_cfg
+local res, err = pcall(function()
+ init_cfg = xml.load(InitFile)
+end)
+if not res and err then
+ init_cfg = xml.new("specific")
+end
-- <IPSettings>
-- <SIPSettings>
-for pg, pg_t in pairs(values) do
- -- Is it of the form regX ?
- local num = string.match(pg, 'reg(%d+)')
- if num then
- if pg_t.extension ~= "" then
- init_cfg[2]:append("SIPServer")[1] = values.device.registrar
- init_cfg[2]:append("SIPUserID")[1] = pg_t.extension
- init_cfg[2]:append("SIPAuthID")[1] = pg_t.extension
- init_cfg[2]:append("SIPAuthPassword")[1] = pg_t.password
- init_cfg[2]:append("DialoutExtension0")[1] = pg_t.hotlinedestination
- init_cfg[2]:append("DialoutID0")[1] = pg_t.callerid
- end
+if values.reg1 then
+ local sipsettings = findOrAppendSection(init_cfg, "SIPSettings")
+ if values.device then
+ setValue(sipsettings, "SIPServer", values.device.registrar)
end
+ setValue(sipsettings, "SIPUserID", values.reg1.extension)
+ setValue(sipsettings, "SIPAuthID", values.reg1.extension)
+ setValue(sipsettings, "SIPAuthPassword", values.reg1.password)
+ setValue(sipsettings, "DialoutExtension0", values.reg1.hotlinedestination)
+ setValue(sipsettings, "DialoutID0", values.reg1.callerid)
end
-- <ClockSettings>
-init_cfg[3]:append("NTPServer")[1] = values.device.sntpserver
-init_cfg[3]:append("NTPTimezone")[1] = values.device.timezone
+if values.device then
+ local clocksettings = findOrAppendSection(init_cfg, "ClockSettings")
+ setValue(clocksettings, "NTPServer", values.device.sntpserver)
+ setValue(clocksettings, "NTPTimezone", values.device.timezone)
+end
-- init_cfg:save("TEST-cyberdata.xml")