Merge pull request #278 from nmav/ocserv
[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         function sipport.cfgvalue(...)
71                 return AbstractValue.cfgvalue(...) or "5060"
72         end
73
74         username  = peer:option(Value, "username", "Authorization ID")
75         password  = peer:option(Value, "secret", "Authorization Password")
76         password.password = true
77
78         outboundproxy = peer:option(Value, "outboundproxy", "Outbound Proxy")
79         outboundport  = peer:option(Value, "outboundproxyport", "Outbound Proxy Port")
80
81         register = peer:option(Flag, "register", "Register with peer")
82         register.enabled  = "yes"
83         register.disabled = "no"
84
85         regext = peer:option(Value, "registerextension", "Extension to register (optional)")
86         regext:depends({register="1"})
87
88         didval = peer:option(ListValue, "_did", "Number of assigned DID numbers")
89         didval:value("", "(none)")
90         for i=1,24 do didval:value(i) end
91
92         dialplan = peer:option(ListValue, "context", "Dialplan Context")
93         dialplan:value(arg[1] .. "_inbound", "(default)")
94         cbimap.uci:foreach("asterisk", "dialplan",
95                 function(s) dialplan:value(s['.name']) end)
96
97         return cbimap
98 end