trunk_sip.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local ast = require("luci.asterisk")
  4. --
  5. -- SIP trunk info
  6. --
  7. if arg[2] == "info" then
  8. form = SimpleForm("asterisk", "SIP Trunk Information")
  9. form.reset = false
  10. form.submit = "Back to overview"
  11. local info, keys = ast.sip.peer(arg[1])
  12. local data = { }
  13. for _, key in ipairs(keys) do
  14. data[#data+1] = {
  15. key = key,
  16. val = type(info[key]) == "boolean"
  17. and ( info[key] and "yes" or "no" )
  18. or ( info[key] == nil or #info[key] == 0 )
  19. and "(none)"
  20. or tostring(info[key])
  21. }
  22. end
  23. itbl = form:section(Table, data, "SIP Trunk %q" % arg[1])
  24. itbl:option(DummyValue, "key", "Key")
  25. itbl:option(DummyValue, "val", "Value")
  26. function itbl.parse(...)
  27. luci.http.redirect(
  28. luci.dispatcher.build_url("admin", "asterisk", "trunks")
  29. )
  30. end
  31. return form
  32. --
  33. -- SIP trunk config
  34. --
  35. elseif arg[1] then
  36. cbimap = Map("asterisk", "Edit SIP Trunk")
  37. peer = cbimap:section(NamedSection, arg[1])
  38. peer.hidden = {
  39. type = "peer",
  40. qualify = "yes",
  41. }
  42. back = peer:option(DummyValue, "_overview", "Back to trunk overview")
  43. back.value = ""
  44. back.titleref = luci.dispatcher.build_url("admin", "asterisk", "trunks")
  45. sipdomain = peer:option(Value, "host", "SIP Domain")
  46. sipport = peer:option(Value, "port", "SIP Port")
  47. function sipport.cfgvalue(...)
  48. return AbstractValue.cfgvalue(...) or "5060"
  49. end
  50. username = peer:option(Value, "username", "Authorization ID")
  51. password = peer:option(Value, "secret", "Authorization Password")
  52. password.password = true
  53. outboundproxy = peer:option(Value, "outboundproxy", "Outbound Proxy")
  54. outboundport = peer:option(Value, "outboundproxyport", "Outbound Proxy Port")
  55. register = peer:option(Flag, "register", "Register with peer")
  56. register.enabled = "yes"
  57. register.disabled = "no"
  58. regext = peer:option(Value, "registerextension", "Extension to register (optional)")
  59. regext:depends({register="1"})
  60. didval = peer:option(ListValue, "_did", "Number of assigned DID numbers")
  61. didval:value("", "(none)")
  62. for i=1,24 do didval:value(i) end
  63. dialplan = peer:option(ListValue, "context", "Dialplan Context")
  64. dialplan:value(arg[1] .. "_inbound", "(default)")
  65. cbimap.uci:foreach("asterisk", "dialplan",
  66. function(s) dialplan:value(s['.name']) end)
  67. return cbimap
  68. end