2 Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
4 This file is part of luci-pbx-voicemail.
6 luci-pbx-voicemail 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-voicemail 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-voicemail. 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-voicemail"
29 vmlogfile = "/tmp/last_sent_voicemail.log"
31 m = Map (modulename, translate("Voicemail Setup"),
32 translate("Here you can configure a global voicemail for this PBX. Since this system is \
33 intended to run on embedded systems like routers, there is no local storage of voicemail - \
34 it must be sent out by email. Therefore you need to configure an outgoing mail (SMTP) server \
35 (for example the SMTP server your ISP provides, or GMail), and provide a list of addresses the \
36 voicemail will be sent to."))
38 -- Recreate the config, and restart services after changes are commited to the configuration.
39 function m.on_after_commit(self)
40 luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
41 luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
45 ----------------------------------------------------------------------------------------------------
46 s = m:section(NamedSection, "global_voicemail", "voicemail", translate("Global Voicemail Setup"),
47 translate("When you enable voicemail, you will have the opportunity to specify \
48 email addresses which receive the message. You must also set up an SMTP server below."))
51 enable = s:option(ListValue, "enabled", translate("Enabled"))
52 enable:value("yes", translate("Yes"))
53 enable:value("no", translate("No"))
56 timeout = s:option(Value, "global_timeout",
57 translate("Timeout before sending callers to voicemail"))
58 timeout:depends("enabled", "yes")
61 emails = s:option(DynamicList, "global_email_addresses",
62 translate("Email addresses to forward to"))
63 emails:depends("enabled", "yes")
65 savepath = s:option(Value, "global_save_path", translate("Directory to save voicemail into"),
66 translate("You can also retain copies of voicemail messages on the device running \
67 your PBX. The path specified here will be created if it doesn't exist. \
68 Beware of limited space on embedded devices like routers, and enable this \
69 option only if you know what you are doing."))
70 savepath.optional = true
72 if nixio.fs.access("/etc/pbx-voicemail/greeting.WAV") then
73 m1 = s:option(DummyValue, "_m1")
74 m1:depends("enabled", "yes")
75 m1.default = "NOTE: Found a voicemail greeting. To check or change your voicemail greeting, dial *789 \
76 and the system will play your current message. You have 5 seconds to hangup, otherwise a \
77 new recording will begin and your old message will be overwritten. Hang up or press # to \
78 stop recording. When you press #, the system will play back the new recording."
80 m1 = s:option(DummyValue, "_m1")
81 m1:depends("enabled", "yes")
82 m1.default = "WARNING: Could not find voicemail greeting. Callers will hear only a beep before \
83 recording starts. To record a greeting, dial *789 and record a greeting after the beep. \
84 Hang up or press # to stop recording. When # is pressed the system will play back the \
89 ----------------------------------------------------------------------------------------------------
90 s = m:section(NamedSection, "voicemail_smtp", "voicemail", translate("Outgoing mail (SMTP) Server"),
91 translate("In order for this PBX to send emails containing voicemail recordings, you need to \
92 set up an SMTP server here. Your ISP usually provides an SMTP server for that purpose. \
93 You can also set up a GMail, Yahoo, or other 3rd party SMTP server."))
96 serv = s:option(Value, "smtp_server", translate("SMTP server hostname or IP"))
97 serv.datatype = "host"
99 port = s:option(Value, "smtp_port", translate("SMTP port number"))
100 port.datatype = "port"
103 tls = s:option(ListValue, "smtp_tls", translate("Use TLS (secure connection)"))
104 tls:value("on", translate("Yes"))
105 tls:value("off", translate("No"))
108 auth = s:option(ListValue, "smtp_auth", translate("SMTP server authentication"))
109 auth:value("on", translate("Yes"))
110 auth:value("off", translate("No"))
113 user = s:option(Value, "smtp_user", translate("SMTP user name"))
114 user:depends("smtp_auth", "on")
116 pwd = s:option(Value, "smtp_password", translate("SMTP Password"),
117 translate("Your real SMTP password is not shown for your protection. It will be changed \
118 only when you change the value in this box."))
120 pwd:depends("smtp_auth", "on")
122 -- We skip reading off the saved value and return nothing.
123 function pwd.cfgvalue(self, section)
124 return "Password Not Displayed"
127 -- We check the entered value against the saved one, and only write if the entered value is
128 -- something other than the empty string, and it differes from the saved value.
129 function pwd.write(self, section, value)
130 local orig_pwd = m:get(section, self.option)
131 if value == "Password Not Displayed" then value = "" end
132 if value and #value > 0 and orig_pwd ~= value then
133 Value.write(self, section, value)
137 ----------------------------------------------------------------------------------------------------
138 s = m:section(NamedSection, "voicemail_log", "voicemail",
139 translate("Last Sent Voicemail Log"))
142 s:option (DummyValue, "vmlog")
144 sts = s:option(DummyValue, "_sts")
145 sts.template = "cbi/tvalue"
148 function sts.cfgvalue(self, section)
149 log = nixio.fs.readfile(vmlogfile)
150 if log == nil or log == "" then
151 log = "No errors or messages reported."