applications/luci-asterisk:
[project/luci.git] / applications / luci-asterisk / luasrc / model / cbi / asterisk / trunk_sip.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 ]]--
15
16 local ast = require("luci.asterisk")
17
18 --
19 -- Specific SIP trunk
20 --
21 if arg[1] then
22 cbimap = Map("asterisk", "Edit SIP Trunk")
23
24 peer = cbimap:section(NamedSection, arg[1])
25 peer.hidden = {
26 type = "peer"
27 }
28
29 back = peer:option(DummyValue, "_overview", "Back to trunk overview")
30 back.value = ""
31 back.titleref = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip")
32
33 sipdomain = peer:option(Value, "host", "SIP Domain")
34 sipport = peer:option(Value, "port", "SIP Port")
35 sipport.default = 5060
36
37 sipnat = peer:option(Flag, "nat", "NAT between this device and provider")
38 sipnat.enabled = "yes"
39 sipnat.disabled = "no"
40
41 username = peer:option(Value, "username", "Authorization ID")
42 password = peer:option(Value, "secret", "Authorization Password")
43 password.password = true
44
45 register = peer:option(ListValue, "register", "Register with peer")
46 register:value("yes", "on")
47 register:value("no", "off")
48
49 regext = peer:option(Value, "registerextension", "Extension to register (optional)")
50 regext:depends({register="yes"})
51
52 didval = peer:option(ListValue, "_did", "Number of assigned DID numbers")
53 for i=1,24 do didval:value(i) end
54
55 return cbimap
56
57 --
58 -- Trunk overview
59 --
60 else
61 cbimap = Map("asterisk", "asterisk", "")
62
63 local sip_peers = { }
64 cbimap.uci:foreach("asterisk", "sip",
65 function(s)
66 if s.type == "peer" then
67 s.name = s['.name']
68 s.info = ast.sip.peer(s.name)
69 sip_peers[s.name] = s
70 end
71 end)
72
73
74 sip_table = cbimap:section(Table, sip_peers, "SIP Trunks")
75 sip_table.template = "cbi/tblsection"
76 sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
77
78 name = sip_table:option(DummyValue, "name")
79 user = sip_table:option(DummyValue, "username")
80
81 host = sip_table:option(DummyValue, "host")
82 function host.cfgvalue(self, s)
83 if sip_peers[s].info.address then
84 return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
85 else
86 return "n/a"
87 end
88 end
89
90 context = sip_table:option(DummyValue, "context")
91 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
92
93 nat = sip_table:option(DummyValue, "nat")
94 function nat.cfgvalue(self, s)
95 return sip_peers[s].info.Nat or "none"
96 end
97
98 online = sip_table:option(DummyValue, "online")
99 function online.cfgvalue(self, s)
100 if sip_peers[s].info.online == nil then
101 return "n/a"
102 else
103 return sip_peers[s].info.online
104 and "yes" or "no (%s)" % sip_peers[s].info.Status:lower()
105 end
106 end
107
108 delay = sip_table:option(DummyValue, "delay")
109 function delay.cfgvalue(self, s)
110 if sip_peers[s].info.online then
111 return "%i ms" % sip_peers[s].info.delay
112 else
113 return "n/a"
114 end
115 end
116
117 return cbimap
118 end