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