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