2 Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
4 This file is part of luci-pbx.
6 luci-pbx is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 luci-pbx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
20 if nixio.fs.access("/etc/init.d/asterisk") then
22 elseif nixio.fs.access("/etc/init.d/freeswitch") then
28 modulename = "pbx-voip"
30 m = Map (modulename, translate("SIP Accounts"),
31 translate("This is where you set up your SIP (VoIP) accounts ts like Sipgate, SipSorcery,\
32 the popular Betamax providers, and any other providers with SIP settings in order to start \
33 using them for dialing and receiving calls (SIP uri and real phone calls). Click \"Add\" to\
34 add as many accounts as you wish."))
36 -- Recreate the config, and restart services after changes are commited to the configuration.
37 function m.on_after_commit(self)
39 -- Create a field "name" for each account which identifies the account in the backend.
40 m.uci:foreach(modulename, "voip_provider",
42 if s1.defaultuser ~= nil and s1.host ~= nil then
43 name=string.gsub(s1.defaultuser.."_"..s1.host, "%W", "_")
44 if s1.name ~= name then
45 m.uci:set(modulename, s1['.name'], "name", name)
50 if commit == true then m.uci:commit(modulename) end
52 luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
53 luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
56 -----------------------------------------------------------------------------
57 s = m:section(TypedSection, "voip_provider", translate("SIP Provider Accounts"))
61 s:option(Value, "defaultuser", translate("User Name"))
62 pwd = s:option(Value, "secret", translate("Password"),
63 translate("When your password is saved, it disappears from this field and is not displayed\
64 for your protection. The previously saved password will be changed only when you\
65 enter a value different from the saved one."))
72 -- We skip reading off the saved value and return nothing.
73 function pwd.cfgvalue(self, section)
77 -- We check the entered value against the saved one, and only write if the entered value is
78 -- something other than the empty string, and it differes from the saved value.
79 function pwd.write(self, section, value)
80 local orig_pwd = m:get(section, self.option)
81 if value and #value > 0 and orig_pwd ~= value then
82 Value.write(self, section, value)
86 h = s:option(Value, "host", translate("SIP Server/Registrar"))
89 p = s:option(ListValue, "register", translate("Enable Incoming Calls (Register via SIP)"),
90 translate("This option should be set to \"Yes\" if you have a DID \(real telephone number\)\
91 associated with this SIP account or want to receive SIP uri calls through this\
93 p:value("yes", translate("Yes"))
94 p:value("no", translate("No"))
97 p = s:option(ListValue, "make_outgoing_calls", translate("Enable Outgoing Calls"),
98 translate("Use this account to make outgoing calls."))
99 p:value("yes", translate("Yes"))
100 p:value("no", translate("No"))
103 from = s:option(Value, "fromdomain",
104 translate("SIP Realm (needed by some providers)"))
106 from.datatype = "host"
108 port = s:option(Value, "port", translate("SIP Server/Registrar Port"))
110 port.datatype = "port"
112 op = s:option(Value, "outboundproxy", translate("Outbound Proxy"))