Rework LuCI build system
[project/luci.git] / applications / luci-app-pbx / luasrc / model / cbi / pbx-users.lua
1 --[[
2 Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
3
4 This file is part of luci-pbx.
5
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.
10
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.
15
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/>.
18 ]]--
19
20 if nixio.fs.access("/etc/init.d/asterisk") then
21 server = "asterisk"
22 elseif nixio.fs.access("/etc/init.d/freeswitch") then
23 server = "freeswitch"
24 else
25 server = ""
26 end
27
28 modulename = "pbx-users"
29 modulenamecalls = "pbx-calls"
30 modulenameadvanced = "pbx-advanced"
31
32
33 m = Map (modulename, translate("User Accounts"),
34 translate("Here you must configure at least one SIP account, that you \
35 will use to register with this service. Use this account either in an Analog Telephony \
36 Adapter (ATA), or in a SIP software like CSipSimple, Linphone, or Sipdroid on your \
37 smartphone, or Ekiga, Linphone, or X-Lite on your computer. By default, all SIP accounts \
38 will ring simultaneously if a call is made to one of your VoIP provider accounts or GV \
39 numbers."))
40
41 -- Recreate the config, and restart services after changes are commited to the configuration.
42 function m.on_after_commit(self)
43 luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
44 luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
45 end
46
47 externhost = m.uci:get(modulenameadvanced, "advanced", "externhost")
48 bindport = m.uci:get(modulenameadvanced, "advanced", "bindport")
49 ipaddr = m.uci:get("network", "lan", "ipaddr")
50
51 -----------------------------------------------------------------------------
52 s = m:section(NamedSection, "server", "user", translate("Server Setting"))
53 s.anonymous = true
54
55 if ipaddr == nil or ipaddr == "" then
56 ipaddr = "(IP address not static)"
57 end
58
59 if bindport ~= nil then
60 just_ipaddr = ipaddr
61 ipaddr = ipaddr .. ":" .. bindport
62 end
63
64 s:option(DummyValue, "ipaddr", translate("Server Setting for Local SIP Devices"),
65 translate("Enter this IP (or IP:port) in the Server/Registrar setting of SIP devices you will \
66 use ONLY locally and never from a remote location.")).default = ipaddr
67
68 if externhost ~= nil then
69 if bindport ~= nil then
70 just_externhost = externhost
71 externhost = externhost .. ":" .. bindport
72 end
73 s:option(DummyValue, "externhost", translate("Server Setting for Remote SIP Devices"),
74 translate("Enter this hostname (or hostname:port) in the Server/Registrar setting of SIP \
75 devices you will use from a remote location (they will work locally too).")
76 ).default = externhost
77 end
78
79 if bindport ~= nil then
80 s:option(DummyValue, "bindport", translate("Port Setting for SIP Devices"),
81 translatef("If setting Server/Registrar to %s or %s does not work for you, try setting \
82 it to %s or %s and entering this port number in a separate field that specifies the \
83 Server/Registrar port number. Beware that some devices have a confusing \
84 setting that sets the port where SIP requests originate from on the SIP \
85 device itself (the bind port). The port specified on this page is NOT this bind port \
86 but the port this service listens on.",
87 ipaddr, externhost, just_ipaddr, just_externhost)).default = bindport
88 end
89
90 -----------------------------------------------------------------------------
91 s = m:section(TypedSection, "local_user", translate("SIP Device/Softphone Accounts"))
92 s.anonymous = true
93 s.addremove = true
94
95 s:option(Value, "fullname", translate("Full Name"),
96 translate("You can specify a real name to show up in the Caller ID here."))
97
98 du = s:option(Value, "defaultuser", translate("User Name"),
99 translate("Use (four to five digit) numeric user name if you are connecting normal telephones \
100 with ATAs to this system (so they can dial user names)."))
101 du.datatype = "uciname"
102
103 pwd = s:option(Value, "secret", translate("Password"),
104 translate("Your password disappears when saved for your protection. It will be changed \
105 only when you enter a value different from the saved one."))
106 pwd.password = true
107 pwd.rmempty = false
108
109 -- We skip reading off the saved value and return nothing.
110 function pwd.cfgvalue(self, section)
111 return ""
112 end
113
114 -- We check the entered value against the saved one, and only write if the entered value is
115 -- something other than the empty string, and it differes from the saved value.
116 function pwd.write(self, section, value)
117 local orig_pwd = m:get(section, self.option)
118 if value and #value > 0 and orig_pwd ~= value then
119 Value.write(self, section, value)
120 end
121 end
122
123 p = s:option(ListValue, "ring", translate("Receives Incoming Calls"))
124 p:value("yes", translate("Yes"))
125 p:value("no", translate("No"))
126 p.default = "yes"
127
128 p = s:option(ListValue, "can_call", translate("Makes Outgoing Calls"))
129 p:value("yes", translate("Yes"))
130 p:value("no", translate("No"))
131 p.default = "yes"
132
133 return m