ca29471384c5e2866f3b4aeb66b9909122f54cea
[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 username = peer:option(Value, "username", "Authorization ID")
38 password = peer:option(Value, "secret", "Authorization Password")
39 password.password = true
40
41 register = peer:option(ListValue, "register", "Register with peer")
42 register:value("yes", "on")
43 register:value("no", "off")
44
45 regext = peer:option(Value, "registerextension", "Extension to register (optional)")
46 regext:depends({register="yes"})
47
48 didval = peer:option(ListValue, "_did", "Number of assigned DID numbers")
49 for i=1,24 do didval:value(i) end
50
51 return cbimap
52
53 --
54 -- Trunk overview
55 --
56 else
57 cbimap = Map("asterisk", "asterisk", "")
58
59 local sip_peers = { }
60 cbimap.uci:foreach("asterisk", "sip",
61 function(s)
62 if s.type == "peer" then
63 s.name = s['.name']
64 s.info = ast.sip.peer(s.name)
65 sip_peers[s.name] = s
66 end
67 end)
68
69
70 sip_table = cbimap:section(Table, sip_peers, "SIP Trunks")
71 sip_table.template = "cbi/tblsection"
72 sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
73
74 name = sip_table:option(DummyValue, "name")
75 user = sip_table:option(DummyValue, "username")
76
77 host = sip_table:option(DummyValue, "host")
78 function host.cfgvalue(self, s)
79 if sip_peers[s].info.address then
80 return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
81 else
82 return "n/a"
83 end
84 end
85
86 context = sip_table:option(DummyValue, "context")
87 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
88
89 nat = sip_table:option(DummyValue, "nat")
90 function nat.cfgvalue(self, s)
91 return sip_peers[s].info.Nat or "none"
92 end
93
94 online = sip_table:option(DummyValue, "online")
95 function online.cfgvalue(self, s)
96 if sip_peers[s].info.online == nil then
97 return "n/a"
98 else
99 return sip_peers[s].info.online and "yes" or "no"
100 end
101 end
102
103 delay = sip_table:option(DummyValue, "delay")
104 function delay.cfgvalue(self, s)
105 if sip_peers[s].info.online then
106 return "%i ms" % sip_peers[s].info.delay
107 else
108 return "n/a"
109 end
110 end
111
112 return cbimap
113 end