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