1 -- Copyright 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
2 -- Licensed to the public under the Apache License 2.0.
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
10 -- Bootstrap theme needs 2 or 3 additional linefeeds for tab description for better optic
11 local LFLF = (DDNS.get_theme() == "Bootstrap") and [[<br /><br />]] or [[]]
13 -- cbi-map definition -- #######################################################
16 -- first need to close <a> from cbi map template our <a> closed by template
17 m.title = [[</a><a href="]] .. DISP.build_url("admin", "services", "ddns") .. [[">]]
18 .. translate("Dynamic DNS")
20 m.description = translate("Dynamic DNS allows that your router can be reached with " ..
21 "a fixed hostname while having a dynamically changing IP address.")
23 m.redirect = DISP.build_url("admin", "services", "ddns")
25 function m.commit_handler(self)
26 if self.changed then -- changes ?
27 os.execute("/etc/init.d/ddns reload &") -- reload configuration
31 -- cbi-section definition -- ###################################################
32 local ns = m:section( NamedSection, "global", "ddns",
33 translate("Global Settings"),
34 translate("Configure here the details for all Dynamic DNS services including this LuCI application.")
36 .. translate("It is NOT recommended for casual users to change settings on this page.")
37 .. [[</strong><br />]]
38 .. [[<a href="http://wiki.openwrt.org/doc/uci/ddns#version_2x1" target="_blank">]]
39 .. translate("For detailed information about parameter settings look here.")
42 -- section might not exist
43 function ns.cfgvalue(self, section)
44 if not self.map:get(section) then
45 self.map:set(section, nil, self.sectiontype)
47 return self.map:get(section)
50 -- allow_local_ip -- ##########################################################
51 local ali = ns:option(Flag, "allow_local_ip")
52 ali.title = translate("Allow non-public IP's")
53 ali.description = translate("Non-public and by default blocked IP's") .. ":"
54 .. [[<br /><strong>IPv4: </strong>]]
55 .. "0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16"
56 .. [[<br /><strong>IPv6: </strong>]]
60 function ali.parse(self, section)
61 DDNS.flag_parse(self, section)
63 function ali.validate(self, value)
64 if value == self.default then
65 return "" -- default = empty
70 -- date_format -- #############################################################
71 local df = ns:option(Value, "date_format")
72 df.title = translate("Date format")
73 df.description = [[<a href="http://www.cplusplus.com/reference/ctime/strftime/" target="_blank">]]
74 .. translate("For supported codes look here")
76 df.template = "ddns/global_value"
80 function df.cfgvalue(self, section)
81 local value = AbstractValue.cfgvalue(self, section) or self.default
82 local epoch = os.time()
83 self.date_string = DDNS.epoch2date(epoch, value)
86 function df.validate(self, value)
87 if value == self.default then
88 return "" -- default = empty
93 -- run_dir -- #################################################################
94 local rd = ns:option(Value, "run_dir")
95 rd.title = translate("Status directory")
96 rd.description = translate("Directory contains PID and other status information for each running section")
98 rd.default = "/var/run/ddns"
99 function rd.validate(self, value)
100 if value == self.default then
101 return "" -- default = empty
106 -- log_dir -- #################################################################
107 local ld = ns:option(Value, "log_dir")
108 ld.title = translate("Log directory")
109 ld.description = translate("Directory contains Log files for each running section")
111 ld.default = "/var/log/ddns"
112 function ld.validate(self, value)
113 if value == self.default then
114 return "" -- default = empty
119 -- log_lines -- ###############################################################
120 local ll = ns:option(Value, "log_lines")
121 ll.title = translate("Log length")
122 ll.description = translate("Number of last lines stored in log files")
125 ll.datatype = "and(uinteger,min(1))"
126 function ll.validate(self, value)
127 local n = tonumber(value)
128 if not n or math.floor(n) ~= n or n < 1 then
129 return nil, self.title .. ": " .. translate("minimum value '1'")
131 if value == self.default then
132 return "" -- default = empty
137 -- use_curl -- ################################################################
138 if (SYS.call([[ grep -i "\+ssl" /usr/bin/wget >/dev/null 2>&1 ]]) == 0)
139 and NXFS.access("/usr/bin/curl") then
140 local pc = ns:option(Flag, "use_curl")
141 pc.title = translate("Use cURL")
142 pc.description = translate("If both cURL and GNU Wget are installed, Wget is used by default.")
144 .. translate("To use cURL activate this option.")
145 pc.orientation = "horizontal"
148 function pc.parse(self, section)
149 DDNS.flag_parse(self, section)
151 function pc.validate(self, value)
152 if value == self.default then
153 return "" -- default = empty