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