applications/luci-ddns: make update url depend on custom service entry
[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
19 m = Map("ddns", translate("Dynamic DNS"), translate("Dynamic DNS allows that your router can be reached with a fixed hostname while having a dynamically changing IP-Address."))
20
21 s = m:section(TypedSection, "service", "")
22 s.addremove = true
23 s.anonymous = false
24
25 s:option(Flag, "enabled", translate("enable"))
26
27 svc = s:option(ListValue, "service_name", translate("Service"))
28 svc.rmempty = true
29
30 local services = { }
31 local fd = io.open("/usr/lib/ddns/services", "r")
32 if fd then
33         local ln
34         repeat
35                 ln = fd:read("*l")
36                 local s = ln and ln:match('^%s*"([^"]+)"')
37                 if s then services[#services+1] = s end
38         until not ln
39         fd:close()
40 end
41
42 local v
43 for _, v in luci.util.vspairs(services) do
44         svc:value(v)
45 end
46
47 svc:value("", translate("-- custom --"))
48
49
50 s:option(Value, "domain", translate("Hostname")).rmempty = true
51 s:option(Value, "username", translate("Username")).rmempty = true
52 pw = s:option(Value, "password", translate("Password"))
53 pw.rmempty = true
54 pw.password = true
55
56
57 if is_mini then
58         s.defaults.ip_source = "network"
59         s.defaults.ip_network = "wan"
60 else
61         require("luci.tools.webadmin")
62
63         src = s:option(ListValue, "ip_source", translate("Source of IP-Address"))
64         src:value("network", translate("Network"))
65         src:value("interface", translate("Interface"))
66         src:value("web", "URL")
67
68         iface = s:option(ListValue, "ip_network", translate("Network"))
69         iface:depends("ip_source", "network")
70         iface.rmempty = true
71         luci.tools.webadmin.cbi_add_networks(iface)
72
73         iface = s:option(ListValue, "ip_interface", translate("Interface"))
74         iface:depends("ip_source", "interface")
75         iface.rmempty = true
76         for k, v in pairs(luci.sys.net.devices()) do
77                 iface:value(v)
78         end
79
80         web = s:option(Value, "ip_url", "URL")
81         web:depends("ip_source", "web")
82         web.rmempty = true
83 end
84
85 url = s:option(Value, "update_url", translate("Custom Update-URL"))
86 url:depends("service_name", "")
87 url.rmempty = true
88
89 s:option(Value, "check_interval", translate("Check for changed IP every")).default = 10
90 unit = s:option(ListValue, "check_unit", translate("Check-Time unit"))
91 unit.default = "minutes"
92 unit:value("minutes", "min")
93 unit:value("hours", "h")
94
95 s:option(Value, "force_interval", translate("Force update every")).default = 72
96 unit = s:option(ListValue, "force_unit", translate("Force-Time unit"))
97 unit.default = "hours"
98 unit:value("minutes", "min")
99 unit:value("hours", "h")
100
101
102 return m