29286c1f7b76e092988b3059d2e24769a5af8b4d
[project/luci.git] / applications / luci-asterisk / luasrc / model / cbi / asterisk / phone_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 phone info
20 --
21 if arg[2] == "info" then
22         form = SimpleForm("asterisk", "SIP Phone 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 Phone %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", "phones")
47                 )
48         end
49
50         return form
51
52 --
53 -- SIP phone configuration
54 --
55 elseif arg[1] then
56         cbimap = Map("asterisk", "Edit SIP Client")
57
58         peer = cbimap:section(NamedSection, arg[1])
59         peer.hidden = {
60                 type        = "friend",
61                 qualify     = "yes",
62                 host        = "dynamic",
63                 nat         = "no",
64                 canreinvite = "no"
65         }
66
67         back = peer:option(DummyValue, "_overview", "Back to phone overview")
68         back.value = ""
69         back.titleref = luci.dispatcher.build_url("admin", "asterisk", "phones")
70
71         exten = peer:option(Value, "extension", "Extension Number")
72         cbimap.uci:foreach("asterisk", "dialplanexten",
73                 function(s)
74                         exten:value(
75                                 s.extension,
76                                 "%s (via %s/%s)" %{ s.extension, s.type:upper(), s.target }
77                         )
78                 end)
79
80         display = peer:option(Value, "callerid", "Display Name")
81
82         username  = peer:option(Value, "username", "Authorization ID")
83         password  = peer:option(Value, "secret", "Authorization Password")
84         password.password = true
85
86         active = peer:option(Flag, "disable", "Active")
87         active.enabled  = "yes"
88         active.disabled = "no"
89         function active.cfgvalue(...)
90                 return AbstractValue.cfgvalue(...) or "yes"
91         end
92
93         regtimeout = peer:option(Value, "registertimeout", "Registration Time Value")
94         function regtimeout.cfgvalue(...)
95                 return AbstractValue.cfgvalue(...) or "60"
96         end
97
98         sipport = peer:option(Value, "port", "SIP Port")
99         function sipport.cfgvalue(...)
100                 return AbstractValue.cfgvalue(...) or "5060"
101         end
102
103         linekey = peer:option(ListValue, "_linekey", "Linekey Mode (broken)")
104         linekey:value("", "Off")
105         linekey:value("trunk", "Trunk Appearance")
106         linekey:value("call", "Call Appearance")
107
108         dialplan = peer:option(ListValue, "context", "Dialplan Context")
109         cbimap.uci:foreach("asterisk", "dialplan",
110                 function(s) dialplan:value(s['.name']) end)
111
112         return cbimap
113 end