diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-01-11 03:05:01 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-01-11 03:05:01 +0000 |
commit | 1b989e556af2e018744dd9f875a01a0e5ea27ded (patch) | |
tree | c83a0595ed723c5b6e616f3178e4b604e29a983a /applications/luci-asterisk/luasrc | |
parent | d17e770dc561eee09a9c7c0b741b1a8993bd4c11 (diff) |
applications/luci-asterisk: add the first few bits of reworked webif code
Diffstat (limited to 'applications/luci-asterisk/luasrc')
3 files changed, 172 insertions, 0 deletions
diff --git a/applications/luci-asterisk/luasrc/controller/asterisk.lua b/applications/luci-asterisk/luasrc/controller/asterisk.lua index 541c67ef3e..8200ce2e5c 100644 --- a/applications/luci-asterisk/luasrc/controller/asterisk.lua +++ b/applications/luci-asterisk/luasrc/controller/asterisk.lua @@ -39,4 +39,10 @@ function index() entry({"admin", "services", "asterisk", "mod", "res", "feature"}, cbi("asterisk-mod-res-feature"), "Feature Module Configuration", 9 ) + + entry({"admin", "asterisk"}, cbi("asterisk/main"), "Asterisk", 99).i18n = "asterisk" + entry({"admin", "asterisk", "trunks"}, cbi("asterisk/trunks"), "Trunks", 1) + entry({"admin", "asterisk", "trunks", "sip"}, cbi("asterisk/trunk_sip"), "SIP", 1).leaf = true + + end diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua new file mode 100644 index 0000000000..3d7e6dc0f0 --- /dev/null +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua @@ -0,0 +1,93 @@ +--[[ +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], "Foo") + + name = peer:option(DummyValue, "username") + + outproxy = peer:option(Value, "outboundproxy") + + + 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 diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunks.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunks.lua new file mode 100644 index 0000000000..b9dd1dfd8d --- /dev/null +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunks.lua @@ -0,0 +1,73 @@ +--[[ +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") + +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 |