e016751936b16ab0e2d1b411a5b9780686d4ffc1
[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 url = s:option(Value, "update_url", translate("Custom update-URL"))
50 url:depends("service_name", "")
51 url.rmempty = true
52
53 s:option(Value, "domain", translate("Hostname")).rmempty = true
54 s:option(Value, "username", translate("Username")).rmempty = true
55 pw = s:option(Value, "password", translate("Password"))
56 pw.rmempty = true
57 pw.password = true
58
59
60 if is_mini then
61         s.defaults.ip_source = "network"
62         s.defaults.ip_network = "wan"
63 else
64         require("luci.tools.webadmin")
65
66         src = s:option(ListValue, "ip_source", translate("Source of IP-Address"))
67         src:value("network", translate("Network"))
68         src:value("interface", translate("Interface"))
69         src:value("web", "URL")
70
71         iface = s:option(ListValue, "ip_network", translate("Network"))
72         iface:depends("ip_source", "network")
73         iface.rmempty = true
74         luci.tools.webadmin.cbi_add_networks(iface)
75
76         iface = s:option(ListValue, "ip_interface", translate("Interface"))
77         iface:depends("ip_source", "interface")
78         iface.rmempty = true
79         for k, v in pairs(luci.sys.net.devices()) do
80                 iface:value(v)
81         end
82
83         web = s:option(Value, "ip_url", "URL")
84         web:depends("ip_source", "web")
85         web.rmempty = true
86 end
87
88 s:option(Value, "check_interval", translate("Check for changed IP every")).default = 10
89 unit = s:option(ListValue, "check_unit", translate("Check-Time unit"))
90 unit.default = "minutes"
91 unit:value("minutes", "min")
92 unit:value("hours", "h")
93
94 s:option(Value, "force_interval", translate("Force update every")).default = 72
95 unit = s:option(ListValue, "force_unit", translate("Force-Time unit"))
96 unit.default = "hours"
97 unit:value("minutes", "min")
98 unit:value("hours", "h")
99
100
101 return m