summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunks.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2014-12-03 15:17:05 +0100
committerJo-Philipp Wich <jow@openwrt.org>2015-01-08 16:26:20 +0100
commit1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch)
tree35e16f100466e4e00657199b38bb3d87d52bf73f /applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunks.lua
parent9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff)
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names * Make each LuCI module its own standalone package * Deploy a shared luci.mk which is used by each module Makefile Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunks.lua')
-rw-r--r--applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunks.lua106
1 files changed, 106 insertions, 0 deletions
diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunks.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunks.lua
new file mode 100644
index 0000000000..85527c297c
--- /dev/null
+++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunks.lua
@@ -0,0 +1,106 @@
+--[[
+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", "Trunks")
+cbimap.pageaction = false
+
+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(TypedSection, "sip", "SIP Trunks")
+sip_table.template = "cbi/tblsection"
+sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
+sip_table.addremove = true
+sip_table.sectionhead = "Extension"
+
+function sip_table.filter(self, s)
+ return s and (
+ cbimap.uci:get("asterisk", s, "type") == nil or
+ cbimap.uci:get_bool("asterisk", s, "provider")
+ )
+end
+
+function sip_table.create(self, section)
+ if TypedSection.create(self, section) then
+ created = section
+ else
+ self.invalid_cts = true
+ end
+end
+
+function sip_table.parse(self, ...)
+ TypedSection.parse(self, ...)
+ if created then
+ cbimap.uci:tset("asterisk", created, {
+ type = "friend",
+ qualify = "yes",
+ provider = "yes"
+ })
+
+ cbimap.uci:save("asterisk")
+ luci.http.redirect(luci.dispatcher.build_url(
+ "admin", "asterisk", "trunks", "sip", created
+ ))
+ end
+end
+
+
+user = sip_table:option(DummyValue, "username", "Username")
+
+context = sip_table:option(DummyValue, "context", "Dialplan")
+context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
+function context.cfgvalue(...)
+ return AbstractValue.cfgvalue(...) or "(default)"
+end
+
+online = sip_table:option(DummyValue, "online", "Registered")
+function online.cfgvalue(self, s)
+ if sip_peers[s] and sip_peers[s].info.online == nil then
+ return "n/a"
+ else
+ return sip_peers[s] and sip_peers[s].info.online
+ and "yes" or "no (%s)" %{
+ sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
+ }
+ end
+end
+
+delay = sip_table:option(DummyValue, "delay", "Delay")
+function delay.cfgvalue(self, s)
+ if sip_peers[s] and sip_peers[s].info.online then
+ return "%i ms" % sip_peers[s].info.delay
+ else
+ return "n/a"
+ end
+end
+
+info = sip_table:option(Button, "_info", "Info")
+function info.write(self, s)
+ luci.http.redirect(luci.dispatcher.build_url(
+ "admin", "asterisk", "trunks", "sip", s, "info"
+ ))
+end
+
+return cbimap