diff options
author | Ted Trask <ttrask01@yahoo.com> | 2011-10-27 19:30:28 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2011-10-27 19:30:28 +0000 |
commit | fed65bf99b00a89f6815095444ec6a335bf094f5 (patch) | |
tree | 2d445cfd8febdee2e6a3493fb6fc491484c66341 | |
parent | 9f82ad9fea04523c34890fc9881499f29a7ecfc6 (diff) | |
download | acf-provisioning-fed65bf99b00a89f6815095444ec6a335bf094f5.tar.bz2 acf-provisioning-fed65bf99b00a89f6815095444ec6a335bf094f5.tar.xz |
Rewrote linksysata-template.lua to handle multiple lines
-rw-r--r-- | config/templates/linksysata-template.lua | 129 |
1 files changed, 70 insertions, 59 deletions
diff --git a/config/templates/linksysata-template.lua b/config/templates/linksysata-template.lua index a8f9022..d7511bf 100644 --- a/config/templates/linksysata-template.lua +++ b/config/templates/linksysata-template.lua @@ -1,22 +1,32 @@ <% -- Linksys ATA Configuration File Template local values = ... -server=values.device.registrar -web_server=string.gsub(ENV['HTTP_HOST'], ":[0-9]*$", "") -moh=values.device.musiconhold -dialpattern="( " .. values.device.digitmap .. " )" -local cid -if values.reg1.callerid == "" then - cid = values.reg1.extension -else - cid = values.reg1.callerid -end -%> - -<% local values = ... %> - -<% +--[[ -- Parameters +values["device"]["adminpassword"] = "" +values["device"]["digitmap"] = "" +values["device"]["mac"] = "" +values["device"]["musiconhold"] = "" +values["device"]["registrar"] = "" +values["device"]["sntpserver"] = "" +values["device"]["template"] = "/etc/provisioning/templates/linksysata-template.lua" +-- Unimplemented -- values["device"]["timezone"] = "" +values["regX"]["callerid"] = "" +values["regX"]["extension"] = "" +values["regX"]["forwardall"] = "" +values["regX"]["forwardallenable"] = false +values["regX"]["forwardbusy"] = "" +values["regX"]["forwardbusyenable"] = false +values["regX"]["forwardnoanswer"] = "" +values["regX"]["forwardnoanswerenable"] = false +values["regX"]["password"] = "" +-- Unimplemented -- values["services"]["callhistoryenable"] = true +values["services"]["callwaitingenable"] = true +values["services"]["forwarding"] = true +-- Unimplemented -- values["services"]["hotlineenable"] = false +-- Unimplemented -- values["services"]["mailbox"] = "" +-- Unimplemented -- values["services"]["speeddialenable"] = true +--]] local function yesno ( bool ) if bool then @@ -25,61 +35,62 @@ local function yesno ( bool ) return "No" end end + +local function xml_elem(elem,value,permissions,i) + local e = elem + if i then e = elem.."_"..tostring(i).."_" end + local output = {"<", e, ' ua="'} + output[#output+1] = (permissions or "na")..'">' + if type(value) == "boolean" then + output[#output+1] = yesno(value) + elseif value then + output[#output+1] = value + end + output[#output+1] = "</"..e..">" + io.write(table.concat(output)) +end %> <flat-profile> <Admin_Passwd ua="na"><%= values.device.adminpassword %></Admin_Passwd> <User_Password ua="na"><%= values.device.adminpassword %></User_Password> +<HostName ua="na"><%= values.reg1.extension %></HostName> +<Primary_NTP_Server ua="na"><%= values.device.sntpserver %></Primary_NTP_Server> -<HostName ua="na"><% io.write(values.reg1.extension) %></HostName> - -<Syslog_Server ua="na"><%= web_server %></Syslog_Server> -<Debug_Server ua="na"><%= web_server %></Debug_Server> - -<Line_Enable_1_ ua="na">Yes</Line_Enable_1_> -<MOH_Server_1_ ua="na"><% io.write(moh) %></MOH_Server_1_> -<Proxy_1_ ua="na"><% io.write(server) %></Proxy_1_> -<Register_1_ ua="na">Yes</Register_1_> -<Make_Call_Without_Reg_1_ ua="na">No</Make_Call_Without_Reg_1_> - -<Display_Name_1_ ua="na"><%= cid %></Display_Name_1_> -<User_ID_1_ ua="na"><% io.write(values.reg1.extension) %></User_ID_1_> -<Password_1_ ua="na"><% io.write(values.reg1.password) %></Password_1_> +<% 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("Line_Enable", "Yes", "na", num) + xml_elem("MOH_Server", values.device.musiconhold, "na", num) + xml_elem("Proxy", values.device.registrar, "na", num) + xml_elem("Call_Waiting_Serv", (values.services and values.services.callwaitingenable), "na", num) + xml_elem("Dial_Plan", "( "..values.device.digitmap.." )", "na", num) -<Call_Waiting_Serv_1_ ua="na"><%= yesno(values.services and values.services.callwaitingenable) %></Call_Waiting_Serv_1_> + if pg_t.callerid == "" then + pg_t.callerid = pg_t.extension + end + xml_elem("Display_Name", pg_t.callerid, "na", num) + xml_elem("User_ID", pg_t.extension, "na", num) + xml_elem("Password", pg_t.password, "na", num) -<Dial_Plan_1_ ua="na"><% io.write(dialpattern) %></Dial_Plan_1_> - -<% - if values.services and values.services.forwarding and values.reg1 then - local pg_t = values.reg1 - local fwddata = {} - - if pg_t.forwardallenable then - fwddata.all = pg_t.forwardall - else - fwddata.all = "" - end - if pg_t.forwardbusyenable then - fwddata.busy = pg_t.forwardbusy + local forwarding = { {param="forwardall", xml="Cfwd_All_Dest"}, + {param="forwardbusy", xml="Cfwd_Busy_Dest"}, + {param="forwardnoanswer", xml="Cfwd_No_Ans_Dest"} } + for i,f in ipairs(forwarding) do + if value.services.forwarding and pg_t[f.param.."enable"] then + xml_elem(f.xml, pg_t[f.param], "na", num) + else + xml_elem(f.xml, "", "na", num) + end + end else - fwddata.busy = "" + xml_elem("Line_Enable", "No", "na", num) +-- xml_elem("Cfwd_No_Ans_Delay", "0", "na", num) end - if pg_t.forwardnoanswerenable then - fwddata.noanswer = pg_t.forwardnoanswer - fwddata.noanswerdelay = "20" - else - fwddata.noanswer = "" - fwddata.noanswerdelay = "" - end -%> -<Cfwd_All_Dest_1_ ua="na"><%= fwddata.all %></Cfwd_All_Dest_1_> -<Cfwd_Busy_Dest_1_ ua="na"><%= fwddata.busy %></Cfwd_Busy_Dest_1_> -<Cfwd_No_Ans_Dest_1_ ua="na"><%= fwddata.noanswer %></Cfwd_No_Ans_Dest_1_> -<Cfwd_No_Ans_Delay_1_ ua="na"><%= fwddata.noanswerdelay %></Cfwd_No_Ans_Delay_1_> -<% end -%> +end %> </flat-profile> |