luci-0.9: merge r5989
[project/luci.git] / applications / luci-ddns / luasrc / model / cbi / ddns / ddns.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 local is_mini = (luci.dispatcher.context.path[1] == "mini")
17
18 m = Map("ddns", translate("ddns"), translate("ddns_desc"))
19
20 s = m:section(TypedSection, "service", "")
21 s.addremove = true
22 s.anonymous = false
23
24 s:option(Flag, "enabled", translate("enable"))
25
26 svc = s:option(Value, "service_name", translate("service"))
27 svc.rmempty = true
28
29 local services = { }
30 local fd = io.open("/usr/lib/ddns/services", "r")
31 if fd then
32 local ln
33 repeat
34 ln = fd:read("*l")
35 local s = ln and ln:match('^%s*"([^"]+)"')
36 if s then services[#services+1] = s end
37 until not ln
38 fd:close()
39 end
40
41 local v
42 for _, v in luci.util.vspairs(services) do
43 svc:value(v)
44 end
45
46
47 s:option(Value, "domain", translate("hostname")).rmempty = true
48 s:option(Value, "username", translate("username")).rmempty = true
49 pw = s:option(Value, "password", translate("password"))
50 pw.rmempty = true
51 pw.password = true
52
53
54 if is_mini then
55 s.defaults.ip_source = "network"
56 s.defaults.ip_network = "wan"
57 else
58 require("luci.tools.webadmin")
59
60 src = s:option(ListValue, "ip_source")
61 src:value("network", translate("network"))
62 src:value("interface", translate("interface"))
63 src:value("web", "URL")
64
65 iface = s:option(ListValue, "ip_network", translate("network"))
66 iface:depends("ip_source", "network")
67 iface.rmempty = true
68 luci.tools.webadmin.cbi_add_networks(iface)
69
70 iface = s:option(ListValue, "ip_interface", translate("interface"))
71 iface:depends("ip_source", "interface")
72 iface.rmempty = true
73 for k, v in pairs(luci.sys.net.devices()) do
74 iface:value(v)
75 end
76
77 web = s:option(Value, "ip_url", "URL")
78 web:depends("ip_source", "web")
79 web.rmempty = true
80
81 s:option(Value, "update_url").optional = true
82 end
83
84
85 s:option(Value, "check_interval").default = 10
86 unit = s:option(ListValue, "check_unit")
87 unit.default = "minutes"
88 unit:value("minutes", "min")
89 unit:value("hours", "h")
90
91 s:option(Value, "force_interval").default = 72
92 unit = s:option(ListValue, "force_unit")
93 unit.default = "hours"
94 unit:value("minutes", "min")
95 unit:value("hours", "h")
96
97
98 return m