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