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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
<?xml version="1.0" standalone="yes"?>
<%
-- CyberData Intercom Configuration File Template
local values = ...
xml = require("LuaXml")
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
local function yesno(xmlobj, name, value)
if value ~= nil then
if (value == false) then
value = "No"
elseif (value == true) then
value = "Yes"
end
setValue(xmlobj, name, 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>
-- <ClockSettings>
if values.device then
local clocksettings = findOrAppendSection(init_cfg, "ClockSettings")
setValue(clocksettings, "NTPServer", values.device.sntpserver)
setValue(clocksettings, "NTPTimezone", values.device.timezone)
end
-- <SIPSettings>
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)
-- These parameters are used by CyberData Intercom
setValue(sipsettings, "DialoutExtension0", values.reg1.hotlinedestination)
setValue(sipsettings, "DialoutID0", values.reg1.callerid)
end
-- <DeviceSettings>
if values.device then
local DeviceSettings = findOrAppendSection(init_cfg, "DeviceSettings")
-- These parameters are used by CyberData Intercom and CyberData Paging Zone Controller
setValue(DeviceSettings, "AdminPassword", values.device.adminpassword)
-- These parameters are used by CyberData Intercom
setValue(DeviceSettings, "SpeakerVolume", values.device.cyberspeakervolume)
setValue(DeviceSettings, "RingVolume", values.device.cyberringvolume)
setValue(DeviceSettings, "MicGain", values.device.cybermicgain)
yesno (DeviceSettings, "ActivateRelayWithDTMF", values.device.activaterelaywithdtmf)
setValue(DeviceSettings, "DTMFActivationCode", values.device.dtmfactivationcode)
setValue(DeviceSettings, "DTMFActivationDuration", values.device.dtmfactivationduration)
yesno (DeviceSettings, "ActivateRelayDuringRing", values.device.activaterelayduringring)
yesno (DeviceSettings, "ActivateRelayDuringCall", values.device.activaterelayduringcall)
yesno (DeviceSettings, "AutoAnswerIncomingCalls", values.device.autoanswerincomingcalls)
-- These parameters are used by CyberData Paging Zone Controller
yesno (DeviceSettings, "BypassDTMF", values.device.bypassdtmf)
yesno (DeviceSettings, "BeepOnInitialization", values.device.beeponinitialization)
yesno (DeviceSettings, "BeepBeforePage", values.device.beepbeforepage)
end
-- <ZoneSettings>
-- These parameters are used by CyberData Paging Zone Controller
if values.device then
local ZoneSettings = findOrAppendSection(init_cfg, "ZoneSettings")
yesno(ZoneSettings, "BypassDTMF", values.device.bypassdtmf)
end
-- Loop through Parameter Groups looking for 'zone' params
for pg, pg_t in pairs(values) do
-- Is it of the form zoneXX ?
local num = string.match(pg, 'zone(%d%d)')
if num then
local ZoneSettings = findOrAppendSection(init_cfg, "ZoneSettings")
yesno(ZoneSettings, 'Zone'..num..'Port1', pg_t.pagingport1)
yesno(ZoneSettings, 'Zone'..num..'Port2', pg_t.pagingport2)
yesno(ZoneSettings, 'Zone'..num..'Port3', pg_t.pagingport3)
yesno(ZoneSettings, 'Zone'..num..'Port4', pg_t.pagingport4)
end
end
-- <ButtonSettings>
-- These parameters are used by CyberData Intercom
if values.device then
local ButtonSettings = findOrAppendSection(init_cfg, "ButtonSettings")
yesno (ButtonSettings, "PlayToneWhileRelayActive", values.device.playtonewhilerelayactive)
end
-- <SensorSettings>
-- These parameters are used by CyberData Intercom
if values.device then
local SensorSettings = findOrAppendSection(init_cfg, "SensorSettings")
yesno (SensorSettings, "SensorNormallyClosed", values.device.sensornormallyclosed)
setValue (SensorSettings, "SensorTimeout", values.device.sensortimeout)
yesno (SensorSettings, "SensorFlashLED", values.device.sensorflashled)
yesno (SensorSettings, "SensorActivateRelay", values.device.sensoractivaterelay)
yesno (SensorSettings, "SensorPlayLocally", values.device.sensorplaylocally)
yesno (SensorSettings, "SensorCall", values.device.sensorcall)
setValue (SensorSettings, "SensorDialOutExtension", values.device.sensordialoutextension)
setValue (SensorSettings, "SensorDialOutID", values.device.sensordialoutid)
yesno (SensorSettings, "SensorRepeat", values.device.sensorrepeat)
yesno (SensorSettings, "SensorPlayRemotely", values.device.sensorplayremotely)
end
-- init_cfg:save("TEST-cyberdata.xml")
print(init_cfg)
%>
|