pbx-voicemail.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. --[[
  2. Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
  3. This file is part of luci-pbx-voicemail.
  4. luci-pbx-voicemail is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. luci-pbx-voicemail is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with luci-pbx-voicemail. If not, see <http://www.gnu.org/licenses/>.
  14. ]]--
  15. if nixio.fs.access("/etc/init.d/asterisk") then
  16. server = "asterisk"
  17. elseif nixio.fs.access("/etc/init.d/freeswitch") then
  18. server = "freeswitch"
  19. else
  20. server = ""
  21. end
  22. modulename = "pbx-voicemail"
  23. vmlogfile = "/tmp/last_sent_voicemail.log"
  24. m = Map (modulename, translate("Voicemail Setup"),
  25. translate("Here you can configure a global voicemail for this PBX. Since this system is \
  26. intended to run on embedded systems like routers, there is no local storage of voicemail - \
  27. it must be sent out by email. Therefore you need to configure an outgoing mail (SMTP) server \
  28. (for example your ISP's, Google's, or Yahoo's SMTP server), and provide a list of \
  29. addresses that receive recorded voicemail."))
  30. -- Recreate the config, and restart services after changes are commited to the configuration.
  31. function m.on_after_commit(self)
  32. luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
  33. luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
  34. end
  35. ----------------------------------------------------------------------------------------------------
  36. s = m:section(NamedSection, "global_voicemail", "voicemail", translate("Global Voicemail Setup"),
  37. translate("When you enable voicemail, you will have the opportunity to specify \
  38. email addresses that receive recorded voicemail. You must also set up an SMTP server below."))
  39. s.anonymous = true
  40. enable = s:option(ListValue, "enabled", translate("Enable Voicemail"))
  41. enable:value("yes", translate("Yes"))
  42. enable:value("no", translate("No"))
  43. enable.default = "no"
  44. emails = s:option(DynamicList, "global_email_addresses",
  45. translate("Email Addresses that Receive Voicemail"))
  46. emails:depends("enabled", "yes")
  47. savepath = s:option(Value, "global_save_path", translate("Local Storage Directory"),
  48. translate("You can also retain copies of voicemail messages on the device running \
  49. your PBX. The path specified here will be created if it doesn't exist. \
  50. Beware of limited space on embedded devices like routers, and enable this \
  51. option only if you know what you are doing."))
  52. savepath.optional = true
  53. if nixio.fs.access("/etc/pbx-voicemail/recordings/greeting.gsm") then
  54. m1 = s:option(DummyValue, "_m1")
  55. m1:depends("enabled", "yes")
  56. m1.default = "NOTE: Found a voicemail greeting. To check or change your voicemail greeting, dial *789 \
  57. and the system will play back your current greeting. After that, a long beep will sound and \
  58. you can press * in order to record a new message. Hang up to avoid recording a message. \
  59. If you press *, a second long beep will sound, and you can record a new greeting. \
  60. Hang up or press # to stop recording. When # is pressed the system will play back the \
  61. new greeting."
  62. else
  63. m1 = s:option(DummyValue, "_m1")
  64. m1:depends("enabled", "yes")
  65. m1.default = "WARNING: Could not find voicemail greeting. Callers will hear only a beep before \
  66. recording starts. To record a greeting, dial *789, and press * after the long beep. \
  67. If you press *, a second long beep will sound, and you can record a new greeting. \
  68. Hang up or press # to stop recording. When # is pressed the system will play back the \
  69. new greeting."
  70. end
  71. ----------------------------------------------------------------------------------------------------
  72. s = m:section(NamedSection, "voicemail_smtp", "voicemail", translate("Outgoing mail (SMTP) Server"),
  73. translate("In order for this PBX to send emails containing voicemail recordings, you need to \
  74. set up an SMTP server here. Your ISP usually provides an SMTP server for that purpose. \
  75. You can also set up a third party SMTP server such as the one provided by Google or Yahoo."))
  76. s.anonymous = true
  77. serv = s:option(Value, "smtp_server", translate("SMTP Server Hostname or IP Address"))
  78. serv.datatype = "host"
  79. port = s:option(Value, "smtp_port", translate("SMTP Port Number"))
  80. port.datatype = "port"
  81. port.default = "25"
  82. tls = s:option(ListValue, "smtp_tls", translate("Secure Connection Using TLS"))
  83. tls:value("on", translate("Yes"))
  84. tls:value("off", translate("No"))
  85. tls.default = "on"
  86. auth = s:option(ListValue, "smtp_auth", translate("SMTP Server Authentication"))
  87. auth:value("on", translate("Yes"))
  88. auth:value("off", translate("No"))
  89. auth.default = "off"
  90. user = s:option(Value, "smtp_user", translate("SMTP User Name"))
  91. user:depends("smtp_auth", "on")
  92. pwd = s:option(Value, "smtp_password", translate("SMTP Password"),
  93. translate("Your real SMTP password is not shown for your protection. It will be changed \
  94. only when you change the value in this box."))
  95. pwd.password = true
  96. pwd:depends("smtp_auth", "on")
  97. -- We skip reading off the saved value and return nothing.
  98. function pwd.cfgvalue(self, section)
  99. return "Password Not Displayed"
  100. end
  101. -- We check the entered value against the saved one, and only write if the entered value is
  102. -- something other than the empty string, and it differes from the saved value.
  103. function pwd.write(self, section, value)
  104. local orig_pwd = m:get(section, self.option)
  105. if value == "Password Not Displayed" then value = "" end
  106. if value and #value > 0 and orig_pwd ~= value then
  107. Value.write(self, section, value)
  108. end
  109. end
  110. ----------------------------------------------------------------------------------------------------
  111. s = m:section(NamedSection, "voicemail_log", "voicemail", translate("Last Sent Voicemail Log"))
  112. s.anonymous = true
  113. s:option (DummyValue, "vmlog")
  114. sts = s:option(DummyValue, "_sts")
  115. sts.template = "cbi/tvalue"
  116. sts.rows = 5
  117. function sts.cfgvalue(self, section)
  118. log = nixio.fs.readfile(vmlogfile)
  119. if log == nil or log == "" then
  120. log = "No errors or messages reported."
  121. end
  122. return log
  123. end
  124. return m