summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua
blob: 900ff516a48cdee3c4f6fac246ad845b369d27c0 (plain)
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
--[[
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")

--
-- 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")
	sipport.default = 5060

	sipnat    = peer:option(Flag, "nat", "NAT between this device and provider")
	sipnat.enabled  = "yes"
	sipnat.disabled = "no"

	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="yes"})

	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("", "(default)")
	cbimap.uci:foreach("asterisk", "dialplan",
		function(s) dialplan:value(s['.name']) end)

	return cbimap
end