900ff516a48cdee3c4f6fac246ad845b369d27c0
[project/luci.git] / applications / luci-asterisk / luasrc / model / cbi / asterisk / trunk_sip.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 ]]--
15
16 local ast = require("luci.asterisk")
17
18 --
19 -- SIP trunk info
20 --
21 if arg[2] == "info" then
22         form = SimpleForm("asterisk", "SIP Trunk Information")
23         form.reset  = false
24         form.submit = "Back to overview"
25
26         local info, keys = ast.sip.peer(arg[1])
27         local data = { }
28
29         for _, key in ipairs(keys) do
30                 data[#data+1] = {
31                         key = key,
32                         val = type(info[key]) == "boolean"
33                                 and ( info[key] and "yes" or "no" )
34                                 or  ( info[key] == nil or #info[key] == 0 )
35                                         and "(none)"
36                                         or  tostring(info[key])
37                 }
38         end
39
40         itbl = form:section(Table, data, "SIP Trunk %q" % arg[1])
41         itbl:option(DummyValue, "key", "Key")
42         itbl:option(DummyValue, "val", "Value")
43
44         function itbl.parse(...)
45                 luci.http.redirect(
46                         luci.dispatcher.build_url("admin", "asterisk", "trunks")
47                 )
48         end
49
50         return form
51
52 --
53 -- SIP trunk config
54 --
55 elseif arg[1] then
56         cbimap = Map("asterisk", "Edit SIP Trunk")
57
58         peer = cbimap:section(NamedSection, arg[1])
59         peer.hidden = {
60                 type    = "peer",
61                 qualify = "yes",
62         }
63
64         back = peer:option(DummyValue, "_overview", "Back to trunk overview")
65         back.value = ""
66         back.titleref = luci.dispatcher.build_url("admin", "asterisk", "trunks")
67
68         sipdomain = peer:option(Value, "host", "SIP Domain")
69         sipport   = peer:option(Value, "port", "SIP Port")
70         sipport.default = 5060
71
72         sipnat    = peer:option(Flag, "nat", "NAT between this device and provider")
73         sipnat.enabled  = "yes"
74         sipnat.disabled = "no"
75
76         username  = peer:option(Value, "username", "Authorization ID")
77         password  = peer:option(Value, "secret", "Authorization Password")
78         password.password = true
79
80         outboundproxy = peer:option(Value, "outboundproxy", "Outbound Proxy")
81         outboundport  = peer:option(Value, "outboundproxyport", "Outbound Proxy Port")
82
83         register = peer:option(Flag, "register", "Register with peer")
84         register.enabled  = "yes"
85         register.disabled = "no"
86
87         regext = peer:option(Value, "registerextension", "Extension to register (optional)")
88         regext:depends({register="yes"})
89
90         didval = peer:option(ListValue, "_did", "Number of assigned DID numbers")
91         didval:value("", "(none)")
92         for i=1,24 do didval:value(i) end
93
94         dialplan = peer:option(ListValue, "context", "Dialplan Context")
95         dialplan:value("", "(default)")
96         cbimap.uci:foreach("asterisk", "dialplan",
97                 function(s) dialplan:value(s['.name']) end)
98
99         return cbimap
100 end