applications/luci-transmission: fix link to transmission gui if uhttpd runs on a...
[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 = false
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 function svc.cfgvalue(...)
51 local v = Value.cfgvalue(...)
52 if not v or #v == 0 then
53 return "-"
54 else
55 return v
56 end
57 end
58
59 function svc.write(self, section, value)
60 if value == "-" then
61 m.uci:delete("ddns", section, self.option)
62 else
63 Value.write(self, section, value)
64 end
65 end
66
67 svc:value("-", "-- "..translate("custom").." --")
68
69 url = s:option(Value, "update_url", translate("Custom update-URL"))
70 url:depends("service_name", "-")
71 url.rmempty = true
72
73 s:option(Value, "domain", translate("Hostname")).rmempty = true
74 s:option(Value, "username", translate("Username")).rmempty = true
75 pw = s:option(Value, "password", translate("Password"))
76 pw.rmempty = true
77 pw.password = true
78
79
80 if is_mini then
81 s.defaults.ip_source = "network"
82 s.defaults.ip_network = "wan"
83 else
84 require("luci.tools.webadmin")
85
86 src = s:option(ListValue, "ip_source",
87 translate("Source of IP address"))
88 src:value("network", translate("network"))
89 src:value("interface", translate("interface"))
90 src:value("web", translate("URL"))
91
92 iface = s:option(ListValue, "ip_network", translate("Network"))
93 iface:depends("ip_source", "network")
94 iface.rmempty = true
95 luci.tools.webadmin.cbi_add_networks(iface)
96
97 iface = s:option(ListValue, "ip_interface", translate("Interface"))
98 iface:depends("ip_source", "interface")
99 iface.rmempty = true
100 for k, v in pairs(luci.sys.net.devices()) do
101 iface:value(v)
102 end
103
104 web = s:option(Value, "ip_url", translate("URL"))
105 web:depends("ip_source", "web")
106 web.rmempty = true
107 end
108
109
110 s:option(Value, "check_interval",
111 translate("Check for changed IP every")).default = 10
112 unit = s:option(ListValue, "check_unit", translate("Check-time unit"))
113 unit.default = "minutes"
114 unit:value("minutes", translate("min"))
115 unit:value("hours", translate("h"))
116
117 s:option(Value, "force_interval", translate("Force update every")).default = 72
118 unit = s:option(ListValue, "force_unit", translate("Force-time unit"))
119 unit.default = "hours"
120 unit:value("minutes", translate("min"))
121 unit:value("hours", translate("h"))
122
123
124 return m