From 1bb4822dca6113f73e3bc89e2acf15935e6f8e92 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 3 Dec 2014 15:17:05 +0100 Subject: 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 --- .../luasrc/model/cbi/asterisk/dialplan_out.lua | 137 ++++++++++++++++++ .../luasrc/model/cbi/asterisk/dialplans.lua | 115 +++++++++++++++ .../luasrc/model/cbi/asterisk/dialzones.lua | 135 ++++++++++++++++++ .../luasrc/model/cbi/asterisk/meetme.lua | 49 +++++++ .../luasrc/model/cbi/asterisk/meetme_settings.lua | 28 ++++ .../luasrc/model/cbi/asterisk/phone_sip.lua | 157 +++++++++++++++++++++ .../luasrc/model/cbi/asterisk/phones.lua | 116 +++++++++++++++ .../luasrc/model/cbi/asterisk/trunk_sip.lua | 98 +++++++++++++ .../luasrc/model/cbi/asterisk/trunks.lua | 106 ++++++++++++++ .../luasrc/model/cbi/asterisk/voicemail.lua | 59 ++++++++ .../model/cbi/asterisk/voicemail_settings.lua | 62 ++++++++ 11 files changed, 1062 insertions(+) create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialplan_out.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialplans.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialzones.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/meetme.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/meetme_settings.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/phones.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunks.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/voicemail.lua create mode 100644 applications/luci-app-asterisk/luasrc/model/cbi/asterisk/voicemail_settings.lua (limited to 'applications/luci-app-asterisk/luasrc/model/cbi/asterisk') diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialplan_out.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialplan_out.lua new file mode 100644 index 000000000..3115e10d6 --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialplan_out.lua @@ -0,0 +1,137 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Jo-Philipp Wich + +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") + +local function find_outgoing_contexts(uci) + local c = { } + local h = { } + +-- uci:foreach("asterisk", "dialplan", +-- function(s) +-- if not h[s['.name']] then +-- c[#c+1] = { s['.name'], "Dialplan: %s" % s['.name'] } +-- h[s['.name']] = true +-- end +-- end) + + uci:foreach("asterisk", "dialzone", + function(s) + if not h[s['.name']] then + c[#c+1] = { s['.name'], "Dialzone: %s" % s['.name'] } + h[s['.name']] = true + end + end) + + return c +end + +local function find_incoming_contexts(uci) + local c = { } + local h = { } + + uci:foreach("asterisk", "sip", + function(s) + if s.context and not h[s.context] and + uci:get_bool("asterisk", s['.name'], "provider") + then + c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context } + h[s.context] = true + end + end) + + return c +end + +local function find_trunks(uci) + local t = { } + + uci:foreach("asterisk", "sip", + function(s) + if uci:get_bool("asterisk", s['.name'], "provider") then + t[#t+1] = { + "SIP/%s" % s['.name'], + "SIP: %s" % s['.name'] + } + end + end) + + uci:foreach("asterisk", "iax", + function(s) + t[#t+1] = { + "IAX/%s" % s['.name'], + "IAX: %s" % s.extension or s['.name'] + } + end) + + return t +end + +--[[ + +dialzone {name} - Outgoing zone. + uses - Outgoing line to use: TYPE/Name + match (list) - Number to match + countrycode - The effective country code of this dialzone + international (list) - International prefix to match + localzone - dialzone for local numbers + addprefix - Prexix required to dial out. + localprefix - Prefix for a local call + +]] + + +-- +-- SIP dialzone configuration +-- +if arg[1] then + cbimap = Map("asterisk", "Edit Dialplan Entry") + + entry = cbimap:section(NamedSection, arg[1]) + + back = entry:option(DummyValue, "_overview", "Back to dialplan overview") + back.value = "" + back.titleref = luci.dispatcher.build_url("admin", "asterisk", "dialplans") + + desc = entry:option(Value, "description", "Description") + function desc.cfgvalue(self, s, ...) + return Value.cfgvalue(self, s, ...) or s + end + + match = entry:option(DynamicList, "match", "Number matches") + + intl = entry:option(DynamicList, "international", "Intl. prefix matches (optional)") + + trunk = entry:option(MultiValue, "uses", "Used trunk") + for _, v in ipairs(find_trunks(cbimap.uci)) do + trunk:value(unpack(v)) + end + + aprefix = entry:option(Value, "addprefix", "Add prefix to dial out (optional)") + --ast.idd.cbifill(aprefix) + + ccode = entry:option(Value, "countrycode", "Effective countrycode (optional)") + ast.cc.cbifill(ccode) + + lzone = entry:option(ListValue, "localzone", "Dialzone for local numbers") + lzone:value("", "no special treatment of local numbers") + for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do + lzone:value(unpack(v)) + end + + lprefix = entry:option(Value, "localprefix", "Prefix for local calls (optional)") + + return cbimap +end diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialplans.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialplans.lua new file mode 100644 index 000000000..3a993da45 --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialplans.lua @@ -0,0 +1,115 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Jo-Philipp Wich + +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", "Registered 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") + +host = sip_table:option(DummyValue, "host", "Hostname") +function host.cfgvalue(self, s) + if sip_peers[s] and 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", "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 diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialzones.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialzones.lua new file mode 100644 index 000000000..4867911c5 --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/dialzones.lua @@ -0,0 +1,135 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Jo-Philipp Wich + +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: trunks.lua 4025 2009-01-11 23:37:21Z jow $ + +]]-- + +local ast = require("luci.asterisk") +local uci = require("luci.model.uci").cursor() + +--[[ + Dialzone overview table +]] + +if not arg[1] then + zonemap = Map("asterisk", "Dial Zones", [[ + Dial zones hold patterns of dialed numbers to match. + Each zone has one or more trunks assigned. If the first trunk is + congested, Asterisk will try to use the next available connection. + If all trunks fail, then the following zones in the parent dialplan + are tried. + ]]) + + local zones, znames = ast.dialzone.zones() + + zonetbl = zonemap:section(Table, zones, "Zone Overview") + zonetbl.sectionhead = "Zone" + zonetbl.addremove = true + zonetbl.anonymous = false + zonetbl.extedit = luci.dispatcher.build_url( + "admin", "asterisk", "dialplans", "zones", "%s" + ) + + function zonetbl.cfgsections(self) + return znames + end + + function zonetbl.parse(self) + for k, v in pairs(self.map:formvaluetable( + luci.cbi.REMOVE_PREFIX .. self.config + ) or {}) do + if k:sub(-2) == ".x" then k = k:sub(1, #k - 2) end + uci:delete("asterisk", k) + uci:save("asterisk") + self.data[k] = nil + for i = 1,#znames do + if znames[i] == k then + table.remove(znames, i) + break + end + end + end + + Table.parse(self) + end + + zonetbl:option(DummyValue, "description", "Description") + zonetbl:option(DummyValue, "addprefix") + + match = zonetbl:option(DummyValue, "matches") + function match.cfgvalue(self, s) + return table.concat(zones[s].matches, ", ") + end + + trunks = zonetbl:option(DummyValue, "trunk") + trunks.template = "asterisk/cbi/cell" + function trunks.cfgvalue(self, s) + return ast.tools.hyperlinks(zones[s].trunks) + end + + return zonemap + +--[[ + Zone edit form +]] + +else + zoneedit = Map("asterisk", "Edit Dialzone") + + entry = zoneedit:section(NamedSection, arg[1]) + entry.title = "Zone %q" % arg[1]; + + back = entry:option(DummyValue, "_overview", "Back to dialzone overview") + back.value = "" + back.titleref = luci.dispatcher.build_url( + "admin", "asterisk", "dialplans", "zones" + ) + + desc = entry:option(Value, "description", "Description") + function desc.cfgvalue(self, s, ...) + return Value.cfgvalue(self, s, ...) or s + end + + trunks = entry:option(MultiValue, "uses", "Used trunks") + trunks.widget = "checkbox" + uci:foreach("asterisk", "sip", + function(s) + if s.provider == "yes" then + trunks:value( + "SIP/%s" % s['.name'], + "SIP/%s (%s)" %{ s['.name'], s.host or 'n/a' } + ) + end + end) + + + match = entry:option(DynamicList, "match", "Number matches") + + intl = entry:option(DynamicList, "international", "Intl. prefix matches (optional)") + + aprefix = entry:option(Value, "addprefix", "Add prefix to dial out (optional)") + ccode = entry:option(Value, "countrycode", "Effective countrycode (optional)") + + lzone = entry:option(ListValue, "localzone", "Dialzone for local numbers") + lzone:value("", "no special treatment of local numbers") + for _, z in ipairs(ast.dialzone.zones()) do + lzone:value(z.name, "%q (%s)" %{ z.name, z.description }) + end + --for _, v in ipairs(find_outgoing_contexts(zoneedit.uci)) do + -- lzone:value(unpack(v)) + --end + + lprefix = entry:option(Value, "localprefix", "Prefix for local calls (optional)") + + return zoneedit + +end diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/meetme.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/meetme.lua new file mode 100644 index 000000000..b02a8f612 --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/meetme.lua @@ -0,0 +1,49 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2009 Jo-Philipp Wich + +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", "MeetMe - Rooms") + +meetme = cbimap:section(TypedSection, "meetme", "MeetMe Rooms") +meetme.addremove = true +meetme.anonymous = true +meetme.template = "cbi/tblsection" +meetme:option(Value, "_description", "Description", "Short room description") + +room = meetme:option(Value, "room", "Room Number", "Unique room identifier") + +function room.write(self, s, val) + if val and #val > 0 then + local old = self:cfgvalue(s) + self.map.uci:foreach("asterisk", "dialplanmeetme", + function(v) + if v.room == old then + self.map:set(v['.name'], "room", val) + end + end) + Value.write(self, s, val) + end +end + + +meetme:option(Value, "pin", "PIN", "PIN required to access") +meetme:option(Value, "adminpin", "Admin PIN", "PIN required for administration") + +function meetme.remove(self, s) + return ast.meetme.remove(self.map:get(s, "room"), self.map.uci) +end + + +return cbimap diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/meetme_settings.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/meetme_settings.lua new file mode 100644 index 000000000..511d7a71a --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/meetme_settings.lua @@ -0,0 +1,28 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2009 Jo-Philipp Wich + +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$ +]]-- + +cbimap = Map("asterisk", "MeetMe - Common Settings", + "Common settings for MeetMe phone conferences.") + +meetme = cbimap:section(TypedSection, "meetmegeneral", "General MeetMe Options") +meetme.addremove = false +meetme.anonymous = true + +audiobuffers = meetme:option(ListValue, "audiobuffers", + "Number of 20ms audio buffers to use for conferences") + +for i = 2, 32 do audiobuffers:value(i) end + + +return cbimap diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua new file mode 100644 index 000000000..49d3a0776 --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua @@ -0,0 +1,157 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Jo-Philipp Wich + +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") + +local function find_outgoing_contexts(uci) + local c = { } + local h = { } + + uci:foreach("asterisk", "dialplan", + function(s) + if not h[s['.name']] then + c[#c+1] = { s['.name'], "Dialplan: %s" % s['.name'] } + h[s['.name']] = true + end + end) + + return c +end + +local function find_incoming_contexts(uci) + local c = { } + local h = { } + + uci:foreach("asterisk", "sip", + function(s) + if s.context and not h[s.context] and + uci:get_bool("asterisk", s['.name'], "provider") + then + c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context } + h[s.context] = true + end + end) + + return c +end + + +-- +-- SIP phone info +-- +if arg[2] == "info" then + form = SimpleForm("asterisk", "SIP Phone Information") + form.reset = false + form.submit = "Back to overview" + + local info, keys = ast.sip.peer(arg[1]) + local data = { } + + for _, key in ipairs(keys) do + data[#data+1] = { + key = key, + val = type(info[key]) == "boolean" + and ( info[key] and "yes" or "no" ) + or ( info[key] == nil or #info[key] == 0 ) + and "(none)" + or tostring(info[key]) + } + end + + itbl = form:section(Table, data, "SIP Phone %q" % arg[1]) + itbl:option(DummyValue, "key", "Key") + itbl:option(DummyValue, "val", "Value") + + function itbl.parse(...) + luci.http.redirect( + luci.dispatcher.build_url("admin", "asterisk", "phones") + ) + end + + return form + +-- +-- SIP phone configuration +-- +elseif arg[1] then + cbimap = Map("asterisk", "Edit SIP Client") + + peer = cbimap:section(NamedSection, arg[1]) + peer.hidden = { + type = "friend", + qualify = "yes", + host = "dynamic", + nat = "no", + canreinvite = "no" + } + + back = peer:option(DummyValue, "_overview", "Back to phone overview") + back.value = "" + back.titleref = luci.dispatcher.build_url("admin", "asterisk", "phones") + + active = peer:option(Flag, "disable", "Account enabled") + active.enabled = "yes" + active.disabled = "no" + function active.cfgvalue(...) + return AbstractValue.cfgvalue(...) or "yes" + end + + exten = peer:option(Value, "extension", "Extension Number") + cbimap.uci:foreach("asterisk", "dialplanexten", + function(s) + exten:value( + s.extension, + "%s (via %s/%s)" %{ s.extension, s.type:upper(), s.target } + ) + end) + + display = peer:option(Value, "callerid", "Display Name") + + username = peer:option(Value, "username", "Authorization ID") + password = peer:option(Value, "secret", "Authorization Password") + password.password = true + + regtimeout = peer:option(Value, "registertimeout", "Registration Time Value") + function regtimeout.cfgvalue(...) + return AbstractValue.cfgvalue(...) or "60" + end + + sipport = peer:option(Value, "port", "SIP Port") + function sipport.cfgvalue(...) + return AbstractValue.cfgvalue(...) or "5060" + end + + linekey = peer:option(ListValue, "_linekey", "Linekey Mode (broken)") + linekey:value("", "Off") + linekey:value("trunk", "Trunk Appearance") + linekey:value("call", "Call Appearance") + + dialplan = peer:option(ListValue, "context", "Assign Dialplan") + dialplan.titleref = luci.dispatcher.build_url("admin", "asterisk", "dialplans") + for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do + dialplan:value(unpack(v)) + end + + incoming = peer:option(StaticList, "incoming", "Receive incoming calls from") + for _, v in ipairs(find_incoming_contexts(cbimap.uci)) do + incoming:value(unpack(v)) + end + + --function incoming.cfgvalue(...) + --error(table.concat(MultiValue.cfgvalue(...),".")) + --end + + return cbimap +end diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/phones.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/phones.lua new file mode 100644 index 000000000..7c8f03f00 --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/phones.lua @@ -0,0 +1,116 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Jo-Philipp Wich + +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", "Registered Phones") +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 Phones") +sip_table.template = "cbi/tblsection" +sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "phones", "sip", "%s") +sip_table.addremove = true + +function sip_table.filter(self, s) + return s and not cbimap.uci:get_bool("asterisk", s, "provider") +end + +function sip_table.create(self, section) + if TypedSection.create(self, section) then + created = section + cbimap.uci:tset("asterisk", section, { + type = "friend", + qualify = "yes", + provider = "no", + host = "dynamic", + nat = "no", + canreinvite = "no", + extension = section:match("^%d+$") and section or "", + username = section:match("^%d+$") and section or "" + }) + else + self.invalid_cts = true + end +end + +function sip_table.parse(self, ...) + TypedSection.parse(self, ...) + if created then + cbimap.uci:save("asterisk") + luci.http.redirect(luci.dispatcher.build_url( + "admin", "asterisk", "phones", "sip", created + )) + end +end + + +user = sip_table:option(DummyValue, "username", "Username") +function user.cfgvalue(self, s) + return sip_peers[s] and sip_peers[s].callerid or + AbstractValue.cfgvalue(self, s) +end + +host = sip_table:option(DummyValue, "host", "Hostname") +function host.cfgvalue(self, s) + if sip_peers[s] and 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", "Dialplan") +context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan") + +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", "phones", "sip", s, "info" + )) +end + +return cbimap diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua new file mode 100644 index 000000000..e2e73eefb --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua @@ -0,0 +1,98 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Jo-Philipp Wich + +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") + +-- +-- SIP trunk info +-- +if arg[2] == "info" then + form = SimpleForm("asterisk", "SIP Trunk Information") + form.reset = false + form.submit = "Back to overview" + + local info, keys = ast.sip.peer(arg[1]) + local data = { } + + for _, key in ipairs(keys) do + data[#data+1] = { + key = key, + val = type(info[key]) == "boolean" + and ( info[key] and "yes" or "no" ) + or ( info[key] == nil or #info[key] == 0 ) + and "(none)" + or tostring(info[key]) + } + end + + itbl = form:section(Table, data, "SIP Trunk %q" % arg[1]) + itbl:option(DummyValue, "key", "Key") + itbl:option(DummyValue, "val", "Value") + + function itbl.parse(...) + luci.http.redirect( + luci.dispatcher.build_url("admin", "asterisk", "trunks") + ) + end + + return form + +-- +-- SIP trunk config +-- +elseif arg[1] then + cbimap = Map("asterisk", "Edit SIP Trunk") + + peer = cbimap:section(NamedSection, arg[1]) + peer.hidden = { + type = "peer", + qualify = "yes", + } + + back = peer:option(DummyValue, "_overview", "Back to trunk overview") + back.value = "" + back.titleref = luci.dispatcher.build_url("admin", "asterisk", "trunks") + + sipdomain = peer:option(Value, "host", "SIP Domain") + sipport = peer:option(Value, "port", "SIP Port") + function sipport.cfgvalue(...) + return AbstractValue.cfgvalue(...) or "5060" + end + + username = peer:option(Value, "username", "Authorization ID") + password = peer:option(Value, "secret", "Authorization Password") + password.password = true + + outboundproxy = peer:option(Value, "outboundproxy", "Outbound Proxy") + outboundport = peer:option(Value, "outboundproxyport", "Outbound Proxy Port") + + register = peer:option(Flag, "register", "Register with peer") + register.enabled = "yes" + register.disabled = "no" + + regext = peer:option(Value, "registerextension", "Extension to register (optional)") + regext:depends({register="1"}) + + didval = peer:option(ListValue, "_did", "Number of assigned DID numbers") + didval:value("", "(none)") + for i=1,24 do didval:value(i) end + + dialplan = peer:option(ListValue, "context", "Dialplan Context") + dialplan:value(arg[1] .. "_inbound", "(default)") + cbimap.uci:foreach("asterisk", "dialplan", + function(s) dialplan:value(s['.name']) end) + + return cbimap +end 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 000000000..85527c297 --- /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 + +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 diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/voicemail.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/voicemail.lua new file mode 100644 index 000000000..5d0de756b --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/voicemail.lua @@ -0,0 +1,59 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2009 Jo-Philipp Wich + +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", "Voicemail - Mailboxes") + +voicemail = cbimap:section(TypedSection, "voicemail", "Voicemail Boxes") +voicemail.addremove = true +voicemail.anonymous = true +voicemail.template = "cbi/tblsection" + +context = voicemail:option(ListValue, "context", "Context") +context:value("default") + +number = voicemail:option(Value, "number", + "Mailbox Number", "Unique mailbox identifier") + +function number.write(self, s, val) + if val and #val > 0 then + local old = self:cfgvalue(s) + self.map.uci:foreach("asterisk", "dialplanvoice", + function(v) + if v.voicebox == old then + self.map:set(v['.name'], "voicebox", val) + end + end) + Value.write(self, s, val) + end +end + + +voicemail:option(Value, "name", "Ownername", "Human readable display name") +voicemail:option(Value, "password", "Password", "Access protection") +voicemail:option(Value, "email", "eMail", "Where to send voice messages") +voicemail:option(Value, "page", "Pager", "Pager number") + +zone = voicemail:option(ListValue, "zone", "Timezone", "Used time format") +zone.titleref = luci.dispatcher.build_url("admin/asterisk/voicemail/settings") +cbimap.uci:foreach("asterisk", "voicezone", + function(s) zone:value(s['.name']) end) + +function voicemail.remove(self, s) + return ast.voicemail.remove(self.map:get(s, "number"), self.map.uci) +end + + +return cbimap diff --git a/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/voicemail_settings.lua b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/voicemail_settings.lua new file mode 100644 index 000000000..cad2adb95 --- /dev/null +++ b/applications/luci-app-asterisk/luasrc/model/cbi/asterisk/voicemail_settings.lua @@ -0,0 +1,62 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2009 Jo-Philipp Wich + +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$ +]]-- + +require "luci.sys.zoneinfo" + + +cbimap = Map("asterisk", "Voicemail - Common Settings") + +voicegeneral = cbimap:section(TypedSection, "voicegeneral", + "General Voicemail Options", "Common settings for all mailboxes are " .. + "defined here. Most of them are optional. The storage format should " .. + "never be changed once set.") + +voicegeneral.anonymous = true +voicegeneral.addremove = false + +format = voicegeneral:option(MultiValue, "Used storage formats") +format.widget = "checkbox" +format:value("wav49") +format:value("gsm") +format:value("wav") + +voicegeneral:option(Flag, "sendvoicemail", "Enable sending of emails") +voicegeneral:option(Flag, "attach", "Attach voice messages to emails") +voicegeneral:option(Value, "serveremail", "Used email sender address") +voicegeneral:option(Value, "emaildateformat", "Date format used in emails").optional = true +voicegeneral:option(Value, "maxlogins", "Max. failed login attempts").optional = true +voicegeneral:option(Value, "maxmsg", "Max. allowed messages per mailbox").optional = true +voicegeneral:option(Value, "minmessage", "Min. number of seconds for voicemail").optional = true +voicegeneral:option(Value, "maxmessage", "Max. number of seconds for voicemail").optional = true +voicegeneral:option(Value, "maxsilence", "Seconds of silence until stop recording").optional = true +voicegeneral:option(Value, "maxgreet", "Max. number of seconds for greetings").optional = true +voicegeneral:option(Value, "skipms", "Milliseconds to skip for rew./ff.").optional = true +voicegeneral:option(Value, "silencethreshold", "Threshold to detect silence").optional = true + + +voicezone = cbimap:section(TypedSection, "voicezone", "Time Zones", + "Time zones define how dates and times are expressen when used in " .. + "an voice mails. Refer to the asterisk manual for placeholder values.") + +voicezone.addremove = true +voicezone.sectionhead = "Name" +voicezone.template = "cbi/tblsection" + +tz = voicezone:option(ListValue, "zone", "Location") +for _, z in ipairs(luci.sys.zoneinfo.TZ) do tz:value(z[1]) end + +voicezone:option(Value, "message", "Date Format") + + +return cbimap -- cgit v1.2.3