applications/luci-asterisk: add the first few bits of reworked webif code
[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 and "yes" or "no"
61 end
62 end
63
64 delay = sip_table:option(DummyValue, "delay")
65 function delay.cfgvalue(self, s)
66 if sip_peers[s].info.online then
67 return "%i ms" % sip_peers[s].info.delay
68 else
69 return "n/a"
70 end
71 end
72
73 return cbimap