applications/luci-asterisk: add the first few bits of reworked webif code
[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], "Foo")
25
26         name = peer:option(DummyValue, "username")
27
28         outproxy = peer:option(Value, "outboundproxy")
29         
30
31         return cbimap
32
33 --
34 -- Trunk overview
35 --
36 else
37         cbimap = Map("asterisk", "asterisk", "")
38
39         local sip_peers = { }
40         cbimap.uci:foreach("asterisk", "sip",
41                 function(s)
42                         if s.type == "peer" then
43                                 s.name = s['.name']
44                                 s.info = ast.sip.peer(s.name)
45                                 sip_peers[s.name] = s
46                         end
47                 end)
48
49
50         sip_table = cbimap:section(Table, sip_peers, "SIP Trunks")
51         sip_table.template = "cbi/tblsection"
52         sip_table.extedit  = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
53
54         name = sip_table:option(DummyValue, "name")
55         user = sip_table:option(DummyValue, "username")
56
57         host = sip_table:option(DummyValue, "host")
58         function host.cfgvalue(self, s)
59                 if sip_peers[s].info.address then
60                         return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
61                 else
62                         return "n/a"
63                 end
64         end
65
66         context = sip_table:option(DummyValue, "context")
67         context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
68
69         nat = sip_table:option(DummyValue, "nat")
70         function nat.cfgvalue(self, s)
71                 return sip_peers[s].info.Nat or "none"
72         end
73
74         online = sip_table:option(DummyValue, "online")
75         function online.cfgvalue(self, s)
76                 if sip_peers[s].info.online == nil then
77                         return "n/a"
78                 else
79                         return sip_peers[s].info.online and "yes" or "no"
80                 end
81         end
82
83         delay = sip_table:option(DummyValue, "delay")
84         function delay.cfgvalue(self, s)
85                 if sip_peers[s].info.online then
86                         return "%i ms" % sip_peers[s].info.delay
87                 else
88                         return "n/a"
89                 end
90         end
91
92         return cbimap
93 end