diff options
Diffstat (limited to 'config/templates/snom-template.lua')
-rw-r--r-- | config/templates/snom-template.lua | 177 |
1 files changed, 138 insertions, 39 deletions
diff --git a/config/templates/snom-template.lua b/config/templates/snom-template.lua index cdf830c..a299054 100644 --- a/config/templates/snom-template.lua +++ b/config/templates/snom-template.lua @@ -1,6 +1,37 @@ <% local values = ... +--[[ -- Parameters +values["device"]["adminpassword"] = "" +-- Unimplemented -- values["device"]["digitmap"] = "" +-- Unimplemented -- values["device"]["digitmaptimeout"] = "" +values["device"]["forwardall"] = "" +values["device"]["forwardallenable"] = false +values["device"]["forwardbusy"] = "" +values["device"]["forwardbusyenable"] = false +values["device"]["forwardnoanswer"] = "" +values["device"]["forwardnoanswerenable"] = false +values["device"]["mac"] = "" +values["device"]["musiconhold"] = "" +values["device"]["pcportenable"] = true +values["device"]["registrar"] = "" +values["device"]["sntpserver"] = "" +values["device"]["template"] = "/etc/provisioning/templates/snom-template.lua" +values["device"]["timezone"] = "" +values["device"]["urldialingenable"] = false +values["regX"]["callerid"] = "" +values["regX"]["extension"] = "" +values["regX"]["password"] = "" +values["services"]["callhistoryenable"] = true +values["services"]["callwaitingenable"] = true +values["services"]["forwarding"] = true +values["services"]["hotlinedestination"] = "" +values["services"]["hotlineenable"] = false +values["services"]["mailbox"] = "" +-- Unimplemented -- values["services"]["mailcallback"] = "" +-- Unimplemented -- values["services"]["speeddialenable"] = true +--]] + local function onoff ( bool ) if bool then return "on" @@ -19,52 +50,120 @@ local function xml_elem(elem,value,permissions,i) output[#output+1] = value end output[#output+1] = "</"..elem..">" - io.write(table.concat(output)) + io.write(table.concat(output).."\n") end %> <?xml version="1.0" encoding="utf-8"?> <settings> <phone-settings> - <admin_mode_password perm="R"><% io.write(values.device.adminpassword) %></admin_mode_password> - <% xml_elem('eth_pc',values.device.pcportenable,'R') %> - <http_pass perm="R"><% io.write(values.device.adminpassword) %></http_pass> - <http_user perm="R">admin</http_user> - <ntp_server perm="RW"><% io.write(values.device.sntpserver) %></ntp_server> - <!--<timezone perm="RW">ITA+1</timezone> http://wiki.snom.com/Settings/timezone --> - <!--<tone_scheme perm="RW">ITA</tone_scheme> http://wiki.snom.com/wiki/index.php/Settings/tone_scheme --> - <% -for pg, pg_t in pairs(values) do +<% + xml_elem('admin_mode_password', values.device.adminpassword, 'R') + xml_elem('http_pass', values.device.adminpassword, 'R') + xml_elem('http_user', 'admin', 'R') + xml_elem('eth_pc', values.device.pcportenable, 'R') + xml_elem('ntp_server', values.device.sntpserver, 'R') + xml_elem('block_url_dialing', not values.device.urldialingenable, 'R') + xml_elem('call_waiting', values.services.callwaitingenable, 'R') + +if values.services.mailbox ~= "" then + xml_elem('user_mailbox', 'sip:'..values.services.mailbox, 'R') +else + xml_elem('user_mailbox', '', 'R') +end + +if values.services and values.services.forwarding then + -- SNOMs do not support per-line forwarding + xml_elem('redirect_allways', values.device.forwardallenable, 'RW') + xml_elem('redirect_number', values.device.forwardall, 'RW') + xml_elem('redirect_on_busy', values.device.forwardbusyenable, 'RW') + xml_elem('redirect_busy_number', values.device.forwardbusy, 'RW') + xml_elem('redirect_on_timeout', values.device.forwardnoanswerenable, 'RW') + xml_elem('redirect_time_number', values.device.forwardnoanswer, 'RW') +else + xml_elem('redirect_allways', false, 'RW') + xml_elem('redirect_on_busy', false, 'RW') + xml_elem('redirect_on_timeout', false, 'RW') +end + +if values.services and values.services.hotlineenable then + xml_elem('action_offhook_url', 'http://127.0.0.1/command.htm?number='..values.services.hotlinedestinaion, 'R') +else + xml_elem('action_offhook_url', '', 'R') +end + +-- Handle Time Zone parameter +-- See http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html +-- TZ variable, with no leading colon +-- Syntax: stdoffset[dst[offset][,start[/time],end[/time]]] +-- Examples: 'GMT0' 'EST5EDT,M3.2.0,M11.1.0' '<GMT+5>5' +-- Parse time zone variable +require('posixtz') +local tz = posixtz.parse(values.device.timezone) +if tz then + -- convert POSIX sign (W of GMT is '+') to Snom (E of GMT is '+') + xml_elem('utc_offset', -1 * tz.offset.total, 'R') + + local function dstrule(t) + local date, time - -- Is it of the form regX ? - local num = string.match(pg, 'reg(%d+)') - if num then - if pg_t.extension ~= "" then - xml_elem('user_active', 'on', 'RW', num ) - xml_elem('record_dialed_calls', pg_t.callhistoryenable, 'R', num) - xml_elem('record_missed_calls', pg_t.callhistoryenable, 'R', num) - xml_elem('record_received_calls', pg_t.callhistoryenable, 'R', num) - -- SNOMs do not support per-line forwarding - xml_elem('redirect_allways',pg_t.forwardallenable,'RW') - xml_elem('redirect_number',pg_t.forwardall,'RW') - xml_elem('redirect_on_busy',pg_t.forwardbusyenable,'RW') - xml_elem('redirect_busy_number',pg_t.forwardbusy,'RW') - xml_elem('redirect_on_timeout',pg_t.forwardnoanswerenable,'RW') - xml_elem('redirect_time_number',pg_t.forwardnoanswer,'RW') - xml_elem('user_host', values.device.registrar, 'R', num ) - xml_elem('user_moh', 'sip:'..values.device.musiconhold, 'R', num) - xml_elem('user_name', pg_t.extension, 'R', num) - xml_elem('user_outbound', values.device.registrar, 'R', num) - xml_elem('user_pass', pg_t.password, 'R', num) - -- Caller ID string - if string.len(pg_t.callerid) == 0 then - xml_elem( 'user_realname', pg_t.extension,'R', num) - else - xml_elem( 'user_realname', pg_t.callerid,'R', num) - end - end - end + if t.day then + date = string.format('%02i', t.day)..'.'..string.format('%02i', t.month) + else + -- POSIX weekday is between 0 (Sun) and 6 (Sat) + -- Snom weekday is between 1=Mon, 7=Sun + if tonumber(t.weekday) == 0 then + t.weekday = 7 + end + date = string.format('%02i', t.month)..'.'..string.format('%02i', t.week)..'.'..string.format('%02i', t.weekday) + end + + + -- Handle explicit hour for DST change (posixtz only handles hour for now) + if t.hour then + time = string.format('%02i', t.hour)..':00:00' + else + time = '2:00:00' + end + + return date..' '..time + end + + if tz.dst then + xml_elem('dst', '3600 '..dstrule(tz.dst.start)..' '..dstrule(tz.dst.stop), 'R') + else + xml_elem('dst', '', 'R') + end +else + xml_elem('utc_offset', 0, 'R') + xml_elem('dst', '', 'R') end - %> + +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 + xml_elem('user_active', 'on', 'R', num ) + xml_elem('record_dialed_calls', values.services.callhistoryenable, 'R', num) + xml_elem('record_missed_calls', values.services.callhistoryenable, 'R', num) + xml_elem('record_received_calls', values.services.callhistoryenable, 'R', num) + xml_elem('user_host', values.device.registrar, 'R', num ) + xml_elem('user_moh', 'sip:'..values.device.musiconhold, 'R', num) + xml_elem('user_name', pg_t.extension, 'R', num) + xml_elem('user_outbound', values.device.registrar, 'R', num) + xml_elem('user_pass', pg_t.password, 'R', num) + -- Caller ID string + if string.len(pg_t.callerid) == 0 then + xml_elem( 'user_realname', pg_t.extension,'R', num) + else + xml_elem( 'user_realname', pg_t.callerid,'R', num) + end + else + xml_elem('user_active', 'off', 'R', num ) + end + end +end +%> </phone-settings> </settings> |