resources/icons: Use gifsicle to save a few bytes.
[project/luci.git] / applications / luci-app-ddns / luasrc / model / cbi / ddns / global.lua
1 -- Copyright 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local NX   = require "nixio"
5 local NXFS = require "nixio.fs"
6 local DISP = require "luci.dispatcher"
7 local SYS  = require "luci.sys"
8 local DDNS = require "luci.tools.ddns"          -- ddns multiused functions
9
10 -- cbi-map definition -- #######################################################
11 local m = Map("ddns")
12
13 -- first need to close <a> from cbi map template our <a> closed by template
14 m.title = [[</a><a href="]] .. DISP.build_url("admin", "services", "ddns") .. [[">]] 
15         .. translate("Dynamic DNS")
16
17 m.description = translate("Dynamic DNS allows that your router can be reached with " ..
18                         "a fixed hostname while having a dynamically changing IP address.")
19
20 m.redirect = DISP.build_url("admin", "services", "ddns")
21
22 function m.commit_handler(self)
23         if self.changed then    -- changes ?
24                 os.execute("/etc/init.d/ddns reload &") -- reload configuration
25         end
26 end
27
28 -- cbi-section definition -- ###################################################
29 local ns = m:section( NamedSection, "global", "ddns",
30         translate("Global Settings"),
31         translate("Configure here the details for all Dynamic DNS services including this LuCI application.") 
32         .. [[<br /><strong>]]
33         .. translate("It is NOT recommended for casual users to change settings on this page.")
34         .. [[</strong><br />]]
35         .. [[<a href="http://wiki.openwrt.org/doc/uci/ddns#version_2x1" target="_blank">]]
36         .. translate("For detailed information about parameter settings look here.")
37         .. [[</a>]]
38         )
39
40 -- section might not exist
41 function ns.cfgvalue(self, section)
42         if not self.map:get(section) then
43                 self.map:set(section, nil, self.sectiontype)
44         end
45         return self.map:get(section)
46 end
47
48 -- allow_local_ip  -- ##########################################################
49 local ali       = ns:option(Flag, "allow_local_ip")
50 ali.title       = translate("Allow non-public IP's")
51 ali.description = translate("Non-public and by default blocked IP's") .. ":"
52                 .. [[<br /><strong>IPv4: </strong>]]
53                 .. "0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16"
54                 .. [[<br /><strong>IPv6: </strong>]]
55                 .. "::/32, f000::/4"
56 ali.reempty     = true
57 ali.default     = "0"
58 function ali.parse(self, section)
59         DDNS.flag_parse(self, section)
60 end
61 function ali.validate(self, value)
62         if value == self.default then
63                 return "" -- default = empty
64         end
65         return value
66 end
67
68 -- date_format  -- #############################################################
69 local df        = ns:option(Value, "date_format")
70 df.title        = translate("Date format")
71 df.description  = [[<a href="http://www.cplusplus.com/reference/ctime/strftime/" target="_blank">]]
72                 .. translate("For supported codes look here") 
73                 .. [[</a>]]
74 df.template     = "ddns/global_value"
75 df.rmempty      = true
76 df.default      = "%F %R"
77 df.date_string  = ""
78 function df.cfgvalue(self, section)
79         local value = AbstractValue.cfgvalue(self, section) or self.default
80         local epoch = os.time()
81         self.date_string = DDNS.epoch2date(epoch, value)
82         return value
83 end
84 function df.validate(self, value)
85         if value == self.default then
86                 return "" -- default = empty
87         end
88         return value
89 end
90
91 -- run_dir  -- #################################################################
92 local rd        = ns:option(Value, "run_dir")
93 rd.title        = translate("Status directory")
94 rd.description  = translate("Directory contains PID and other status information for each running section")
95 rd.rmempty      = true
96 rd.default      = "/var/run/ddns"
97 function rd.validate(self, value)
98         if value == self.default then
99                 return "" -- default = empty
100         end
101         return value
102 end
103
104 -- log_dir  -- #################################################################
105 local ld        = ns:option(Value, "log_dir")
106 ld.title        = translate("Log directory")
107 ld.description  = translate("Directory contains Log files for each running section")
108 ld.rmempty      = true
109 ld.default      = "/var/log/ddns"
110 function ld.validate(self, value)
111         if value == self.default then
112                 return "" -- default = empty
113         end
114         return value
115 end
116
117 -- log_lines  -- ###############################################################
118 local ll        = ns:option(Value, "log_lines")
119 ll.title        = translate("Log length")
120 ll.description  = translate("Number of last lines stored in log files")
121 ll.rmempty      = true
122 ll.default      = "250"
123 function ll.validate(self, value)
124         local n = tonumber(value)
125         if not n or math.floor(n) ~= n or n < 1 then
126                 return nil, self.title .. ": " .. translate("minimum value '1'")
127         end
128         if value == self.default then
129                 return "" -- default = empty
130         end
131         return value
132 end
133
134 -- use_curl  -- ################################################################
135 if (SYS.call([[ grep -i "\+ssl" /usr/bin/wget >/dev/null 2>&1 ]]) == 0) 
136 and NXFS.access("/usr/bin/curl") then
137         local pc        = ns:option(Flag, "use_curl")
138         pc.title        = translate("Use cURL")
139         pc.description  = translate("If both cURL and GNU Wget are installed, Wget is used by default.")
140                 .. [[<br />]]
141                 .. translate("To use cURL activate this option.")
142         pc.orientation  = "horizontal"
143         pc.rmempty      = true
144         pc.default      = "0"
145         function pc.parse(self, section)
146                 DDNS.flag_parse(self, section)
147         end
148         function pc.validate(self, value)
149                 if value == self.default then
150                         return "" -- default = empty
151                 end
152                 return value
153         end
154 end
155
156 return m