applications/luci-asterisk:
[project/luci.git] / applications / luci-asterisk / luasrc / model / cbi / asterisk / trunks.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 cbimap = Map("asterisk", "asterisk", "")
19
20 local sip_peers = { }
21 cbimap.uci:foreach("asterisk", "sip",
22         function(s)
23                 if s.type == "peer" then
24                         s.name = s['.name']
25                         s.info = ast.sip.peer(s.name)
26                         sip_peers[s.name] = s
27                 end
28         end)
29
30
31 sip_table = cbimap:section(Table, sip_peers, "SIP Trunks")
32 sip_table.template = "cbi/tblsection"
33 sip_table.extedit  = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
34
35 name = sip_table:option(DummyValue, "name")
36 user = sip_table:option(DummyValue, "username")
37
38 host = sip_table:option(DummyValue, "host")
39 function host.cfgvalue(self, s)
40         if sip_peers[s].info.address then
41                 return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
42         else
43                 return "n/a"
44         end
45 end
46
47 context = sip_table:option(DummyValue, "context")
48 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
49
50 nat = sip_table:option(DummyValue, "nat")
51 function nat.cfgvalue(self, s)
52         return sip_peers[s].info.Nat or "none"
53 end
54
55 online = sip_table:option(DummyValue, "online")
56 function online.cfgvalue(self, s)
57         if sip_peers[s].info.online == nil then
58                 return "n/a"
59         else
60                 return sip_peers[s].info.online
61                         and "yes" or "no (%s)" % sip_peers[s].info.Status:lower()
62         end
63 end
64
65 delay = sip_table:option(DummyValue, "delay")
66 function delay.cfgvalue(self, s)
67         if sip_peers[s].info.online then
68                 return "%i ms" % sip_peers[s].info.delay
69         else
70                 return "n/a"
71         end
72 end
73
74 return cbimap